@matekit/react 0.0.0-stage → 0.1.0

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 (268) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +56 -0
  4. package/README.md +115 -2
  5. package/dist/atoms/Divider/Divider.d.ts +49 -0
  6. package/dist/atoms/Divider/Divider.js +29 -0
  7. package/dist/atoms/FocusRing/FocusRing.d.ts +16 -0
  8. package/dist/atoms/FocusRing/FocusRing.js +16 -0
  9. package/dist/atoms/Group/Group.d.ts +38 -0
  10. package/dist/atoms/Group/Group.js +34 -0
  11. package/dist/atoms/Icon/Icon.d.ts +23 -0
  12. package/dist/atoms/Icon/Icon.js +19 -0
  13. package/dist/atoms/Interactive/Interactive.d.ts +98 -0
  14. package/dist/atoms/Interactive/Interactive.js +87 -0
  15. package/dist/atoms/Ripple/Ripple.d.ts +14 -0
  16. package/dist/atoms/Ripple/Ripple.js +63 -0
  17. package/dist/atoms/Shape/Shape.d.ts +24 -0
  18. package/dist/atoms/Shape/Shape.js +19 -0
  19. package/dist/atoms/Shape/shapes.d.ts +8 -0
  20. package/dist/atoms/Shape/shapes.js +40 -0
  21. package/dist/atoms/Stack/Stack.d.ts +58 -0
  22. package/dist/atoms/Stack/Stack.js +33 -0
  23. package/dist/atoms/StateLayer/StateLayer.d.ts +17 -0
  24. package/dist/atoms/StateLayer/StateLayer.js +17 -0
  25. package/dist/atoms/index.d.ts +10 -0
  26. package/dist/atoms/index.js +10 -0
  27. package/dist/fonts/roboto-flex/OFL.txt +93 -0
  28. package/dist/fonts/roboto-flex/roboto-flex-cyrillic-ext.woff2 +0 -0
  29. package/dist/fonts/roboto-flex/roboto-flex-cyrillic.woff2 +0 -0
  30. package/dist/fonts/roboto-flex/roboto-flex-greek.woff2 +0 -0
  31. package/dist/fonts/roboto-flex/roboto-flex-latin-ext.woff2 +0 -0
  32. package/dist/fonts/roboto-flex/roboto-flex-latin.woff2 +0 -0
  33. package/dist/fonts/roboto-flex/roboto-flex-vietnamese.woff2 +0 -0
  34. package/dist/icons/icons.d.ts +89 -0
  35. package/dist/icons/icons.js +186 -0
  36. package/dist/icons/index.d.ts +1 -0
  37. package/dist/icons/index.js +3 -0
  38. package/dist/index.d.ts +8 -0
  39. package/dist/index.js +12 -0
  40. package/dist/internal/accessible-name.d.ts +17 -0
  41. package/dist/internal/accessible-name.js +33 -0
  42. package/dist/internal/anchor-position.d.ts +99 -0
  43. package/dist/internal/anchor-position.js +159 -0
  44. package/dist/internal/anchored-drag.d.ts +25 -0
  45. package/dist/internal/anchored-drag.js +106 -0
  46. package/dist/internal/dev.d.ts +2 -0
  47. package/dist/internal/dev.js +18 -0
  48. package/dist/internal/diagnostics.d.ts +46 -0
  49. package/dist/internal/diagnostics.js +125 -0
  50. package/dist/internal/group-label.d.ts +22 -0
  51. package/dist/internal/group-label.js +50 -0
  52. package/dist/internal/interactive.d.ts +28 -0
  53. package/dist/internal/interactive.js +18 -0
  54. package/dist/internal/layout-element.d.ts +21 -0
  55. package/dist/internal/layout-element.js +33 -0
  56. package/dist/internal/merge-refs.d.ts +13 -0
  57. package/dist/internal/merge-refs.js +35 -0
  58. package/dist/internal/modal-dialog.d.ts +63 -0
  59. package/dist/internal/modal-dialog.js +267 -0
  60. package/dist/internal/navigation-count.d.ts +38 -0
  61. package/dist/internal/navigation-count.js +60 -0
  62. package/dist/internal/navigation-item.d.ts +14 -0
  63. package/dist/internal/navigation-item.js +17 -0
  64. package/dist/internal/nearest-scroller.d.ts +4 -0
  65. package/dist/internal/nearest-scroller.js +17 -0
  66. package/dist/internal/open-state.d.ts +15 -0
  67. package/dist/internal/open-state.js +42 -0
  68. package/dist/internal/roving-focus.d.ts +41 -0
  69. package/dist/internal/roving-focus.js +126 -0
  70. package/dist/internal/settle-animations.d.ts +33 -0
  71. package/dist/internal/settle-animations.js +48 -0
  72. package/dist/internal/time-period.d.ts +10 -0
  73. package/dist/internal/time-period.js +26 -0
  74. package/dist/internal/time.d.ts +23 -0
  75. package/dist/internal/time.js +69 -0
  76. package/dist/internal/typeahead.d.ts +17 -0
  77. package/dist/internal/typeahead.js +35 -0
  78. package/dist/molecules/Badge/Badge.d.ts +25 -0
  79. package/dist/molecules/Badge/Badge.js +16 -0
  80. package/dist/molecules/Button/Button.d.ts +48 -0
  81. package/dist/molecules/Button/Button.js +34 -0
  82. package/dist/molecules/Card/Card.d.ts +159 -0
  83. package/dist/molecules/Card/Card.js +119 -0
  84. package/dist/molecules/Checkbox/Checkbox.d.ts +26 -0
  85. package/dist/molecules/Checkbox/Checkbox.js +40 -0
  86. package/dist/molecules/Chip/AssistChip.d.ts +23 -0
  87. package/dist/molecules/Chip/AssistChip.js +22 -0
  88. package/dist/molecules/Chip/ChipGroup.d.ts +85 -0
  89. package/dist/molecules/Chip/ChipGroup.js +92 -0
  90. package/dist/molecules/Chip/FilterChip.d.ts +33 -0
  91. package/dist/molecules/Chip/FilterChip.js +30 -0
  92. package/dist/molecules/Chip/InputChip.d.ts +60 -0
  93. package/dist/molecules/Chip/InputChip.js +107 -0
  94. package/dist/molecules/Chip/SuggestionChip.d.ts +24 -0
  95. package/dist/molecules/Chip/SuggestionChip.js +17 -0
  96. package/dist/molecules/Chip/chip-content.d.ts +39 -0
  97. package/dist/molecules/Chip/chip-content.js +95 -0
  98. package/dist/molecules/Chip/chip-element.d.ts +14 -0
  99. package/dist/molecules/Chip/chip-element.js +14 -0
  100. package/dist/molecules/Chip/strings.d.ts +8 -0
  101. package/dist/molecules/Chip/strings.js +5 -0
  102. package/dist/molecules/Fab/Fab.d.ts +78 -0
  103. package/dist/molecules/Fab/Fab.js +52 -0
  104. package/dist/molecules/IconButton/IconButton.d.ts +59 -0
  105. package/dist/molecules/IconButton/IconButton.js +36 -0
  106. package/dist/molecules/LoadingIndicator/LoadingIndicator.d.ts +38 -0
  107. package/dist/molecules/LoadingIndicator/LoadingIndicator.js +25 -0
  108. package/dist/molecules/LoadingIndicator/determinate.d.ts +3 -0
  109. package/dist/molecules/LoadingIndicator/determinate.js +47 -0
  110. package/dist/molecules/LoadingIndicator/loading-indicator-data.d.ts +21 -0
  111. package/dist/molecules/LoadingIndicator/loading-indicator-data.js +72 -0
  112. package/dist/molecules/ProgressIndicator/CircularProgressIndicator.d.ts +35 -0
  113. package/dist/molecules/ProgressIndicator/CircularProgressIndicator.js +30 -0
  114. package/dist/molecules/ProgressIndicator/LinearProgressIndicator.d.ts +43 -0
  115. package/dist/molecules/ProgressIndicator/LinearProgressIndicator.js +28 -0
  116. package/dist/molecules/ProgressIndicator/circular-wavy-data.d.ts +5 -0
  117. package/dist/molecules/ProgressIndicator/circular-wavy-data.js +19 -0
  118. package/dist/molecules/ProgressIndicator/progress.d.ts +24 -0
  119. package/dist/molecules/ProgressIndicator/progress.js +60 -0
  120. package/dist/molecules/RadioButton/RadioButton.d.ts +27 -0
  121. package/dist/molecules/RadioButton/RadioButton.js +70 -0
  122. package/dist/molecules/RadioButton/RadioGroup.d.ts +73 -0
  123. package/dist/molecules/RadioButton/RadioGroup.js +82 -0
  124. package/dist/molecules/ScrollField/ScrollField.d.ts +61 -0
  125. package/dist/molecules/ScrollField/ScrollField.js +352 -0
  126. package/dist/molecules/Slider/RangeSlider.d.ts +60 -0
  127. package/dist/molecules/Slider/RangeSlider.js +169 -0
  128. package/dist/molecules/Slider/Slider.d.ts +54 -0
  129. package/dist/molecules/Slider/Slider.js +71 -0
  130. package/dist/molecules/Slider/slider-shared.d.ts +26 -0
  131. package/dist/molecules/Slider/slider-shared.js +98 -0
  132. package/dist/molecules/Switch/Switch.d.ts +22 -0
  133. package/dist/molecules/Switch/Switch.js +20 -0
  134. package/dist/molecules/TextField/TextField.d.ts +83 -0
  135. package/dist/molecules/TextField/TextField.js +146 -0
  136. package/dist/molecules/TextField/TextFieldSlots.d.ts +22 -0
  137. package/dist/molecules/TextField/TextFieldSlots.js +24 -0
  138. package/dist/molecules/TimeInput/TimeInput.d.ts +108 -0
  139. package/dist/molecules/TimeInput/TimeInput.js +347 -0
  140. package/dist/molecules/TimeInput/strings.d.ts +13 -0
  141. package/dist/molecules/TimeInput/strings.js +10 -0
  142. package/dist/molecules/TimeScroll/TimeScroll.d.ts +106 -0
  143. package/dist/molecules/TimeScroll/TimeScroll.js +213 -0
  144. package/dist/molecules/TimeScroll/strings.d.ts +13 -0
  145. package/dist/molecules/TimeScroll/strings.js +12 -0
  146. package/dist/molecules/index.d.ts +27 -0
  147. package/dist/molecules/index.js +25 -0
  148. package/dist/organisms/BottomSheet/BottomSheet.d.ts +128 -0
  149. package/dist/organisms/BottomSheet/BottomSheet.js +432 -0
  150. package/dist/organisms/BottomSheet/BottomSheetSlots.d.ts +17 -0
  151. package/dist/organisms/BottomSheet/BottomSheetSlots.js +16 -0
  152. package/dist/organisms/BottomSheet/StandardBottomSheet.d.ts +37 -0
  153. package/dist/organisms/BottomSheet/StandardBottomSheet.js +206 -0
  154. package/dist/organisms/BottomSheet/bottom-sheet-context.d.ts +31 -0
  155. package/dist/organisms/BottomSheet/bottom-sheet-context.js +12 -0
  156. package/dist/organisms/BottomSheet/sheet-drag.d.ts +1 -0
  157. package/dist/organisms/BottomSheet/sheet-drag.js +4 -0
  158. package/dist/organisms/BottomSheet/strings.d.ts +9 -0
  159. package/dist/organisms/BottomSheet/strings.js +8 -0
  160. package/dist/organisms/ButtonGroup/ButtonGroup.d.ts +97 -0
  161. package/dist/organisms/ButtonGroup/ButtonGroup.js +242 -0
  162. package/dist/organisms/ButtonGroup/ButtonGroupItem.d.ts +36 -0
  163. package/dist/organisms/ButtonGroup/ButtonGroupItem.js +47 -0
  164. package/dist/organisms/Dialog/Dialog.d.ts +186 -0
  165. package/dist/organisms/Dialog/Dialog.js +193 -0
  166. package/dist/organisms/Dialog/DialogSlots.d.ts +60 -0
  167. package/dist/organisms/Dialog/DialogSlots.js +54 -0
  168. package/dist/organisms/Dialog/strings.d.ts +5 -0
  169. package/dist/organisms/Dialog/strings.js +5 -0
  170. package/dist/organisms/FabMenu/FabMenu.d.ts +104 -0
  171. package/dist/organisms/FabMenu/FabMenu.js +142 -0
  172. package/dist/organisms/FabMenu/strings.d.ts +9 -0
  173. package/dist/organisms/FabMenu/strings.js +5 -0
  174. package/dist/organisms/List/List.d.ts +190 -0
  175. package/dist/organisms/List/List.js +148 -0
  176. package/dist/organisms/Menu/Menu.d.ts +313 -0
  177. package/dist/organisms/Menu/Menu.js +865 -0
  178. package/dist/organisms/Menu/MenuSlots.d.ts +35 -0
  179. package/dist/organisms/Menu/MenuSlots.js +36 -0
  180. package/dist/organisms/NavigationBar/NavigationBar.d.ts +96 -0
  181. package/dist/organisms/NavigationBar/NavigationBar.js +77 -0
  182. package/dist/organisms/NavigationRail/ModalNavigationRail.d.ts +105 -0
  183. package/dist/organisms/NavigationRail/ModalNavigationRail.js +272 -0
  184. package/dist/organisms/NavigationRail/NavigationRail.d.ts +148 -0
  185. package/dist/organisms/NavigationRail/NavigationRail.js +114 -0
  186. package/dist/organisms/NavigationRail/NavigationRailSection.d.ts +54 -0
  187. package/dist/organisms/NavigationRail/NavigationRailSection.js +96 -0
  188. package/dist/organisms/NavigationRail/strings.d.ts +7 -0
  189. package/dist/organisms/NavigationRail/strings.js +7 -0
  190. package/dist/organisms/NavigationSuite/NavigationSuite.d.ts +109 -0
  191. package/dist/organisms/NavigationSuite/NavigationSuite.js +86 -0
  192. package/dist/organisms/PaneScaffold/PaneScaffold.d.ts +106 -0
  193. package/dist/organisms/PaneScaffold/PaneScaffold.js +120 -0
  194. package/dist/organisms/Search/Search.d.ts +207 -0
  195. package/dist/organisms/Search/Search.js +754 -0
  196. package/dist/organisms/Search/SearchSlots.d.ts +16 -0
  197. package/dist/organisms/Search/SearchSlots.js +17 -0
  198. package/dist/organisms/Search/strings.d.ts +21 -0
  199. package/dist/organisms/Search/strings.js +12 -0
  200. package/dist/organisms/Select/Select.d.ts +186 -0
  201. package/dist/organisms/Select/Select.js +597 -0
  202. package/dist/organisms/Select/SelectSlots.d.ts +12 -0
  203. package/dist/organisms/Select/SelectSlots.js +12 -0
  204. package/dist/organisms/SideSheet/SideSheet.d.ts +88 -0
  205. package/dist/organisms/SideSheet/SideSheet.js +109 -0
  206. package/dist/organisms/SideSheet/SideSheetSlots.d.ts +35 -0
  207. package/dist/organisms/SideSheet/SideSheetSlots.js +37 -0
  208. package/dist/organisms/SideSheet/strings.d.ts +7 -0
  209. package/dist/organisms/SideSheet/strings.js +6 -0
  210. package/dist/organisms/Snackbar/Snackbar.d.ts +46 -0
  211. package/dist/organisms/Snackbar/Snackbar.js +36 -0
  212. package/dist/organisms/Snackbar/SnackbarHost.d.ts +57 -0
  213. package/dist/organisms/Snackbar/SnackbarHost.js +221 -0
  214. package/dist/organisms/Snackbar/snackbar-queue.d.ts +81 -0
  215. package/dist/organisms/Snackbar/snackbar-queue.js +114 -0
  216. package/dist/organisms/Snackbar/strings.d.ts +8 -0
  217. package/dist/organisms/Snackbar/strings.js +5 -0
  218. package/dist/organisms/SplitButton/SplitButton.d.ts +73 -0
  219. package/dist/organisms/SplitButton/SplitButton.js +77 -0
  220. package/dist/organisms/SplitButton/strings.d.ts +9 -0
  221. package/dist/organisms/SplitButton/strings.js +5 -0
  222. package/dist/organisms/Tabs/TabLink.d.ts +27 -0
  223. package/dist/organisms/Tabs/TabLink.js +25 -0
  224. package/dist/organisms/Tabs/TabNav.d.ts +19 -0
  225. package/dist/organisms/Tabs/TabNav.js +55 -0
  226. package/dist/organisms/Tabs/Tabs.d.ts +147 -0
  227. package/dist/organisms/Tabs/Tabs.js +223 -0
  228. package/dist/organisms/Tabs/tab-content.d.ts +23 -0
  229. package/dist/organisms/Tabs/tab-content.js +105 -0
  230. package/dist/organisms/Tabs/tab-fit.d.ts +4 -0
  231. package/dist/organisms/Tabs/tab-fit.js +65 -0
  232. package/dist/organisms/Tabs/tab-motion.d.ts +2 -0
  233. package/dist/organisms/Tabs/tab-motion.js +68 -0
  234. package/dist/organisms/TimePickerDialog/TimePickerDialog.d.ts +26 -0
  235. package/dist/organisms/TimePickerDialog/TimePickerDialog.js +34 -0
  236. package/dist/organisms/Toolbar/Toolbar.d.ts +75 -0
  237. package/dist/organisms/Toolbar/Toolbar.js +84 -0
  238. package/dist/organisms/Toolbar/ToolbarLayout.d.ts +44 -0
  239. package/dist/organisms/Toolbar/ToolbarLayout.js +90 -0
  240. package/dist/organisms/Toolbar/ToolbarScroll.d.ts +8 -0
  241. package/dist/organisms/Toolbar/ToolbarScroll.js +222 -0
  242. package/dist/organisms/Tooltip/RichTooltip.d.ts +73 -0
  243. package/dist/organisms/Tooltip/RichTooltip.js +250 -0
  244. package/dist/organisms/Tooltip/Tooltip.d.ts +52 -0
  245. package/dist/organisms/Tooltip/Tooltip.js +99 -0
  246. package/dist/organisms/Tooltip/tooltip-behavior.d.ts +43 -0
  247. package/dist/organisms/Tooltip/tooltip-behavior.js +307 -0
  248. package/dist/organisms/TopAppBar/TopAppBar.d.ts +107 -0
  249. package/dist/organisms/TopAppBar/TopAppBar.js +78 -0
  250. package/dist/organisms/TopAppBar/TopAppBarScroll.d.ts +7 -0
  251. package/dist/organisms/TopAppBar/TopAppBarScroll.js +155 -0
  252. package/dist/organisms/index.d.ts +36 -0
  253. package/dist/organisms/index.js +36 -0
  254. package/dist/palettes/blue.css +275 -0
  255. package/dist/palettes/green.css +275 -0
  256. package/dist/palettes/index.css +823 -0
  257. package/dist/palettes/orange.css +275 -0
  258. package/dist/shapes.css +115 -0
  259. package/dist/strings/index.d.ts +35 -0
  260. package/dist/strings/index.js +39 -0
  261. package/dist/styles-no-fonts.css +11991 -0
  262. package/dist/styles.css +12089 -0
  263. package/dist/stylesheet.d.ts +2 -0
  264. package/dist/tokens/breakpoints.d.ts +33 -0
  265. package/dist/tokens/breakpoints.js +31 -0
  266. package/dist/tokens/space.d.ts +26 -0
  267. package/dist/tokens/space.js +26 -0
  268. package/package.json +110 -3
