Accordion
A collapsible component used to organize content into toggleable sections. It's an ideal solution for FAQs, progressive disclosure, or compacting complex information.
Props
Prop | Type | Default | Description |
|---|---|---|---|
variant | string | '' | Custom CSS class to apply to the accordion wrapper. |
header | Snippet<[{ isExpanded: boolean }]> | required | Snippet for the toggleable header content. |
body | Snippet | required | Snippet for the collapsible body content. |
transitionFunction | function | slide | Svelte transition function for the expansion animation. |
transitionDuration | number | 250 | Duration of the expansion animation in ms. |
Samples
Standard Accordion
The default look with chevron indicators.
0
<Accordion>1
{#snippet header({ isExpanded })}2
<Text>Title</Text>3
<Icon icon={isExpanded ? 'up' : 'down'} />4
{/snippet}5
{#snippet body()}6
<Text>Hidden content</Text>7
{/snippet}8
</Accordion>Custom Transition
Using different Svelte transitions and durations.
0
import { fade } from 'svelte/transition';1
2
<Accordion transitionFunction={fade} transitionDuration={500}>3
...4
</Accordion>