Accordion
Collapsible sections with optional anchor copy-link.
Accordions collapse/expand client-side. Giving an item an id adds a copy-link
button that copies #<id> to the clipboard.
Closed by default
Section titled “Closed by default”accordions()
No React, no runtime dependencies — builders return HTML strings and one small vanilla runtime wires the hooks.
Everything is namespaced: cpd- classes, --cpd-* variables and data-cpd-* hooks.
accordions([ { title: 'Why pure TypeScript?', content: '<p>No React, no runtime dependencies.</p>' }, { title: 'How do styles stay isolated?', content: '<p>Everything is namespaced.</p>' },]);Open by default, with anchors
Section titled “Open by default, with anchors”defaultOpen + id
This one starts expanded and exposes a copy-link anchor.
accordion( { title: 'Single accordion, open', content: '<p>This one starts expanded.</p>', id: 'open-acc', defaultOpen: true },);| Option | Type | Default | Description |
|---|---|---|---|
title | string | — | Accordion header (required). |
content | string | '' | Collapsible body (HTML allowed). |
id | string | — | Anchor id; also enables the copy-link button. |
defaultOpen | boolean | false | Start expanded. |
accordions(items)wraps a list ofAccordionOptionsin adata-cpd-accordionscontainer;accordion(options)builds a single item.- The
aria-expandedattribute is set server-side fromdefaultOpen, then maintained by the runtime.