Skip to content

Commit f93f6d5

Browse files
mannycarrera4manuel.carreraNicholasBoll
authored
docs: Add info to create compound component regarding createComponent (Workday#3057)
Add docs around `createContainer` vs `createComponent` in the `create compound component` section in our docs. [category:Documentation] Co-authored-by: manuel.carrera <[email protected]> Co-authored-by: @NicholasBoll <[email protected]>
1 parent 2dcaa4e commit f93f6d5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

modules/docs/mdx/CREATING_COMPOUND_COMPONENTS.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,43 @@ document to learn about what a compound component is.
99
This document will go through building a simplified Disclosure component to help solidify the
1010
concepts. We will cover:
1111

12+
- [Non Coordinated Components](#non-coordinated-components)
1213
- [Models](#models)
1314
- [Container Components](#disclosure-component)
1415
- [Sub-components](#disclosuretarget-component)
1516
- [Model Composition](#model-composition)
1617
- [Behavior hooks](#behavior-hooks)
1718

19+
## Non Coordinated Components
20+
21+
In most cases you'll create compound components that have a model and share information across subcomponents. However, in the case where information doesn't need to be shared, you can create a non
22+
coordinated component. These components often represent some styled element with no associated role
23+
or behavior and don't rely on state and events such as a `Card`, `Flex` or `Button` components. Use
24+
`createComponent` factory function in these scenarios.
25+
26+
### `createComponent`
27+
28+
Use `createComponent` when you want to create a rendered element with _no behavior_. This is useful
29+
for elements that you want to use for styling purposes like container elements, or subcomponents
30+
that are simple rendered elements. This utility function will wrap your component in a
31+
`React.ForwardRef` and allow you to add subcomponents as well.
32+
33+
```tsx
34+
export const Card = createComponent('div')({
35+
displayName: 'Card',
36+
subComponents: {
37+
Heading: CardHeading, // this is also using createComponent
38+
},
39+
Component: ({children, ...elemProps}: CardProps, ref, Element) => {
40+
return (
41+
<Box as={Element} {...elemProps} ref={ref}>
42+
{children}
43+
</Box>
44+
);
45+
},
46+
});
47+
```
48+
1849
## Models
1950

2051
A model is composed of state and events. The shape of the model used by components looks like this:

0 commit comments

Comments
 (0)