@human-kit/ui 1.0.0-beta.0 → 1.0.0-beta.2

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 (159) hide show
  1. package/README.md +2 -0
  2. package/dist/FOCUS_STATE_CONTRACT.md +1 -0
  3. package/dist/accordion/root/accordion-root.svelte +15 -3
  4. package/dist/accordion/root/context.svelte.js +4 -4
  5. package/dist/accordion/types.d.ts +9 -2
  6. package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +6 -0
  7. package/dist/calendar/root/context.svelte.js +8 -2
  8. package/dist/checkbox/root/checkbox-root.svelte +28 -11
  9. package/dist/checkbox/root/checkbox-root.svelte.d.ts +13 -0
  10. package/dist/clock/root/create-time-selection-state.svelte.d.ts +5 -0
  11. package/dist/clock/root/create-time-selection-state.svelte.js +113 -10
  12. package/dist/clock/root/wheel-options.d.ts +7 -3
  13. package/dist/clock/root/wheel-options.js +7 -15
  14. package/dist/clock/wheel-column/clock-wheel-column.svelte +10 -2
  15. package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +2 -1
  16. package/dist/collapsible/root/collapsible-root.svelte +9 -4
  17. package/dist/collapsible/types.d.ts +9 -0
  18. package/dist/combobox/input/combobox-input.svelte +12 -1
  19. package/dist/combobox/list/combobox-listbox.svelte +93 -1
  20. package/dist/combobox/list/combobox-listbox.svelte.d.ts +20 -0
  21. package/dist/combobox/root/combobox.svelte +118 -45
  22. package/dist/combobox/root/combobox.svelte.d.ts +11 -0
  23. package/dist/combobox/root/context.d.ts +12 -0
  24. package/dist/combobox/status/README.md +2 -2
  25. package/dist/combobox/tag-remove/combobox-tag-remove.svelte +14 -2
  26. package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +7 -0
  27. package/dist/combobox/tags/combobox-tags.svelte +5 -2
  28. package/dist/combobox/tags/combobox-tags.svelte.d.ts +2 -0
  29. package/dist/combobox/trigger/combobox-trigger.svelte +4 -1
  30. package/dist/datepicker/README.md +3 -2
  31. package/dist/datepicker/root/date-picker-root.svelte +38 -2
  32. package/dist/datepicker/root/date-picker-root.svelte.d.ts +2 -0
  33. package/dist/datepicker/root/draft-evaluation.d.ts +7 -0
  34. package/dist/datepicker/root/draft-evaluation.js +2 -2
  35. package/dist/daterangepicker/root/date-range-picker-root.svelte +19 -1
  36. package/dist/daterangepicker/root/date-range-picker-root.svelte.d.ts +2 -0
  37. package/dist/dialog/README.md +9 -1
  38. package/dist/dialog/close/dialog-close.svelte +57 -0
  39. package/dist/dialog/close/dialog-close.svelte.d.ts +19 -0
  40. package/dist/dialog/content/dialog-content.svelte +2 -0
  41. package/dist/dialog/description/dialog-description.svelte +46 -0
  42. package/dist/dialog/description/dialog-description.svelte.d.ts +20 -0
  43. package/dist/dialog/index.d.ts +9 -0
  44. package/dist/dialog/index.js +3 -0
  45. package/dist/dialog/index.parts.d.ts +3 -0
  46. package/dist/dialog/index.parts.js +3 -0
  47. package/dist/dialog/root/context.d.ts +8 -0
  48. package/dist/dialog/root/dialog-root.svelte +58 -16
  49. package/dist/dialog/root/dialog-root.svelte.d.ts +10 -3
  50. package/dist/dialog/root/dialog-stack.d.ts +6 -22
  51. package/dist/dialog/root/dialog-stack.js +4 -33
  52. package/dist/dialog/title/dialog-title.svelte +43 -0
  53. package/dist/dialog/title/dialog-title.svelte.d.ts +21 -0
  54. package/dist/drawer/README.md +111 -0
  55. package/dist/drawer/body/drawer-body.svelte +47 -0
  56. package/dist/drawer/body/drawer-body.svelte.d.ts +32 -0
  57. package/dist/drawer/close/drawer-close.svelte +52 -0
  58. package/dist/drawer/close/drawer-close.svelte.d.ts +20 -0
  59. package/dist/drawer/content/drawer-content.svelte +597 -0
  60. package/dist/drawer/content/drawer-content.svelte.d.ts +28 -0
  61. package/dist/drawer/description/drawer-description.svelte +40 -0
  62. package/dist/drawer/description/drawer-description.svelte.d.ts +20 -0
  63. package/dist/drawer/indent/drawer-indent-background.svelte +36 -0
  64. package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +17 -0
  65. package/dist/drawer/indent/drawer-indent.svelte +59 -0
  66. package/dist/drawer/indent/drawer-indent.svelte.d.ts +32 -0
  67. package/dist/drawer/index.d.ts +49 -0
  68. package/dist/drawer/index.js +25 -0
  69. package/dist/drawer/index.parts.d.ts +14 -0
  70. package/dist/drawer/index.parts.js +15 -0
  71. package/dist/drawer/overlay/drawer-overlay.svelte +67 -0
  72. package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +12 -0
  73. package/dist/drawer/portal/drawer-portal.svelte +57 -0
  74. package/dist/drawer/portal/drawer-portal.svelte.d.ts +13 -0
  75. package/dist/drawer/root/context.d.ts +81 -0
  76. package/dist/drawer/root/context.js +20 -0
  77. package/dist/drawer/root/drawer-root.svelte +333 -0
  78. package/dist/drawer/root/drawer-root.svelte.d.ts +77 -0
  79. package/dist/drawer/root/drawer-stack.svelte.d.ts +73 -0
  80. package/dist/drawer/root/drawer-stack.svelte.js +113 -0
  81. package/dist/drawer/root/handle.svelte.d.ts +39 -0
  82. package/dist/drawer/root/handle.svelte.js +64 -0
  83. package/dist/drawer/root/keyboard-context.d.ts +13 -0
  84. package/dist/drawer/root/keyboard-context.js +8 -0
  85. package/dist/drawer/root/presence-context.d.ts +22 -0
  86. package/dist/drawer/root/presence-context.js +8 -0
  87. package/dist/drawer/root/snap-points.d.ts +68 -0
  88. package/dist/drawer/root/snap-points.js +120 -0
  89. package/dist/drawer/root/starting-style.svelte.d.ts +18 -0
  90. package/dist/drawer/root/starting-style.svelte.js +38 -0
  91. package/dist/drawer/root/types.d.ts +36 -0
  92. package/dist/drawer/root/types.js +1 -0
  93. package/dist/drawer/root/viewport-context.d.ts +2 -0
  94. package/dist/drawer/root/viewport-context.js +16 -0
  95. package/dist/drawer/swipe-area/drawer-swipe-area.svelte +143 -0
  96. package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +22 -0
  97. package/dist/drawer/title/drawer-title.svelte +37 -0
  98. package/dist/drawer/title/drawer-title.svelte.d.ts +21 -0
  99. package/dist/drawer/trigger/drawer-trigger.svelte +90 -0
  100. package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +41 -0
  101. package/dist/drawer/viewport/drawer-viewport.svelte +69 -0
  102. package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +15 -0
  103. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +88 -0
  104. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +29 -0
  105. package/dist/hooks/use-virtual-focus.svelte.d.ts +9 -0
  106. package/dist/hooks/use-virtual-focus.svelte.js +7 -1
  107. package/dist/index.d.ts +2 -0
  108. package/dist/index.js +2 -0
  109. package/dist/listbox/item/listbox-item.svelte +8 -1
  110. package/dist/listbox/root/context.d.ts +30 -0
  111. package/dist/listbox/root/context.js +10 -0
  112. package/dist/listbox/root/listbox.svelte +291 -8
  113. package/dist/listbox/root/listbox.svelte.d.ts +35 -2
  114. package/dist/menu/content/menu-content.svelte +3 -1
  115. package/dist/menu/overlay/menu-overlay.svelte +1 -1
  116. package/dist/numberfield/root/number-field-root.svelte +2 -1
  117. package/dist/popover/content/popover-content.svelte +1 -1
  118. package/dist/popover/overlay/popover-overlay.svelte +1 -1
  119. package/dist/popover/root/popover-root.svelte +23 -11
  120. package/dist/popover/root/popover-root.svelte.d.ts +10 -2
  121. package/dist/primitives/floating.d.ts +7 -0
  122. package/dist/primitives/floating.js +6 -2
  123. package/dist/primitives/index.d.ts +1 -0
  124. package/dist/primitives/index.js +1 -0
  125. package/dist/primitives/keyboard-navigation.js +3 -1
  126. package/dist/primitives/layer-stack.d.ts +29 -0
  127. package/dist/primitives/layer-stack.js +35 -0
  128. package/dist/primitives/list-virtualizer.d.ts +75 -0
  129. package/dist/primitives/list-virtualizer.js +59 -0
  130. package/dist/primitives/scroll-lock.d.ts +23 -3
  131. package/dist/primitives/scroll-lock.js +122 -9
  132. package/dist/primitives/swipe-gesture.d.ts +126 -0
  133. package/dist/primitives/swipe-gesture.js +351 -0
  134. package/dist/primitives/text.d.ts +8 -0
  135. package/dist/primitives/text.js +13 -0
  136. package/dist/switch/root/switch-root.svelte +23 -9
  137. package/dist/switch/root/switch-root.svelte.d.ts +9 -2
  138. package/dist/table/body/table-body.svelte +84 -9
  139. package/dist/table/cell/table-cell.svelte +1 -3
  140. package/dist/table/column/table-column.svelte +5 -1
  141. package/dist/table/column-resizer/table-column-resizer.svelte +1 -5
  142. package/dist/table/index.d.ts +1 -1
  143. package/dist/table/index.js +1 -1
  144. package/dist/table/interactive-cell/table-interactive-cell.svelte +1 -3
  145. package/dist/table/root/context.svelte.js +99 -49
  146. package/dist/table/row/table-row.svelte +7 -7
  147. package/dist/table/sort-trigger/table-sort-trigger.svelte +5 -1
  148. package/dist/table/types.d.ts +6 -0
  149. package/dist/tabs/root/tabs-root.svelte +20 -6
  150. package/dist/tabs/types.d.ts +9 -0
  151. package/dist/timepicker/root/time-picker-root.svelte +11 -0
  152. package/dist/timepicker/root/time-picker-root.svelte.d.ts +2 -0
  153. package/dist/toggle-group/root/context.svelte.js +11 -4
  154. package/dist/toggle-group/root/toggle-group-root.svelte +19 -4
  155. package/dist/toggle-group/types.d.ts +9 -0
  156. package/dist/tree/root/context.svelte.js +6 -0
  157. package/dist/tree/root/tree-root.svelte +22 -8
  158. package/dist/tree/types.d.ts +13 -0
  159. package/package.json +227 -224
