Collapsible Panel
A compound component that provides a collapsible panel with a header and content area. The header can be clicked to toggle the visibility of the content.
This panel starts expanded. Click the header to collapse it.
This panel starts collapsed. Click the header to expand it and see this content.
This panel contains more content to demonstrate the smooth animation.
- Item one
- Item two
- Item three
Installation
Install the following dependencies
Loading...
API Reference
Component props
CollapsiblePanel
| Prop | Type | Default | Description |
|---|---|---|---|
isExpanded | boolean | - | Whether the panel content is currently expanded or collapsed. |
onToggle | () => void | - | Callback function called when the panel header is clicked to toggle the expanded state. |
children | ReactNode | - | Child components, typically CollapsiblePanelHeader and CollapsiblePanelContent. |
className | string | - | Additional CSS classes to apply to the panel container. |
CollapsiblePanelHeader
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | The content to display in the header. A chevron icon is automatically added to indicate the expand/collapse state. |
className | string | - | Additional CSS classes to apply to the header button. |
CollapsiblePanelContent
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | The content to display when the panel is expanded. |
className | string | - | Additional CSS classes to apply to the content container. |
Behavior
The component uses a context-based pattern for state management:
CollapsiblePanelprovides a context that contains theisExpandedstate andonTogglecallback.CollapsiblePanelHeaderuses the context to access the toggle function and displays a chevron icon that rotates based on the expanded state.CollapsiblePanelContentuses the context to conditionally show/hide content with smooth transitions.- The content area uses CSS transitions with max-height and opacity for smooth expand/collapse animations (300ms duration).
- The component includes proper ARIA attributes (
aria-expandedandaria-controls) for accessibility. - All standard HTML attributes are supported through spread props on each component.
Usage Example
Basic usage with state management
Loading...