Disclosure
Slant / Controls
Expandable sections that animate open and closed.
Demo
Usage
import { Disclosure, Text } from '@tuttn/slant'
// Uncontrolled: it keeps its own state, starting from defaultOpen (false).
<Disclosure title="Does it work offline?" defaultOpen>
Yes. Tasks and checkpoints live in a local project folder.
</Disclosure>
// Controlled, one open at a time: pass open, and update it in onOpenChange.
const [open, setOpen] = useState(0)
{questions.map((item, index) => <Disclosure key={item.q} title={item.q} open={open === index}
onOpenChange={next => setOpen(next ? index : -1)}>{item.a}</Disclosure>)}
// The panel sets its own muted 13px text; pass plain text or Text, not <p>.
<Disclosure title="Where is my data stored?" heading="h2">
<Text>On your machine, in plain files you can read and back up.</Text>
</Disclosure>Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | The toggle button's visible text. |
open | boolean | — | Whether the panel is open. Pass it to control the disclosure; leave it out and it keeps its own state. |
defaultOpen | boolean | false | Whether the panel starts open when uncontrolled. |
onOpenChange | (open: boolean) => void | — | Called with the requested state when the toggle is pressed. |
heading | 'h2' | 'h3' | 'h4' | 'div' | 'h3' | The element wrapping the toggle button, so it sits in the page's outline. |
disabled | boolean | — | Disables the toggle button: the panel stays as it is, open or closed, and the toggle leaves the tab order. |
toggleProps | Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'disabled' | 'aria-expanded' | 'aria-controls' | 'children'> | — | Extra attributes for the toggle button, such as `id`, `aria-describedby` or `aria-disabled`. With `aria-disabled` the toggle stays focusable but a press does nothing. Its `onClick` runs first and can call `preventDefault()` to keep the panel as it is. |
children | ReactNode | — | The panel's content. The panel sets a muted body text style, so pass plain text or `Text`. |
…rest | HTMLAttributes<HTMLDivElement> | — | The ref, className, style and other attributes go on the root div. |