Accordion

Sections under headings that open and close, one at a time or several, and a single disclosure for extra options.

You pay for the days left in the period. The charge shows on your next invoice as a separate line.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/accordion

Usage

import { Accordion } from "./ui/uicontext/components/Accordion.ts"
const Message = UiSchema.TaggedEnum({ ToggledQuestions: { open: Schema.Array(Schema.String) } })const questions = [	{ value: "seats", title: "What happens when I add seats?", answer: "You pay for the days left in the period." },	{ value: "invoices", title: "Where are my invoices?", answer: "Settings → Billing → Invoices." },]export const Faq = (h: Html.H<typeof Message.Type>, open: ReadonlyArray<string>) =>	Accordion(h, {		items: questions,		open,		onToggle: (next) => Message.ToggledQuestions({ open: next }),		panel: (q) => h.p.children(q.answer),	})

Examples

Several open, boxed

multiple keeps every group you open. A disabled heading stays visible but won't open.

Disclosure

One section behind a small button, for settings most people never change.

API reference

AccordionView function

Options

Accordion options
NameTypeDefaultDescription
keystring—Names the accordion among others in the same view; needed for more than one.
itemsrequiredAccordionItemData[]——
openrequiredstring[]—The values of the open items. The caller keeps them and stores what onToggle asks for.
multipleboolean—Several items open at once; one at a time by default, so opening one closes the others.
onTogglerequired(open: string[]) => Message—The values to keep: store them and pass them back as open.
panelrequired(item: AccordionItemData) => View.Content—What an open item shows.
headingLevel2 | 3 | 4 | 5 | 63The heading level for the titles, to fit the page's outline; 3 by default.
boxedboolean—A bordered box around the items; bare rows with dividers by default.
styleStyle—StyleX styles applied after the accordion's own.

DisclosureView function

Options

Disclosure options
NameTypeDescription
keystringNames the disclosure among others in the same view; needed for more than one.
titlerequiredstringThe button's words: "Advanced options", "Show 3 earlier steps".
openrequiredbooleanWhether it's open. The caller keeps it and stores what onToggle asks for.
onTogglerequired(open: boolean) => Message—
disabledboolean—
childrenrequiredView.ChildrenWhat it shows when open.
styleStyleStyleX styles applied after the disclosure's own.

Source