@matekit/react 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/CHANGELOG.md +102 -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 +118 -0
  193. package/dist/organisms/PaneScaffold/PaneScaffold.js +132 -0
  194. package/dist/organisms/Search/Search.d.ts +213 -0
  195. package/dist/organisms/Search/Search.js +783 -0
  196. package/dist/organisms/Search/SearchSlots.d.ts +18 -0
  197. package/dist/organisms/Search/SearchSlots.js +19 -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 +12025 -0
  262. package/dist/styles.css +12123 -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,206 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ // Bottom sheet standard (no modal), el de BottomSheetScaffold de Compose. ADR-0030.
4
+ //
5
+ // Cliente (ADR-0003): tiene estado (asomado o expandido), mide su alto y sigue al puntero al
6
+ // arrastrar. Sin <dialog>: no hay scrim, foco atrapado ni página inerte; el contenido de atrás
7
+ // sigue usable. Es un <aside> (región complementaria, como el SideSheet standard) que se ubica
8
+ // contra el borde de abajo de su bloque contenedor; como hijo de un PaneScaffold, sobre el área
9
+ // de los paneles (arriba de la barra de navegación), y los paneles reciben un relleno de abajo
10
+ // igual al asomo (pane-scaffold.css).
11
+ //
12
+ // El arrastre es el del modal (BottomSheet.tsx): eventos de puntero, el gesto pasa al sheet al
13
+ // superar 8 px si es vertical, sigue al puntero (--_drag) y al soltar decide computeTarget de
14
+ // src/internal/anchored-drag.ts con los umbrales de Compose (56 px, 125 px/s). Dentro de
15
+ // BottomSheetContent, el desplazamiento anidado se decide igual que en el modal.
16
+ import { useEffect, useId, useMemo, useRef, useState, } from 'react';
17
+ import { mergeRefs } from '../../internal/merge-refs.js';
18
+ import { computeTarget, DRAG_SLOP, VelocityTracker } from '../../internal/anchored-drag.js';
19
+ import { BottomSheetContext, } from './bottom-sheet-context.js';
20
+ const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
21
+ // Campos donde el mouse selecciona o edita: ahí no empieza un arrastre con mouse.
22
+ const FIELD = 'input, textarea, select, [contenteditable]:not([contenteditable="false"])';
23
+ // Hay un elemento con desplazamiento vertical, ya desplazado, entre `target` y el sheet.
24
+ function scrolledBetween(target, sheet) {
25
+ for (let el = target; el && el !== sheet; el = el.parentElement) {
26
+ if (el.scrollTop > 0 && el.scrollHeight > el.clientHeight) {
27
+ const overflow = getComputedStyle(el).overflowY;
28
+ if (overflow === 'auto' || overflow === 'scroll')
29
+ return true;
30
+ }
31
+ }
32
+ return false;
33
+ }
34
+ // El sheet standard; lo dibuja `BottomSheet` con `modal={false}`.
35
+ export function StandardBottomSheet({ modal: _modal, open = true, onClose, state: stateProp, defaultState = 'partial', onStateChange, className, children, ref, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onClickCapture, onFocus, ...props }) {
36
+ const controlled = stateProp !== undefined;
37
+ const [uncontrolled, setUncontrolled] = useState(defaultState);
38
+ const state = controlled ? stateProp : uncontrolled;
39
+ const live = useRef({ state, controlled, onStateChange, onClose });
40
+ live.current = { state, controlled, onStateChange, onClose };
41
+ const sheetRef = useRef(null);
42
+ const drag = useRef(null);
43
+ const swallowClick = useRef(false);
44
+ const requestState = (next, reason) => {
45
+ const l = live.current;
46
+ if (next === l.state)
47
+ return;
48
+ if (!l.controlled) {
49
+ setUncontrolled(next);
50
+ l.state = next;
51
+ }
52
+ l.onStateChange?.(next, reason);
53
+ };
54
+ // Un gesto táctil del que se adueñó el sheet no desplaza el contenido ni la página: hace falta
55
+ // un manejador nativo no pasivo (el `onTouchMove` de React es pasivo).
56
+ useEffect(() => {
57
+ const sheet = sheetRef.current;
58
+ if (!sheet)
59
+ return;
60
+ const onTouchMove = (e) => {
61
+ if (drag.current?.active && e.cancelable)
62
+ e.preventDefault();
63
+ };
64
+ sheet.addEventListener('touchmove', onTouchMove, { passive: false });
65
+ return () => sheet.removeEventListener('touchmove', onTouchMove);
66
+ }, []);
67
+ // Desplazamiento actual hacia abajo desde expandido, medido en pantalla (incluye el corrimiento).
68
+ const currentOffset = (sheet) => {
69
+ const parent = sheet.offsetParent;
70
+ const top = parent ? parent.getBoundingClientRect().top + parent.clientTop : 0;
71
+ return sheet.getBoundingClientRect().top - top - sheet.offsetTop;
72
+ };
73
+ // Anclas del arrastre: expandido en 0, asomado y, si se puede ocultar, oculto.
74
+ const anchors = (sheet) => {
75
+ const height = sheet.offsetHeight;
76
+ // --_bottom-sheet-peek está registrada como <length>: su valor calculado ya viene en px.
77
+ const peek = Number.parseFloat(getComputedStyle(sheet).getPropertyValue('--_bottom-sheet-peek')) || 0;
78
+ const list = [['expanded', 0], ['partial', Math.max(0, height - peek)]];
79
+ if (live.current.onClose)
80
+ list.push(['hidden', height]);
81
+ return list;
82
+ };
83
+ const clearDrag = (sheet) => {
84
+ sheet.removeAttribute('data-dragging');
85
+ sheet.style.removeProperty('--_drag');
86
+ };
87
+ const handlePointerDown = (e) => {
88
+ onPointerDown?.(e);
89
+ swallowClick.current = false;
90
+ if (e.defaultPrevented || !e.isPrimary || e.button !== 0 || drag.current || !open)
91
+ return;
92
+ const target = e.target;
93
+ const mouse = e.pointerType === 'mouse';
94
+ const inContent = !!target.closest('.mk-bottom-sheet-content');
95
+ if (mouse && (inContent || target.closest(FIELD)))
96
+ return;
97
+ const sheet = e.currentTarget;
98
+ const tracker = new VelocityTracker();
99
+ tracker.add(performance.now(), e.clientY);
100
+ const from = currentOffset(sheet);
101
+ drag.current = { id: e.pointerId, mouse, inContent, target, startX: e.clientX, startY: e.clientY, from, offset: from, active: false, tracker };
102
+ };
103
+ const handlePointerMove = (e) => {
104
+ onPointerMove?.(e);
105
+ const d = drag.current;
106
+ if (!d || d.id !== e.pointerId)
107
+ return;
108
+ const sheet = e.currentTarget;
109
+ const dx = e.clientX - d.startX;
110
+ const dy = e.clientY - d.startY;
111
+ if (!d.active) {
112
+ if (Math.hypot(dx, dy) < DRAG_SLOP)
113
+ return;
114
+ const vertical = Math.abs(dy) > Math.abs(dx);
115
+ // Como el modal: en el contenido, el sheet se queda con el gesto si está asomado o si se
116
+ // desliza hacia abajo con el contenido arriba de todo; si no, el gesto desplaza.
117
+ const ownsGesture = !d.inContent || live.current.state === 'partial' || (dy > 0 && !scrolledBetween(d.target, sheet));
118
+ if (!vertical || !ownsGesture) {
119
+ drag.current = null;
120
+ return;
121
+ }
122
+ d.active = true;
123
+ d.startY = e.clientY;
124
+ d.from = currentOffset(sheet);
125
+ try {
126
+ sheet.setPointerCapture(e.pointerId);
127
+ }
128
+ catch {
129
+ // NotFoundError: un evento sintético sin puntero activo detrás.
130
+ }
131
+ sheet.setAttribute('data-dragging', '');
132
+ }
133
+ e.preventDefault();
134
+ const list = anchors(sheet);
135
+ const max = Math.max(...list.map((a) => a[1]));
136
+ d.offset = Math.min(Math.max(d.from + (e.clientY - d.startY), 0), max);
137
+ d.tracker.add(performance.now(), e.clientY);
138
+ sheet.style.setProperty('--_drag', `${d.offset}px`);
139
+ };
140
+ const release = (sheet, velocity) => {
141
+ const d = drag.current;
142
+ drag.current = null;
143
+ if (!d?.active)
144
+ return;
145
+ swallowClick.current = d.mouse;
146
+ const target = velocity === null ? live.current.state : computeTarget(anchors(sheet), d.offset, velocity, undefined, undefined, 'BottomSheet');
147
+ clearDrag(sheet);
148
+ if (target === 'hidden') {
149
+ // Ocultar se pide al padre; si no pasa `open={false}`, el sheet vuelve a su estado.
150
+ live.current.onClose?.('drag');
151
+ return;
152
+ }
153
+ requestState(target, 'drag');
154
+ };
155
+ const handlePointerUp = (e) => {
156
+ onPointerUp?.(e);
157
+ const d = drag.current;
158
+ if (!d || d.id !== e.pointerId)
159
+ return;
160
+ release(e.currentTarget, d.active ? d.tracker.velocity(performance.now()) : 0);
161
+ };
162
+ const handlePointerCancel = (e) => {
163
+ onPointerCancel?.(e);
164
+ if (drag.current?.id !== e.pointerId)
165
+ return;
166
+ release(e.currentTarget, null);
167
+ };
168
+ const handleClickCapture = (e) => {
169
+ onClickCapture?.(e);
170
+ if (!swallowClick.current)
171
+ return;
172
+ swallowClick.current = false;
173
+ e.preventDefault();
174
+ e.stopPropagation();
175
+ };
176
+ // El foco (con Tab) en algo que el asomo deja fuera de la vista expande el sheet.
177
+ const handleFocus = (e) => {
178
+ onFocus?.(e);
179
+ const target = e.target;
180
+ if (live.current.state !== 'partial' || target === e.currentTarget)
181
+ return;
182
+ // El borde de abajo de lo visible es el del bloque contenedor: donde termina el sheet sin
183
+ // corrimiento (offsetTop no cuenta el translate).
184
+ const sheet = e.currentTarget;
185
+ const parent = sheet.offsetParent;
186
+ const bottom = parent ? parent.getBoundingClientRect().top + parent.clientTop + sheet.offsetTop + sheet.offsetHeight : innerHeight;
187
+ if (target.getBoundingClientRect().bottom > bottom + 1)
188
+ requestState('expanded', 'focus');
189
+ };
190
+ const setRef = useMemo(() => mergeRefs(sheetRef, ref), [ref]);
191
+ const generatedId = useId();
192
+ const [titleId, setTitleId] = useState(undefined);
193
+ const ctx = useMemo(() => ({
194
+ titleId: `${generatedId}title`,
195
+ setTitleId,
196
+ state,
197
+ hasPartial: true,
198
+ requestState,
199
+ // El asa nunca cierra el standard (siempre hay asomo): ocultar es del arrastre o de la app.
200
+ requestClose: (reason) => live.current.onClose?.(reason),
201
+ }),
202
+ // requestState y requestClose leen de refs.
203
+ [generatedId, state]);
204
+ const labelledBy = props['aria-labelledby'] ?? titleId;
205
+ return (_jsx(BottomSheetContext, { value: ctx, children: _jsx("aside", { ...props, ref: setRef, className: cx('mk-bottom-sheet-standard', className), "data-state": state, "data-closed": open ? undefined : '', inert: !open || undefined, "aria-labelledby": labelledBy || undefined, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, onPointerCancel: handlePointerCancel, onClickCapture: handleClickCapture, onFocus: handleFocus, children: children }) }));
206
+ }
@@ -0,0 +1,31 @@
1
+ /** State of the open sheet: partially expanded (modal: half the window; standard: peeking) or expanded. */
2
+ export type BottomSheetState = 'partial' | 'expanded';
3
+ /**
4
+ * Why the state changed (`onStateChange`):
5
+ * - `drag`: a drag was released and the sheet settles in another state;
6
+ * - `handle`: the drag handle (click or keyboard);
7
+ * - `focus`: focus reached something the partial state leaves out of view and the sheet expands;
8
+ * - `resize` (modal only): the partial state stopped being available (the sheet is no longer taller
9
+ * than half the window, or `skipPartiallyExpanded`) and the sheet is shown expanded, or it became
10
+ * available again and the sheet, with `state="partial"`, goes back to partial.
11
+ */
12
+ export type BottomSheetStateChangeReason = 'drag' | 'handle' | 'focus' | 'resize';
13
+ /**
14
+ * Why a bottom sheet asks to close (`onClose(reason)`). Shares `drag` and `handle` with
15
+ * `BottomSheetStateChangeReason`:
16
+ * - `drag`: a drag (or a fast fling) down from the lowest state was released;
17
+ * - `handle`: the drag handle, when there is no partial state (modal only);
18
+ * - `escape`, `scrim`, `native` (modal only): Escape or the platform's close request, a click on
19
+ * the scrim, or the `<dialog>` closing itself (`<form method="dialog">`, `close()`), as in `Dialog`.
20
+ */
21
+ export type BottomSheetCloseReason = 'drag' | 'handle' | 'escape' | 'scrim' | 'native';
22
+ export interface BottomSheetContextValue {
23
+ titleId: string;
24
+ setTitleId: (id: string | undefined) => void;
25
+ state: BottomSheetState;
26
+ hasPartial: boolean;
27
+ requestState: (state: BottomSheetState, reason: BottomSheetStateChangeReason) => void;
28
+ requestClose: (reason: BottomSheetCloseReason) => void;
29
+ }
30
+ export declare const BottomSheetContext: import("react").Context<BottomSheetContextValue | null>;
31
+ export declare function useBottomSheet(part: string): BottomSheetContextValue;
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ // Contexto de las partes del bottom sheet (BottomSheetHandle y BottomSheetTitle), compartido por el
3
+ // modal (BottomSheet.tsx) y el standard (StandardBottomSheet.tsx, ADR-0030). Interno: no se exporta.
4
+ import { createContext, use } from 'react';
5
+ import { partOutsideParent } from '../../internal/diagnostics.js';
6
+ export const BottomSheetContext = createContext(null);
7
+ export function useBottomSheet(part) {
8
+ const ctx = use(BottomSheetContext);
9
+ if (!ctx)
10
+ throw partOutsideParent(part, 'BottomSheet');
11
+ return ctx;
12
+ }
@@ -0,0 +1 @@
1
+ export * from '../../internal/anchored-drag.ts';
@@ -0,0 +1,4 @@
1
+ // La decisión al soltar un arrastre pasó a src/internal/anchored-drag.ts (2026-11-27), para
2
+ // compartirla con el ModalNavigationRail (ADR-0029). Este módulo la reexporta sin cambios para el
3
+ // BottomSheet y sus pruebas.
4
+ export * from '../../internal/anchored-drag.js';
@@ -0,0 +1,9 @@
1
+ export interface BottomSheetStrings {
2
+ /** `BottomSheetHandle` `expandLabel`: the handle when it expands the partial sheet. */
3
+ expandLabel: string;
4
+ /** `BottomSheetHandle` `collapseLabel`: the handle when it takes the expanded sheet to partial. */
5
+ collapseLabel: string;
6
+ /** `BottomSheetHandle` `closeLabel`: the handle when it closes the sheet (no partial state). */
7
+ closeLabel: string;
8
+ }
9
+ export declare const bottomSheetStrings: BottomSheetStrings;
@@ -0,0 +1,8 @@
1
+ // Textos por defecto de BottomSheet (en inglés: son salida para quien usa la librería). Cada clave
2
+ // se llama como la prop de `BottomSheetHandle` que lo cambia; el índice src/strings/index.ts los
3
+ // reúne con los demás.
4
+ export const bottomSheetStrings = {
5
+ expandLabel: 'Expand',
6
+ collapseLabel: 'Collapse',
7
+ closeLabel: 'Close',
8
+ };
@@ -0,0 +1,97 @@
1
+ import { type HTMLAttributes, type MouseEvent, type ReactNode, type Ref } from 'react';
2
+ import type { AccessibleNameProps } from '../../internal/accessible-name.ts';
3
+ /** `standard`: separate buttons that keep their shape. `connected`: joined segments (the replacement for segmented buttons). */
4
+ export type ButtonGroupVariant = 'standard' | 'connected';
5
+ export type ButtonGroupOrientation = 'horizontal' | 'vertical';
6
+ export type ButtonGroupSelectionMode = 'none' | 'single' | 'multiple';
7
+ /** What `useButtonGroup()` exposes about the group. */
8
+ export interface ButtonGroupState {
9
+ variant: ButtonGroupVariant;
10
+ /** `none` if the group does not handle selection. */
11
+ selectionMode: ButtonGroupSelectionMode;
12
+ /** Selected values (in `single`, zero or one). */
13
+ value: readonly string[];
14
+ }
15
+ interface ButtonGroupContextValue extends ButtonGroupState {
16
+ toggle: (value: string, event: MouseEvent<HTMLButtonElement>) => void;
17
+ }
18
+ export declare const useButtonGroupContext: () => ButtonGroupContextValue | null;
19
+ /**
20
+ * State of the `ButtonGroup` that contains the component, or `null` outside a group. Use it to
21
+ * compose your own segments, or for the filled icon of the selected one in an uncontrolled group.
22
+ */
23
+ export declare function useButtonGroup(): ButtonGroupState | null;
24
+ interface ButtonGroupBaseProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'defaultValue' | 'aria-label' | 'aria-labelledby' | 'aria-orientation'> {
25
+ /** Defaults to `standard`. */
26
+ variant?: ButtonGroupVariant | undefined;
27
+ /** Buttons in a row or in a column. In a column, the arrows are up and down. Defaults to `horizontal`. */
28
+ orientation?: ButtonGroupOrientation | undefined;
29
+ /**
30
+ * Button, IconButton (also wrapped in a Tooltip), ButtonGroupItem or ButtonGroupIconItem, all the
31
+ * same size. They must be the direct children: the connected shape comes from their position.
32
+ */
33
+ children?: ReactNode;
34
+ /** Ref to the `<div role="toolbar">`. */
35
+ ref?: Ref<HTMLDivElement> | undefined;
36
+ }
37
+ interface NoSelection {
38
+ selectionMode?: 'none' | undefined;
39
+ value?: undefined;
40
+ defaultValue?: undefined;
41
+ onValueChange?: undefined;
42
+ required?: undefined;
43
+ }
44
+ interface SingleSelection {
45
+ /** One ButtonGroupItem selected at a time. */
46
+ selectionMode: 'single';
47
+ /** Selected value (controlled); `null`, none. */
48
+ value?: string | null | undefined;
49
+ /** Initially selected value (uncontrolled). */
50
+ defaultValue?: string | null | undefined;
51
+ /** Called on selecting or deselecting, with the new value and the button's event. */
52
+ onValueChange?: ((value: string | null, event: MouseEvent<HTMLButtonElement>) => void) | undefined;
53
+ /**
54
+ * Always one selected: pressing the selected one again does not deselect it (`required` in
55
+ * @material/web, and Compose's single-selection examples). Defaults to `false`.
56
+ */
57
+ required?: boolean | undefined;
58
+ }
59
+ interface MultipleSelection {
60
+ /** Any number of ButtonGroupItem selected. */
61
+ selectionMode: 'multiple';
62
+ /** Selected values (controlled). */
63
+ value?: readonly string[] | undefined;
64
+ /** Initially selected values (uncontrolled). */
65
+ defaultValue?: readonly string[] | undefined;
66
+ /** Called on selecting or deselecting, with the new list (in click order) and the event. */
67
+ onValueChange?: ((value: string[], event: MouseEvent<HTMLButtonElement>) => void) | undefined;
68
+ required?: undefined;
69
+ }
70
+ export type ButtonGroupProps = ButtonGroupBaseProps & AccessibleNameProps & (NoSelection | SingleSelection | MultipleSelection);
71
+ /**
72
+ * Material 3 Expressive button group: a `<div role="toolbar">` with a required accessible name
73
+ * (`label`, `aria-label` or `aria-labelledby`), a single Tab stop and arrow keys.
74
+ *
75
+ * - `standard`: separate buttons (18, 12 or 8 px apart depending on the size) that keep their
76
+ * shape; the pressed one widens and shrinks its neighbors.
77
+ * - `connected`: segments 2 px apart with round outer corners (or square with `shape="square"` on
78
+ * the buttons) and small inner ones, which shrink when pressed; the selected one becomes fully
79
+ * round. Replaces segmented buttons.
80
+ *
81
+ * With `selectionMode`, it handles the selection of `ButtonGroupItem` and `ButtonGroupIconItem`:
82
+ *
83
+ * ```tsx
84
+ * <ButtonGroup variant="connected" label="View" selectionMode="single" required value={view} onValueChange={setView}>
85
+ * <ButtonGroupItem value="day">Day</ButtonGroupItem>
86
+ * <ButtonGroupItem value="week">Week</ButtonGroupItem>
87
+ * <ButtonGroupItem value="month">Month</ButtonGroupItem>
88
+ * </ButtonGroup>
89
+ *
90
+ * <ButtonGroup label="Editing">
91
+ * <Button variant="tonal">Copy</Button>
92
+ * <Button variant="tonal">Paste</Button>
93
+ * </ButtonGroup>
94
+ * ```
95
+ */
96
+ export declare function ButtonGroup(props: ButtonGroupProps): import("react").JSX.Element;
97
+ export {};
@@ -0,0 +1,242 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ // Organismo interactivo (excepción al ADR-0003, ADR-0031, como el ChipGroup del ADR-0019 y la
4
+ // Toolbar del ADR-0027): el foco itinerante, la selección por contexto y el ensanche al presionar
5
+ // necesitan estado, efectos, contexto y eventos. Los hijos (Button, IconButton, Tooltip) siguen
6
+ // siendo lo que son y pueden venir de un Server Component; solo ButtonGroupItem y
7
+ // ButtonGroupIconItem, que leen la selección, son cliente.
8
+ //
9
+ // - Teclado: patrón APG "Toolbar", como el ChipGroup, la Toolbar y el button group de
10
+ // @material/web (labs/gb/components/buttongroup: `role="toolbar"` y `focusgroup="toolbar wrap
11
+ // inline"`): una sola parada de Tab y flechas en el eje, con vuelta, Inicio y Fin, RTL
12
+ // (src/internal/roving-focus.ts).
13
+ // - Selección (opcional): `selectionMode` `single` o `multiple`, con `value`/`defaultValue`/
14
+ // `onValueChange`, repartida por contexto a los ButtonGroupItem. Toggles con `aria-pressed` en los
15
+ // dos modos, como el ChipGroup y @material/web (normalizeSelection, `required`).
16
+ // - Forma: la del connected la resuelve CSS sobre Group (ADR-0017); ver button-group.css.
17
+ // - Ensanche al presionar (standard horizontal, ButtonGroup.kt de Compose y @material/web): al
18
+ // apretar, se mide el botón y sus vecinos y se dejan los corrimientos en variables del propio
19
+ // elemento; el CSS los anima con el resorte FastSpatial (ver pressWiden abajo).
20
+ import { createContext, use, useCallback, useEffect, useMemo, useRef, useState, } from 'react';
21
+ import { Group } from '../../atoms/Group/Group.js';
22
+ import { mkWarn } from '../../internal/diagnostics.js';
23
+ import { isDevelopment } from '../../internal/dev.js';
24
+ import { cx } from '../../internal/interactive.js';
25
+ import { mergeRefs } from '../../internal/merge-refs.js';
26
+ import { useRovingFocus } from '../../internal/roving-focus.js';
27
+ const ButtonGroupContext = createContext(null);
28
+ // Contexto completo, para ButtonGroupItem (no se exporta desde el índice).
29
+ export const useButtonGroupContext = () => use(ButtonGroupContext);
30
+ /**
31
+ * State of the `ButtonGroup` that contains the component, or `null` outside a group. Use it to
32
+ * compose your own segments, or for the filled icon of the selected one in an uncontrolled group.
33
+ */
34
+ export function useButtonGroup() {
35
+ const ctx = use(ButtonGroupContext);
36
+ const variant = ctx?.variant;
37
+ const mode = ctx?.selectionMode;
38
+ const value = ctx?.value;
39
+ return useMemo(() => (variant === undefined || mode === undefined || value === undefined ? null : { variant, selectionMode: mode, value }), [variant, mode, value]);
40
+ }
41
+ // Paradas: botones y enlaces del grupo, sin los de un menú, tooltip, diálogo u otro grupo anidado.
42
+ const ROVING_STOP = ':is(button, a[href])';
43
+ const ROVING_SCOPE = '.mk-button-group, [role="toolbar"], [role="menu"], [popover], dialog';
44
+ const toArray = (v) => v == null ? [] : typeof v === 'string' ? [v] : v;
45
+ // Los bloques del grupo: sus hijos directos, sin el popover que un Tooltip deja como hermano.
46
+ const blocks = (root) => [...root.children].filter((el) => el instanceof HTMLElement && !el.matches('[popover]'));
47
+ // --- Ensanche al presionar (standard) ---
48
+ // Portado de ButtonGroup.kt de Compose (ButtonGroupMeasurePolicy, commit 76990c62ac del 2026-11-24):
49
+ // el presionado crece `PRESSED_RATIO` de su ancho a costa de sus vecinos, cada uno cede como mucho
50
+ // su relleno lateral (`compressionLimit`, el relleno final del botón). El del medio toma la mitad de
51
+ // cada lado; el primero, todo del siguiente; el último, todo del anterior.
52
+ // StandardButtonGroup*Tokens.PressedItemWidthMultiplierPercent = 15 (y @material/web, 15 %).
53
+ const PRESSED_RATIO = 0.15;
54
+ const GROW_START = '--_bg-grow-start';
55
+ const GROW_END = '--_bg-grow-end';
56
+ // Cuánto puede ceder un bloque: su relleno lateral (Button) o su espacio lateral (IconButton).
57
+ function compressionLimit(el) {
58
+ const cs = getComputedStyle(el);
59
+ const raw = el.classList.contains('mk-icon-button') ? cs.getPropertyValue('--_space') : el.classList.contains('mk-button') ? cs.getPropertyValue('--_padding') : '';
60
+ const value = Number.parseFloat(raw);
61
+ return Number.isFinite(value) ? value : 0;
62
+ }
63
+ function clearWiden(root) {
64
+ for (const el of blocks(root)) {
65
+ el.style.removeProperty(GROW_START);
66
+ el.style.removeProperty(GROW_END);
67
+ }
68
+ }
69
+ // Ensancha `pressed` y achica sus vecinos (en orden del documento: inicio y final lógicos).
70
+ function pressWiden(root, pressed) {
71
+ clearWiden(root);
72
+ const items = blocks(root);
73
+ const index = items.indexOf(pressed);
74
+ if (index === -1 || items.length < 2)
75
+ return;
76
+ const width = pressed.getBoundingClientRect().width;
77
+ const prev = items[index - 1];
78
+ const next = items[index + 1];
79
+ let start = 0;
80
+ let end = 0;
81
+ if (prev && next) {
82
+ const growth = Math.min((PRESSED_RATIO * width) / 2, compressionLimit(prev), compressionLimit(next));
83
+ start = Math.min(growth, prev.getBoundingClientRect().width);
84
+ end = Math.min(growth, next.getBoundingClientRect().width);
85
+ }
86
+ else if (next) {
87
+ end = Math.min(PRESSED_RATIO * width, compressionLimit(next), next.getBoundingClientRect().width);
88
+ }
89
+ else if (prev) {
90
+ start = Math.min(PRESSED_RATIO * width, compressionLimit(prev), prev.getBoundingClientRect().width);
91
+ }
92
+ // Valores en px enteros, como Compose (roundToInt): evita medio píxel de corrimiento.
93
+ start = Math.round(start);
94
+ end = Math.round(end);
95
+ if (start > 0 && prev) {
96
+ pressed.style.setProperty(GROW_START, `${start}px`);
97
+ prev.style.setProperty(GROW_END, `${-start}px`);
98
+ }
99
+ if (end > 0 && next) {
100
+ pressed.style.setProperty(GROW_END, `${end}px`);
101
+ next.style.setProperty(GROW_START, `${-end}px`);
102
+ }
103
+ }
104
+ /**
105
+ * Material 3 Expressive button group: a `<div role="toolbar">` with a required accessible name
106
+ * (`label`, `aria-label` or `aria-labelledby`), a single Tab stop and arrow keys.
107
+ *
108
+ * - `standard`: separate buttons (18, 12 or 8 px apart depending on the size) that keep their
109
+ * shape; the pressed one widens and shrinks its neighbors.
110
+ * - `connected`: segments 2 px apart with round outer corners (or square with `shape="square"` on
111
+ * the buttons) and small inner ones, which shrink when pressed; the selected one becomes fully
112
+ * round. Replaces segmented buttons.
113
+ *
114
+ * With `selectionMode`, it handles the selection of `ButtonGroupItem` and `ButtonGroupIconItem`:
115
+ *
116
+ * ```tsx
117
+ * <ButtonGroup variant="connected" label="View" selectionMode="single" required value={view} onValueChange={setView}>
118
+ * <ButtonGroupItem value="day">Day</ButtonGroupItem>
119
+ * <ButtonGroupItem value="week">Week</ButtonGroupItem>
120
+ * <ButtonGroupItem value="month">Month</ButtonGroupItem>
121
+ * </ButtonGroup>
122
+ *
123
+ * <ButtonGroup label="Editing">
124
+ * <Button variant="tonal">Copy</Button>
125
+ * <Button variant="tonal">Paste</Button>
126
+ * </ButtonGroup>
127
+ * ```
128
+ */
129
+ export function ButtonGroup(props) {
130
+ const { variant = 'standard', orientation = 'horizontal', selectionMode = 'none', value: valueProp, defaultValue, onValueChange, required = false, label, 'aria-label': ariaLabel, className, children, onKeyDown, onKeyUp, onFocus, onBlur, onPointerDown, ref, ...rest } = props;
131
+ const rootRef = useRef(null);
132
+ const mergedRef = useMemo(() => mergeRefs(ref, rootRef), [ref]);
133
+ const [uncontrolled, setUncontrolled] = useState(() => toArray(defaultValue));
134
+ const controlled = valueProp !== undefined;
135
+ const value = controlled ? toArray(valueProp) : uncontrolled;
136
+ const toggle = useCallback((item, event) => {
137
+ if (selectionMode === 'none')
138
+ return;
139
+ const on = value.includes(item);
140
+ if (selectionMode === 'single') {
141
+ if (on && required)
142
+ return;
143
+ const next = on ? null : item;
144
+ if (!controlled)
145
+ setUncontrolled(toArray(next));
146
+ onValueChange?.(next, event);
147
+ }
148
+ else {
149
+ const next = on ? value.filter((v) => v !== item) : [...value, item];
150
+ if (!controlled)
151
+ setUncontrolled(next);
152
+ onValueChange?.(next, event);
153
+ }
154
+ }, [selectionMode, value, controlled, required, onValueChange]);
155
+ const context = useMemo(() => ({ variant, selectionMode, value, toggle }), [variant, selectionMode, value, toggle]);
156
+ const roving = useRovingFocus(rootRef, { stop: ROVING_STOP, scope: ROVING_SCOPE, orientation });
157
+ // Hijos que no son botones de matekit en el connected: la forma por posición caería en el
158
+ // envoltorio (un <span>, un <div>) y no en el botón. Se revisa sobre el DOM, como el foco
159
+ // itinerante, para ver también lo que dibuja otro componente.
160
+ const warned = useRef({});
161
+ useEffect(() => {
162
+ const root = rootRef.current;
163
+ if (!root || variant !== 'connected' || !isDevelopment())
164
+ return;
165
+ const foreign = blocks(root).filter((el) => !el.matches('.mk-button, .mk-icon-button'));
166
+ if (foreign.length === 0)
167
+ return;
168
+ mkWarn('MK_BUTTON_GROUP_FOREIGN_CHILD', {
169
+ component: 'ButtonGroup',
170
+ problem: 'a connected group has a child that is not a Button or IconButton, so its position shape is applied to that element instead of a button',
171
+ fix: 'render Button, IconButton, ButtonGroupItem or ButtonGroupIconItem as direct children (a Tooltip around them is fine); move wrappers outside the group',
172
+ }, { tags: foreign.map((el) => el.tagName.toLowerCase()) }, { once: warned.current });
173
+ });
174
+ // Ensanche al presionar: solo el standard en fila. Se suelta con el puntero en cualquier lugar.
175
+ const widens = variant === 'standard' && orientation === 'horizontal';
176
+ const pressable = (target) => {
177
+ const root = rootRef.current;
178
+ if (!root || !(target instanceof Element))
179
+ return undefined;
180
+ const block = blocks(root).find((el) => el.contains(target));
181
+ if (!block || !block.matches(ROVING_STOP) || block.matches(':disabled, [aria-disabled="true"]'))
182
+ return undefined;
183
+ return block;
184
+ };
185
+ useEffect(() => {
186
+ const root = rootRef.current;
187
+ if (!root || !widens)
188
+ return;
189
+ const release = () => clearWiden(root);
190
+ document.addEventListener('pointerup', release);
191
+ document.addEventListener('pointercancel', release);
192
+ return () => {
193
+ document.removeEventListener('pointerup', release);
194
+ document.removeEventListener('pointercancel', release);
195
+ clearWiden(root);
196
+ };
197
+ }, [widens]);
198
+ const handlePointerDown = (event) => {
199
+ onPointerDown?.(event);
200
+ if (!widens || event.button !== 0)
201
+ return;
202
+ const block = pressable(event.target);
203
+ if (block)
204
+ pressWiden(event.currentTarget, block);
205
+ };
206
+ const handleKeyDown = (event) => {
207
+ onKeyDown?.(event);
208
+ roving.onKeyDown(event);
209
+ if (widens && !event.repeat && (event.key === ' ' || event.key === 'Enter')) {
210
+ const block = pressable(event.target);
211
+ if (block)
212
+ pressWiden(event.currentTarget, block);
213
+ }
214
+ };
215
+ const handleKeyUp = (event) => {
216
+ onKeyUp?.(event);
217
+ if (widens && (event.key === ' ' || event.key === 'Enter'))
218
+ clearWiden(event.currentTarget);
219
+ };
220
+ const handleFocus = (event) => {
221
+ onFocus?.(event);
222
+ roving.onFocus(event);
223
+ };
224
+ const handleBlur = (event) => {
225
+ onBlur?.(event);
226
+ if (widens)
227
+ clearWiden(event.currentTarget);
228
+ };
229
+ const shared = {
230
+ ...rest,
231
+ role: 'toolbar',
232
+ 'aria-label': label ?? ariaLabel,
233
+ 'aria-orientation': orientation,
234
+ 'data-variant': variant,
235
+ onKeyDown: handleKeyDown,
236
+ onKeyUp: handleKeyUp,
237
+ onFocus: handleFocus,
238
+ onBlur: handleBlur,
239
+ onPointerDown: handlePointerDown,
240
+ };
241
+ return (_jsx(ButtonGroupContext, { value: context, children: variant === 'connected' ? (_jsx(Group, { ...shared, ref: mergedRef, orientation: orientation, className: cx('mk-button-group', className), children: children })) : (_jsx("div", { ...shared, ref: mergedRef, "data-orientation": orientation, className: cx('mk-button-group', className), children: children })) }));
242
+ }
@@ -0,0 +1,36 @@
1
+ import { type ButtonProps } from '../../molecules/Button/Button.tsx';
2
+ import { type IconButtonProps } from '../../molecules/IconButton/IconButton.tsx';
3
+ /** The `<button>` form of Button and IconButton (no links: a link is not selected). */
4
+ type ButtonForm<P> = Extract<P, {
5
+ href?: undefined;
6
+ render?: undefined;
7
+ }>;
8
+ interface ItemOwnProps {
9
+ /** This button's value in the group's selection (also the `<button>`'s `value`). */
10
+ value: string;
11
+ }
12
+ /** `ButtonGroupItem` props: those of a `<button>` Button without `selected` (the group sets it), plus `value`. */
13
+ export type ButtonGroupItemProps = Omit<ButtonForm<ButtonProps>, 'selected' | 'value' | 'aria-pressed'> & ItemOwnProps;
14
+ /** `ButtonGroupIconItem` props: those of a `<button>` IconButton without `selected`, plus `value`. */
15
+ export type ButtonGroupIconItemProps = Omit<ButtonForm<IconButtonProps>, 'selected' | 'value' | 'aria-pressed'> & ItemOwnProps;
16
+ /**
17
+ * Text (and icon) button of a `ButtonGroup` that handles selection: selected according to the
18
+ * group's `value` (`aria-pressed`). In the connected variant it defaults to `tonal` (the kit's
19
+ * colors); in the standard one, to the Button's default style.
20
+ *
21
+ * ```tsx
22
+ * <ButtonGroupItem value="week"><CalendarIcon />Week</ButtonGroupItem>
23
+ * ```
24
+ */
25
+ export declare function ButtonGroupItem({ value, variant, onClick, ...props }: ButtonGroupItemProps): import("react").JSX.Element;
26
+ /**
27
+ * Icon button of a `ButtonGroup` that handles selection (`label` is required, as in IconButton). In
28
+ * the connected variant it defaults to `tonal`; in the standard one, to the IconButton's default
29
+ * style.
30
+ *
31
+ * ```tsx
32
+ * <ButtonGroupIconItem value="bold" label="Bold"><BoldIcon /></ButtonGroupIconItem>
33
+ * ```
34
+ */
35
+ export declare function ButtonGroupIconItem({ value, variant, onClick, ...props }: ButtonGroupIconItemProps): import("react").JSX.Element;
36
+ export {};