@@ -0,0 +1,432 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ // Organismo interactivo (ADR-0003, ADR-0025): como el Dialog, el <dialog> solo queda modal si se
4
+ // abre con showModal() (efecto), y además el sheet tiene estado (parcial o expandido), mide su alto
5
+ // para ubicar el parcial y sigue el puntero al arrastrar (eventos y medidas en el cliente).
6
+ //
7
+ // El título comparte su id con el <dialog> para aria-labelledby y el asa lee y cambia el estado:
8
+ // los dos viajan por contexto y son cliente. BottomSheetContent no necesita nada de eso y es
9
+ // universal (BottomSheetSlots.tsx).
10
+ //
11
+ // Arrastre (ADR-0025): eventos de puntero sobre el <dialog>, con la decisión al soltar portada de
12
+ // Compose (src/internal/anchored-drag.ts). Dentro de BottomSheetContent, un gesto táctil hacia abajo con el
13
+ // contenido arriba de todo, o cualquier gesto vertical con el sheet parcial, mueve el sheet en lugar
14
+ // de desplazar (el desplazamiento anidado de Compose, ConsumeSwipeWithinBottomSheetBounds…): se
15
+ // decide al pasar el umbral de 8 px y, si el sheet se queda con el gesto, un `touchmove` no pasivo
16
+ // cancela el desplazamiento nativo. El resto de los gestos desplazan el contenido como siempre.
17
+ import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
18
+ import { FocusRing } from '../../atoms/FocusRing/FocusRing.js';
19
+ import { onScrim, useModalDialog, useRegisteredId } from '../../internal/modal-dialog.js';
20
+ import { computeTarget, DRAG_SLOP, VelocityTracker } from '../../internal/anchored-drag.js';
21
+ import { bottomSheetStrings } from './strings.js';
22
+ import { BottomSheetContext, useBottomSheet, } from './bottom-sheet-context.js';
23
+ import { StandardBottomSheet } from './StandardBottomSheet.js';
24
+ // Variable CSS con el avance del sheet: lo visible de su alto, de 0 (cerrado) a 1 (expandido).
25
+ const PROGRESS = '--mk-bottom-sheet-progress';
26
+ const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
27
+ // Campos donde el mouse selecciona o edita: ahí no empieza un arrastre con mouse.
28
+ const FIELD = 'input, textarea, select, [contenteditable]:not([contenteditable="false"])';
29
+ // Hay un elemento con desplazamiento vertical, ya desplazado, entre `target` y el sheet.
30
+ function scrolledBetween(target, sheet) {
31
+ for (let el = target; el && el !== sheet; el = el.parentElement) {
32
+ if (el.scrollTop > 0 && el.scrollHeight > el.clientHeight) {
33
+ const overflow = getComputedStyle(el).overflowY;
34
+ if (overflow === 'auto' || overflow === 'scroll')
35
+ return true;
36
+ }
37
+ }
38
+ return false;
39
+ }
40
+ // Alto del bloque que contiene al sheet: la ventana, sin barras de desplazamiento.
41
+ const viewportHeight = () => document.documentElement.clientHeight;
42
+ /**
43
+ * Material 3 bottom sheet. **Modal** (the default): on the native `<dialog>` opened with `showModal()`,
44
+ * like `Dialog` (trapped focus, inert page, scrim, Escape, animated exit, focus returned on close).
45
+ *
46
+ * ```tsx
47
+ * <BottomSheet open={open} onClose={() => setOpen(false)}>
48
+ * <BottomSheetHandle />
49
+ * <BottomSheetTitle>Share</BottomSheetTitle>
50
+ * <BottomSheetContent>…</BottomSheetContent>
51
+ * </BottomSheet>
52
+ * ```
53
+ *
54
+ * - **States:** partially expanded and expanded, like Compose's `SheetState`. It opens partially
55
+ * expanded if the sheet is taller than half the window (and there is no `skipPartiallyExpanded`);
56
+ * otherwise, expanded. The current state is in `data-state` (`partial` or `expanded`). When focus
57
+ * lands on something the partial state leaves outside the window, it expands. Controlled with
58
+ * `state` and `onStateChange`, or with `defaultState` (like `RadioGroup`'s `value`/`defaultValue`):
59
+ *
60
+ * ```tsx
61
+ * const [state, setState] = useState<BottomSheetState>('partial')
62
+ * <BottomSheet open={open} onClose={close} state={state} onStateChange={(next) => setState(next)}>
63
+ * ```
64
+ * - **Progress:** `--mk-bottom-sheet-progress` on the `<dialog>`, the visible part of its height
65
+ * (0 closed, 1 expanded; partial, half the window over the sheet's height), while dragging and
66
+ * during animations, without re-rendering with React. The content and the `::backdrop` inherit
67
+ * it (in all three engines): use it to dim the scrim or reveal something on expand.
68
+ * - **Drag:** with mouse, touch or pen from anywhere on the sheet (with a mouse, not from the
69
+ * content or from fields: there it selects text), following the pointer. On release it decides
70
+ * by velocity (125 px/s) and distance (56 px), like Compose: next state, back, or close. In
71
+ * scrollable content, swiping down while scrolled to the top moves the sheet.
72
+ * - **Name:** from `BottomSheetTitle` (`aria-labelledby`); without a title, pass `aria-label` or
73
+ * `aria-labelledby`. A modal sheet with none of them warns in development (`MK_SURFACE_UNNAMED`)
74
+ * once it opens. There is no description by default: point `aria-describedby` at a paragraph of
75
+ * your own if the sheet needs one.
76
+ * - Maximum width 640 px, centered (`BottomSheetDefaults.SheetMaxWidth`). While it is open, the
77
+ * page does not scroll.
78
+ *
79
+ * **Standard** (`modal={false}`, ADR-0030): the one in Compose's `BottomSheetScaffold`, an `<aside>`
80
+ * without a scrim that lives alongside the content, peeking (the handle and the first line of the
81
+ * title, or 56 px without a title; `--mk-bottom-sheet-peek-height`) or expanded; it goes as a child
82
+ * of a `PaneScaffold`, which pads the bottom of the panes. Same parts, same drag and
83
+ * `state`/`defaultState`/`onStateChange`; `open` (defaults to `true`) and, with `onClose`, it can be
84
+ * hidden by dragging (`onClose('drag')`). See `BottomSheetStandardProps`.
85
+ *
86
+ * Native props and `ref` reach the `<dialog>` (or the `<aside>`); so do `className` and `style`.
87
+ */
88
+ export function BottomSheet(props) {
89
+ return props.modal === false ? _jsx(StandardBottomSheet, { ...props }) : _jsx(ModalBottomSheet, { ...props });
90
+ }
91
+ function ModalBottomSheet({ modal: _modal, open = false, onClose, closeOnScrimClick = true, skipPartiallyExpanded = false, state: stateProp, defaultState, onStateChange, className, children, ref, onCancel, onClick, onClickCapture, onKeyDown, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onFocus, ...props }) {
92
+ // Controlado o no, como RadioGroup (ADR-0012). `requested` es lo pedido; `state`, lo que se
93
+ // muestra: el parcial pedido sin parcial disponible se muestra expandido.
94
+ const controlled = stateProp !== undefined;
95
+ const [uncontrolled, setUncontrolled] = useState(defaultState ?? 'partial');
96
+ const requested = controlled ? stateProp : uncontrolled;
97
+ const [hasPartial, setHasPartial] = useState(false);
98
+ const state = requested === 'partial' && !hasPartial ? 'expanded' : requested;
99
+ // Copias para los manejadores nativos y las medidas, que no esperan a un nuevo render.
100
+ const live = useRef({ state, requested, controlled, skipPartiallyExpanded, defaultState, onStateChange });
101
+ live.current = { state, requested, controlled, skipPartiallyExpanded, defaultState, onStateChange };
102
+ const anchors = useRef({ partial: null, hidden: 0 });
103
+ const drag = useRef(null);
104
+ // Después de un arrastre, el clic que sigue (el del asa, o el de un botón donde empezó) no cuenta.
105
+ const swallowClick = useRef(false);
106
+ const progressFrame = useRef(0);
107
+ // Pide otro estado: sin controlar, lo aplica; controlado, solo avisa (si el padre no cambia
108
+ // `state`, el sheet vuelve al que tenía). Una llamada por cambio.
109
+ const requestState = (next, reason) => {
110
+ const l = live.current;
111
+ if (next === l.state)
112
+ return;
113
+ // Controlado, lo que se muestra no cambia hasta que el padre cambie `state`: la copia queda
114
+ // igual, así un pedido vetado se puede repetir.
115
+ if (!l.controlled) {
116
+ setUncontrolled(next);
117
+ l.state = next;
118
+ }
119
+ l.onStateChange?.(next, reason);
120
+ };
121
+ // Mide el sheet: si cabe el parcial y dónde queda (`--_partial`).
122
+ const measure = (dialog, opening) => {
123
+ const l = live.current;
124
+ const height = dialog.offsetHeight;
125
+ const half = viewportHeight() / 2;
126
+ const available = !l.skipPartiallyExpanded && height > half;
127
+ const partial = available ? Math.round(height - half) : null;
128
+ anchors.current = { partial, hidden: height };
129
+ if (partial === null)
130
+ dialog.style.removeProperty('--_partial');
131
+ else
132
+ dialog.style.setProperty('--_partial', `${partial}px`);
133
+ setHasPartial(available);
134
+ // Al abrir sin controlar, vuelve al estado inicial (el parcial si existe, o defaultState). Se
135
+ // elige en el efecto de apertura: React vuelve a dibujar antes del primer cuadro.
136
+ let wanted = l.requested;
137
+ if (opening && !l.controlled) {
138
+ wanted = l.defaultState ?? (available ? 'partial' : 'expanded');
139
+ setUncontrolled(wanted);
140
+ }
141
+ const shown = wanted === 'partial' && !available ? 'expanded' : wanted;
142
+ const before = opening ? wanted : l.state;
143
+ // La copia se actualiza ya: otra medición (el efecto pasivo, el ResizeObserver) puede correr
144
+ // antes del próximo render y no tiene que volver a avisar.
145
+ l.requested = wanted;
146
+ l.state = shown;
147
+ if (shown === before)
148
+ return;
149
+ // El parcial apareció o desapareció: se avisa con 'resize'. Sin controlar, el estado queda en
150
+ // el que se muestra (como Compose, que pasa al expandido y se queda ahí).
151
+ if (!l.controlled)
152
+ setUncontrolled(shown);
153
+ l.onStateChange?.(shown, 'resize');
154
+ };
155
+ // Escribe el progreso a partir de la posición en pantalla.
156
+ const writeProgress = (dialog, offset) => {
157
+ const height = dialog.offsetHeight;
158
+ if (!dialog.open || height === 0) {
159
+ dialog.style.setProperty(PROGRESS, '0');
160
+ return;
161
+ }
162
+ const y = offset ?? dialog.getBoundingClientRect().top - (viewportHeight() - height);
163
+ const progress = Math.min(1, Math.max(0, 1 - y / height));
164
+ dialog.style.setProperty(PROGRESS, String(Math.round(progress * 10000) / 10000));
165
+ };
166
+ // Sigue el progreso cuadro a cuadro mientras haya arrastre o animaciones del sheet.
167
+ const trackProgress = (dialog) => {
168
+ writeProgress(dialog);
169
+ if (progressFrame.current)
170
+ return;
171
+ const tick = () => {
172
+ writeProgress(dialog);
173
+ const moving = drag.current?.active || dialog.getAnimations().some((a) => a.playState === 'running');
174
+ progressFrame.current = moving ? requestAnimationFrame(tick) : 0;
175
+ };
176
+ progressFrame.current = requestAnimationFrame(tick);
177
+ };
178
+ const clearDrag = (dialog) => {
179
+ dialog.removeAttribute('data-dragging');
180
+ dialog.style.removeProperty('--_drag');
181
+ };
182
+ const { dialogRef, setRef, requestClose, dialogProps } = useModalDialog({
183
+ open,
184
+ onRequestClose: onClose,
185
+ closeOnScrimClick,
186
+ ref,
187
+ contentSelector: '.mk-bottom-sheet-content',
188
+ unnamed: {
189
+ component: 'BottomSheet',
190
+ fix: 'add a <BottomSheetTitle>, or pass aria-label (<BottomSheet aria-label="Share">) or aria-labelledby',
191
+ },
192
+ onCancel,
193
+ onClick,
194
+ onKeyDown,
195
+ onPointerDown,
196
+ onOpen: (dialog) => {
197
+ drag.current = null;
198
+ clearDrag(dialog);
199
+ measure(dialog, true);
200
+ trackProgress(dialog);
201
+ },
202
+ onClosed: (dialog) => {
203
+ drag.current = null;
204
+ clearDrag(dialog);
205
+ writeProgress(dialog);
206
+ },
207
+ });
208
+ // Mientras está abierto, el parcial sigue al alto del sheet y de la ventana.
209
+ useEffect(() => {
210
+ const dialog = dialogRef.current;
211
+ if (!open || !dialog)
212
+ return;
213
+ const remeasure = () => {
214
+ if (dialog.open)
215
+ measure(dialog, false);
216
+ };
217
+ const observer = new ResizeObserver(remeasure);
218
+ observer.observe(dialog);
219
+ window.addEventListener('resize', remeasure);
220
+ // Un gesto táctil del que se adueñó el sheet no desplaza el contenido. Tiene que ser un
221
+ // manejador nativo no pasivo: el `onTouchMove` de React es pasivo y no puede cancelar.
222
+ const onTouchMove = (e) => {
223
+ if (drag.current?.active && e.cancelable)
224
+ e.preventDefault();
225
+ };
226
+ dialog.addEventListener('touchmove', onTouchMove, { passive: false });
227
+ return () => {
228
+ observer.disconnect();
229
+ window.removeEventListener('resize', remeasure);
230
+ dialog.removeEventListener('touchmove', onTouchMove);
231
+ };
232
+ // measure lee todo de refs: no hace falta volver a suscribirse cuando cambia.
233
+ }, [open, dialogRef]);
234
+ // El progreso sigue a cada cambio de estado (la transición hacia el nuevo) y a la salida.
235
+ // Después del efecto de useModalDialog, que acaba de poner data-closing.
236
+ useLayoutEffect(() => {
237
+ const dialog = dialogRef.current;
238
+ if (dialog?.open)
239
+ trackProgress(dialog);
240
+ }, [state, open, dialogRef]);
241
+ useEffect(() => () => {
242
+ cancelAnimationFrame(progressFrame.current);
243
+ progressFrame.current = 0;
244
+ }, []);
245
+ // El padre pide el parcial y no existe: se muestra expandido y se avisa (como al medir).
246
+ // Solo cuando cambia `state` con el sheet abierto: al abrir ya avisa la medición.
247
+ const previousStateProp = useRef(stateProp);
248
+ useLayoutEffect(() => {
249
+ const changed = previousStateProp.current !== stateProp;
250
+ previousStateProp.current = stateProp;
251
+ const dialog = dialogRef.current;
252
+ if (!changed || !dialog?.open || stateProp !== 'partial' || anchors.current.partial !== null)
253
+ return;
254
+ live.current.onStateChange?.('expanded', 'resize');
255
+ }, [stateProp, dialogRef]);
256
+ // Cambiar skipPartiallyExpanded con el sheet abierto vuelve a medir.
257
+ useEffect(() => {
258
+ const dialog = dialogRef.current;
259
+ if (dialog?.open)
260
+ measure(dialog, false);
261
+ }, [skipPartiallyExpanded, dialogRef]);
262
+ // Desplazamiento actual del sheet (px hacia abajo desde expandido), medido en pantalla.
263
+ const currentOffset = (dialog) => dialog.getBoundingClientRect().top - (viewportHeight() - dialog.offsetHeight);
264
+ const handlePointerDown = (e) => {
265
+ dialogProps.onPointerDown(e);
266
+ swallowClick.current = false;
267
+ const dialog = e.currentTarget;
268
+ if (e.defaultPrevented || !e.isPrimary || e.button !== 0 || drag.current)
269
+ return;
270
+ if (dialog.hasAttribute('data-closing') || onScrim(dialog, e))
271
+ return;
272
+ const target = e.target;
273
+ const mouse = e.pointerType === 'mouse';
274
+ const inContent = !!target.closest('.mk-bottom-sheet-content');
275
+ if (mouse && (inContent || target.closest(FIELD)))
276
+ return;
277
+ const tracker = new VelocityTracker();
278
+ tracker.add(performance.now(), e.clientY);
279
+ const from = currentOffset(dialog);
280
+ drag.current = { id: e.pointerId, mouse, inContent, target, startX: e.clientX, startY: e.clientY, from, offset: from, active: false, tracker };
281
+ };
282
+ const handlePointerMove = (e) => {
283
+ onPointerMove?.(e);
284
+ const d = drag.current;
285
+ if (!d || d.id !== e.pointerId)
286
+ return;
287
+ const dialog = e.currentTarget;
288
+ const dx = e.clientX - d.startX;
289
+ const dy = e.clientY - d.startY;
290
+ if (!d.active) {
291
+ if (Math.hypot(dx, dy) < DRAG_SLOP)
292
+ return;
293
+ // Un gesto horizontal no es del sheet (un carrusel adentro, por ejemplo).
294
+ const vertical = Math.abs(dy) > Math.abs(dx);
295
+ // En el contenido, el sheet se queda con el gesto si está parcial (hacia arriba se expande,
296
+ // hacia abajo baja) o si se desliza hacia abajo con el contenido arriba de todo; si no, el
297
+ // gesto desplaza el contenido.
298
+ const ownsGesture = !d.inContent || live.current.state === 'partial' || (dy > 0 && !scrolledBetween(d.target, dialog));
299
+ if (!vertical || !ownsGesture) {
300
+ drag.current = null;
301
+ return;
302
+ }
303
+ d.active = true;
304
+ // Sigue al puntero desde acá, sin el salto del umbral.
305
+ d.startY = e.clientY;
306
+ d.from = currentOffset(dialog);
307
+ // Los movimientos fuera del sheet le siguen llegando. Un evento sintético (sin puntero
308
+ // activo detrás) no se puede capturar: el arrastre sigue igual.
309
+ try {
310
+ dialog.setPointerCapture(e.pointerId);
311
+ }
312
+ catch {
313
+ // NotFoundError: sin puntero activo con ese id.
314
+ }
315
+ dialog.setAttribute('data-dragging', '');
316
+ }
317
+ e.preventDefault();
318
+ d.offset = Math.min(Math.max(d.from + (e.clientY - d.startY), 0), anchors.current.hidden);
319
+ d.tracker.add(performance.now(), e.clientY);
320
+ dialog.style.setProperty('--_drag', `${d.offset}px`);
321
+ writeProgress(dialog, d.offset);
322
+ };
323
+ const release = (dialog, velocity) => {
324
+ const d = drag.current;
325
+ drag.current = null;
326
+ if (!d?.active)
327
+ return;
328
+ // Con mouse, el mismo gesto siempre termina en un clic (con la captura, al menos sobre el
329
+ // <dialog>): ese no cuenta. Táctil y lápiz no generan clic después de moverse; si dejaran la
330
+ // marca, se comería la próxima activación del asa con el teclado.
331
+ swallowClick.current = d.mouse;
332
+ const list = [['expanded', 0]];
333
+ if (anchors.current.partial !== null)
334
+ list.push(['partial', anchors.current.partial]);
335
+ list.push(['hidden', anchors.current.hidden]);
336
+ // Cancelado (pointercancel): vuelve al estado donde estaba, sin cerrar.
337
+ const target = velocity === null ? live.current.state : computeTarget(list, d.offset, velocity);
338
+ if (target !== 'hidden') {
339
+ // Sin data-dragging vuelve la transición: el sheet va del punto donde se soltó a su estado
340
+ // (o al anterior, si el padre controla `state` y no lo cambia).
341
+ clearDrag(dialog);
342
+ requestState(target, 'drag');
343
+ trackProgress(dialog);
344
+ return;
345
+ }
346
+ // Cerrar: se pide al padre. Si cierra, la salida parte del punto donde se soltó (data-closing
347
+ // le gana a data-dragging). Si no, el sheet vuelve a su estado en el cuadro siguiente.
348
+ dialog.removeAttribute('data-dragging');
349
+ requestClose('drag');
350
+ requestAnimationFrame(() => {
351
+ if (!dialog.hasAttribute('data-closing'))
352
+ dialog.style.removeProperty('--_drag');
353
+ trackProgress(dialog);
354
+ });
355
+ };
356
+ const handlePointerUp = (e) => {
357
+ onPointerUp?.(e);
358
+ const d = drag.current;
359
+ if (!d || d.id !== e.pointerId)
360
+ return;
361
+ release(e.currentTarget, d.active ? d.tracker.velocity(performance.now()) : 0);
362
+ };
363
+ const handlePointerCancel = (e) => {
364
+ onPointerCancel?.(e);
365
+ if (drag.current?.id !== e.pointerId)
366
+ return;
367
+ release(e.currentTarget, null);
368
+ };
369
+ const handleClickCapture = (e) => {
370
+ onClickCapture?.(e);
371
+ if (!swallowClick.current)
372
+ return;
373
+ swallowClick.current = false;
374
+ e.preventDefault();
375
+ e.stopPropagation();
376
+ };
377
+ // El foco en algo que el parcial deja fuera de la ventana (con Tab) expande el sheet. El
378
+ // contenido desplazable en sí (que recibe el foco inicial si no tiene enfocables adentro) se ve
379
+ // en parte: no cuenta.
380
+ const handleFocus = (e) => {
381
+ onFocus?.(e);
382
+ const target = e.target;
383
+ if (live.current.state !== 'partial' || target === e.currentTarget)
384
+ return;
385
+ if (target.matches('.mk-bottom-sheet-content'))
386
+ return;
387
+ if (target.getBoundingClientRect().bottom > viewportHeight())
388
+ requestState('expanded', 'focus');
389
+ };
390
+ const generatedId = useId();
391
+ const [titleId, setTitleId] = useState(undefined);
392
+ const ctx = useMemo(() => ({
393
+ titleId: `${generatedId}title`,
394
+ setTitleId,
395
+ state,
396
+ hasPartial,
397
+ requestState,
398
+ requestClose,
399
+ }),
400
+ // requestState lee todo de refs; requestClose cambia con onClose.
401
+ [generatedId, state, hasPartial, onClose]);
402
+ const labelledBy = props['aria-labelledby'] ?? titleId;
403
+ return (_jsx(BottomSheetContext, { value: ctx, children: _jsx("dialog", { ...props, ...dialogProps, ref: setRef, className: cx('mk-bottom-sheet', className), "data-state": state, "aria-labelledby": labelledBy || undefined, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, onPointerCancel: handlePointerCancel, onClickCapture: handleClickCapture, onFocus: handleFocus, children: children }) }));
404
+ }
405
+ /**
406
+ * Drag handle: the 32 × 4 bar at the top of the sheet, which is also a button for keyboard and
407
+ * screen reader users. Like Compose's handle (which does the same when tapped): with the sheet
408
+ * partially expanded it expands it ("Expand"), expanded it takes it to partial ("Collapse") and,
409
+ * without a partial state, it closes it ("Close"). The name changes with the action.
410
+ *
411
+ * Goes as the first child of `BottomSheet`: it receives focus on open.
412
+ */
413
+ export function BottomSheetHandle({ expandLabel = bottomSheetStrings.expandLabel, collapseLabel = bottomSheetStrings.collapseLabel, closeLabel = bottomSheetStrings.closeLabel, className, onClick, ...props }) {
414
+ const ctx = useBottomSheet('BottomSheetHandle');
415
+ const action = !ctx.hasPartial ? 'close' : ctx.state === 'partial' ? 'expand' : 'collapse';
416
+ const label = action === 'close' ? closeLabel : action === 'expand' ? expandLabel : collapseLabel;
417
+ return (_jsx("button", { type: "button", ...props, "aria-label": label, className: cx('mk-bottom-sheet-handle', className), onClick: (e) => {
418
+ onClick?.(e);
419
+ if (e.defaultPrevented)
420
+ return;
421
+ if (action === 'close')
422
+ ctx.requestClose('handle');
423
+ else
424
+ ctx.requestState(action === 'expand' ? 'expanded' : 'partial', 'handle');
425
+ }, children: _jsx(FocusRing, {}) }));
426
+ }
427
+ /** The sheet's title (Title Large, `on-surface`), in an `<h2>`. It is the sheet's accessible name. */
428
+ export function BottomSheetTitle({ id, className, ...props }) {
429
+ const ctx = useBottomSheet('BottomSheetTitle');
430
+ const ownId = useRegisteredId(id, ctx.titleId, ctx.setTitleId);
431
+ return _jsx("h2", { ...props, id: ownId, className: cx('mk-bottom-sheet-title', className) });
432
+ }
@@ -0,0 +1,17 @@
1
+ import type { HTMLAttributes, Ref } from 'react';
2
+ export interface BottomSheetContentProps extends HTMLAttributes<HTMLDivElement> {
3
+ ref?: Ref<HTMLDivElement> | undefined;
4
+ }
5
+ /**
6
+ * The sheet's content: the only part that scrolls (the handle and the title stay fixed). No padding
7
+ * of its own (a `List` already has its own). With a finger, swiping down while scrolled to the top
8
+ * moves the sheet instead of scrolling; with the sheet partially expanded, any vertical swipe moves
9
+ * it. With a mouse, the content does not drag the sheet: it selects text.
10
+ *
11
+ * ```tsx
12
+ * <BottomSheetContent>
13
+ * <List>…</List>
14
+ * </BottomSheetContent>
15
+ * ```
16
+ */
17
+ export declare function BottomSheetContent({ className, ...props }: BottomSheetContentProps): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * The sheet's content: the only part that scrolls (the handle and the title stay fixed). No padding
4
+ * of its own (a `List` already has its own). With a finger, swiping down while scrolled to the top
5
+ * moves the sheet instead of scrolling; with the sheet partially expanded, any vertical swipe moves
6
+ * it. With a mouse, the content does not drag the sheet: it selects text.
7
+ *
8
+ * ```tsx
9
+ * <BottomSheetContent>
10
+ * <List>…</List>
11
+ * </BottomSheetContent>
12
+ * ```
13
+ */
14
+ export function BottomSheetContent({ className, ...props }) {
15
+ return _jsx("div", { ...props, className: className ? `mk-bottom-sheet-content ${className}` : 'mk-bottom-sheet-content' });
16
+ }
@@ -0,0 +1,37 @@
1
+ import { type HTMLAttributes, type Ref } from 'react';
2
+ import { type BottomSheetCloseReason, type BottomSheetState, type BottomSheetStateChangeReason } from './bottom-sheet-context.ts';
3
+ export interface BottomSheetStandardProps extends Omit<HTMLAttributes<HTMLElement>, 'onClose'> {
4
+ /**
5
+ * Standard (non-modal): lives alongside the content, peeking (by default the handle and the first
6
+ * line of the title, 80 px; without a title, 56 px; `--mk-bottom-sheet-peek-height` changes it) or
7
+ * expanded, with no scrim or trapped focus. Goes as a child of a `PaneScaffold` (or of an element
8
+ * with `position: relative`), against its bottom edge.
9
+ */
10
+ modal: false;
11
+ /**
12
+ * Shown (default) or hidden. Hidden, it slides down and is out of focus and accessibility (`inert`).
13
+ */
14
+ open?: boolean | undefined;
15
+ /**
16
+ * A request to hide it, with the reason (`BottomSheetCloseReason`; here always `'drag'`: dragging
17
+ * or flinging down from the peek). Without `onClose` the sheet cannot be hidden (Compose:
18
+ * `skipHiddenState = true`, the default); with it, the app decides by passing `open={false}`, or
19
+ * refuses by keeping `open` (the sheet goes back to the peek).
20
+ */
21
+ onClose?: ((reason: BottomSheetCloseReason) => void) | undefined;
22
+ /** Controlled state: `partial` (peeking) or `expanded`. See `onStateChange`. */
23
+ state?: BottomSheetState | undefined;
24
+ /** Initial state, uncontrolled. Defaults to `partial` (peeking), as in Compose. */
25
+ defaultState?: BottomSheetState | undefined;
26
+ /**
27
+ * The state settled on another value (or, when controlled, was requested): on releasing a drag
28
+ * (`drag`), with the handle (`handle`) or when focus reaches something the peek leaves out of view
29
+ * (`focus`).
30
+ */
31
+ onStateChange?: ((state: BottomSheetState, reason: BottomSheetStateChangeReason) => void) | undefined;
32
+ closeOnScrimClick?: never;
33
+ skipPartiallyExpanded?: never;
34
+ /** Ref to the `<aside>`. */
35
+ ref?: Ref<HTMLElement> | undefined;
36
+ }
37
+ export declare function StandardBottomSheet({ modal: _modal, open, onClose, state: stateProp, defaultState, onStateChange, className, children, ref, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onClickCapture, onFocus, ...props }: BottomSheetStandardProps): import("react").JSX.Element;