@@ -5,10 +5,11 @@
5
5
  */
6
6
  import { pushLayer, removeLayer, isTopmostLayer, getLayerCount, getLayerKindIndex, subscribeLayerStack } from '../../primitives/layer-stack';
7
7
  /**
8
- * Base z-index for dialogs. Each nested dialog increments by 10.
8
+ * The z-index scale lives in `primitives/layer-stack.ts` — it is shared by every
9
+ * layer kind (drawers included), not dialog-specific. Re-exported here so the
10
+ * existing Dialog call sites keep their import path.
9
11
  */
10
- const BASE_Z_INDEX = 9990;
11
- const Z_INDEX_INCREMENT = 10;
12
+ export { getOverlayZIndex, getContentZIndex, getFloatingLayerZIndex, getFloatingLayerOverlayZIndex } from '../../primitives/layer-stack';
12
13
  /**
13
14
  * Register a dialog when it opens.
14
15
  * Returns the dialog ID and level for z-index calculation. The level is the dialog's
@@ -50,39 +51,9 @@ export function popDialog(id) {
50
51
  export function isTopmostDialog(id) {
51
52
  return isTopmostLayer(id);
52
53
  }
53
- /**
54
- * Get the z-index for the overlay based on dialog level.
55
- */
56
- export function getOverlayZIndex(level) {
57
- return BASE_Z_INDEX + level * Z_INDEX_INCREMENT;
58
- }
59
- /**
60
- * Get the z-index for the content based on dialog level.
61
- */
62
- export function getContentZIndex(level) {
63
- return BASE_Z_INDEX + level * Z_INDEX_INCREMENT + 1;
64
- }
65
54
  /**
66
55
  * Get the number of open dialogs.
67
56
  */
