CM2: Composition #1028
Closed
matheusps
started this conversation in
Technical RFCs
Replies: 1 comment 1 reply
-
In your opinion what kind of use case do you imagine people using/needing this behaviour? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Shoreline composition
Composition is often useful for easily extending behavior. Shoreline relies on the children's property for this task. Composable components accept the
asChild
boolean property. When true, the component will not render its default DOM element, cloning the props to the first child instead. The recipe is:For example, the
Collapsible
component has a composableCollapsibleTrigger
:Caveats
Not all components are composable
The composition will not be present in every component of Shoreline. This decision was made to keep the simplicity of the components itself. When available, it will be documented.
Custom components must be extendable
To be cloned and extended, custom components must be extendable. The two requirements for this are:
const Component = (props) => (<button {...props} />)
References
This API takes inspiration from:
Beta Was this translation helpful? Give feedback.
All reactions