@funstack/ui 0.1.0-alpha.20 → 0.1.0-alpha.21

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 (105) hide show
  1. package/dist/alert-dialog/alert-dialog-root.mjs +2 -1
  2. package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -1
  3. package/dist/avatar/avatar-context.mjs +24 -0
  4. package/dist/avatar/avatar-context.mjs.map +1 -0
  5. package/dist/avatar/avatar-fallback.d.mts +32 -0
  6. package/dist/avatar/avatar-fallback.d.mts.map +1 -0
  7. package/dist/avatar/avatar-fallback.mjs +31 -0
  8. package/dist/avatar/avatar-fallback.mjs.map +1 -0
  9. package/dist/avatar/avatar-image.d.mts +37 -0
  10. package/dist/avatar/avatar-image.d.mts.map +1 -0
  11. package/dist/avatar/avatar-image.mjs +91 -0
  12. package/dist/avatar/avatar-image.mjs.map +1 -0
  13. package/dist/avatar/avatar-root.d.mts +48 -0
  14. package/dist/avatar/avatar-root.d.mts.map +1 -0
  15. package/dist/avatar/avatar-root.mjs +81 -0
  16. package/dist/avatar/avatar-root.mjs.map +1 -0
  17. package/dist/avatar/index.d.mts +24 -0
  18. package/dist/avatar/index.d.mts.map +1 -0
  19. package/dist/avatar/index.mjs +24 -0
  20. package/dist/avatar/index.mjs.map +1 -0
  21. package/dist/dialog/dialog-close.d.mts.map +1 -1
  22. package/dist/dialog/dialog-close.mjs +14 -3
  23. package/dist/dialog/dialog-close.mjs.map +1 -1
  24. package/dist/dialog/dialog-context.mjs +7 -1
  25. package/dist/dialog/dialog-context.mjs.map +1 -1
  26. package/dist/dialog/dialog-popup.d.mts +1 -0
  27. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  28. package/dist/dialog/dialog-popup.mjs +20 -2
  29. package/dist/dialog/dialog-popup.mjs.map +1 -1
  30. package/dist/dialog/dialog-root.mjs +6 -4
  31. package/dist/dialog/dialog-root.mjs.map +1 -1
  32. package/dist/docs/components/avatar.md +354 -0
  33. package/dist/docs/components/drawer.md +622 -0
  34. package/dist/docs/components/otp-field.md +501 -0
  35. package/dist/docs/components/scroll-area.md +294 -0
  36. package/dist/docs/index.md +5 -1
  37. package/dist/docs/roadmap.md +6 -0
  38. package/dist/drawer/drawer-close.d.mts +26 -0
  39. package/dist/drawer/drawer-close.d.mts.map +1 -0
  40. package/dist/drawer/drawer-close.mjs +19 -0
  41. package/dist/drawer/drawer-close.mjs.map +1 -0
  42. package/dist/drawer/drawer-description.d.mts +23 -0
  43. package/dist/drawer/drawer-description.d.mts.map +1 -0
  44. package/dist/drawer/drawer-description.mjs +18 -0
  45. package/dist/drawer/drawer-description.mjs.map +1 -0
  46. package/dist/drawer/drawer-form.d.mts +24 -0
  47. package/dist/drawer/drawer-form.d.mts.map +1 -0
  48. package/dist/drawer/drawer-form.mjs +19 -0
  49. package/dist/drawer/drawer-form.mjs.map +1 -0
  50. package/dist/drawer/drawer-popup.d.mts +77 -0
  51. package/dist/drawer/drawer-popup.d.mts.map +1 -0
  52. package/dist/drawer/drawer-popup.mjs +124 -0
  53. package/dist/drawer/drawer-popup.mjs.map +1 -0
  54. package/dist/drawer/drawer-root.d.mts +31 -0
  55. package/dist/drawer/drawer-root.d.mts.map +1 -0
  56. package/dist/drawer/drawer-root.mjs +23 -0
  57. package/dist/drawer/drawer-root.mjs.map +1 -0
  58. package/dist/drawer/drawer-swipe.d.mts +5 -0
  59. package/dist/drawer/drawer-swipe.d.mts.map +1 -0
  60. package/dist/drawer/drawer-swipe.mjs +193 -0
  61. package/dist/drawer/drawer-swipe.mjs.map +1 -0
  62. package/dist/drawer/drawer-title.d.mts +23 -0
  63. package/dist/drawer/drawer-title.d.mts.map +1 -0
  64. package/dist/drawer/drawer-title.mjs +18 -0
  65. package/dist/drawer/drawer-title.mjs.map +1 -0
  66. package/dist/drawer/drawer-trigger.d.mts +23 -0
  67. package/dist/drawer/drawer-trigger.d.mts.map +1 -0
  68. package/dist/drawer/drawer-trigger.mjs +18 -0
  69. package/dist/drawer/drawer-trigger.mjs.map +1 -0
  70. package/dist/drawer/index.d.mts +34 -0
  71. package/dist/drawer/index.d.mts.map +1 -0
  72. package/dist/drawer/index.mjs +33 -0
  73. package/dist/drawer/index.mjs.map +1 -0
  74. package/dist/index.d.mts +19 -1
  75. package/dist/index.mjs +4 -1
  76. package/dist/internal/swipe-arithmetic.mjs +75 -0
  77. package/dist/internal/swipe-arithmetic.mjs.map +1 -0
  78. package/dist/internal/swipe.mjs +169 -0
  79. package/dist/internal/swipe.mjs.map +1 -0
  80. package/dist/menu/menu-context-trigger.mjs +1 -1
  81. package/dist/menu/menu-popup.mjs +1 -1
  82. package/dist/otp-field/index.d.mts +23 -0
  83. package/dist/otp-field/index.d.mts.map +1 -0
  84. package/dist/otp-field/index.mjs +23 -0
  85. package/dist/otp-field/index.mjs.map +1 -0
  86. package/dist/otp-field/otp-field-context.mjs +13 -0
  87. package/dist/otp-field/otp-field-context.mjs.map +1 -0
  88. package/dist/otp-field/otp-field-filter.d.mts +5 -0
  89. package/dist/otp-field/otp-field-filter.d.mts.map +1 -0
  90. package/dist/otp-field/otp-field-filter.mjs +135 -0
  91. package/dist/otp-field/otp-field-filter.mjs.map +1 -0
  92. package/dist/otp-field/otp-field-input.d.mts +41 -0
  93. package/dist/otp-field/otp-field-input.d.mts.map +1 -0
  94. package/dist/otp-field/otp-field-input.mjs +177 -0
  95. package/dist/otp-field/otp-field-input.mjs.map +1 -0
  96. package/dist/otp-field/otp-field-root.d.mts +143 -0
  97. package/dist/otp-field/otp-field-root.d.mts.map +1 -0
  98. package/dist/otp-field/otp-field-root.mjs +397 -0
  99. package/dist/otp-field/otp-field-root.mjs.map +1 -0
  100. package/dist/otp-field/otp-field-slot.d.mts +52 -0
  101. package/dist/otp-field/otp-field-slot.d.mts.map +1 -0
  102. package/dist/otp-field/otp-field-slot.mjs +67 -0
  103. package/dist/otp-field/otp-field-slot.mjs.map +1 -0
  104. package/package.json +4 -1
  105. package/skills/funstack-ui-knowledge/SKILL.md +5 -1