68
57
  export function getDialogCount() {
69
58
  return getLayerCount('dialog');
70
59
  }
71
- /**
72
- * Z-index a floating layer (popover/calendar) should use so it renders ABOVE the
73
- * topmost open dialog — or above page content when no dialog is open. Without this,
74
- * a popover opened inside a (nested) dialog kept its fixed z-index and rendered
75
- * behind the dialog, because each nested dialog's content sits at a higher z-index
76
- * than the popover's old constant. Resolves to 9999 with no dialogs open (the prior
77
- * fixed value), and climbs past the dialog stack as dialogs nest.
78
- */
79
- export function getFloatingLayerZIndex() {
80
- return BASE_Z_INDEX + getLayerCount('dialog') * Z_INDEX_INCREMENT + 9;
81
- }
82
- /**
83
- * Z-index for a floating layer's backdrop — one below its content (mirrors the
84
- * dialog overlay/content pairing).
85
- */
86
- export function getFloatingLayerOverlayZIndex() {
87
- return getFloatingLayerZIndex() - 1;
88
- }
@@ -0,0 +1,43 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { getDialogContext } from '../root/context';
5
+
6
+ /**
7
+ * Dialog.Title — the dialog's accessible name.
8
+ *
9
+ * Registers its id with the root, which hands it to `Dialog.Content` as
10
+ * `aria-labelledby`. Writing a bare heading instead leaves the dialog unnamed: a
11
+ * `role="dialog"` takes its name from `aria-labelledby`/`aria-label`, never from
12
+ * the text inside it.
13
+ */
14
+ type DialogTitleProps = {
15
+ /** The dialog's name. */
16
+ children?: Snippet;
17
+ /** CSS class for the heading. */
18
+ class?: string;
19
+ /** Overrides the generated id. */
20
+ id?: string;
21
+ } & Omit<HTMLAttributes<HTMLHeadingElement>, 'class' | 'children' | 'id'>;
22
+
23
+ let { children, class: className = '', id: idProp, ...restProps }: DialogTitleProps = $props();
24
+
25
+ const ctx = getDialogContext();
26
+
27
+ if (!ctx) {
28
+ throw new Error('Dialog.Title must be used inside a Dialog.Root');
29
+ }
30
+
31
+ const dialogCtx = ctx;
32
+ const generatedId = $props.id();
33
+ const id = $derived(idProp ?? generatedId);
34
+
35
+ // The returned unregister runs on destroy, and again whenever the id changes.
36
+ $effect(() => dialogCtx.registerLabel(id));
37
+ </script>
38
+
39
+ <h2 {id} class={className} data-dialog-title {...restProps}>
40
+ {#if children}
41
+ {@render children()}
42
+ {/if}
43
+ </h2>
@@ -0,0 +1,21 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ /**
4
+ * Dialog.Title — the dialog's accessible name.
5
+ *
6
+ * Registers its id with the root, which hands it to `Dialog.Content` as
7
+ * `aria-labelledby`. Writing a bare heading instead leaves the dialog unnamed: a
8
+ * `role="dialog"` takes its name from `aria-labelledby`/`aria-label`, never from
9
+ * the text inside it.
10
+ */
11
+ type DialogTitleProps = {
12
+ /** The dialog's name. */
13
+ children?: Snippet;
14
+ /** CSS class for the heading. */
15
+ class?: string;
16
+ /** Overrides the generated id. */
17
+ id?: string;
18
+ } & Omit<HTMLAttributes<HTMLHeadingElement>, 'class' | 'children' | 'id'>;
19
+ declare const DialogTitle: import("svelte").Component<DialogTitleProps, {}, "">;
20
+ type DialogTitle = ReturnType<typeof DialogTitle>;
21
+ export default DialogTitle;
@@ -0,0 +1,111 @@
1
+ # Drawer
2
+
3
+ ## Description
4
+
5
+ `Drawer` is a panel anchored to an edge of the viewport that can be dismissed by swiping it away. It is a modal dialog by behaviour — focus trap, scroll lock, Escape, outside press — with the gesture, snap points, stacking and software-keyboard handling a sheet needs on a phone.
6
+
7
+ ## Usage guidelines
8
+
9
+ - Place all drawer parts inside `Drawer.Root`.
10
+ - Render `Drawer.Overlay` and the panel inside `Drawer.Portal`.
11
+ - Always give the drawer a `Drawer.Title`. A `role="dialog"` takes its name from `aria-labelledby`, not from the text inside it.
12
+ - Always give a dismissible drawer a `Drawer.Close`. A swipe has no keyboard or screen-reader equivalent, so a drawer that can only be swiped away is unreachable for some users.
13
+ - Wrap the content in `Drawer.Body` so a scroll that reaches its end does not chain out to the page behind, and so a mouse drag inside it selects text instead of throwing the panel across the screen. Leave the grab bar outside it, as the surface a mouse can still drag by.
14
+ - Mark any control with a drag of its own — a slider, a carousel — with `data-hk-swipe-ignore`. Valueless opts it out for every input type; `="mouse"` opts it out for a mouse only.
15
+ - Put `Drawer.SwipeArea` OUTSIDE `Drawer.Portal` — it has to exist while the drawer is closed.
16
+ - Wrap `Drawer.Root` in `Drawer.VirtualKeyboardProvider` when the panel contains form fields.
17
+
18
+ ## Anatomy
19
+
20
+ ```svelte
21
+ <Drawer.Root side="bottom">
22
+ <Drawer.Trigger>Open</Drawer.Trigger>
23
+ <Drawer.Portal>
24
+ <Drawer.Overlay />
25
+ <Drawer.Content>
26
+ <Drawer.Title>Title</Drawer.Title>
27
+ <Drawer.Description>Supporting text.</Drawer.Description>
28
+ <Drawer.Body>…</Drawer.Body>
29
+ <Drawer.Close>Close</Drawer.Close>
30
+ </Drawer.Content>
31
+ </Drawer.Portal>
32
+ </Drawer.Root>
33
+ ```
34
+
35
+ - `Drawer.Root`
36
+ - `Drawer.Trigger`
37
+ - `Drawer.Portal`
38
+ - `Drawer.Overlay`
39
+ - `Drawer.Viewport` (optional positioning layer)
40
+ - `Drawer.Content`
41
+ - `Drawer.Body`
42
+ - `Drawer.Title`
43
+ - `Drawer.Description`
44
+ - `Drawer.Close`
45
+ - `Drawer.SwipeArea`
46
+ - `Drawer.Indent` / `Drawer.IndentBackground`
47
+ - `Drawer.VirtualKeyboardProvider`
48
+ - `createDrawerHandle()`
49
+
50
+ ## Custom properties
51
+
52
+ `Drawer.Content` publishes these for the consumer's CSS to animate against:
53
+
54
+ | Property | Meaning |
55
+ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
56
+ | `--drawer-swipe-movement-x` | Signed horizontal drag, in px. Apply directly in a `translateX`. |
57
+ | `--drawer-swipe-movement-y` | Signed vertical drag, in px. |
58
+ | `--drawer-swipe-progress` | `0`–`1` toward dismissal — `0` for the whole trip between snap points. Also on `Drawer.Overlay`. |
59
+ | `--drawer-swipe-strength` | `1` for a still release down to `0.1` for a hard flick. Scale the release transition by it. |
60
+ | `--drawer-overdrag` | Resisted pull past fully open, in px; `0` the rest of the time. |
61
+ | `--drawer-snap-point-offset` | Translation of the current snap point, in px. |
62
+ | `--drawer-width` / `--drawer-height` | The panel's own measured size. |
63
+ | `--drawer-frontmost-height` | Extent of the drawer on top of the stack. |
64
+ | `--nested-drawers` | Distance from the front of the stack; `0` is frontmost. |
65
+ | `--drawer-keyboard-inset` | Height covered by the software keyboard. Only set while it is up, so `var(--drawer-keyboard-inset, 0px)` is the right fallback. |
66
+
67
+ `Drawer.Indent` and `Drawer.IndentBackground` publish `--drawer-indent-progress`.
68
+
69
+ The resting transform is the sum of the snap point and the drag:
70
+
71
+ ```css
72
+ .DrawerContent {
73
+ transform: translateY(calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
74
+ transition: transform calc(300ms * var(--drawer-swipe-strength));
75
+ }
76
+ .DrawerContent[data-swiping] {
77
+ transition: none;
78
+ }
79
+ ```
80
+
81
+ ## Data attributes
82
+
83
+ | Attribute | On | When |
84
+ | -------------------------------- | ------------------------ | ------------------------------------------------------------------------------ |
85
+ | `data-state` | overlay, viewport, panel | `open` / `closed` |
86
+ | `data-entering` / `data-exiting` | overlay, viewport, panel | during the enter / exit animation |
87
+ | `data-starting-style` | overlay, panel | the first painted frame after mounting, so a transition has somewhere to start |
88
+ | `data-side` | panel, overlay, viewport | the anchored edge |
89
+ | `data-nested` | overlay | a drawer is already open behind this one, so this backdrop stands down |
90
+ | `data-swiping` | panel, overlay | a drag is in flight |
91
+ | `data-swipe-dismiss` | panel | the drawer was dismissed by a swipe |
92
+ | `data-swipe-direction` | panel, swipe area | direction of the gesture |
93
+ | `data-expanded` | panel | at the most open snap point |
94
+ | `data-nested-drawer-open` | panel | a drawer opened after this one is open |
95
+ | `data-nested-drawer-swiping` | panel | that nested drawer is being dragged |
96
+
97
+ ## Accessibility
98
+
99
+ - `Drawer.Content` renders `role="dialog"`, with `aria-modal="true"` while open and `modal` is `true`.
100
+ - `Drawer.Title` and `Drawer.Description` wire `aria-labelledby` / `aria-describedby` automatically.
101
+ - Focus is trapped inside the open drawer, and content outside it is hidden from assistive technology.
102
+ - Escape closes the topmost dismissable layer, so a popover opened inside the drawer closes first.
103
+ - Closing returns focus to the trigger that opened it — with a detached handle, the specific trigger, not whichever registered last.
104
+ - Page scroll is locked while a modal drawer is open, using the `position: fixed` body pin that also stops iOS Safari touch scrolling.
105
+
106
+ ## Notes on Base UI parity
107
+
108
+ This drawer is modelled on Base UI's, with two deliberate differences:
109
+
110
+ - The panel part is `Drawer.Content` (Base UI calls it `Popup`) and the scrolling region is `Drawer.Body` (Base UI calls that one `Content`), so the naming matches `Dialog` and `Popover` in this library.
111
+ - There is no `Drawer.Provider`. The drawer stack is module-global here, so a provider would have nothing left to coordinate; `Drawer.Indent` reads the stack directly.
@@ -0,0 +1,47 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { SWIPE_IGNORE_ATTRIBUTE } from '../../primitives/swipe-gesture';
5
+
6
+ /**
7
+ * Drawer.Body — the content region inside the panel.
8
+ *
9
+ * Two things happen here that do not happen on the panel itself:
10
+ *
11
+ * 1. `overscroll-behavior: contain`, so a scroll that reaches the end of the body
12
+ * does not chain out to the page behind the drawer.
13
+ * 2. The drawer cannot be dragged from it. At all, by any pointer — not "it can
14
+ * but it resists", which still moves the panel a little and springs it back.
15
+ *
16
+ * On the second: Base UI scopes the equivalent rule to a mouse, on the reasoning
17
+ * that a finger has no drag-to-select to compete with. That leaves the same
18
+ * square of the panel behaving three different ways depending on the pointer, the
19
+ * region and the direction of travel, and nobody can build a mental model of
20
+ * that. One rule instead: the body is content, the panel around it — grab bar,
21
+ * header, padding — is the handle. Which is also how the sheets people already
22
+ * know behave.
23
+ *
24
+ * Bring your own `overflow`: whether the body scrolls is a layout decision, and
25
+ * forcing it here would fight consumers whose panel sizes to its content.
26
+ */
27
+ type DrawerBodyProps = {
28
+ /** Content of the body region. */
29
+ children?: Snippet;
30
+ /** CSS class for the body. */
31
+ class?: string;
32
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>;
33
+
34
+ let { children, class: className = '', ...restProps }: DrawerBodyProps = $props();
35
+ </script>
36
+
37
+ <div
38
+ class={className}
39
+ data-drawer-body
40
+ {...{ [SWIPE_IGNORE_ATTRIBUTE]: '' }}
41
+ style="overscroll-behavior: contain;"
42
+ {...restProps}
43
+ >
44
+ {#if children}
45
+ {@render children()}
46
+ {/if}
47
+ </div>
@@ -0,0 +1,32 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ /**
4
+ * Drawer.Body — the content region inside the panel.
5
+ *
6
+ * Two things happen here that do not happen on the panel itself:
7
+ *
8
+ * 1. `overscroll-behavior: contain`, so a scroll that reaches the end of the body
9
+ * does not chain out to the page behind the drawer.
10
+ * 2. The drawer cannot be dragged from it. At all, by any pointer — not "it can
11
+ * but it resists", which still moves the panel a little and springs it back.
12
+ *
13
+ * On the second: Base UI scopes the equivalent rule to a mouse, on the reasoning
14
+ * that a finger has no drag-to-select to compete with. That leaves the same
15
+ * square of the panel behaving three different ways depending on the pointer, the
16
+ * region and the direction of travel, and nobody can build a mental model of
17
+ * that. One rule instead: the body is content, the panel around it — grab bar,
18
+ * header, padding — is the handle. Which is also how the sheets people already
19
+ * know behave.
20
+ *
21
+ * Bring your own `overflow`: whether the body scrolls is a layout decision, and
22
+ * forcing it here would fight consumers whose panel sizes to its content.
23
+ */
24
+ type DrawerBodyProps = {
25
+ /** Content of the body region. */
26
+ children?: Snippet;
27
+ /** CSS class for the body. */
28
+ class?: string;
29
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>;
30
+ declare const DrawerBody: import("svelte").Component<DrawerBodyProps, {}, "">;
31
+ type DrawerBody = ReturnType<typeof DrawerBody>;
32
+ export default DrawerBody;
@@ -0,0 +1,52 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLButtonAttributes } from 'svelte/elements';
4
+ import { ButtonRoot } from '../../button/index.js';
5
+ import { requireDrawerContext } from '../root/context';
6
+
7
+ /**
8
+ * Drawer.Close — a button that closes the drawer.
9
+ *
10
+ * A swipe is not an accessible dismissal on its own: it has no keyboard or
11
+ * screen-reader equivalent, so a drawer that can only be swiped away is
12
+ * unreachable for some users. Every dismissible drawer wants one of these.
13
+ */
14
+ export type DrawerCloseProps = Omit<HTMLButtonAttributes, 'type' | 'class' | 'children'> & {
15
+ /** Button label. */
16
+ children?: Snippet;
17
+ /** CSS class for the button. */
18
+ class?: string;
19
+ /** Bindable reference to the rendered button. */
20
+ element?: HTMLButtonElement | null;
21
+ };
22
+
23
+ type DrawerCloseMouseEvent = MouseEvent & {
24
+ currentTarget: EventTarget & HTMLButtonElement;
25
+ };
26
+
27
+ let {
28
+ children,
29
+ class: className = '',
30
+ element = $bindable<HTMLButtonElement | null>(null),
31
+ onclick: onClickExternal,
32
+ ...restProps
33
+ }: DrawerCloseProps = $props();
34
+
35
+ const ctx = requireDrawerContext('Drawer.Close');
36
+
37
+ function handleClick(event: DrawerCloseMouseEvent) {
38
+ ctx.close('imperative-action', event);
39
+ onClickExternal?.(event);
40
+ }
41
+ </script>
42
+
43
+ <ButtonRoot
44
+ {...restProps}
45
+ bind:element
46
+ class={className}
47
+ type="button"
48
+ data-drawer-close="true"
49
+ onclick={handleClick}
50
+ >
51
+ {@render children?.()}
52
+ </ButtonRoot>
@@ -0,0 +1,20 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLButtonAttributes } from 'svelte/elements';
3
+ /**
4
+ * Drawer.Close — a button that closes the drawer.
5
+ *
6
+ * A swipe is not an accessible dismissal on its own: it has no keyboard or
7
+ * screen-reader equivalent, so a drawer that can only be swiped away is
8
+ * unreachable for some users. Every dismissible drawer wants one of these.
9
+ */
10
+ export type DrawerCloseProps = Omit<HTMLButtonAttributes, 'type' | 'class' | 'children'> & {
11
+ /** Button label. */
12
+ children?: Snippet;
13
+ /** CSS class for the button. */
14
+ class?: string;
15
+ /** Bindable reference to the rendered button. */
16
+ element?: HTMLButtonElement | null;
17
+ };
18
+ declare const DrawerClose: import("svelte").Component<DrawerCloseProps, {}, "element">;
19
+ type DrawerClose = ReturnType<typeof DrawerClose>;
20
+ export default DrawerClose;