Coding task · JavaScript and React course · Module 15: Patterns and Architecture
Practice: Composition Pattern
A container does not know in advance what it will get inside: everything the parent writes between the tags of the component lands in the children prop. When one children is not enough, the other places are ordinary props holding JSX elements, called slots, and you display them just like children: in curly braces. You read the colour from the object by the variant name in square brackets, for example VARIANT_COLORS['danger'] gives '#f44336'.
Task
Finish two components built with composition. SpaceCard is a container (containment). ___BLANK1___: the border colour is the value from the VARIANT_COLORS object for the variant prop (info, warning or danger). ___BLANK2___: the card body shows everything the parent writes between <SpaceCard> and </SpaceCard>. SpaceLayout has three slots: ___BLANK3___ shows the element from the header prop in <header>, ___BLANK4___ shows the element from the sidebar prop in <aside>, and the children go into <main>.