The Collapsible component provides a simple way to show and hide content. It consists of a trigger that controls the visibility of a panel.
import { Collapsible } from '@raystack/apsara';
import { ChevronDownIcon } from '@radix-ui/react-icons';
export default function Example() {
return (
<Collapsible>
<Collapsible.Trigger>
<span>Show more information</span>
<ChevronDownIcon />
</Collapsible.Trigger>
<Collapsible.Panel>
<p>This is the collapsible content that can be shown or hidden.</p>
</Collapsible.Panel>
</Collapsible>
);
}
Controlled collapsible
import { Collapsible } from '@raystack/apsara';
import { useState } from 'react';
export default function ControlledExample() {
const [open, setOpen] = useState(false);
return (
<Collapsible open={open} onOpenChange={setOpen}>
<Collapsible.Trigger>
{open ? 'Hide' : 'Show'} details
</Collapsible.Trigger>
<Collapsible.Panel>
<p>Controlled collapsible content.</p>
</Collapsible.Panel>
</Collapsible>
);
}
API reference
Collapsible (Root)
The root container for the collapsible.
The controlled open state of the collapsible.
The default open state when uncontrolled.
Callback fired when the open state changes.
Whether the collapsible is disabled.
Collapsible.Trigger
The button that toggles the collapsible state.
Additional CSS class for the trigger.
The content of the trigger button.
Collapsible.Panel
The collapsible content area.
Additional CSS class for the panel.
The content to display when expanded.