@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,146 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Molécula interactiva (ADR-0003): la etiqueta, el input y el texto de ayuda son partes
4
+ // separadas (ADR-0002) que tienen que compartir ids para la asociación accesible
5
+ // (<label htmlFor> ↔ input y aria-describedby ↔ texto de ayuda). Esos ids viajan por
6
+ // contexto de React, que solo existe en el cliente.
7
+ //
8
+ // Lo visual no depende de JavaScript: la etiqueta flotante, los estados (hover, foco, error,
9
+ // deshabilitado) y el corte del borde del outlined se resuelven en text-field.css. Las partes
10
+ // sin ids (TextFieldLeading, TextFieldTrailing) son universales y están en TextFieldSlots.tsx.
11
+ import { createContext, use, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
12
+ import { StateLayer } from '../../atoms/StateLayer/StateLayer.js';
13
+ import { mkWarn, partOutsideParent } from '../../internal/diagnostics.js';
14
+ import { hasAccessibleName } from '../../internal/accessible-name.js';
15
+ import { isDevelopment } from '../../internal/dev.js';
16
+ import { mergeRefs } from '../../internal/merge-refs.js';
17
+ const TextFieldContext = createContext(null);
18
+ function useTextField(part) {
19
+ const ctx = use(TextFieldContext);
20
+ if (!ctx)
21
+ throw partOutsideParent(part, 'TextField');
22
+ return ctx;
23
+ }
24
+ const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
25
+ /**
26
+ * Material 3 text field, built by composition. The parts go as direct children (the container is
27
+ * a grid that places them by class, in any order):
28
+ *
29
+ * ```tsx
30
+ * <TextField variant="outlined" error={!!err}>
31
+ * <TextFieldLeading><SearchIcon /></TextFieldLeading>
32
+ * <TextFieldLabel>Search</TextFieldLabel>
33
+ * <TextFieldInput value={q} onChange={(e) => setQ(e.target.value)} />
34
+ * <TextFieldTrailing><IconButton label="Clear"><CancelIcon /></IconButton></TextFieldTrailing>
35
+ * <TextFieldSupporting>{err ?? 'At least 3 letters'}</TextFieldSupporting>
36
+ * </TextField>
37
+ * ```
38
+ *
39
+ * The label is associated with the input and the supporting text becomes its description without
40
+ * passing ids; if you pass them (`id` on `TextFieldInput` or `TextFieldSupporting`), they are kept.
41
+ * `className` and `style` go to the container; the default width is 280 px (the kit's), with
42
+ * `max-width: 100%`. In a form it usually looks better full width (`width: 100%`). Inside a CSS
43
+ * grid, the implicit column takes the minimum width of its content (the 280 px) even if the
44
+ * container is narrower: use `grid-template-columns: minmax(0, 1fr)` on the grid so the field
45
+ * shrinks.
46
+ */
47
+ export function TextField({ variant = 'filled', error = false, disabled = false, className, children, ref, ...props }) {
48
+ const generatedId = useId();
49
+ const [customInputId, setCustomInputId] = useState(undefined);
50
+ const [supportingId, setSupportingId] = useState(undefined);
51
+ const inputId = customInputId ?? `${generatedId}input`;
52
+ const ctx = useMemo(() => ({ variant, error, disabled, inputId, supportingId, setCustomInputId, setSupportingId }), [variant, error, disabled, inputId, supportingId]);
53
+ return (_jsx(TextFieldContext, { value: ctx, children: _jsxs("div", { ...props, ref: ref, className: cx('mk-text-field', className), "data-variant": variant, "data-error": error || undefined, children: [_jsx("span", { className: "mk-text-field-container", "aria-hidden": "true", children: _jsx(StateLayer, {}) }), children] }) }));
54
+ }
55
+ /**
56
+ * Label of the field: at rest it takes the place of the text (Body Large) and floats up (Body
57
+ * Small) with focus or a value. It is a `<label>` associated with the input.
58
+ *
59
+ * In the outlined field it also draws the border (a `<fieldset>` with a `<legend>`, hidden from
60
+ * screen readers): the `<legend>` holds an invisible copy of the text and the browser cuts the
61
+ * border to its size. So the content should be text only.
62
+ */
63
+ export function TextFieldLabel({ className, htmlFor, children, ...props }) {
64
+ const { inputId, variant } = useTextField('TextFieldLabel');
65
+ return (_jsxs(_Fragment, { children: [_jsx("label", { ...props, htmlFor: htmlFor ?? inputId, className: cx('mk-text-field-label', className), children: children }), variant === 'outlined' && (_jsx("fieldset", { className: "mk-text-field-outline", "aria-hidden": "true", children: _jsx("legend", { className: "mk-text-field-notch", children: _jsx("span", { children: children }) }) }))] }));
66
+ }
67
+ // Registra un id propio del input para que la etiqueta lo use.
68
+ function useInputId(id, part) {
69
+ const ctx = useTextField(part);
70
+ const { setCustomInputId } = ctx;
71
+ useLayoutEffect(() => {
72
+ if (id === undefined)
73
+ return;
74
+ setCustomInputId(id);
75
+ return () => setCustomInputId(undefined);
76
+ }, [id, setCustomInputId]);
77
+ return ctx;
78
+ }
79
+ // El `<input>` o `<textarea>` sin nombre accesible (MK_FIELD_UNNAMED): sin `TextFieldLabel`, un
80
+ // `<label>` propio, `aria-label` ni `aria-labelledby`, el lector anuncia solo "edit text". Se mide en
81
+ // el DOM un cuadro después de montar (la etiqueta apunta a un id que puede registrarse en un efecto),
82
+ // una vez por instancia. Devuelve la `ref` del campo combinada con la de la app.
83
+ function useFieldName(part, ref) {
84
+ const own = useRef(null);
85
+ const setRef = useMemo(() => mergeRefs(own, ref), [ref]);
86
+ const warned = useRef({});
87
+ useEffect(() => {
88
+ if (!isDevelopment())
89
+ return;
90
+ const frame = requestAnimationFrame(() => {
91
+ const field = own.current;
92
+ if (!field?.isConnected || hasAccessibleName(field))
93
+ return;
94
+ mkWarn('MK_FIELD_UNNAMED', {
95
+ component: part,
96
+ problem: 'the field has no accessible name, so a screen reader announces only its role; a placeholder is not a label',
97
+ fix: `add a <TextFieldLabel> to the TextField (<TextFieldLabel>Email</TextFieldLabel>), or pass aria-label or aria-labelledby to the <${part}>`,
98
+ }, undefined, { once: warned.current });
99
+ });
100
+ return () => cancelAnimationFrame(frame);
101
+ }, [part]);
102
+ return setRef;
103
+ }
104
+ const describedBy = (own, supporting) => [own, supporting].filter(Boolean).join(' ') || undefined;
105
+ /**
106
+ * The field's native `<input>`. It accepts all its props (`type`, `value`, `defaultValue`,
107
+ * `onChange`, `name`, `required`, `maxLength`, `autoComplete`…) and `ref`.
108
+ *
109
+ * Its accessible name comes from `TextFieldLabel`; without one, pass `aria-label` or
110
+ * `aria-labelledby` (a `placeholder` is not a name). Development builds warn when it ends up
111
+ * unnamed (`MK_FIELD_UNNAMED`).
112
+ *
113
+ * Without a `placeholder`, a one-space one is used: the floating label needs it to know, with
114
+ * `:placeholder-shown`, whether the field is empty. Your own `placeholder` shows only once the
115
+ * label has floated (with focus), as in Material 3.
116
+ */
117
+ export function TextFieldInput({ id, className, placeholder, ref, ...props }) {
118
+ const ctx = useInputId(id, 'TextFieldInput');
119
+ const setRef = useFieldName('TextFieldInput', ref);
120
+ return (_jsx("input", { ...props, ref: setRef, id: id ?? ctx.inputId, className: cx('mk-text-field-input', className), placeholder: placeholder || ' ', disabled: ctx.disabled || props.disabled, "aria-invalid": ctx.error || props['aria-invalid'] || undefined, "aria-describedby": describedBy(props['aria-describedby'], ctx.supportingId) }));
121
+ }
122
+ /**
123
+ * Multi-line variant: a native `<textarea>` instead of the input. The field grows with `rows`
124
+ * (defaults to 2) or with CSS (`field-sizing: content`, `resize`). Same label, placeholder and
125
+ * accessible association rules as `TextFieldInput`.
126
+ */
127
+ export function TextFieldTextarea({ id, className, placeholder, ref, ...props }) {
128
+ const ctx = useInputId(id, 'TextFieldTextarea');
129
+ const setRef = useFieldName('TextFieldTextarea', ref);
130
+ return (_jsx("textarea", { ...props, ref: setRef, id: id ?? ctx.inputId, className: cx('mk-text-field-input mk-text-field-textarea', className), placeholder: placeholder || ' ', disabled: ctx.disabled || props.disabled, "aria-invalid": ctx.error || props['aria-invalid'] || undefined, "aria-describedby": describedBy(props['aria-describedby'], ctx.supportingId) }));
131
+ }
132
+ /**
133
+ * Supporting text below the field (Body Small). It becomes the input's accessible description
134
+ * (`aria-describedby`). In error it takes the error color: to show the error message, change its
135
+ * content.
136
+ */
137
+ export function TextFieldSupporting({ id, className, ...props }) {
138
+ const { setSupportingId } = useTextField('TextFieldSupporting');
139
+ const generatedId = useId();
140
+ const ownId = id ?? generatedId;
141
+ useLayoutEffect(() => {
142
+ setSupportingId(ownId);
143
+ return () => setSupportingId(undefined);
144
+ }, [ownId, setSupportingId]);
145
+ return _jsx("div", { ...props, id: ownId, className: cx('mk-text-field-supporting', className) });
146
+ }
@@ -0,0 +1,22 @@
1
+ import type { HTMLAttributes } from 'react';
2
+ export interface TextFieldSlotProps extends HTMLAttributes<HTMLSpanElement> {
3
+ }
4
+ /**
5
+ * Leading icon of the field, in a 48 × 48 area with the 24 icon centered. It can hold an icon
6
+ * (decorative) or an `IconButton`.
7
+ *
8
+ * ```tsx
9
+ * <TextFieldLeading><SearchIcon /></TextFieldLeading>
10
+ * ```
11
+ */
12
+ export declare function TextFieldLeading({ className, ...props }: TextFieldSlotProps): import("react").JSX.Element;
13
+ /**
14
+ * Trailing icon or button of the field, in a 48 × 48 area. In error, an icon or a standard
15
+ * `IconButton` takes the error color. If the field is disabled, pass `disabled` to the
16
+ * `IconButton` too.
17
+ *
18
+ * ```tsx
19
+ * <TextFieldTrailing><IconButton label="Clear" onClick={clear}><CancelIcon /></IconButton></TextFieldTrailing>
20
+ * ```
21
+ */
22
+ export declare function TextFieldTrailing({ className, ...props }: TextFieldSlotProps): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Leading icon of the field, in a 48 × 48 area with the 24 icon centered. It can hold an icon
4
+ * (decorative) or an `IconButton`.
5
+ *
6
+ * ```tsx
7
+ * <TextFieldLeading><SearchIcon /></TextFieldLeading>
8
+ * ```
9
+ */
10
+ export function TextFieldLeading({ className, ...props }) {
11
+ return _jsx("span", { ...props, className: className ? `mk-text-field-leading ${className}` : 'mk-text-field-leading' });
12
+ }
13
+ /**
14
+ * Trailing icon or button of the field, in a 48 × 48 area. In error, an icon or a standard
15
+ * `IconButton` takes the error color. If the field is disabled, pass `disabled` to the
16
+ * `IconButton` too.
17
+ *
18
+ * ```tsx
19
+ * <TextFieldTrailing><IconButton label="Clear" onClick={clear}><CancelIcon /></IconButton></TextFieldTrailing>
20
+ * ```
21
+ */
22
+ export function TextFieldTrailing({ className, ...props }) {
23
+ return _jsx("span", { ...props, className: className ? `mk-text-field-trailing ${className}` : 'mk-text-field-trailing' });
24
+ }
@@ -0,0 +1,108 @@
1
+ import { type ChangeEvent, type FormEvent, type HTMLAttributes, type KeyboardEvent, type MouseEvent, type ReactNode, type Ref } from 'react';
2
+ import { type TimeHourCycle } from '../../internal/time.ts';
3
+ export type { TimeHourCycle } from '../../internal/time.ts';
4
+ /** The event that changed the value: typing in a field, a key on a field or the period, or a click on the period. */
5
+ export type TimeInputChangeEvent = ChangeEvent<HTMLInputElement> | KeyboardEvent<HTMLElement> | MouseEvent<HTMLElement>;
6
+ export interface TimeInputProps extends Omit<HTMLAttributes<HTMLDivElement>, 'color' | 'defaultValue' | 'onChange' | 'onInvalid' | 'role'> {
7
+ /**
8
+ * The time, controlled: `"HH:mm"` on the 24-hour clock (`"07:05"`, `"19:30"`), the same text as the
9
+ * value of `<input type="time">`, or `''` for no time. Any other text counts as `''` and warns in
10
+ * development (`MK_TIME_VALUE_INVALID`).
11
+ */
12
+ value?: string | undefined;
13
+ /** The initial time when uncontrolled, and the one `form.reset()` restores. Defaults to `''`. */
14
+ defaultValue?: string | undefined;
15
+ /**
16
+ * The time changed: the new value (`"HH:mm"`, or `''` while a field is empty or out of range) and the
17
+ * event (`TimeInputChangeEvent`). Called on every change, as with a native `<input type="time">`;
18
+ * not called by `form.reset()`.
19
+ */
20
+ onValueChange?: ((value: string, event: TimeInputChangeEvent) => void) | undefined;
21
+ /**
22
+ * The clock: `12` (hours 1–12 and an AM/PM selector) or `24` (hours 0–23). Without it, the clock of
23
+ * `locale`, or of the browser's language once the page has hydrated (server HTML uses `24`): pass it
24
+ * on server-rendered pages so the first paint already has the right clock.
25
+ */
26
+ hourCycle?: TimeHourCycle | undefined;
27
+ /**
28
+ * BCP 47 language tag (`"en-US"`, `"es-AR"`) for the default clock and the AM/PM names (`Intl`).
29
+ * Without it, the browser's language once the page has hydrated. Digits are always `0`–`9`.
30
+ */
31
+ locale?: string | undefined;
32
+ /** Error state: error colors and `aria-invalid` on both fields. Put the message in `TimeInputSupporting`. */
33
+ error?: boolean | undefined;
34
+ /** Disabled: not focusable, not submitted and not validated, like a disabled `<input type="time">`. */
35
+ disabled?: boolean | undefined;
36
+ /** A time is required to submit the form (native validation, `aria-required` on both fields). */
37
+ required?: boolean | undefined;
38
+ /** The name the value (`"HH:mm"`) is submitted under. */
39
+ name?: string | undefined;
40
+ /** The `id` of the `<form>` the value belongs to, when the time input is outside it. */
41
+ form?: string | undefined;
42
+ /** The hidden native `<input>` failed validation (the form was submitted without a time). */
43
+ onInvalid?: ((event: FormEvent<HTMLInputElement>) => void) | undefined;
44
+ /**
45
+ * Ref to the hidden native `<input>` that takes part in the form (its value is the `"HH:mm"` text), for its validity API
46
+ * (`setCustomValidity`, `validity`, `reportValidity`).
47
+ */
48
+ inputRef?: Ref<HTMLInputElement> | undefined;
49
+ /** Ref to the hour field (the first `role="spinbutton"`), for example to focus it. */
50
+ hourRef?: Ref<HTMLInputElement> | undefined;
51
+ /** Label below the hour field, which names it. Defaults to `"Hour"`. */
52
+ hourLabel?: string | undefined;
53
+ /** Label below the minute field, which names it. Defaults to `"Minute"`. */
54
+ minuteLabel?: string | undefined;
55
+ /** Name of the AM/PM selector. Defaults to `"AM or PM"`. */
56
+ periodLabel?: string | undefined;
57
+ /** The morning option. Defaults to the locale's name (`Intl`), or `"AM"` until the locale is known. */
58
+ amLabel?: string | undefined;
59
+ /** The afternoon option. Defaults to the locale's name (`Intl`), or `"PM"` until the locale is known. */
60
+ pmLabel?: string | undefined;
61
+ /** Ref to the container (`role="group"`). */
62
+ ref?: Ref<HTMLDivElement> | undefined;
63
+ /** The optional parts: `TimeInputLabel` and `TimeInputSupporting`. */
64
+ children?: ReactNode;
65
+ }
66
+ /**
67
+ * Material 3 time input: the time picker's keyboard mode (Compose `TimeInput`), with an hour field
68
+ * and a minute field and, on the 12-hour clock, an AM/PM selector. Inline in a form, or inside a
69
+ * `TimePickerDialog` with Cancel and OK. It submits with `name` in a `<form>` as `"HH:mm"`, like
70
+ * `<input type="time">`.
71
+ *
72
+ * ```tsx
73
+ * const [time, setTime] = useState('07:30')
74
+ *
75
+ * <TimeInput value={time} onValueChange={setTime} hourCycle={12} name="alarm" required>
76
+ * <TimeInputLabel>Alarm</TimeInputLabel>
77
+ * <TimeInputSupporting>Rings every weekday</TimeInputSupporting>
78
+ * </TimeInput>
79
+ * ```
80
+ *
81
+ * - **Keyboard:** each field is a spin button. Digits replace the number; the hour moves on to the
82
+ * minute once it cannot take another digit. Arrow Up and Arrow Down add or take 1 (wrapping), Page
83
+ * Up and Page Down 2 hours or 15 minutes, Home and End go to the first or last value. Arrow Right at
84
+ * the end of the hour and Arrow Left at the start of the minute move between fields, and Backspace on
85
+ * an empty minute goes back to the hour. On the 12-hour clock, typing the first letter of AM or PM
86
+ * chooses it; the selector itself is a radio group (arrows switch).
87
+ * - The clock and the AM/PM names follow `hourCycle` and `locale` (see each prop). Digits always read
88
+ * left to right, also in right-to-left pages.
89
+ * - Native props, `className`, `style` and `ref` go to the container (`role="group"`, named by
90
+ * `TimeInputLabel` or `aria-label`).
91
+ */
92
+ export declare function TimeInput({ value: controlledValue, defaultValue, onValueChange, hourCycle, locale, error, disabled, required, name, form, onInvalid, inputRef, hourRef, hourLabel, minuteLabel, periodLabel, amLabel, pmLabel, className, children, ref, ...props }: TimeInputProps): import("react").JSX.Element;
93
+ export interface TimeInputLabelProps extends HTMLAttributes<HTMLSpanElement> {
94
+ }
95
+ /**
96
+ * Title above the fields (Label Medium, `on-surface-variant`), like the kit's "Enter time" header. It
97
+ * names the group (`aria-labelledby`). Inside a `TimePickerDialog`, the `DialogHeadline` plays this
98
+ * role instead.
99
+ */
100
+ export declare function TimeInputLabel({ id, className, ...props }: TimeInputLabelProps): import("react").JSX.Element;
101
+ export interface TimeInputSupportingProps extends HTMLAttributes<HTMLDivElement> {
102
+ }
103
+ /**
104
+ * Supporting text below the fields (Body Small). It becomes the description of both fields
105
+ * (`aria-describedby`). In error it takes the error color: to show the error message, change its
106
+ * content.
107
+ */
108
+ export declare function TimeInputSupporting({ id, className, ...props }: TimeInputSupportingProps): import("react").JSX.Element;
@@ -0,0 +1,347 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Molécula interactiva (ADR-0003, ADR-0042): la entrada de hora por teclado del time picker de
4
+ // Material 3 (el "Keyboard picker" del kit, `TimeInput` de Compose). Necesita estado (lo que se está
5
+ // escribiendo en cada campo, el valor sin controlar), efectos (reinicio del formulario, avisos) y
6
+ // contexto (los ids de la etiqueta y la ayuda), así que todo el módulo es cliente.
7
+ //
8
+ // - Campos: dos `<input type="text" inputmode="numeric">` con `role="spinbutton"` (ARIA in HTML lo
9
+ // permite en un input de texto): se escribe como en un campo (cursor, teclado numérico en el
10
+ // teléfono) y las flechas, Re Pág, Av Pág, Inicio y Fin cambian el número como en el spinbutton de
11
+ // APG. La lógica de lo que se escribe sale del segmento de React Aria (`useDateSegment`): un número
12
+ // fuera de rango vuelve a empezar con la tecla nueva, y la hora pasa sola al minuto cuando ya no
13
+ // admite otro dígito; los saltos de página son los suyos (2 horas, 15 minutos).
14
+ // - Período (12 horas): el radiogroup de src/internal/time-period.tsx, común con TimeScroll (como el
15
+ // `selectableGroup` de Compose). En los campos, la inicial de AM o PM también lo elige.
16
+ // - Valor: "HH:mm" en 24 horas o '' (el de `<input type="time">`), compartido con la rueda (TimeScroll,
17
+ // src/internal/time.ts). Lo escrito vive en `draft` y se vuelve a leer del valor cuando el valor
18
+ // cambia desde afuera, como `hourInput` y `hour` del TimePickerState de Compose.
19
+ // - Ciclo e idioma: `hourCycle` y `locale` mandan; sin ellos, el idioma del navegador se lee con
20
+ // useSyncExternalStore, que al hidratar usa el del servidor (sin idioma: 24 horas, "AM"/"PM" de
21
+ // strings.ts) y después el del cliente, sin error de hidratación.
22
+ // - Formulario: un `<input type="text">` oculto (aria-hidden, fuera del orden de Tab) con el valor
23
+ // "HH:mm" lleva `name`, `required`, `disabled` y `form`: FormData, validación nativa y reinicio, como
24
+ // el `<select>` del Select (un `<input type="hidden">` no valida; CLAUDE.md, "Motores"). No es
25
+ // `type="time"`: en WebKit de macOS, el envío fallido lo enfocaba y el foco no pasaba a la hora
26
+ // (comprobado dos veces el 2026-11-30; con `type="text"`, como el del Select, pasa en los tres).
27
+ // - Los dígitos van siempre de izquierda a derecha (`dir="ltr"` en la fila de la hora), como Compose
28
+ // (`LocalLayoutDirection provides Ltr`) y el `<input type="time">`; el período sigue la dirección
29
+ // del documento (en RTL queda a la izquierda).
30
+ import { Children, createContext, isValidElement, use, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
31
+ import { isDevelopment } from '../../internal/dev.js';
32
+ import { mkWarn, partOutsideParent } from '../../internal/diagnostics.js';
33
+ import { mergeRefs } from '../../internal/merge-refs.js';
34
+ import { TimePeriod } from '../../internal/time-period.js';
35
+ import { clientLocale, displayHour, formatTime, hourRange, localeHourCycle, localePeriodLabels, pad2, parseTime, serverLocale, subscribeToLocale, toHours24, } from '../../internal/time.js';
36
+ import { timeInputStrings } from './strings.js';
37
+ const TimeInputContext = createContext(null);
38
+ function useTimeInput(part) {
39
+ const ctx = use(TimeInputContext);
40
+ if (!ctx)
41
+ throw partOutsideParent(part, 'TimeInput');
42
+ return ctx;
43
+ }
44
+ const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
45
+ const MINUTE_RANGE = { min: 0, max: 59 };
46
+ // Saltos de Re Pág y Av Pág, los de React Aria (PAGE_STEP de useDateFieldState).
47
+ const PAGE_STEP = { hour: 2, minute: 15 };
48
+ const rangeOf = (field, cycle) => (field === 'hour' ? hourRange(cycle) : MINUTE_RANGE);
49
+ function draftFrom(parts, cycle, pm) {
50
+ if (!parts)
51
+ return { hour: '', minute: '', pm };
52
+ return { hour: pad2(displayHour(parts.hours, cycle)), minute: pad2(parts.minutes), pm: parts.hours >= 12 };
53
+ }
54
+ // El número de un campo si está dentro de su rango; `null` si está vacío o fuera.
55
+ function fieldNumber(text, range) {
56
+ if (text === '')
57
+ return null;
58
+ const n = Number(text);
59
+ return n >= range.min && n <= range.max ? n : null;
60
+ }
61
+ // Lo escrito → el valor ("HH:mm" o '' si falta un campo).
62
+ function valueOf(draft, cycle) {
63
+ const hour = fieldNumber(draft.hour, hourRange(cycle));
64
+ const minutes = fieldNumber(draft.minute, MINUTE_RANGE);
65
+ if (hour === null || minutes === null)
66
+ return '';
67
+ return formatTime({ hours: toHours24(hour, cycle, draft.pm), minutes });
68
+ }
69
+ // Recorre los hijos directos (y los de fragmentos) sin renderizar: así el grupo y los campos ya salen
70
+ // nombrados y descritos en el HTML del servidor. Una parte envuelta en un componente propio se
71
+ // registra al montar.
72
+ function scanParts(children, ids, found) {
73
+ Children.forEach(children, (child) => {
74
+ if (!isValidElement(child))
75
+ return;
76
+ if (child.type === TimeInputLabel)
77
+ found.label = child.props.id ?? ids.label;
78
+ else if (child.type === TimeInputSupporting)
79
+ found.supporting = child.props.id ?? ids.supporting;
80
+ else if (typeof child.type === 'symbol')
81
+ scanParts(child.props.children, ids, found);
82
+ });
83
+ }
84
+ /**
85
+ * Material 3 time input: the time picker's keyboard mode (Compose `TimeInput`), with an hour field
86
+ * and a minute field and, on the 12-hour clock, an AM/PM selector. Inline in a form, or inside a
87
+ * `TimePickerDialog` with Cancel and OK. It submits with `name` in a `<form>` as `"HH:mm"`, like
88
+ * `<input type="time">`.
89
+ *
90
+ * ```tsx
91
+ * const [time, setTime] = useState('07:30')
92
+ *
93
+ * <TimeInput value={time} onValueChange={setTime} hourCycle={12} name="alarm" required>
94
+ * <TimeInputLabel>Alarm</TimeInputLabel>
95
+ * <TimeInputSupporting>Rings every weekday</TimeInputSupporting>
96
+ * </TimeInput>
97
+ * ```
98
+ *
99
+ * - **Keyboard:** each field is a spin button. Digits replace the number; the hour moves on to the
100
+ * minute once it cannot take another digit. Arrow Up and Arrow Down add or take 1 (wrapping), Page
101
+ * Up and Page Down 2 hours or 15 minutes, Home and End go to the first or last value. Arrow Right at
102
+ * the end of the hour and Arrow Left at the start of the minute move between fields, and Backspace on
103
+ * an empty minute goes back to the hour. On the 12-hour clock, typing the first letter of AM or PM
104
+ * chooses it; the selector itself is a radio group (arrows switch).
105
+ * - The clock and the AM/PM names follow `hourCycle` and `locale` (see each prop). Digits always read
106
+ * left to right, also in right-to-left pages.
107
+ * - Native props, `className`, `style` and `ref` go to the container (`role="group"`, named by
108
+ * `TimeInputLabel` or `aria-label`).
109
+ */
110
+ export function TimeInput({ value: controlledValue, defaultValue = '', onValueChange, hourCycle, locale, error = false, disabled = false, required = false, name, form, onInvalid, inputRef, hourRef, hourLabel = timeInputStrings.hourLabel, minuteLabel = timeInputStrings.minuteLabel, periodLabel = timeInputStrings.periodLabel, amLabel, pmLabel, className, children, ref, ...props }) {
111
+ const id = useId();
112
+ const defaultLabelId = `${id}label`;
113
+ const defaultSupportingId = `${id}supporting`;
114
+ const hourId = `${id}hour`;
115
+ const minuteId = `${id}minute`;
116
+ // Idioma y ciclo (ver arriba): en el servidor y al hidratar, sin idioma del usuario.
117
+ const browserLocale = useSyncExternalStore(subscribeToLocale, clientLocale, serverLocale);
118
+ const resolvedLocale = locale ?? browserLocale;
119
+ const cycle = hourCycle ?? (resolvedLocale ? localeHourCycle(resolvedLocale) : 24);
120
+ const periods = resolvedLocale ? localePeriodLabels(resolvedLocale) : null;
121
+ const am = amLabel ?? periods?.am ?? timeInputStrings.amLabel;
122
+ const pm = pmLabel ?? periods?.pm ?? timeInputStrings.pmLabel;
123
+ const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
124
+ const controlled = controlledValue !== undefined;
125
+ const value = controlled ? controlledValue : uncontrolledValue;
126
+ const parts = parseTime(value);
127
+ // El valor que valida y envía el formulario: '' si el de la app no es una hora.
128
+ const formValue = parts ? value : '';
129
+ // Lo escrito sigue al valor cuando el valor cambia desde afuera (o cambia el reloj): se ajusta en el
130
+ // render, sin efecto, como recomienda React para un estado que depende de una prop.
131
+ const [draft, setDraft] = useState(() => draftFrom(parts, cycle, false));
132
+ const [synced, setSynced] = useState({ value, cycle });
133
+ let shown = draft;
134
+ if (synced.value !== value || synced.cycle !== cycle) {
135
+ setSynced({ value, cycle });
136
+ if (synced.cycle !== cycle || valueOf(draft, cycle) !== formValue) {
137
+ shown = draftFrom(parts, cycle, draft.pm);
138
+ setDraft(shown);
139
+ }
140
+ }
141
+ const [registeredLabelId, setLabelId] = useState(null);
142
+ const [registeredSupportingId, setSupportingId] = useState(null);
143
+ const found = { label: null, supporting: null };
144
+ scanParts(children, { label: defaultLabelId, supporting: defaultSupportingId }, found);
145
+ const labelId = registeredLabelId ?? found.label;
146
+ const supportingId = registeredSupportingId ?? found.supporting;
147
+ const hourInput = useRef(null);
148
+ const minuteInput = useRef(null);
149
+ const nativeRef = useRef(null);
150
+ const setHourRef = useMemo(() => mergeRefs(hourInput, hourRef), [hourRef]);
151
+ const setNativeRef = useMemo(() => mergeRefs(nativeRef, inputRef), [inputRef]);
152
+ const inputOf = (field) => (field === 'hour' ? hourInput : minuteInput).current;
153
+ const update = (next, event) => {
154
+ setDraft(next);
155
+ const nextValue = valueOf(next, cycle);
156
+ if (nextValue === formValue)
157
+ return;
158
+ if (!controlled)
159
+ setUncontrolledValue(nextValue);
160
+ onValueChange?.(nextValue, event);
161
+ };
162
+ const handleChange = (field) => (e) => {
163
+ const range = rangeOf(field, cycle);
164
+ const raw = e.target.value;
165
+ let digits = raw.replace(/\D/g, '');
166
+ // Un tercer dígito o un número fuera de rango empieza de nuevo con la tecla nueva (React Aria): la
167
+ // que quedó justo antes del cursor, esté donde esté.
168
+ const caret = e.target.selectionStart ?? raw.length;
169
+ const typed = raw.slice(Math.max(0, caret - 1), caret).replace(/\D/g, '');
170
+ if (digits.length > 2)
171
+ digits = typed || digits.slice(-1);
172
+ if (digits.length === 2 && (Number(digits) > range.max || Number(digits) < range.min))
173
+ digits = typed || digits.slice(-1);
174
+ update({ ...shown, [field]: digits }, e);
175
+ // La hora completa (dos dígitos, o uno que no admite otro: 3–9 en 24 horas, 2–9 en 12) pasa al minuto.
176
+ const inserted = e.nativeEvent.inputType?.startsWith('insert') ?? true;
177
+ if (field === 'hour' && inserted && digits !== '' && (digits.length === 2 || Number(digits) * 10 > range.max)) {
178
+ minuteInput.current?.focus();
179
+ }
180
+ };
181
+ // Al salir, "7" pasa a "07"; lo que no es una hora del reloj (un 0 en 12 horas) se borra.
182
+ // Con actualización funcional: el paso automático al minuto saca el foco de la hora dentro del mismo
183
+ // evento de escritura, antes de que el render vea el dígito nuevo.
184
+ const handleBlur = (field) => () => {
185
+ setDraft((current) => {
186
+ const text = current[field];
187
+ if (text === '' || text.length === 2)
188
+ return current;
189
+ const n = fieldNumber(text, rangeOf(field, cycle));
190
+ return { ...current, [field]: n === null ? '' : pad2(n) };
191
+ });
192
+ };
193
+ const setPeriod = (isPm, event) => {
194
+ if (shown.pm !== isPm)
195
+ update({ ...shown, pm: isPm }, event);
196
+ };
197
+ const handleKeyDown = (field) => (e) => {
198
+ if (e.defaultPrevented || disabled || e.altKey || e.ctrlKey || e.metaKey)
199
+ return;
200
+ const range = rangeOf(field, cycle);
201
+ const input = e.currentTarget;
202
+ const current = fieldNumber(shown[field], range);
203
+ const set = (n) => {
204
+ e.preventDefault();
205
+ update({ ...shown, [field]: pad2(n) }, e);
206
+ };
207
+ const span = range.max - range.min + 1;
208
+ // Suma con vuelta (de 59 a 00, de 12 a 1); un campo vacío empieza en el primero o el último.
209
+ const step = (delta) => {
210
+ if (current === null)
211
+ return set(delta > 0 ? range.min : range.max);
212
+ set(range.min + ((((current - range.min + delta) % span) + span) % span));
213
+ };
214
+ switch (e.key) {
215
+ case 'ArrowUp':
216
+ return step(1);
217
+ case 'ArrowDown':
218
+ return step(-1);
219
+ case 'PageUp':
220
+ return step(PAGE_STEP[field]);
221
+ case 'PageDown':
222
+ return step(-PAGE_STEP[field]);
223
+ case 'Home':
224
+ return set(range.min);
225
+ case 'End':
226
+ return set(range.max);
227
+ case 'ArrowRight':
228
+ if (field === 'hour' && input.selectionEnd === input.value.length) {
229
+ e.preventDefault();
230
+ minuteInput.current?.focus();
231
+ }
232
+ return;
233
+ case 'ArrowLeft':
234
+ if (field === 'minute' && input.selectionStart === 0) {
235
+ e.preventDefault();
236
+ hourInput.current?.focus();
237
+ }
238
+ return;
239
+ case 'Backspace':
240
+ if (field === 'minute' && input.value === '') {
241
+ e.preventDefault();
242
+ hourInput.current?.focus();
243
+ }
244
+ return;
245
+ }
246
+ // La inicial de AM o PM elige el período (12 horas), como en el segmento de React Aria.
247
+ if (cycle === 12 && e.key.length === 1 && !/\d/.test(e.key)) {
248
+ const key = e.key.toLocaleLowerCase();
249
+ const amKey = am.charAt(0).toLocaleLowerCase();
250
+ const pmKey = pm.charAt(0).toLocaleLowerCase();
251
+ if (amKey === pmKey)
252
+ return;
253
+ if (key === amKey || key === pmKey) {
254
+ e.preventDefault();
255
+ setPeriod(key === pmKey, e);
256
+ }
257
+ }
258
+ };
259
+ // Con el foco, todo el número queda elegido: lo que se escribe lo reemplaza. WebKit pone el cursor
260
+ // donde se soltó el clic (y deshace la selección): el primer mouseup después del foco se cancela.
261
+ const justFocused = useRef(false);
262
+ const handleFocus = (e) => {
263
+ e.currentTarget.select();
264
+ justFocused.current = true;
265
+ };
266
+ const handleMouseUp = (e) => {
267
+ if (justFocused.current)
268
+ e.preventDefault();
269
+ justFocused.current = false;
270
+ };
271
+ // form.reset(): el evento llega antes del reinicio; se espera a que el navegador termine (Select).
272
+ const latest = useRef({ controlled, defaultValue, formValue });
273
+ latest.current = { controlled, defaultValue, formValue };
274
+ useEffect(() => {
275
+ const owner = nativeRef.current?.form;
276
+ if (!owner)
277
+ return;
278
+ const onReset = () => {
279
+ setTimeout(() => {
280
+ const { controlled: isControlled, defaultValue: initial, formValue: current } = latest.current;
281
+ if (!isControlled)
282
+ setUncontrolledValue(initial);
283
+ const native = nativeRef.current;
284
+ if (native)
285
+ native.value = isControlled ? current : parseTime(initial) ? initial : '';
286
+ });
287
+ };
288
+ owner.addEventListener('reset', onReset);
289
+ return () => owner.removeEventListener('reset', onReset);
290
+ }, [form]);
291
+ // Un valor que no es una hora (MK_TIME_VALUE_INVALID): funciona como '' pero es un error de la app.
292
+ const warned = useRef({});
293
+ useEffect(() => {
294
+ if (!isDevelopment() || value === '' || parts)
295
+ return;
296
+ mkWarn('MK_TIME_VALUE_INVALID', {
297
+ component: 'TimeInput',
298
+ problem: 'the value is not a time on the 24-hour clock in "HH:mm" format, so the fields show no time',
299
+ fix: 'pass the time with two-digit hours and minutes (value="07:05", value="19:30"), or "" for no time',
300
+ }, { value }, { once: warned.current });
301
+ }, [value, parts]);
302
+ const ctx = useMemo(() => ({ labelId: defaultLabelId, supportingId: defaultSupportingId, setLabelId, setSupportingId }), [defaultLabelId, defaultSupportingId]);
303
+ const ariaLabel = props['aria-label'];
304
+ const labelledBy = props['aria-labelledby'] ?? (labelId && !ariaLabel ? labelId : undefined);
305
+ const field = (which, label) => {
306
+ const range = rangeOf(which, cycle);
307
+ const text = shown[which];
308
+ const n = fieldNumber(text, range);
309
+ const fieldId = which === 'hour' ? hourId : minuteId;
310
+ return (_jsxs("div", { className: "mk-time-input-field", "data-field": which, children: [_jsx("input", { ref: which === 'hour' ? setHourRef : minuteInput, id: fieldId, className: "mk-time-input-input", type: "text", size: 2, inputMode: "numeric", autoComplete: "off", spellCheck: false, enterKeyHint: which === 'hour' ? 'next' : 'done', role: "spinbutton", "aria-valuemin": range.min, "aria-valuemax": range.max, "aria-valuenow": n ?? undefined, "aria-valuetext": which === 'hour' && cycle === 12 && n != null ? `${n} ${shown.pm ? pm : am}` : undefined, "aria-required": required || undefined, "aria-invalid": error || undefined, "aria-describedby": supportingId ?? undefined, disabled: disabled, value: text, onChange: handleChange(which), onKeyDown: handleKeyDown(which), onFocus: handleFocus, onMouseUp: handleMouseUp, onBlur: () => {
311
+ justFocused.current = false;
312
+ handleBlur(which)();
313
+ } }), _jsx("label", { className: "mk-time-input-field-label", htmlFor: fieldId, children: label })] }));
314
+ };
315
+ return (_jsx(TimeInputContext, { value: ctx, children: _jsxs("div", { ...props, ref: ref, role: "group", className: cx('mk-time-input', className), "data-hour-cycle": cycle, "data-error": error || undefined, "data-disabled": disabled || undefined, "aria-labelledby": labelledBy, children: [_jsxs("div", { className: "mk-time-input-row", children: [_jsxs("div", { className: "mk-time-input-clock", dir: "ltr", children: [field('hour', hourLabel), _jsx("span", { className: "mk-time-input-separator", "aria-hidden": "true", children: ":" }), field('minute', minuteLabel)] }), cycle === 12 && (_jsx(TimePeriod, { pm: shown.pm, amLabel: am, pmLabel: pm, label: periodLabel, disabled: disabled, onChange: setPeriod }))] }), _jsx("input", { ref: setNativeRef, type: "text", className: "mk-time-input-native", "aria-hidden": "true", tabIndex: -1, name: name, form: form, required: required, disabled: disabled, value: formValue, onChange: () => { }, onInvalid: onInvalid,
316
+ // El navegador enfoca el control inválido al enviar: el foco pasa a la hora.
317
+ onFocus: () => hourInput.current?.focus() }), children] }) }));
318
+ }
319
+ // Registra en el TimeInput el id de una parte (para las que vienen envueltas en otro componente).
320
+ function useRegisteredId(id, register) {
321
+ useLayoutEffect(() => {
322
+ register(id);
323
+ return () => register(null);
324
+ }, [id, register]);
325
+ }
326
+ /**
327
+ * Title above the fields (Label Medium, `on-surface-variant`), like the kit's "Enter time" header. It
328
+ * names the group (`aria-labelledby`). Inside a `TimePickerDialog`, the `DialogHeadline` plays this
329
+ * role instead.
330
+ */
331
+ export function TimeInputLabel({ id, className, ...props }) {
332
+ const ctx = useTimeInput('TimeInputLabel');
333
+ const ownId = id ?? ctx.labelId;
334
+ useRegisteredId(ownId, ctx.setLabelId);
335
+ return _jsx("span", { ...props, id: ownId, className: cx('mk-time-input-label', className) });
336
+ }
337
+ /**
338
+ * Supporting text below the fields (Body Small). It becomes the description of both fields
339
+ * (`aria-describedby`). In error it takes the error color: to show the error message, change its
340
+ * content.
341
+ */
342
+ export function TimeInputSupporting({ id, className, ...props }) {
343
+ const ctx = useTimeInput('TimeInputSupporting');
344
+ const ownId = id ?? ctx.supportingId;
345
+ useRegisteredId(ownId, ctx.setSupportingId);
346
+ return _jsx("div", { ...props, id: ownId, className: cx('mk-time-input-supporting', className) });
347
+ }