@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +331 -0
  4. package/dist/accordion.js +25 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +8 -0
  7. package/dist/alert-dialog.d.ts +56 -0
  8. package/dist/alert-dialog.js +45 -0
  9. package/dist/async-options.d.ts +22 -0
  10. package/dist/async-options.js +56 -0
  11. package/dist/autocomplete.d.ts +102 -0
  12. package/dist/autocomplete.js +195 -0
  13. package/dist/avatar.d.ts +301 -0
  14. package/dist/avatar.js +17 -0
  15. package/dist/button.d.ts +21 -0
  16. package/dist/button.js +45 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +9 -0
  19. package/dist/calendar.d.ts +80 -0
  20. package/dist/calendar.js +257 -0
  21. package/dist/carousel.d.ts +52 -0
  22. package/dist/carousel.js +151 -0
  23. package/dist/checkbox.d.ts +24 -0
  24. package/dist/checkbox.js +98 -0
  25. package/dist/children.d.ts +38 -0
  26. package/dist/children.js +63 -0
  27. package/dist/collapsible.d.ts +302 -0
  28. package/dist/collapsible.js +19 -0
  29. package/dist/color-picker.d.ts +72 -0
  30. package/dist/color-picker.js +133 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +22 -0
  33. package/dist/combobox.d.ts +152 -0
  34. package/dist/combobox.js +338 -0
  35. package/dist/command.d.ts +88 -0
  36. package/dist/command.js +233 -0
  37. package/dist/controller-target.d.ts +3 -0
  38. package/dist/controller-target.js +59 -0
  39. package/dist/date-input.d.ts +19 -0
  40. package/dist/date-input.js +58 -0
  41. package/dist/date-picker.d.ts +47 -0
  42. package/dist/date-picker.js +310 -0
  43. package/dist/date.d.ts +2 -0
  44. package/dist/date.js +60 -0
  45. package/dist/dialog-parts.d.ts +23 -0
  46. package/dist/dialog-parts.js +142 -0
  47. package/dist/dialog.d.ts +57 -0
  48. package/dist/dialog.js +32 -0
  49. package/dist/drawer.d.ts +70 -0
  50. package/dist/drawer.js +158 -0
  51. package/dist/editor-context.d.ts +4 -0
  52. package/dist/editor-context.js +9 -0
  53. package/dist/field-context.d.ts +47 -0
  54. package/dist/field-context.js +87 -0
  55. package/dist/field.d.ts +49 -0
  56. package/dist/field.js +169 -0
  57. package/dist/file-input.d.ts +46 -0
  58. package/dist/file-input.js +170 -0
  59. package/dist/form-inputs.d.ts +5 -0
  60. package/dist/form-inputs.js +22 -0
  61. package/dist/gesture.d.ts +1 -0
  62. package/dist/gesture.js +16 -0
  63. package/dist/history.d.ts +2 -0
  64. package/dist/history.js +12 -0
  65. package/dist/hover-card.d.ts +33 -0
  66. package/dist/hover-card.js +84 -0
  67. package/dist/image-cropper.d.ts +333 -0
  68. package/dist/image-cropper.js +37 -0
  69. package/dist/image.d.ts +2 -0
  70. package/dist/image.js +6 -0
  71. package/dist/input.d.ts +22 -0
  72. package/dist/input.js +51 -0
  73. package/dist/label.d.ts +294 -0
  74. package/dist/label.js +9 -0
  75. package/dist/list-items.d.ts +15 -0
  76. package/dist/list-items.js +39 -0
  77. package/dist/list-text.d.ts +4 -0
  78. package/dist/list-text.js +15 -0
  79. package/dist/listbox.d.ts +56 -0
  80. package/dist/listbox.js +122 -0
  81. package/dist/menu.d.ts +116 -0
  82. package/dist/menu.js +426 -0
  83. package/dist/menubar-context.d.ts +4 -0
  84. package/dist/menubar-context.js +7 -0
  85. package/dist/menubar.d.ts +11 -0
  86. package/dist/menubar.js +32 -0
  87. package/dist/meter.d.ts +312 -0
  88. package/dist/meter.js +30 -0
  89. package/dist/navigation-menu.d.ts +61 -0
  90. package/dist/navigation-menu.js +169 -0
  91. package/dist/number-input.d.ts +44 -0
  92. package/dist/number-input.js +185 -0
  93. package/dist/number.d.ts +2 -0
  94. package/dist/number.js +40 -0
  95. package/dist/observe.d.ts +2 -0
  96. package/dist/observe.js +8 -0
  97. package/dist/otp-input.d.ts +29 -0
  98. package/dist/otp-input.js +94 -0
  99. package/dist/overlays.d.ts +26 -0
  100. package/dist/overlays.js +82 -0
  101. package/dist/pagination.d.ts +336 -0
  102. package/dist/pagination.js +71 -0
  103. package/dist/password-input.d.ts +23 -0
  104. package/dist/password-input.js +65 -0
  105. package/dist/popover.d.ts +54 -0
  106. package/dist/popover.js +151 -0
  107. package/dist/popup.d.ts +41 -0
  108. package/dist/popup.js +180 -0
  109. package/dist/preferences.d.ts +35 -0
  110. package/dist/preferences.js +93 -0
  111. package/dist/primitive.d.ts +2 -0
  112. package/dist/primitive.js +14 -0
  113. package/dist/progress.d.ts +312 -0
  114. package/dist/progress.js +30 -0
  115. package/dist/radio.d.ts +22 -0
  116. package/dist/radio.js +86 -0
  117. package/dist/rating.d.ts +20 -0
  118. package/dist/rating.js +94 -0
  119. package/dist/render-element.d.ts +35 -0
  120. package/dist/render-element.js +103 -0
  121. package/dist/resizable.d.ts +302 -0
  122. package/dist/resizable.js +23 -0
  123. package/dist/scroll-area.d.ts +324 -0
  124. package/dist/scroll-area.js +49 -0
  125. package/dist/segmented-control.d.ts +24 -0
  126. package/dist/segmented-control.js +78 -0
  127. package/dist/segmented-input.d.ts +15 -0
  128. package/dist/segmented-input.js +48 -0
  129. package/dist/select.d.ts +125 -0
  130. package/dist/select.js +330 -0
  131. package/dist/separator.d.ts +290 -0
  132. package/dist/separator.js +9 -0
  133. package/dist/shortcuts.d.ts +32 -0
  134. package/dist/shortcuts.js +61 -0
  135. package/dist/slider.d.ts +38 -0
  136. package/dist/slider.js +163 -0
  137. package/dist/switch.d.ts +15 -0
  138. package/dist/switch.js +39 -0
  139. package/dist/tabs.d.ts +331 -0
  140. package/dist/tabs.js +28 -0
  141. package/dist/text-control.d.ts +22 -0
  142. package/dist/text-control.js +24 -0
  143. package/dist/text-match.d.ts +2 -0
  144. package/dist/text-match.js +8 -0
  145. package/dist/textarea.d.ts +10 -0
  146. package/dist/textarea.js +48 -0
  147. package/dist/time-input.d.ts +19 -0
  148. package/dist/time-input.js +63 -0
  149. package/dist/timeline.d.ts +327 -0
  150. package/dist/timeline.js +31 -0
  151. package/dist/toast-parts.d.ts +63 -0
  152. package/dist/toast-parts.js +144 -0
  153. package/dist/toast.d.ts +2 -0
  154. package/dist/toast.js +22 -0
  155. package/dist/toggle.d.ts +23 -0
  156. package/dist/toggle.js +76 -0
  157. package/dist/token-input.d.ts +35 -0
  158. package/dist/token-input.js +100 -0
  159. package/dist/toolbar-context.d.ts +6 -0
  160. package/dist/toolbar-context.js +16 -0
  161. package/dist/toolbar.d.ts +38 -0
  162. package/dist/toolbar.js +63 -0
  163. package/dist/tooltip.d.ts +39 -0
  164. package/dist/tooltip.js +108 -0
  165. package/dist/tree.d.ts +51 -0
  166. package/dist/tree.js +150 -0
  167. package/dist/trigger-menu.d.ts +83 -0
  168. package/dist/trigger-menu.js +167 -0
  169. package/dist/use-primitive.d.ts +178 -0
  170. package/dist/use-primitive.js +674 -0
  171. package/dist/waterfall.d.ts +80 -0
  172. package/dist/waterfall.js +108 -0
  173. package/docs/README.md +89 -0
  174. package/docs/agents.md +1523 -0
  175. package/docs/components/accordion.md +1391 -0
  176. package/docs/components/alert-dialog.md +850 -0
  177. package/docs/components/autocomplete.md +1963 -0
  178. package/docs/components/avatar.md +252 -0
  179. package/docs/components/button.md +444 -0
  180. package/docs/components/calendar.md +1687 -0
  181. package/docs/components/carousel.md +1244 -0
  182. package/docs/components/checkbox.md +1069 -0
  183. package/docs/components/collapsible.md +567 -0
  184. package/docs/components/color-picker.md +736 -0
  185. package/docs/components/combobox.md +3647 -0
  186. package/docs/components/command.md +1573 -0
  187. package/docs/components/date-input.md +608 -0
  188. package/docs/components/date-picker.md +1266 -0
  189. package/docs/components/dialog.md +1469 -0
  190. package/docs/components/drawer.md +1197 -0
  191. package/docs/components/field.md +549 -0
  192. package/docs/components/file-input.md +609 -0
  193. package/docs/components/hover-card.md +514 -0
  194. package/docs/components/image-cropper.md +579 -0
  195. package/docs/components/input.md +301 -0
  196. package/docs/components/label.md +217 -0
  197. package/docs/components/listbox.md +1130 -0
  198. package/docs/components/menu.md +1286 -0
  199. package/docs/components/menubar.md +455 -0
  200. package/docs/components/meter.md +304 -0
  201. package/docs/components/navigation-menu.md +1581 -0
  202. package/docs/components/number-input.md +1086 -0
  203. package/docs/components/otp-input.md +565 -0
  204. package/docs/components/pagination.md +648 -0
  205. package/docs/components/password-input.md +737 -0
  206. package/docs/components/popover.md +1552 -0
  207. package/docs/components/preferences.md +220 -0
  208. package/docs/components/progress.md +443 -0
  209. package/docs/components/radio.md +846 -0
  210. package/docs/components/rating.md +458 -0
  211. package/docs/components/resizable.md +982 -0
  212. package/docs/components/scroll-area.md +980 -0
  213. package/docs/components/segmented-control.md +465 -0
  214. package/docs/components/select.md +2133 -0
  215. package/docs/components/separator.md +243 -0
  216. package/docs/components/slider.md +1169 -0
  217. package/docs/components/switch.md +613 -0
  218. package/docs/components/tabs.md +1014 -0
  219. package/docs/components/textarea.md +318 -0
  220. package/docs/components/time-input.md +231 -0
  221. package/docs/components/timeline.md +677 -0
  222. package/docs/components/toast.md +1395 -0
  223. package/docs/components/toggle.md +541 -0
  224. package/docs/components/token-input.md +1007 -0
  225. package/docs/components/toolbar.md +787 -0
  226. package/docs/components/tooltip.md +884 -0
  227. package/docs/components/tree.md +1346 -0
  228. package/docs/components/trigger-menu.md +1257 -0
  229. package/docs/components/waterfall.md +754 -0
  230. package/docs/controllers.md +89 -0
  231. package/docs/core.md +8027 -0
  232. package/docs/custom-parts.md +120 -0
  233. package/docs/first-component.md +83 -0
  234. package/docs/forms.md +148 -0
  235. package/docs/hooks/async-options.md +366 -0
  236. package/docs/hooks/shortcuts.md +221 -0
  237. package/docs/installation.md +45 -0
  238. package/docs/introduction.md +32 -0
  239. package/docs/lists-and-menus.md +170 -0
  240. package/docs/llms.txt +1844 -0
  241. package/docs/parts-and-composition.md +93 -0
  242. package/docs/popups.md +117 -0
  243. package/docs/rendering.md +121 -0
  244. package/docs/server-rendering.md +253 -0
  245. package/docs/state-and-events.md +105 -0
  246. package/docs/styling-and-animation.md +176 -0
  247. package/package.json +333 -3
