Collapsible
A Collapsible component is a container that allows toggling the display of its content.
Usageβ
import { Collapsible, useCollapsibleState } from '@vtex/admin-ui'
function Example() {
const state = useCollapsibleState()
return (s
<Collapsible state={state} csx={{ width: 500 }}>
<CollapsibleHeader label="Build for Community" />
<CollapsibleContent>
Itβs all about being ready to grow and reach new levels. Have a solid
foundation, modular thinking and flexible essence.
</CollapsibleContent>
</Collapsible>
)
}
Behaviorβ
When using Collapsible you should always use its composites: CollapsibleHeader and CollapsibleContent
Stateβ
For convenience, we provide a hook that already implements the state logic for you. It can be very handy if you have a group of collapsible and want to handle the states of each one. You should pass the hook return to the state property.
Variationβ
Actions Panelβ
You can render a set of actions on the right side of the collapsible's header. Just pass the buttons to the CollapsibleHeader children.
Initially Visibleβ
You can set the CollapsibleContent to be initially visible. Just define the property visible to be true, in the useCollapsibleState hook.
Nestedβ
It is possible to render a Collapsible inside another, just pass the Collapsible as a child of CollapsibleContent. Note that each nested collapsible has different padding than the one at the root, this is a design requirement, each internal collapsible must have a 16px padding, while the one in the root has a 24px padding.
Compositesβ
The Collapsible component uses two composites, CollapsibleHeader and CollapsibleContent.
Headerβ
As the title says, it represents the header of the collapsible. It renders a <header> and is always visible.
Disclosure Buttonβ
It represents the button that controls the content visibility and is always located on the left side of the header. Collapsible's label property defines the disclosure button label.
Actions Panelβ
It represents a set of buttons and is always located on the right side of the header. You should pass this set of buttons to the CollapsibleHeader children, to this panel to be rendered.
Contentβ
As the name already says, it represents the content of the collapsible. It renders a <section> and can be hidden or visible.
Propsβ
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| state | State | Component state, useCollapsibleState's return | β | - |
| csx | StyleObject | Custom styles | π« | {} |
| disabled | boolean | Same as the HTML attribute | π« | false |
| children | ReactNode | Collapsible children | π« | - |
CollapsibleHeader Propsβ
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| csx | StyleObject | Custom styles | π« | {} |
| label | ReactNode | Toggle button label | π« | - |
| children | ReactNode | CollapsibleHeader children | π« | - |
CollapsibleContent Propsβ
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| csx | StyleObject | Custom styles | π« | {} |
| children | ReactNode | CollapsibleContent children | π« | - |
Stateβ
| Name | Type | Description | Default |
|---|---|---|---|
| visible | boolean | Whether the content is visible or not | - |
| toggle | () => void | Toggles the visible state | - |
useCollapsibleState paramsβ
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
| visible | boolean | Whether it is visible by default | π« | false |