@@ -0,0 +1,622 @@
1
+ # Drawer
2
+
3
+ A drawer (a sheet) is a `<dialog>` on an edge of the screen: a bottom sheet of filters on a phone, a navigation panel from the side. It is a [Dialog](dialog.md), with one prop that says which edge and one gesture: drag it toward that edge and let go past a quarter of its size, or flick it, and it slides out and closes. The library tracks the pointer and writes where it is; your stylesheet places the drawer and moves it.
4
+
5
+ ```tsx title="DrawerFilters.tsx"
6
+ "use client";
7
+ import { startTransition, useState } from "react";
8
+ import { Drawer } from "@funstack/ui/drawer";
9
+ import { fakeSave } from "./fake-api.js";
10
+
11
+ const brands = [
12
+ "Acme",
13
+ "Borealis",
14
+ "Cobalt",
15
+ "Dune",
16
+ "Ember",
17
+ "Fjord",
18
+ "Granite",
19
+ "Harbor",
20
+ "Iris",
21
+ "Juniper",
22
+ "Kestrel",
23
+ "Lumen",
24
+ ];
25
+
26
+ // A bottom sheet. Drag the grabber, the title or the footer down to close it (mouse, pen or
27
+ // touch): past a quarter of its height or with a flick it slides out and closes, which
28
+ // `onOpenChange` hears as a dismissal; a short drag returns. The list scrolls in its own
29
+ // `overflow-y: auto` body, where a press scrolls and never drags. "Apply" is a Close with an
30
+ // `action`: pending while the fake request runs, then the sheet closes.
31
+ export function DrawerFilters() {
32
+ const [applied, setApplied] = useState<readonly string[]>([]);
33
+ const [draft, setDraft] = useState<readonly string[]>([]);
34
+ const [lastClose, setLastClose] = useState("");
35
+
36
+ return (
37
+ <div className="demo-row">
38
+ <Drawer.Root
39
+ defaultOpen={false}
40
+ openChangeAction={(open) => {
41
+ if (open) setDraft(applied);
42
+ }}
43
+ onOpenChange={(_open, { event }) =>
44
+ setLastClose(event?.type === "pointerup" ? "swiped away" : "dismissed")
45
+ }
46
+ >
47
+ <Drawer.Trigger className="demo-button">Filters ({applied.length})</Drawer.Trigger>
48
+ <Drawer.Popup className="demo-drawer" side="bottom">
49
+ <div className="demo-drawer-grabber" aria-hidden />
50
+ <Drawer.Title>Brands</Drawer.Title>
51
+ <div className="demo-drawer-body">
52
+ {brands.map((brand) => (
53
+ <label key={brand} className="demo-drawer-row">
54
+ <input
55
+ type="checkbox"
56
+ checked={draft.includes(brand)}
57
+ onChange={(event) =>
58
+ setDraft((current) =>
59
+ event.target.checked
60
+ ? [...current, brand]
61
+ : current.filter((b) => b !== brand),
62
+ )
63
+ }
64
+ />
65
+ {brand}
66
+ </label>
67
+ ))}
68
+ </div>
69
+ <div className="demo-drawer-footer">
70
+ <Drawer.Close className="demo-button">Cancel</Drawer.Close>
71
+ <Drawer.Close
72
+ className="demo-button demo-primary"
73
+ action={async () => {
74
+ await fakeSave("filters", { ms: 700 });
75
+ // After an await: wrap the update yourself (React limitation).
76
+ startTransition(() => {
77
+ setApplied(draft);
78
+ setLastClose("applied");
79
+ });
80
+ }}
81
+ >
82
+ {({ pending }) => (
83
+ <>
84
+ {pending && <span className="demo-spinner" aria-hidden />}
85
+ Apply
86
+ </>
87
+ )}
88
+ </Drawer.Close>
89
+ </div>
90
+ </Drawer.Popup>
91
+ </Drawer.Root>
92
+ <output className="demo-readout">
93
+ {applied.length === 0 ? "All brands" : applied.join(", ")}
94
+ {lastClose !== "" && ` (last close: ${lastClose})`}
95
+ </output>
96
+ </div>
97
+ );
98
+ }
99
+ ```
100
+
101
+ ```css title="drawer.css"
102
+ /* Drawer: the Popup is the <dialog> itself, with `data-side`. The library places nothing and
103
+ moves nothing: these rules put it on its edge, slide it in and out, and follow the swipe
104
+ through `--drawer-swipe-x` / `-y` / `-progress`, which the library writes while a pointer
105
+ drags (with `data-swiping`). One `transition` on `translate` is the enter, the exit, the
106
+ release of a swipe and the return of a cancelled one. */
107
+
108
+ .demo-drawer {
109
+ position: fixed;
110
+ margin: 0;
111
+ padding: 0 20px 16px;
112
+ border: 0;
113
+ box-sizing: border-box;
114
+ max-inline-size: none;
115
+ max-block-size: none;
116
+ flex-direction: column;
117
+ gap: 8px;
118
+ background: var(--color-bg);
119
+ color: var(--color-text);
120
+ box-shadow: 0 0 40px rgb(0 0 0 / 0.3);
121
+ transition:
122
+ translate 300ms cubic-bezier(0.32, 0.72, 0, 1),
123
+ display 300ms allow-discrete,
124
+ overlay 300ms allow-discrete;
125
+ }
126
+
127
+ .demo-drawer h2 {
128
+ margin: 0;
129
+ padding: 0;
130
+ border: 0;
131
+ font-size: 1.1rem;
132
+ }
133
+
134
+ /* Placement per side. `:where()` keeps the closed positions at the specificity of
135
+ `.demo-drawer`, below the `:open` rule. */
136
+ .demo-drawer:where([data-side="bottom"]) {
137
+ inset: auto 0 0 0;
138
+ inline-size: 100%;
139
+ max-block-size: min(70dvh, 32rem);
140
+ border-radius: 14px 14px 0 0;
141
+ translate: 0 100%;
142
+ /* The dialog does not scroll: its body does (a bottom drawer's swipe owns the vertical axis
143
+ for touch, so the dialog itself could not be scrolled by touch). */
144
+ overflow: hidden;
145
+ }
146
+
147
+ .demo-drawer:where([data-side="inline-start"]) {
148
+ inset-block: 0;
149
+ inset-inline: 0 auto;
150
+ block-size: 100dvh;
151
+ inline-size: min(18rem, 85vw);
152
+ padding-block-start: 16px;
153
+ /* A side drawer scrolls in the Popup itself; its swipe is horizontal. */
154
+ overflow-y: auto;
155
+ }
156
+
157
+ .demo-drawer:where([data-side="inline-start"]:dir(ltr)) {
158
+ translate: -100% 0;
159
+ }
160
+
161
+ .demo-drawer:where([data-side="inline-start"]:dir(rtl)) {
162
+ translate: 100% 0;
163
+ }
164
+
165
+ /* Open: rest at the edge, moved by the swipe while a pointer drags. `display` only here: a
166
+ closed <dialog> keeps the browser's `display: none`. */
167
+ .demo-drawer:open {
168
+ display: flex;
169
+ translate: var(--drawer-swipe-x, 0px) var(--drawer-swipe-y, 0px);
170
+ }
171
+
172
+ @starting-style {
173
+ .demo-drawer[data-side="bottom"]:open {
174
+ translate: 0 100%;
175
+ }
176
+ .demo-drawer[data-side="inline-start"]:dir(ltr):open {
177
+ translate: -100% 0;
178
+ }
179
+ .demo-drawer[data-side="inline-start"]:dir(rtl):open {
180
+ translate: 100% 0;
181
+ }
182
+ }
183
+
184
+ /* The backdrop fades with the drag: `::backdrop` inherits the custom properties. */
185
+ .demo-drawer::backdrop {
186
+ background: rgb(0 0 0 / 0.45);
187
+ opacity: 0;
188
+ transition:
189
+ opacity 300ms,
190
+ display 300ms allow-discrete,
191
+ overlay 300ms allow-discrete;
192
+ }
193
+
194
+ .demo-drawer:open::backdrop {
195
+ opacity: calc(1 - var(--drawer-swipe-progress, 0));
196
+ }
197
+
198
+ @starting-style {
199
+ .demo-drawer:open::backdrop {
200
+ opacity: 0;
201
+ }
202
+ }
203
+
204
+ /* The finger leads while dragging: no transition, on the drawer and its backdrop. */
205
+ .demo-drawer[data-swiping],
206
+ .demo-drawer[data-swiping]::backdrop {
207
+ transition: none;
208
+ }
209
+
210
+ /* Reduced motion: no slide. A swipe still follows the pointer (direct manipulation); its
211
+ release closes at once or snaps back. */
212
+ @media (prefers-reduced-motion: reduce) {
213
+ .demo-drawer,
214
+ .demo-drawer::backdrop {
215
+ transition: none;
216
+ }
217
+ }
218
+
219
+ /* CSS-only scroll lock while a modal drawer is open (Dialog's recipe). */
220
+ html:has(.demo-drawer:modal) {
221
+ overflow: hidden;
222
+ }
223
+
224
+ .demo-drawer-grabber {
225
+ align-self: center;
226
+ inline-size: 40px;
227
+ block-size: 5px;
228
+ margin-block: 10px 4px;
229
+ border-radius: 3px;
230
+ background: var(--color-border);
231
+ }
232
+
233
+ /* The body scrolls; a press in it is the scroller's, for every pointer type. */
234
+ .demo-drawer-body {
235
+ overflow-y: auto;
236
+ overscroll-behavior: contain;
237
+ min-block-size: 0;
238
+ flex: 1;
239
+ display: grid;
240
+ gap: 2px;
241
+ }
242
+
243
+ .demo-drawer-row {
244
+ display: flex;
245
+ align-items: center;
246
+ gap: 10px;
247
+ padding: 8px 4px;
248
+ }
249
+
250
+ .demo-drawer-footer {
251
+ display: flex;
252
+ justify-content: flex-end;
253
+ gap: 8px;
254
+ padding-block-start: 8px;
255
+ border-block-start: 1px solid var(--color-border);
256
+ /* A drag that starts here moves the drawer instead of selecting the buttons' text. */
257
+ user-select: none;
258
+ }
259
+
260
+ .demo-drawer-nav {
261
+ list-style: none;
262
+ margin: 0;
263
+ padding: 0;
264
+ flex: 1;
265
+ }
266
+
267
+ .demo-drawer-nav a {
268
+ display: block;
269
+ padding: 10px 8px;
270
+ border-radius: 6px;
271
+ color: inherit;
272
+ text-decoration: none;
273
+ }
274
+
275
+ .demo-drawer-nav a:hover {
276
+ background: var(--color-bg-secondary, rgb(127 127 127 / 0.12));
277
+ }
278
+ ```
279
+
280
+ ## Anatomy
281
+
282
+ ```tsx
283
+ import { Drawer } from "@funstack/ui/drawer";
284
+
285
+ <Drawer.Root> {/* no DOM: ids, mode, state */}
286
+ <Drawer.Trigger>Filters</Drawer.Trigger>
287
+ <Drawer.Popup side="bottom"> {/* dialog[data-side=bottom] */}
288
+ <div className="grabber" aria-hidden /> {/* decoration, yours */}
289
+ <Drawer.Title>Filters</Drawer.Title>
290
+ <div className="drawer-body">…</div> {/* scrolls; a press here never drags */}
291
+ <Drawer.Close>Done</Drawer.Close>
292
+ </Drawer.Popup>
293
+ </Drawer.Root>
294
+ ```
295
+
296
+ - **Every part is a Dialog part.** Root, Trigger, Popup, Title, Description, Close and Form run the code of the Dialog parts of the same name. Everything the [Dialog](dialog.md) page says applies unless this page says otherwise: the two modes, focus and focus return, Escape, `keepMounted`, `initialFocus`, `transition`, `render`, the Form. A `Dialog.Close` inside a `Drawer.Popup` closes the drawer, and an [AlertDialog](alert-dialog.md) nested in a drawer is its confirm.
297
+ - **What it adds.** `side` (the edge, rendered as `data-side`), `swipeDismiss` (on by default), and `lightDismiss` on by default for a modal drawer.
298
+ - **What it does not.** No handle, backdrop, portal or viewport part (a grabber is a `<div aria-hidden>`: the whole drawer is the grab area; the backdrop is `::backdrop`), no snap points, no swipe from the screen edge to open, no scaling of the page behind it. The library ships no CSS and writes no inset, size or transform.
299
+ - **Always render a Close.** It is the way to close the drawer before hydration on a phone, and the alternative to the swipe that WCAG 2.5.1 asks for. Development warns when a drawer with the swipe has shown without one.
300
+
301
+ ## How it works
302
+
303
+ | | Drawer |
304
+ | - | - |
305
+ | Edge | `side`: `"top"`, `"bottom"` (default), `"left"`, `"right"`, `"inline-start"`, `"inline-end"`; rendered as `data-side` in every mode and in the server HTML. Your CSS places the drawer from it |
306
+ | Swipe | Mouse, pen or touch, one pointer, after hydration. A drag toward the edge sets `data-swiping` and the inline `--drawer-swipe-x`, `--drawer-swipe-y`, `--drawer-swipe-progress`; your `translate` follows them |
307
+ | Release | Past 25% of the drawer's extent, or faster than 0.5 px/ms toward the edge: the library writes the full extent, waits for your transition to carry the drawer off, then calls `requestClose()`. Moving back at the release, or short of the threshold: the properties are removed and your transition brings it back |
308
+ | The close | A dismissal, a fact: `onOpenChange(false, { reason: "dismiss", event: <the pointerup>, returnValue: "" })`. Never `openChangeAction`, never pending, never a view transition |
309
+ | Scroll | A press inside a scroll container along the drawer's axis scrolls it and never drags. The Popup renders an inline `touch-action` that leaves that axis to the gesture |
310
+ | Backdrop press | Closes a modal drawer (`lightDismiss` defaults to the Root's `modal`), a dismissal; a non-modal drawer stays open |
311
+ | Escape, Close, Form | Dialog's |
312
+ | Modes | Dialog's: JS-free without open-state props on the Root, library mode with any. The swipe works in both after hydration |
313
+
314
+ ## The swipe
315
+
316
+ A press is only recorded: no capture, no `preventDefault()`, so a tap, a click and a text field are untouched. The press becomes a drag when the pointer has moved 6 px, more along the drawer's axis than across it and toward the edge; a first move in another direction drops it for good. From then on the pointer is captured on the dialog, and the offset (never below 0) is written on every move, with no React render. The numbers are fixed: 25% of the extent (the distance that takes the drawer fully off its edge, measured when the drag starts), 0.5 px/ms measured over the last 100 ms, and a return when the pointer was moving back faster than 0.1 px/ms.
317
+
318
+ | A press that never drags | Why |
319
+ | - | - |
320
+ | On the `::backdrop` | It is a press outside (light dismiss) |
321
+ | Inside a nested `<dialog>` or an open popover | The press is that layer's |
322
+ | On an `input`, `textarea`, `select` or `[contenteditable]` | Text entry and range controls keep their pointer |
323
+ | Inside a scroll container along the drawer's axis | By computed `overflow` (`auto` or `scroll`), whether or not it overflows now: the scroller's (see below) |
324
+ | Its `pointerdown` was `preventDefault()`-ed | Your opt-out, read when the drag would start, so a React handler counts. It also stops a mouse press from focusing or selecting there: use it on non-focusable regions |
325
+ | Another element captured the pointer | A slider thumb, a map, a canvas |
326
+ | While the drawer slides out after a release | One gesture at a time |
327
+
328
+ A mouse drag moves the drawer and does not select text: a selection the press made is removed while it drags. The `click` that follows a mouse drag lands on the dialog, so the button the drag started on is not activated. `pointercancel`, a lost capture, a second pointer's press, or the dialog closing for another reason (Escape, a Form settling) ends the drag: the drawer returns, or closes with that other cause.
329
+
330
+ > **The drag needs a CSS transition on translate**
331
+ >
332
+ > The release is your `transition` on `translate`: it carries the drawer off its edge (the library waits for it, in Firefox too, which has no CSS exit for a `<dialog>`) and brings a cancelled drag back. A drawer with only a `transition` prop (a view transition) and no CSS transition jumps at the release: a swipe never starts a view transition. Both may be set.
333
+
334
+ ## Scroll inside the drawer
335
+
336
+ A press inside a scroll container along the drawer's axis is that container's, for every pointer type: the body scrolls; the header, the grabber, the footer and the padding drag. The Popup renders `touch-action: pan-x pinch-zoom` (top and bottom) or `pan-y pinch-zoom` (the side drawers), so a touch drag on the drawer's axis reaches the gesture instead of panning the page; a `style` of yours overrides it.
337
+
338
+ - **A top or bottom drawer scrolls in a child.** Give the body `overflow-y: auto` and the dialog `overflow: hidden`. The dialog itself cannot be scrolled by touch while the swipe owns the vertical axis; development warns when a top or bottom drawer is its own scroller and its content overflows.
339
+ - **A side drawer scrolls in the Popup.** Its content scrolls vertically, natively; a horizontal drag is the swipe. Note that `overflow-y: auto` on a child also makes it a horizontal scroll container (CSS computes the other axis to `auto`), so a press in a scrolling child of a side drawer does not drag. To drag from such a list, give it `overflow-x: hidden` and `touch-action: pan-y pinch-zoom` (as in the starter stylesheet). Development warns once when a press in a side drawer is refused by such a list.
340
+ - Add `overscroll-behavior: contain` on the scrolling body so a scroll that reaches its end does not move the page, and lock the page's scroll with the CSS recipe in the example (`html:has(.drawer:modal) { overflow: hidden }`).
341
+ - Pulling a list that is scrolled to its top to drag the sheet down (the phone idiom) is not in this version.
342
+
343
+ ## Props
344
+
345
+ ### `Drawer.Root`
346
+
347
+ | Prop | Type | Default | Description |
348
+ | - | - | - | - |
349
+ | `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Selects library mode. Pass `onOpenChange` too: Escape, a backdrop press and a swipe close the drawer without asking (development warns). |
350
+ | `defaultOpen` | `boolean` | – | Initial open state in uncontrolled library mode. `defaultOpen={false}` selects library mode without an action. |
351
+ | `openChangeAction` | `ChangeAction<boolean, DrawerOpenChangeDetails>` | – | Requests only: the Trigger (`true`), a Close, a Form submit or settle, a foreign close command (`false`, with `details.returnValue` the part's `value`). Awaited; the drawer opens or closes when it resolves; a controlled parent that keeps `open` vetoes a close. Never called for a swipe, Escape or a backdrop press. Runs in the Root's transition; may be a Server Function; rejections reach the nearest Error Boundary above the Root. Selects library mode. |
352
+ | `onOpenChange` | `UrgentChangeHandler<boolean, DrawerOpenChangeDetails>` | – | Facts only: a swipe released past the threshold, Escape, a backdrop press, Android back, a script `close()` / `requestClose()`. Always `false`, with `reason: "dismiss"` and `returnValue` as the browser left it (`""`). A swipe's `details.event` is its `pointerup`: tell it from Escape with `details.event?.type`. Called synchronously in the `close` event, outside any transition. In controlled mode set state directly here (`onOpenChange={setOpen}`); a parent that keeps `open={true}` gets the drawer shown again at once, and your CSS enter slides it back in. Selects library mode. |
353
+ | `modal` | `boolean` | `true` | `showModal()` (top layer, backdrop, inert page, Escape) or `show()`: a non-modal drawer is a side panel next to a page that stays usable. A non-modal drawer needs JavaScript to open (there is no `show` command). |
354
+ | `children` | `ReactNode \| ((state: DrawerRootState) => ReactNode)` | – | The parts. The function form receives the optimistic state and must not suspend. |
355
+
356
+ - **State**: `DrawerRootState` is `{ open, pending, modal }` (Dialog's).
357
+ - **Owned**: nothing rendered: the Root has no element.
358
+
359
+ ### `Drawer.Trigger`
360
+
361
+ `Dialog.Trigger`, unchanged: `<button command="show-modal">` in JS-free mode, a request through the Root with `data-open` and `data-pending` in library mode. Props: `disabled`, `className`, `style`, `children` (functions of `DrawerTriggerState`, `{ open, pending, disabled }`), `render`. See [Dialog.Trigger](dialog.md#props).
362
+
363
+ ### `Drawer.Popup`
364
+
365
+ | Prop | Type | Default | Description |
366
+ | - | - | - | - |
367
+ | `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end"` | `"bottom"` | The edge the drawer is attached to. Rendered as `data-side` (a prop echo, also in the server HTML) and `state.side`; the swipe goes toward it. `inline-start` / `inline-end` follow the drawer's own `direction` (read at the press). The library places nothing: style `[data-side]`. |
368
+ | `swipeDismiss` | `boolean` | `true` | Let the user drag the drawer toward its edge to close it (mouse, pen, touch; after hydration). The close is a dismissal: `onOpenChange`, never `openChangeAction`. While dragging the drawer has `data-swiping` and the `--drawer-swipe-*` properties. Also renders the inline `touch-action`. `false`: a drawer only its buttons, Escape and the backdrop close. |
369
+ | `lightDismiss` | `boolean` | `` the Root's `modal` `` | Close on a press outside the drawer (the `::backdrop` of a modal one): Dialog's JS `pointerdown` and `click` baseline, or native `closedby="any"` with `experimental_closedBy`. On for a modal drawer, off for a non-modal one (a side panel must survive clicks on the page). Before hydration, without the flag, a backdrop press does nothing. |
370
+ | `experimental_closedBy` | `boolean` | `false` | As on `Dialog.Popup`: renders `closedby` (`"any"` with `lightDismiss`, else `"closerequest"`) and skips the JS dismiss listeners where the browser implements it. See [Experimental features](../concepts/experimental.md). |
371
+ | `initialFocus` | `RefObject<HTMLElement \| null> \| string` | – | As on `Dialog.Popup`: the element to focus on open. |
372
+ | `keepMounted` | `boolean` | `false` | Library mode: keep the children in `<Activity mode="hidden">` while closed instead of unmounting them. Ignored in JS-free mode (always mounted). |
373
+ | `transition` | `ViewTransitionClass` | – | Library mode only. Forwarded to the `<ViewTransition>` around the dialog: animates the open and every library-driven close (Close, Form, a controlled close). A swipe, Escape and a backdrop press animate with CSS only. Types `fsui-drawer`, `fsui-drawer-open`, `fsui-drawer-close`. |
374
+ | `className` | `string \| ((state: DrawerPopupState) => string \| undefined)` | – | A class name, or a function of the part's state. |
375
+ | `style` | `CSSProperties \| ((state: DrawerPopupState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
376
+ | `children` | `ReactNode \| ((state: DrawerPopupState) => ReactNode)` | – | Content, or a function of the part's state. |
377
+ | `render` | `ReactElement \| ((props, state: DrawerPopupState) => ReactNode)` | – | Replace the default \<dialog> (element form) or take over rendering (function form). |
378
+
379
+ - **State**: `DrawerPopupState` is `{ open, modal, side }`; `open` is committed (`false` in JS-free mode; `:open` is the DOM truth). A drag is not in the state: it is `data-swiping` and the custom properties.
380
+ - **Owned**: Dialog.Popup's (`id`, `open`, `closedby`, `data-modal`, `suppressHydrationWarning`; `aria-labelledby` and `aria-describedby` merged with yours), `data-side`, `data-swiping`. The inline `touch-action` is merged under your `style`. The `--drawer-swipe-*` properties are written through the DOM and are not part of the rendered `style`: do not set them yourself.
381
+
382
+ `role`, `onCancel` and the other `<dialog>` props pass through.
383
+
384
+ ### `Drawer.Close`
385
+
386
+ `Dialog.Close`, unchanged: `<button command="request-close">` in JS-free mode, a close request through the Root in library mode; with an `action`, the action runs first in the button's own transition (`data-pending`) and a rejection leaves the drawer open. Props: `action`, `whilePending`, `value`, `disabled`, `className`, `style`, `children` (functions of `DrawerCloseState`, `{ pending, disabled }`), `render`. See [Dialog.Close](dialog.md#props).
387
+
388
+ ### `Drawer.Form`, `Drawer.Title`, `Drawer.Description`
389
+
390
+ `Dialog.Form`, `Dialog.Title` and `Dialog.Description`, unchanged: the same props, state types (`DrawerFormState` is `{ pending }`; Title and Description get the Popup's `{ open, modal }`) and owned keys. See [the Dialog props](dialog.md#props).
391
+
392
+ ## Data attributes and custom properties
393
+
394
+ | Hook | On | Meaning |
395
+ | - | - | - |
396
+ | `:open`, `:modal`, `::backdrop` | Popup | As on a Dialog. |
397
+ | `data-side` | Popup | The `side` prop, in every mode and in the server HTML. Never flipped. |
398
+ | `data-modal` | Popup | The Root's `modal` is `true`. |
399
+ | `data-swiping` | Popup | A pointer is dragging the drawer, from the drag's start to its release. Written by the gesture, never server-rendered, not in the state. Turn your transitions off under it. |
400
+ | `--drawer-swipe-x`, `--drawer-swipe-y` | Popup (inline) | The offset as a physical vector in px: `0px 120px` for a bottom drawer pulled down 120 px, `-80px 0px` for a left one. Absent when nothing has moved the drawer; set to the full extent during a release's slide; removed by the close or the return. |
401
+ | `--drawer-swipe-progress` | Popup (inline) | Offset / extent, from 0 to 1. `::backdrop` inherits it. |
402
+ | `data-open`, `data-pending` | Trigger | Library mode, as on a Dialog. |
403
+ | `data-pending` | Close | Its `action` is in flight. |
404
+ | `data-disabled` | Trigger, Close | The `disabled` prop. |
405
+
406
+ ## Keyboard and ARIA
407
+
408
+ A drawer is a dialog: the role, the name (the Title), the description, the focus moves and the keys are [Dialog's](dialog.md#keyboard-and-aria). Escape closes a modal drawer (and, through the library, a non-modal one). The swipe is a path-based gesture, so it always has an alternative: Escape, the backdrop of a modal drawer, and the Close part. A grabber is decoration (`aria-hidden`), not a button: no key could perform its action.
409
+
410
+ ## Transition types
411
+
412
+ Concept: [Transitions & ViewTransition](../concepts/transitions.md#transition-types)
413
+
414
+ Library mode tags an open with `fsui-drawer` plus `fsui-drawer-open`, a Close or Form close with `fsui-drawer` plus `fsui-drawer-close`. Not Dialog's types: a drawer slides where a dialog fades, so a page-level `:active-view-transition-type()` rule can tell them apart. A swipe, Escape and a backdrop press are facts and carry none.
415
+
416
+ ## Optimistic and pending
417
+
418
+ Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
419
+
420
+ As a Dialog's: the Trigger is pending while an open is in flight, a Close with an `action` is pending while it runs. A swipe is never pending: it is a fact, reported the moment the browser closes the dialog, and it supersedes a close a part asked for. A Close action that is still running keeps running; its close is then a no-op.
421
+
422
+ ### Walkthrough: a swipe
423
+
424
+ 1. Press on the header and drag down: `data-swiping` appears and `--drawer-swipe-y` follows the pointer; your `translate` moves the drawer and your backdrop fades with `--drawer-swipe-progress`.
425
+ 2. Release at 40%: `data-swiping` goes, the properties jump to the full extent, and your transition slides the drawer off its edge.
426
+ 3. When that transition has finished (at once with `transition: none`), the library calls `requestClose()`. Your `onCancel` sees it: preventing it keeps the drawer open, and it slides back. Otherwise the dialog closes, focus returns to the Trigger, and `onOpenChange(false, { reason: "dismiss", event })` is called with the `pointerup`.
427
+
428
+ ## Suspense
429
+
430
+ Concept: [Suspense](../concepts/suspense.md)
431
+
432
+ As a Dialog's: content that suspends holds the open, the Trigger is pending, and the drawer slides in complete. A child that re-renders or suspends while a pointer drags changes nothing: the gesture holds no React state.
433
+
434
+ ## Browser-owned state
435
+
436
+ Concept: [Browser-owned state](../concepts/browser-owned-state.md)
437
+
438
+ JS-free mode: the browser owns everything, and the swipe closes the dialog with `requestClose()` after hydration. Library mode: the Trigger, Close and Form are requests (`openChangeAction`); a swipe, Escape and a backdrop press are the browser's facts (`onOpenChange`). Pass the same setter to both props of a controlled Root.
439
+
440
+ ## Before hydration
441
+
442
+ Concept: [Server Components](../concepts/server-components.md#before-hydration)
443
+
444
+ JS-free mode: the Trigger (`command="show-modal"`), the Close (`command="request-close"`), Escape, the content, `data-side` and the `touch-action` are in the server HTML, and the CSS enter and exit run; it works from a Server Component. Before hydration a backdrop press does nothing (without `experimental_closedBy`) and a swipe does nothing (the drawer's axis does not pan the page either): the Close is what closes it on a phone. After hydration the swipe works in JS-free mode too.
445
+
446
+ ```tsx title="DrawerNavigation.tsx"
447
+ import { Drawer } from "@funstack/ui/drawer";
448
+
449
+ const pages = [
450
+ ["Dialog", "/components/dialog"],
451
+ ["AlertDialog", "/components/alert-dialog"],
452
+ ["Drawer", "/components/drawer"],
453
+ ["Popover", "/components/popover"],
454
+ ["Menu", "/components/menu"],
455
+ ["Tooltip", "/components/tooltip"],
456
+ ["HoverCard", "/components/hover-card"],
457
+ ["Toast", "/components/toast"],
458
+ ] as const;
459
+
460
+ // A side navigation drawer, written as a Server Component: the Root has no open-state props,
461
+ // so the Drawer is JS-free. The Trigger and the Close are Invoker Commands, the content and
462
+ // `data-side` are in the server HTML, CSS slides it in and out, and Escape closes it before
463
+ // hydration. After hydration a drag toward its edge closes it too (no callback exists in this
464
+ // mode). `inline-start` follows the page's direction: on the left here, on the right in a
465
+ // right-to-left page. The Popup itself scrolls: a side drawer's swipe is horizontal.
466
+ export function DrawerNavigation() {
467
+ return (
468
+ <div className="demo-row">
469
+ <Drawer.Root>
470
+ <Drawer.Trigger className="demo-button">Menu</Drawer.Trigger>
471
+ <Drawer.Popup className="demo-drawer" side="inline-start">
472
+ <Drawer.Title>Overlays</Drawer.Title>
473
+ <nav aria-label="Overlay components">
474
+ <ul className="demo-drawer-nav">
475
+ {pages.map(([label, href]) => (
476
+ <li key={href}>
477
+ <a href={href}>{label}</a>
478
+ </li>
479
+ ))}
480
+ </ul>
481
+ </nav>
482
+ <Drawer.Close className="demo-button">Close</Drawer.Close>
483
+ </Drawer.Popup>
484
+ </Drawer.Root>
485
+ </div>
486
+ );
487
+ }
488
+ ```
489
+
490
+ `drawer.css`: the same file as above.
491
+
492
+ This navigation drawer is a Server Component, on `side="inline-start"`: on the left in a left-to-right page, on the right in a right-to-left one, with no script.
493
+
494
+ ## CSS recipes
495
+
496
+ ### The starter stylesheet
497
+
498
+ One `transition` on `translate` is the enter, the exit, the release of a swipe and the return of a cancelled one. Closed positions go in `:where()` so that the `:open` rule wins whatever the side selector's specificity:
499
+
500
+ ```css
501
+ .drawer {
502
+ position: fixed; margin: 0; border: 0;
503
+ max-inline-size: none; max-block-size: none;
504
+ transition: translate 300ms cubic-bezier(.32, .72, 0, 1),
505
+ display 300ms allow-discrete, overlay 300ms allow-discrete;
506
+ }
507
+ .drawer:where([data-side="bottom"]) {
508
+ inset: auto 0 0 0; inline-size: 100%; max-block-size: 90dvh;
509
+ overflow: hidden; /* scroll in a child */
510
+ translate: 0 100%; /* closed: off its edge */
511
+ }
512
+ .drawer:where([data-side="inline-end"]) {
513
+ inset-block: 0; inset-inline: auto 0; block-size: 100dvh; inline-size: min(24rem, 90vw);
514
+ }
515
+ .drawer:where([data-side="inline-end"]:dir(ltr)) { translate: 100% 0; }
516
+ .drawer:where([data-side="inline-end"]:dir(rtl)) { translate: -100% 0; }
517
+
518
+ /* Open: at the edge, moved by the swipe. */
519
+ .drawer:open { translate: var(--drawer-swipe-x, 0px) var(--drawer-swipe-y, 0px); }
520
+ @starting-style {
521
+ .drawer[data-side="bottom"]:open { translate: 0 100%; }
522
+ /* … one line per side you use */
523
+ }
524
+
525
+ /* While a pointer drags, the pointer leads. */
526
+ .drawer[data-swiping], .drawer[data-swiping]::backdrop { transition: none; }
527
+
528
+ /* A side drawer's vertical list that the swipe may start in (see Scroll inside the drawer). */
529
+ .drawer:where(:not([data-side="top"], [data-side="bottom"])) .drawer-list {
530
+ overflow-x: hidden; overflow-y: auto; touch-action: pan-y pinch-zoom;
531
+ }
532
+ ```
533
+
534
+ ### The backdrop follows the drag
535
+
536
+ `::backdrop` inherits custom properties from its dialog in every engine, so the backdrop can fade as the drawer goes:
537
+
538
+ ```css
539
+ .drawer::backdrop {
540
+ background: rgb(0 0 0 / .45);
541
+ opacity: 0;
542
+ transition: opacity 300ms, display 300ms allow-discrete, overlay 300ms allow-discrete;
543
+ }
544
+ .drawer:open::backdrop { opacity: calc(1 - var(--drawer-swipe-progress, 0)); }
545
+ @starting-style { .drawer:open::backdrop { opacity: 0; } }
546
+ ```
547
+
548
+ ### Using the swipe variables
549
+
550
+ The two physical components serve every side with one rule. Anything else can read them too, inside the drawer:
551
+
552
+ ```css
553
+ /* Rounder corners as the sheet is pulled down. */
554
+ .drawer[data-side="bottom"] {
555
+ border-radius: calc(12px + 12px * var(--drawer-swipe-progress, 0))
556
+ calc(12px + 12px * var(--drawer-swipe-progress, 0)) 0 0;
557
+ }
558
+
559
+ /* A slight resistance: the drawer moves at 80% of the pointer. */
560
+ .drawer.stiff[data-swiping] {
561
+ translate: calc(var(--drawer-swipe-x, 0px) * .8) calc(var(--drawer-swipe-y, 0px) * .8);
562
+ }
563
+ ```
564
+
565
+ Do not set the properties yourself: the library writes and removes them. Scale them only under `[data-swiping]`: the release writes the full extent, which an always-scaled rule would stop short of the edge. Scaling changes only how far the drawer moves during the drag, not where the release decides: the threshold is measured on the pointer.
566
+
567
+ ### Reduced motion
568
+
569
+ The library makes no `matchMedia` check. The drag is direct manipulation and stays; turn off the slides, and the release closes the drawer at once (there is nothing to wait for) or puts it back in one frame:
570
+
571
+ ```css
572
+ @media (prefers-reduced-motion: reduce) {
573
+ .drawer, .drawer::backdrop { transition: none; }
574
+ }
575
+ ```
576
+
577
+ ### Scaling the page behind it
578
+
579
+ Not a feature: the element is yours, outside the component. The static effect is one rule; it does not follow the finger (the properties are on the dialog, not on its ancestors).
580
+
581
+ ```css
582
+ .app { transition: scale 300ms, border-radius 300ms; transform-origin: top; }
583
+ html:has(.drawer:modal) .app { scale: .96; border-radius: 12px; }
584
+
585
+ /* A drawer that steps back while a nested one is open (the inner one is in the top layer). */
586
+ .drawer:has(dialog:open) { scale: .96; }
587
+ ```
588
+
589
+ ## Recipes
590
+
591
+ ### Tell a swipe from Escape
592
+
593
+ ```tsx
594
+ <Drawer.Root
595
+ defaultOpen={false}
596
+ onOpenChange={(_open, { event }) => {
597
+ track(event?.type === "pointerup" ? "drawer swiped" : "drawer dismissed");
598
+ }}
599
+ >
600
+ ```
601
+
602
+ ### A side panel that only its buttons close
603
+
604
+ ```tsx
605
+ <Drawer.Root defaultOpen={false} modal={false}>
606
+ <Drawer.Trigger>Inspector</Drawer.Trigger>
607
+ <Drawer.Popup side="inline-end" swipeDismiss={false}> {/* no swipe, no light dismiss */}
608
+ <Drawer.Title>Inspector</Drawer.Title>
609
+ …
610
+ <Drawer.Close>Close</Drawer.Close>
611
+ </Drawer.Popup>
612
+ </Drawer.Root>
613
+ ```
614
+
615
+ ### Opt a region out of the swipe
616
+
617
+ ```tsx
618
+ {/* A map or a canvas with its own drag: prevent the press. */}
619
+ <div className="map" onPointerDown={(event) => event.preventDefault()} />
620
+ ```
621
+
622
+ Preventing the `pointerdown` also cancels the compatibility `mousedown`: a mouse press in that region no longer moves focus or starts a text selection. Use it on regions that are not focusable and hold no text to select (a map, a canvas, a custom slider that handles its own focus), not on a form or a list of links.