@@ -0,0 +1,567 @@
1
+ # Collapsible
2
+
3
+ Show and hide a panel, preserve its contents, and animate its height.
4
+
5
+ Use a collapsible to show and hide one panel of content. For a set of panels, use an [accordion](./accordion.md).
6
+
7
+ ```tsx title="basic.tsx"
8
+ "use client"
9
+
10
+ import {
11
+ Collapsible,
12
+ CollapsiblePanel,
13
+ CollapsibleTrigger,
14
+ } from "@ui-sdk/react/collapsible"
15
+ import { ChevronDownIcon } from "lucide-react"
16
+
17
+ const items = [
18
+ { name: "Linen shirt", price: "$48.00" },
19
+ { name: "Canvas tote", price: "$18.00" },
20
+ { name: "Wool socks", price: "$18.00" },
21
+ ]
22
+
23
+ function Example() {
24
+ return (
25
+ <Collapsible data-variant="card">
26
+ <CollapsibleTrigger>
27
+ <span data-slot="stack">
28
+ <span>Order #4189</span>
29
+ <span data-slot="hint">3 items, $84.00</span>
30
+ </span>
31
+ <ChevronDownIcon />
32
+ </CollapsibleTrigger>
33
+ <CollapsiblePanel>
34
+ {items.map((item) => (
35
+ <div data-slot="row" key={item.name}>
36
+ <span>{item.name}</span>
37
+ <span>{item.price}</span>
38
+ </div>
39
+ ))}
40
+ </CollapsiblePanel>
41
+ </Collapsible>
42
+ )
43
+ }
44
+
45
+ export { Example }
46
+ ```
47
+
48
+ Press Order #4189, or focus it and press Enter or Space, to show the items.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install @ui-sdk/react @ui-sdk/core
54
+ ```
55
+
56
+ ## Composition
57
+
58
+ Use the following composition to build a `Collapsible`:
59
+
60
+ ```text
61
+ Collapsible
62
+ ├── CollapsibleTrigger
63
+ └── CollapsiblePanel
64
+ ```
65
+
66
+ The root and panel render divs, and the trigger renders a native button. Put other content around them, like a heading or a summary that always shows.
67
+
68
+ ## Usage
69
+
70
+ Import the parts and put them together:
71
+
72
+ ```tsx
73
+ import {
74
+ Collapsible,
75
+ CollapsiblePanel,
76
+ CollapsibleTrigger,
77
+ } from "@ui-sdk/react/collapsible"
78
+
79
+ function Example() {
80
+ return (
81
+ <Collapsible>
82
+ <CollapsibleTrigger>Order details</CollapsibleTrigger>
83
+ <CollapsiblePanel>2 × Linen shirt</CollapsiblePanel>
84
+ </Collapsible>
85
+ )
86
+ }
87
+
88
+ export { Example }
89
+ ```
90
+
91
+ ## Build Your Own
92
+
93
+ `@ui-sdk/react/collapsible` comes with a ready-made Collapsible. If you'd like to build your own, with your own names, start from the `collapsible` primitive in `@ui-sdk/core`:
94
+
95
+ ```ts title="spoiler.ts"
96
+ "use client"
97
+
98
+ import { collapsible } from "@ui-sdk/core/collapsible"
99
+ import { createParts } from "@ui-sdk/react/primitive"
100
+
101
+ const {
102
+ Root: Spoiler,
103
+ Trigger: SpoilerToggle,
104
+ Panel: SpoilerContent,
105
+ } = createParts(collapsible, {
106
+ root: "div",
107
+ trigger: "button",
108
+ panel: "div",
109
+ })
110
+
111
+ export { Spoiler, SpoilerContent, SpoilerToggle }
112
+ ```
113
+
114
+ ```tsx
115
+ <Spoiler>
116
+ <SpoilerToggle>Show the ending</SpoilerToggle>
117
+ <SpoilerContent>The butler did it.</SpoilerContent>
118
+ </Spoiler>
119
+ ```
120
+
121
+ Each part keeps the behavior, state and data attributes of its ready-made counterpart. See [Rendering](../rendering.md) and [Custom Parts](../custom-parts.md) for more.
122
+
123
+ ## Disabled
124
+
125
+ Set `disabled` on the root to stop its trigger from opening or closing the panel. The trigger stays in the tab order and reports `aria-disabled="true"`. A disabled `<fieldset>` around the collapsible disables it too.
126
+
127
+ ```tsx
128
+ <Collapsible disabled>
129
+ <CollapsibleTrigger>Gift options</CollapsibleTrigger>
130
+ <CollapsiblePanel>Add a gift message and wrapping.</CollapsiblePanel>
131
+ </Collapsible>
132
+ ```
133
+
134
+ ## Keep Mounted
135
+
136
+ Panels unmount when they close, so Tab skips their contents. Set `keepMounted` on the panel to keep it mounted and hidden, so a field keeps what you typed into it.
137
+
138
+ ```tsx title="keep-mounted.tsx"
139
+ import {
140
+ Collapsible,
141
+ CollapsiblePanel,
142
+ CollapsibleTrigger,
143
+ } from "@ui-sdk/react/collapsible"
144
+ import { Field, FieldLabel } from "@ui-sdk/react/field"
145
+ import { Textarea } from "@ui-sdk/react/textarea"
146
+ import { ChevronDownIcon } from "lucide-react"
147
+
148
+ function Example() {
149
+ return (
150
+ <Collapsible data-variant="card">
151
+ <CollapsibleTrigger>
152
+ <span data-slot="stack">
153
+ <span>Add a delivery note</span>
154
+ <span data-slot="hint">Optional, for the courier</span>
155
+ </span>
156
+ <ChevronDownIcon />
157
+ </CollapsibleTrigger>
158
+ <CollapsiblePanel keepMounted>
159
+ <Field>
160
+ <FieldLabel>Delivery note</FieldLabel>
161
+ <Textarea placeholder="Leave it with the front desk…" />
162
+ </Field>
163
+ </CollapsiblePanel>
164
+ </Collapsible>
165
+ )
166
+ }
167
+
168
+ export { Example }
169
+ ```
170
+
171
+ Open Add a delivery note, type a note, then close and reopen the panel. Your note is still there.
172
+
173
+ ## Find in Page
174
+
175
+ Set `hiddenUntilFound` on the panel to keep it in the DOM as `hidden="until-found"`. Browser Find and links to content inside the panel can reveal it. The panel opens without an animation so the match is visible immediately.
176
+
177
+ React serializes `hidden` as a boolean on the server. The closed panel becomes findable after hydration.
178
+
179
+ ```tsx title="find-in-page.tsx"
180
+ import {
181
+ Collapsible,
182
+ CollapsiblePanel,
183
+ CollapsibleTrigger,
184
+ } from "@ui-sdk/react/collapsible"
185
+ import { ChevronDownIcon } from "lucide-react"
186
+
187
+ function Example() {
188
+ return (
189
+ <Collapsible data-variant="card">
190
+ <CollapsibleTrigger>
191
+ <span data-slot="stack">
192
+ <span>Ingredients</span>
193
+ <span data-slot="hint">Morning buns, makes 12</span>
194
+ </span>
195
+ <ChevronDownIcon />
196
+ </CollapsibleTrigger>
197
+ <CollapsiblePanel hiddenUntilFound>
198
+ <p>
199
+ Flour, butter, brown sugar, eggs, a pinch of cardamom and sea salt.
200
+ </p>
201
+ </CollapsiblePanel>
202
+ </Collapsible>
203
+ )
204
+ }
205
+
206
+ export { Example }
207
+ ```
208
+
209
+ Leave Ingredients closed. Open your browser's Find command and search for cardamom to reveal the panel.
210
+
211
+ ## Controlled
212
+
213
+ Pass `open` and update it in `onOpenChange`. Call `details.cancel()` in the callback to cancel the change.
214
+
215
+ For a button elsewhere on the page, create a [controller](#controller) with `createCollapsibleController()` and pass it as `controller`. Create one controller per mounted collapsible.
216
+
217
+ ```tsx title="controlled.tsx"
218
+ "use client"
219
+
220
+ import {
221
+ Collapsible,
222
+ CollapsiblePanel,
223
+ CollapsibleTrigger,
224
+ createCollapsibleController,
225
+ } from "@ui-sdk/react/collapsible"
226
+ import { ChevronDownIcon } from "lucide-react"
227
+ import { useLog } from "./log"
228
+ import * as React from "react"
229
+
230
+ const recoveryCodes = ["7KQ2-M9XD", "P4TR-8HZC", "W3NB-6JUE", "C5YF-2LSA"]
231
+
232
+ function Example() {
233
+ const log = useLog()
234
+ const [collapsible] = React.useState(createCollapsibleController)
235
+ const [open, setOpen] = React.useState(false)
236
+
237
+ return (
238
+ <div data-slot="stack">
239
+ <div data-slot="controls">
240
+ <button type="button" onClick={() => collapsible.toggle()}>
241
+ Toggle
242
+ </button>
243
+ </div>
244
+ <Collapsible
245
+ data-variant="card"
246
+ open={open}
247
+ onOpenChange={(next, details) => {
248
+ setOpen(next)
249
+ log(`${next ? "Opened" : "Closed"} (${details.reason})`)
250
+ }}
251
+ controller={collapsible}
252
+ >
253
+ <CollapsibleTrigger>
254
+ <span data-slot="stack">
255
+ <span>Recovery codes</span>
256
+ <span data-slot="hint">Each code signs you in once</span>
257
+ </span>
258
+ <ChevronDownIcon />
259
+ </CollapsibleTrigger>
260
+ <CollapsiblePanel>
261
+ <div data-slot="stack">
262
+ <ul>
263
+ {recoveryCodes.map((code) => (
264
+ <li key={code}>{code}</li>
265
+ ))}
266
+ </ul>
267
+ <button type="button" onClick={() => collapsible.close()}>
268
+ Done
269
+ </button>
270
+ </div>
271
+ </CollapsiblePanel>
272
+ </Collapsible>
273
+ </div>
274
+ )
275
+ }
276
+
277
+ export { Example }
278
+ ```
279
+
280
+ Open Recovery codes with Toggle or its trigger, then press Done. The console logs each change and its reason, and Done returns focus to the trigger.
281
+
282
+ ## Animation
283
+
284
+ Animate the measured `--collapsible-panel-height` between zero and the content's height. `data-starting-style` marks the opening frame, and `data-ending-style` stays on while it closes. The panel stays mounted until its closing animation finishes, and a panel open on its first paint doesn't animate.
285
+
286
+ ```css
287
+ [data-slot="collapsible-panel"] {
288
+ height: var(--collapsible-panel-height);
289
+ overflow: hidden;
290
+ transition: height 0.2s ease-out;
291
+
292
+ &:is([data-starting-style], [data-ending-style]) {
293
+ height: 0;
294
+ }
295
+ }
296
+ ```
297
+
298
+ `onOpenChangeComplete` reports when opening or closing has finished.
299
+
300
+ ```tsx title="animation.tsx"
301
+ "use client"
302
+
303
+ import {
304
+ Collapsible,
305
+ CollapsiblePanel,
306
+ CollapsibleTrigger,
307
+ } from "@ui-sdk/react/collapsible"
308
+ import { ChevronDownIcon } from "lucide-react"
309
+ import { useLog } from "./log"
310
+
311
+ const notes = [
312
+ "Search now matches file contents, not only names.",
313
+ "Shared links remember the folder they were opened from.",
314
+ "Uploads resume after the connection drops.",
315
+ ]
316
+
317
+ function Example() {
318
+ const log = useLog()
319
+ return (
320
+ <Collapsible
321
+ data-variant="card"
322
+ onOpenChangeComplete={(open) =>
323
+ log(open ? "Finished opening" : "Finished closing")
324
+ }
325
+ >
326
+ <CollapsibleTrigger>
327
+ <span data-slot="stack">
328
+ <span>Release notes</span>
329
+ <span data-slot="hint">Version 2.4, released October 28</span>
330
+ </span>
331
+ <ChevronDownIcon />
332
+ </CollapsibleTrigger>
333
+ <CollapsiblePanel>
334
+ <ul>
335
+ {notes.map((note) => (
336
+ <li key={note}>{note}</li>
337
+ ))}
338
+ </ul>
339
+ </CollapsiblePanel>
340
+ </Collapsible>
341
+ )
342
+ }
343
+
344
+ export { Example }
345
+ ```
346
+
347
+ Open and close Release notes. The console logs when each animation finishes.
348
+
349
+ ## Custom Rendering
350
+
351
+ Use `render` to choose the element for a part, or a render function to read its state. The trigger below renders inside a heading, and the panel renders as an ordered list.
352
+
353
+ ```tsx title="render.tsx"
354
+ "use client"
355
+
356
+ import {
357
+ Collapsible,
358
+ CollapsiblePanel,
359
+ CollapsibleTrigger,
360
+ } from "@ui-sdk/react/collapsible"
361
+ import { ChevronDownIcon } from "lucide-react"
362
+
363
+ const updates = [
364
+ { label: "Out for delivery", time: "07:40" },
365
+ { label: "Arrived at the local depot", time: "05:12" },
366
+ { label: "Left the sorting center", time: "Wed 21:03" },
367
+ ]
368
+
369
+ function Example() {
370
+ return (
371
+ <Collapsible data-variant="card">
372
+ <CollapsibleTrigger
373
+ render={(props) => (
374
+ <h3>
375
+ <button {...props} />
376
+ </h3>
377
+ )}
378
+ >
379
+ {(state) => (
380
+ <>
381
+ <span data-slot="stack">
382
+ <span>Track parcel</span>
383
+ <span data-slot="hint">
384
+ {state.open ? "3 updates" : "Arrives Thursday"}
385
+ </span>
386
+ </span>
387
+ <ChevronDownIcon />
388
+ </>
389
+ )}
390
+ </CollapsibleTrigger>
391
+ <CollapsiblePanel render={<ol />}>
392
+ {updates.map((update) => (
393
+ <li data-slot="row" key={update.label}>
394
+ <span>{update.label}</span>
395
+ <span>{update.time}</span>
396
+ </li>
397
+ ))}
398
+ </CollapsiblePanel>
399
+ </Collapsible>
400
+ )
401
+ }
402
+
403
+ export { Example }
404
+ ```
405
+
406
+ Press Track parcel to open the ordered list. The summary changes from Arrives Thursday to 3 updates.
407
+
408
+ ## Styling
409
+
410
+ Use `data-open`, `data-closed` and `data-disabled` to style each state. The examples turn their chevron from the trigger's `data-open`.
411
+
412
+ Each part has a `data-slot`, such as `collapsible-panel`, and its state attributes are listed under [Data Attributes](#data-attributes).
413
+
414
+ ### CollapsiblePanel
415
+ - `--collapsible-panel-height`: The panel's content height in pixels while it animates, auto once open and 0px while closed.
416
+ - `--collapsible-panel-width`: The panel's content width, the same way. For panels that open sideways.
417
+
418
+ ## Data Attributes
419
+
420
+ ### Collapsible
421
+ `[data-slot="collapsible"]`
422
+
423
+ - `data-open`: Present while the panel is open.
424
+ - `data-closed`: Present while the panel is closed, including while it animates out.
425
+ - `data-disabled`: Present when the collapsible can't open or close.
426
+
427
+ ### CollapsibleTrigger
428
+ `[data-slot="collapsible-trigger"]`
429
+
430
+ - `data-open`: Present while the panel is open.
431
+ - `data-closed`: Present while the panel is closed, including while it animates out.
432
+ - `data-disabled`: Present when the collapsible can't open or close.
433
+
434
+ ### CollapsiblePanel
435
+ `[data-slot="collapsible-panel"]`
436
+
437
+ - `data-open`: Present while the panel is open.
438
+ - `data-closed`: Present while the panel is closed, including while it animates out.
439
+ - `data-disabled`: Present when the collapsible can't open or close.
440
+ - `data-starting-style`: Present for the panel's first frame. Style the state you animate from.
441
+ - `data-ending-style`: Present while the panel animates closed. Style the state you animate to.
442
+
443
+ ## API Reference
444
+
445
+ Props and callbacks are the same as below, as React props.
446
+
447
+ ### Collapsible
448
+
449
+ - `open?` (`boolean`): Whether the panel is open. Pass it to control the collapsible.
450
+ - `defaultOpen?` (`boolean`): Whether the panel is open at first, when uncontrolled.
451
+ - `onOpenChange?` (`((open: boolean, details: ChangeDetails<CollapsibleOpenChangeReason>) => void)`): Runs when the panel wants to open or close. `details.reason` says why, and `details.cancel()` stops it.
452
+ - `onOpenChangeComplete?` (`((open: boolean) => void)`): Runs once the panel has finished opening or closing, after any animation.
453
+ - `disabled?` (`boolean`): Stops the trigger from opening or closing the panel. The trigger stays focusable.
454
+ - `controller?` (`object`): Opens and closes the panel from anywhere. Create one with `createCollapsibleController()`.
455
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
456
+
457
+ ### CollapsibleTrigger
458
+
459
+ The trigger takes no options of its own, only the props of the element it renders.
460
+
461
+ ### CollapsiblePanel
462
+
463
+ - `keepMounted?` (`boolean`): Whether the panel stays in the page, hidden, while closed.
464
+ - `hiddenUntilFound?` (`boolean`): Keeps the closed panel in the page as `hidden="until-found"`, so the browser's find in page can match its text and open it.
465
+
466
+ ### State
467
+
468
+ What render functions, state-based class names and slots receive. The trigger and the panel receive the same
469
+ state as the collapsible.
470
+
471
+ - `open` (`boolean`): Whether the panel is open.
472
+ - `disabled` (`boolean`): Whether the trigger ignores presses, by its own `disabled` or a disabled fieldset around it. The `open` option and the controller can still open and close it.
473
+
474
+ ### Reasons
475
+
476
+ `details.reason` says why the panel opened or closed.
477
+
478
+ - `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
479
+ - `find-in-page` (`Event`): The browser's find in page matched hidden content.
480
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
481
+
482
+ ### Controller
483
+
484
+ Create one with `createCollapsibleController()` and pass it as `controller`.
485
+
486
+ Every write method takes an optional `{ reason, event }`, and returns `false` when the change was canceled or changed nothing.
487
+
488
+ - `isOpen()` (`() => boolean`): Whether the panel is open.
489
+ - `setOpen(open, options?)` (`(open: boolean, options?: CollapsibleChangeOptions | undefined) => boolean`): Opens or closes the panel. Returns false when the change was canceled or not possible.
490
+ - `open(options?)` (`(options?: CollapsibleChangeOptions | undefined) => boolean`): Opens the panel.
491
+ - `close(options?)` (`(options?: CollapsibleChangeOptions | undefined) => boolean`): Closes the panel.
492
+ - `toggle(options?)` (`(options?: CollapsibleChangeOptions | undefined) => boolean`): Opens the panel when it's closed, and closes it when it's open.
493
+ - `focus()` (`() => void`): Moves focus to the trigger.
494
+
495
+ ### Events
496
+
497
+ Callbacks get the new state first, then the details.
498
+
499
+ | Prop | On | Receives |
500
+ | ---------------------- | ------------- | ------------------------------------------------------------ |
501
+ | `onOpenChange` | `Collapsible` | `(open, details)`: the new state, and the [reason](#reasons) |
502
+ | `onOpenChangeComplete` | `Collapsible` | `(open)`, after the panel's animation |
503
+
504
+ ## Accessibility
505
+
506
+ The collapsible follows the [WAI-ARIA disclosure pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/). The trigger says whether the panel is open with `aria-expanded`, and points to the panel with `aria-controls` while it's mounted. Every line below is an automated test.
507
+
508
+ ### Keyboard
509
+
510
+ | Key | Does |
511
+ | ------------ | ------------------------------------------------------ |
512
+ | Enter, Space | Opens or closes the panel. Focus stays on the trigger. |
513
+ | Tab | Moves from the trigger into an open panel |
514
+
515
+ Closing a panel while focus is inside it moves focus back to the trigger.
516
+
517
+ ### Tested Behavior
518
+
519
+ **Opening and closing**
520
+
521
+ - Starts closed, with the panel out of the page.
522
+ - Clicking the trigger opens the panel, and clicking again closes it.
523
+ - The trigger controls the panel.
524
+ - Generated ids start with ui-sdk-.
525
+ - It can start open.
526
+ - An opening can be canceled.
527
+ - A disabled collapsible doesn't open.
528
+ - A disabled trigger stays focusable and says it's disabled.
529
+ - A controller opens and closes it from anywhere.
530
+
531
+ **Keyboard**
532
+
533
+ - Enter toggles the panel and keeps focus on the trigger.
534
+ - Space toggles the panel and keeps focus on the trigger.
535
+ - Tab moves from the open trigger into the panel.
536
+ - Tab skips a closed panel.
537
+
538
+ **Mounting**
539
+
540
+ - With keepMounted, the closed panel stays in the page, hidden.
541
+ - With keepMounted, a class that sets display doesn't show the closed panel.
542
+ - With hiddenUntilFound, the closed panel stays findable.
543
+ - With hiddenUntilFound, a class that sets display keeps the closed panel findable.
544
+ - Finding text in the closed panel opens it.
545
+ - Following a link into the closed panel opens it.
546
+ - The browser's own find opens the closed panel.
547
+
548
+ Runs in React, Vue and web components.
549
+
550
+ Beyond the pattern's baseline:
551
+
552
+ **Enhancements**
553
+
554
+ - Closing the panel while focus is inside it moves focus to the trigger.
555
+ - OnOpenChangeComplete runs once the animation has finished.
556
+ - Find in page reports its own reason and opens without an animation.
557
+ - A canceled find in page keeps the panel hidden until found.
558
+ - An infinite exit animation still unmounts the panel.
559
+ - Parts report open and closed through data attributes.
560
+
561
+ Runs in React, Vue and web components.
562
+
563
+ Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:
564
+
565
+ - Announcements while using the collapsible with a keyboard.
566
+
567
+ Runs in React, Vue and web components.