Components / Structure
Accordion01
Sections that open and close, for FAQs and long settings pages. The height springs open and the arrow turns and squashes. Arcade numbers the sections like levels.
<Accordion>
<AccordionItem id="ship" title="When does it ship?">
Orders leave the studio within two days.
</AccordionItem>
<AccordionItem id="return" title="Can I return it?">
Yes, for 30 days.
</AccordionItem>
</Accordion>Usage
import { Accordion, AccordionItem } from "plonk-ui";
export function Faq() {
return (
<Accordion>
<AccordionItem id="ship" title="When does it ship?">
Orders leave the studio within two days.
</AccordionItem>
<AccordionItem id="return" title="Can I return it?">
Yes, for 30 days.
</AccordionItem>
</Accordion>
);
}By default one section is open at a time: opening another closes the first.
allowsMultipleExpanded lets them stay open together.
Heading level
Every section's title is a heading, <h3> by default. Set headingLevel so it
fits the page around it: under an <h3>, the questions should be <h4>.
Yes. It's open source under the MIT license.
import { Accordion, AccordionItem } from "plonk-ui";
const FAQ = [
{
id: "free",
q: "Is Plonk free?",
a: "Yes. It's open source under the MIT license.",
},
{
id: "tailwind",
q: "Do I need Tailwind?",
a: "Yes, Plonk's components are styled with Tailwind v4 and CSS variables.",
},
{
id: "personality",
q: "Can I mix personalities?",
a: "Yes. Nest providers and each part of the page keeps its own.",
},
];
export default function Faq() {
return (
<Accordion className="w-full max-w-sm" defaultExpandedKeys={["free"]}>
{FAQ.map(({ id, q, a }) => (
<AccordionItem key={id} id={id} title={q} headingLevel={4}>
{a}
</AccordionItem>
))}
</Accordion>
);
}defaultExpandedKeys opens sections on first render; expandedKeys and
onExpandedChange control them.
Personalities
- Sticker: the height springs open and the arrow turns and squashes.
- Retro: opens in steps.
- Comic: the open section's title becomes a yellow caption box and the body gets an ink line.
- Arcade: sections are numbered 01, 02, 03 like levels, and the open one gets a neon frame and a cursor.
Accessibility
- Each title is a button inside a heading, so screen reader users can jump between sections by heading.
EnterorSpaceopens and closes a section; the button says whether it's expanded.- Arcade's numbers are decoration and aren't read.
API
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Extra classes for the wrapper. |
allowsMultipleExpanded | boolean | — | Lets several sections stay open. By default, opening one closes the others. |
expandedKeys | Iterable<Key> | — | Controlled open sections, by id. |
defaultExpandedKeys | Iterable<Key> | — | Open sections on first render. |
onExpandedChange | (keys: Set<Key>) => any | — | Called with the Set of open ids. |
isDisabled | boolean | — | Disables every section. |
AccordionItem
| Prop | Type | Default | Description |
|---|---|---|---|
title* | ReactNode | — | Section heading, inside the button that opens it. |
headingLevel | 2 | 3 | 4 | 5 | 6 | 3 | Heading level of the title, so it fits your page's outline. |
className | string | — | Extra classes for the section. |
id | Key | — | Key used by the accordion's expandedKeys. |
isExpanded | boolean | — | Controlled open state, for a single section. |
defaultExpanded | boolean | — | Open on first render. |
onExpandedChange | (isExpanded: boolean) => void | — | Called with true or false. |
isDisabled | boolean | — | Can't be opened or closed. |