@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.
- package/CHANGELOG.md +102 -0
- package/LICENSE +202 -0
- package/NOTICE +56 -0
- package/README.md +115 -2
- package/dist/atoms/Divider/Divider.d.ts +49 -0
- package/dist/atoms/Divider/Divider.js +29 -0
- package/dist/atoms/FocusRing/FocusRing.d.ts +16 -0
- package/dist/atoms/FocusRing/FocusRing.js +16 -0
- package/dist/atoms/Group/Group.d.ts +38 -0
- package/dist/atoms/Group/Group.js +34 -0
- package/dist/atoms/Icon/Icon.d.ts +23 -0
- package/dist/atoms/Icon/Icon.js +19 -0
- package/dist/atoms/Interactive/Interactive.d.ts +98 -0
- package/dist/atoms/Interactive/Interactive.js +87 -0
- package/dist/atoms/Ripple/Ripple.d.ts +14 -0
- package/dist/atoms/Ripple/Ripple.js +63 -0
- package/dist/atoms/Shape/Shape.d.ts +24 -0
- package/dist/atoms/Shape/Shape.js +19 -0
- package/dist/atoms/Shape/shapes.d.ts +8 -0
- package/dist/atoms/Shape/shapes.js +40 -0
- package/dist/atoms/Stack/Stack.d.ts +58 -0
- package/dist/atoms/Stack/Stack.js +33 -0
- package/dist/atoms/StateLayer/StateLayer.d.ts +17 -0
- package/dist/atoms/StateLayer/StateLayer.js +17 -0
- package/dist/atoms/index.d.ts +10 -0
- package/dist/atoms/index.js +10 -0
- package/dist/fonts/roboto-flex/OFL.txt +93 -0
- package/dist/fonts/roboto-flex/roboto-flex-cyrillic-ext.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-cyrillic.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-greek.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-latin-ext.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-latin.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-vietnamese.woff2 +0 -0
- package/dist/icons/icons.d.ts +89 -0
- package/dist/icons/icons.js +186 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +12 -0
- package/dist/internal/accessible-name.d.ts +17 -0
- package/dist/internal/accessible-name.js +33 -0
- package/dist/internal/anchor-position.d.ts +99 -0
- package/dist/internal/anchor-position.js +159 -0
- package/dist/internal/anchored-drag.d.ts +25 -0
- package/dist/internal/anchored-drag.js +106 -0
- package/dist/internal/dev.d.ts +2 -0
- package/dist/internal/dev.js +18 -0
- package/dist/internal/diagnostics.d.ts +46 -0
- package/dist/internal/diagnostics.js +125 -0
- package/dist/internal/group-label.d.ts +22 -0
- package/dist/internal/group-label.js +50 -0
- package/dist/internal/interactive.d.ts +28 -0
- package/dist/internal/interactive.js +18 -0
- package/dist/internal/layout-element.d.ts +21 -0
- package/dist/internal/layout-element.js +33 -0
- package/dist/internal/merge-refs.d.ts +13 -0
- package/dist/internal/merge-refs.js +35 -0
- package/dist/internal/modal-dialog.d.ts +63 -0
- package/dist/internal/modal-dialog.js +267 -0
- package/dist/internal/navigation-count.d.ts +38 -0
- package/dist/internal/navigation-count.js +60 -0
- package/dist/internal/navigation-item.d.ts +14 -0
- package/dist/internal/navigation-item.js +17 -0
- package/dist/internal/nearest-scroller.d.ts +4 -0
- package/dist/internal/nearest-scroller.js +17 -0
- package/dist/internal/open-state.d.ts +15 -0
- package/dist/internal/open-state.js +42 -0
- package/dist/internal/roving-focus.d.ts +41 -0
- package/dist/internal/roving-focus.js +126 -0
- package/dist/internal/settle-animations.d.ts +33 -0
- package/dist/internal/settle-animations.js +48 -0
- package/dist/internal/time-period.d.ts +10 -0
- package/dist/internal/time-period.js +26 -0
- package/dist/internal/time.d.ts +23 -0
- package/dist/internal/time.js +69 -0
- package/dist/internal/typeahead.d.ts +17 -0
- package/dist/internal/typeahead.js +35 -0
- package/dist/molecules/Badge/Badge.d.ts +25 -0
- package/dist/molecules/Badge/Badge.js +16 -0
- package/dist/molecules/Button/Button.d.ts +48 -0
- package/dist/molecules/Button/Button.js +34 -0
- package/dist/molecules/Card/Card.d.ts +159 -0
- package/dist/molecules/Card/Card.js +119 -0
- package/dist/molecules/Checkbox/Checkbox.d.ts +26 -0
- package/dist/molecules/Checkbox/Checkbox.js +40 -0
- package/dist/molecules/Chip/AssistChip.d.ts +23 -0
- package/dist/molecules/Chip/AssistChip.js +22 -0
- package/dist/molecules/Chip/ChipGroup.d.ts +85 -0
- package/dist/molecules/Chip/ChipGroup.js +92 -0
- package/dist/molecules/Chip/FilterChip.d.ts +33 -0
- package/dist/molecules/Chip/FilterChip.js +30 -0
- package/dist/molecules/Chip/InputChip.d.ts +60 -0
- package/dist/molecules/Chip/InputChip.js +107 -0
- package/dist/molecules/Chip/SuggestionChip.d.ts +24 -0
- package/dist/molecules/Chip/SuggestionChip.js +17 -0
- package/dist/molecules/Chip/chip-content.d.ts +39 -0
- package/dist/molecules/Chip/chip-content.js +95 -0
- package/dist/molecules/Chip/chip-element.d.ts +14 -0
- package/dist/molecules/Chip/chip-element.js +14 -0
- package/dist/molecules/Chip/strings.d.ts +8 -0
- package/dist/molecules/Chip/strings.js +5 -0
- package/dist/molecules/Fab/Fab.d.ts +78 -0
- package/dist/molecules/Fab/Fab.js +52 -0
- package/dist/molecules/IconButton/IconButton.d.ts +59 -0
- package/dist/molecules/IconButton/IconButton.js +36 -0
- package/dist/molecules/LoadingIndicator/LoadingIndicator.d.ts +38 -0
- package/dist/molecules/LoadingIndicator/LoadingIndicator.js +25 -0
- package/dist/molecules/LoadingIndicator/determinate.d.ts +3 -0
- package/dist/molecules/LoadingIndicator/determinate.js +47 -0
- package/dist/molecules/LoadingIndicator/loading-indicator-data.d.ts +21 -0
- package/dist/molecules/LoadingIndicator/loading-indicator-data.js +72 -0
- package/dist/molecules/ProgressIndicator/CircularProgressIndicator.d.ts +35 -0
- package/dist/molecules/ProgressIndicator/CircularProgressIndicator.js +30 -0
- package/dist/molecules/ProgressIndicator/LinearProgressIndicator.d.ts +43 -0
- package/dist/molecules/ProgressIndicator/LinearProgressIndicator.js +28 -0
- package/dist/molecules/ProgressIndicator/circular-wavy-data.d.ts +5 -0
- package/dist/molecules/ProgressIndicator/circular-wavy-data.js +19 -0
- package/dist/molecules/ProgressIndicator/progress.d.ts +24 -0
- package/dist/molecules/ProgressIndicator/progress.js +60 -0
- package/dist/molecules/RadioButton/RadioButton.d.ts +27 -0
- package/dist/molecules/RadioButton/RadioButton.js +70 -0
- package/dist/molecules/RadioButton/RadioGroup.d.ts +73 -0
- package/dist/molecules/RadioButton/RadioGroup.js +82 -0
- package/dist/molecules/ScrollField/ScrollField.d.ts +61 -0
- package/dist/molecules/ScrollField/ScrollField.js +352 -0
- package/dist/molecules/Slider/RangeSlider.d.ts +60 -0
- package/dist/molecules/Slider/RangeSlider.js +169 -0
- package/dist/molecules/Slider/Slider.d.ts +54 -0
- package/dist/molecules/Slider/Slider.js +71 -0
- package/dist/molecules/Slider/slider-shared.d.ts +26 -0
- package/dist/molecules/Slider/slider-shared.js +98 -0
- package/dist/molecules/Switch/Switch.d.ts +22 -0
- package/dist/molecules/Switch/Switch.js +20 -0
- package/dist/molecules/TextField/TextField.d.ts +83 -0
- package/dist/molecules/TextField/TextField.js +146 -0
- package/dist/molecules/TextField/TextFieldSlots.d.ts +22 -0
- package/dist/molecules/TextField/TextFieldSlots.js +24 -0
- package/dist/molecules/TimeInput/TimeInput.d.ts +108 -0
- package/dist/molecules/TimeInput/TimeInput.js +347 -0
- package/dist/molecules/TimeInput/strings.d.ts +13 -0
- package/dist/molecules/TimeInput/strings.js +10 -0
- package/dist/molecules/TimeScroll/TimeScroll.d.ts +106 -0
- package/dist/molecules/TimeScroll/TimeScroll.js +213 -0
- package/dist/molecules/TimeScroll/strings.d.ts +13 -0
- package/dist/molecules/TimeScroll/strings.js +12 -0
- package/dist/molecules/index.d.ts +27 -0
- package/dist/molecules/index.js +25 -0
- package/dist/organisms/BottomSheet/BottomSheet.d.ts +128 -0
- package/dist/organisms/BottomSheet/BottomSheet.js +432 -0
- package/dist/organisms/BottomSheet/BottomSheetSlots.d.ts +17 -0
- package/dist/organisms/BottomSheet/BottomSheetSlots.js +16 -0
- package/dist/organisms/BottomSheet/StandardBottomSheet.d.ts +37 -0
- package/dist/organisms/BottomSheet/StandardBottomSheet.js +206 -0
- package/dist/organisms/BottomSheet/bottom-sheet-context.d.ts +31 -0
- package/dist/organisms/BottomSheet/bottom-sheet-context.js +12 -0
- package/dist/organisms/BottomSheet/sheet-drag.d.ts +1 -0
- package/dist/organisms/BottomSheet/sheet-drag.js +4 -0
- package/dist/organisms/BottomSheet/strings.d.ts +9 -0
- package/dist/organisms/BottomSheet/strings.js +8 -0
- package/dist/organisms/ButtonGroup/ButtonGroup.d.ts +97 -0
- package/dist/organisms/ButtonGroup/ButtonGroup.js +242 -0
- package/dist/organisms/ButtonGroup/ButtonGroupItem.d.ts +36 -0
- package/dist/organisms/ButtonGroup/ButtonGroupItem.js +47 -0
- package/dist/organisms/Dialog/Dialog.d.ts +186 -0
- package/dist/organisms/Dialog/Dialog.js +193 -0
- package/dist/organisms/Dialog/DialogSlots.d.ts +60 -0
- package/dist/organisms/Dialog/DialogSlots.js +54 -0
- package/dist/organisms/Dialog/strings.d.ts +5 -0
- package/dist/organisms/Dialog/strings.js +5 -0
- package/dist/organisms/FabMenu/FabMenu.d.ts +104 -0
- package/dist/organisms/FabMenu/FabMenu.js +142 -0
- package/dist/organisms/FabMenu/strings.d.ts +9 -0
- package/dist/organisms/FabMenu/strings.js +5 -0
- package/dist/organisms/List/List.d.ts +190 -0
- package/dist/organisms/List/List.js +148 -0
- package/dist/organisms/Menu/Menu.d.ts +313 -0
- package/dist/organisms/Menu/Menu.js +865 -0
- package/dist/organisms/Menu/MenuSlots.d.ts +35 -0
- package/dist/organisms/Menu/MenuSlots.js +36 -0
- package/dist/organisms/NavigationBar/NavigationBar.d.ts +96 -0
- package/dist/organisms/NavigationBar/NavigationBar.js +77 -0
- package/dist/organisms/NavigationRail/ModalNavigationRail.d.ts +105 -0
- package/dist/organisms/NavigationRail/ModalNavigationRail.js +272 -0
- package/dist/organisms/NavigationRail/NavigationRail.d.ts +148 -0
- package/dist/organisms/NavigationRail/NavigationRail.js +114 -0
- package/dist/organisms/NavigationRail/NavigationRailSection.d.ts +54 -0
- package/dist/organisms/NavigationRail/NavigationRailSection.js +96 -0
- package/dist/organisms/NavigationRail/strings.d.ts +7 -0
- package/dist/organisms/NavigationRail/strings.js +7 -0
- package/dist/organisms/NavigationSuite/NavigationSuite.d.ts +109 -0
- package/dist/organisms/NavigationSuite/NavigationSuite.js +86 -0
- package/dist/organisms/PaneScaffold/PaneScaffold.d.ts +118 -0
- package/dist/organisms/PaneScaffold/PaneScaffold.js +132 -0
- package/dist/organisms/Search/Search.d.ts +213 -0
- package/dist/organisms/Search/Search.js +783 -0
- package/dist/organisms/Search/SearchSlots.d.ts +18 -0
- package/dist/organisms/Search/SearchSlots.js +19 -0
- package/dist/organisms/Search/strings.d.ts +21 -0
- package/dist/organisms/Search/strings.js +12 -0
- package/dist/organisms/Select/Select.d.ts +186 -0
- package/dist/organisms/Select/Select.js +597 -0
- package/dist/organisms/Select/SelectSlots.d.ts +12 -0
- package/dist/organisms/Select/SelectSlots.js +12 -0
- package/dist/organisms/SideSheet/SideSheet.d.ts +88 -0
- package/dist/organisms/SideSheet/SideSheet.js +109 -0
- package/dist/organisms/SideSheet/SideSheetSlots.d.ts +35 -0
- package/dist/organisms/SideSheet/SideSheetSlots.js +37 -0
- package/dist/organisms/SideSheet/strings.d.ts +7 -0
- package/dist/organisms/SideSheet/strings.js +6 -0
- package/dist/organisms/Snackbar/Snackbar.d.ts +46 -0
- package/dist/organisms/Snackbar/Snackbar.js +36 -0
- package/dist/organisms/Snackbar/SnackbarHost.d.ts +57 -0
- package/dist/organisms/Snackbar/SnackbarHost.js +221 -0
- package/dist/organisms/Snackbar/snackbar-queue.d.ts +81 -0
- package/dist/organisms/Snackbar/snackbar-queue.js +114 -0
- package/dist/organisms/Snackbar/strings.d.ts +8 -0
- package/dist/organisms/Snackbar/strings.js +5 -0
- package/dist/organisms/SplitButton/SplitButton.d.ts +73 -0
- package/dist/organisms/SplitButton/SplitButton.js +77 -0
- package/dist/organisms/SplitButton/strings.d.ts +9 -0
- package/dist/organisms/SplitButton/strings.js +5 -0
- package/dist/organisms/Tabs/TabLink.d.ts +27 -0
- package/dist/organisms/Tabs/TabLink.js +25 -0
- package/dist/organisms/Tabs/TabNav.d.ts +19 -0
- package/dist/organisms/Tabs/TabNav.js +55 -0
- package/dist/organisms/Tabs/Tabs.d.ts +147 -0
- package/dist/organisms/Tabs/Tabs.js +223 -0
- package/dist/organisms/Tabs/tab-content.d.ts +23 -0
- package/dist/organisms/Tabs/tab-content.js +105 -0
- package/dist/organisms/Tabs/tab-fit.d.ts +4 -0
- package/dist/organisms/Tabs/tab-fit.js +65 -0
- package/dist/organisms/Tabs/tab-motion.d.ts +2 -0
- package/dist/organisms/Tabs/tab-motion.js +68 -0
- package/dist/organisms/TimePickerDialog/TimePickerDialog.d.ts +26 -0
- package/dist/organisms/TimePickerDialog/TimePickerDialog.js +34 -0
- package/dist/organisms/Toolbar/Toolbar.d.ts +75 -0
- package/dist/organisms/Toolbar/Toolbar.js +84 -0
- package/dist/organisms/Toolbar/ToolbarLayout.d.ts +44 -0
- package/dist/organisms/Toolbar/ToolbarLayout.js +90 -0
- package/dist/organisms/Toolbar/ToolbarScroll.d.ts +8 -0
- package/dist/organisms/Toolbar/ToolbarScroll.js +222 -0
- package/dist/organisms/Tooltip/RichTooltip.d.ts +73 -0
- package/dist/organisms/Tooltip/RichTooltip.js +250 -0
- package/dist/organisms/Tooltip/Tooltip.d.ts +52 -0
- package/dist/organisms/Tooltip/Tooltip.js +99 -0
- package/dist/organisms/Tooltip/tooltip-behavior.d.ts +43 -0
- package/dist/organisms/Tooltip/tooltip-behavior.js +307 -0
- package/dist/organisms/TopAppBar/TopAppBar.d.ts +107 -0
- package/dist/organisms/TopAppBar/TopAppBar.js +78 -0
- package/dist/organisms/TopAppBar/TopAppBarScroll.d.ts +7 -0
- package/dist/organisms/TopAppBar/TopAppBarScroll.js +155 -0
- package/dist/organisms/index.d.ts +36 -0
- package/dist/organisms/index.js +36 -0
- package/dist/palettes/blue.css +275 -0
- package/dist/palettes/green.css +275 -0
- package/dist/palettes/index.css +823 -0
- package/dist/palettes/orange.css +275 -0
- package/dist/shapes.css +115 -0
- package/dist/strings/index.d.ts +35 -0
- package/dist/strings/index.js +39 -0
- package/dist/styles-no-fonts.css +12025 -0
- package/dist/styles.css +12123 -0
- package/dist/stylesheet.d.ts +2 -0
- package/dist/tokens/breakpoints.d.ts +33 -0
- package/dist/tokens/breakpoints.js +31 -0
- package/dist/tokens/space.d.ts +26 -0
- package/dist/tokens/space.js +26 -0
- package/package.json +110 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FocusRing } from '../atoms/FocusRing/FocusRing.js';
|
|
3
|
+
import { Ripple } from '../atoms/Ripple/Ripple.js';
|
|
4
|
+
import { StateLayer } from '../atoms/StateLayer/StateLayer.js';
|
|
5
|
+
import { Interactive, } from '../atoms/Interactive/Interactive.js';
|
|
6
|
+
import { assertRenderElement, cx } from './interactive.js';
|
|
7
|
+
// Dibuja un destino de navegación.
|
|
8
|
+
//
|
|
9
|
+
// name: nombre del componente, para el mensaje de error de `render`.
|
|
10
|
+
// base: clase base (`mk-navigation-bar-item`, `mk-navigation-rail-item`); el indicador
|
|
11
|
+
// lleva `${base}-indicator`.
|
|
12
|
+
export function navigationItem(name, base, props) {
|
|
13
|
+
const { current, className, children, ...rest } = props;
|
|
14
|
+
const ariaCurrent = current ? { 'aria-current': 'page' } : {};
|
|
15
|
+
assertRenderElement(name, rest.render);
|
|
16
|
+
return (_jsxs(Interactive, { ...ariaCurrent, ...rest, className: cx(base, className), children: [_jsx("span", { className: `${base}-indicator`, "aria-hidden": "true" }), _jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), children] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Módulo interno (no se exporta desde src/index.ts): el contenedor que se desplaza más cercano a un
|
|
2
|
+
// elemento, como `scroll(nearest)` y `position: sticky`. Lo usan las partes cliente de TopAppBar
|
|
3
|
+
// (ADR-0024) y de Toolbar (ADR-0027), que escuchan el desplazamiento del mismo contenedor que usa
|
|
4
|
+
// su `position: sticky`.
|
|
5
|
+
/**
|
|
6
|
+
* El primer ancestro cuyo `overflow` no es `visible` ni `clip`. `null` es el documento (la ventana).
|
|
7
|
+
*/
|
|
8
|
+
export function nearestScroller(el) {
|
|
9
|
+
for (let node = el.parentElement; node; node = node.parentElement) {
|
|
10
|
+
if (node === document.body || node === document.documentElement)
|
|
11
|
+
return null;
|
|
12
|
+
const { overflowY } = getComputedStyle(node);
|
|
13
|
+
if (overflowY !== 'visible' && overflowY !== 'clip')
|
|
14
|
+
return node;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface OpenStateOptions<R extends string> {
|
|
2
|
+
open?: boolean | undefined;
|
|
3
|
+
defaultOpen?: boolean | undefined;
|
|
4
|
+
onOpenChange?: ((open: boolean, reason: R) => void) | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* `isOpen` es lo que se muestra. `setOpen(next, reason)` es estable: sin controlar, aplica el cambio;
|
|
8
|
+
* controlado, solo avisa (si el padre no cambia `open`, nada cambia). No avisa si `next` es el estado
|
|
9
|
+
* actual, y lo anota enseguida: dos pedidos seguidos en el mismo evento no avisan dos veces.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useOpenState<R extends string>({ open, defaultOpen, onOpenChange }: OpenStateOptions<R>): {
|
|
12
|
+
isOpen: boolean;
|
|
13
|
+
setOpen: (next: boolean, reason: R) => void;
|
|
14
|
+
isOpenNow: () => boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Módulo interno (no se exporta desde src/index.ts): un hook, así que solo lo usan componentes
|
|
2
|
+
// cliente.
|
|
3
|
+
//
|
|
4
|
+
// Estado abierto controlado o no, con el motivo de cada cambio (ADR-0034): la forma de los componentes
|
|
5
|
+
// que se abren solos porque tienen un disparador propio, `open`/`defaultOpen`/`onOpenChange(open,
|
|
6
|
+
// reason)`: Menu, Tooltip, RichTooltip, Select, y con el Menu el SplitButton y el FabMenu. Las superficies que
|
|
7
|
+
// abre la app (Dialog, los sheets, ModalNavigationRail) no lo usan: piden cerrar con `onClose(reason)`.
|
|
8
|
+
// Era el useOpenState del Tooltip (ADR-0021); el Menu tenía una copia sin el motivo.
|
|
9
|
+
import { useCallback, useRef, useState } from 'react';
|
|
10
|
+
/**
|
|
11
|
+
* `isOpen` es lo que se muestra. `setOpen(next, reason)` es estable: sin controlar, aplica el cambio;
|
|
12
|
+
* controlado, solo avisa (si el padre no cambia `open`, nada cambia). No avisa si `next` es el estado
|
|
13
|
+
* actual, y lo anota enseguida: dos pedidos seguidos en el mismo evento no avisan dos veces.
|
|
14
|
+
*/
|
|
15
|
+
export function useOpenState({ open, defaultOpen = false, onOpenChange }) {
|
|
16
|
+
const [uncontrolled, setUncontrolled] = useState(defaultOpen);
|
|
17
|
+
const controlled = open !== undefined;
|
|
18
|
+
const isOpen = controlled ? open : uncontrolled;
|
|
19
|
+
const latest = useRef({ isOpen, controlled, onOpenChange });
|
|
20
|
+
latest.current = { isOpen, controlled, onOpenChange };
|
|
21
|
+
const setOpen = useCallback((next, reason) => {
|
|
22
|
+
const { isOpen: current, controlled: isControlled, onOpenChange: notify } = latest.current;
|
|
23
|
+
if (next === current)
|
|
24
|
+
return;
|
|
25
|
+
if (!isControlled)
|
|
26
|
+
setUncontrolled(next);
|
|
27
|
+
const pending = { ...latest.current, isOpen: next };
|
|
28
|
+
latest.current = pending;
|
|
29
|
+
// Controlado, el padre puede vetar el cambio sin volver a dibujar: al terminar la tarea, si
|
|
30
|
+
// ningún render reemplazó la copia, vuelve al valor de `open`, así el pedido se puede repetir
|
|
31
|
+
// (un Escape vetado en un Menu avisa también el segundo).
|
|
32
|
+
if (isControlled) {
|
|
33
|
+
queueMicrotask(() => {
|
|
34
|
+
if (latest.current === pending)
|
|
35
|
+
latest.current = { ...pending, isOpen: current };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
notify?.(next, reason);
|
|
39
|
+
}, []);
|
|
40
|
+
const isOpenNow = useCallback(() => latest.current.isOpen, []);
|
|
41
|
+
return { isOpen, setOpen, isOpenNow };
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type FocusEvent, type KeyboardEvent, type RefObject } from 'react';
|
|
2
|
+
export type RovingOrientation = 'horizontal' | 'vertical' | 'both';
|
|
3
|
+
export interface RovingFocusOptions {
|
|
4
|
+
/** Selector de las paradas (`[data-chip-stop]`, `[role="tab"]`). */
|
|
5
|
+
stop: string;
|
|
6
|
+
/**
|
|
7
|
+
* Selector del grupo: una parada es de este grupo si su ancestro más cercano que lo cumple es la
|
|
8
|
+
* raíz (así no se cuentan las de un grupo anidado).
|
|
9
|
+
*/
|
|
10
|
+
scope: string;
|
|
11
|
+
/** Qué flechas mueven el foco. Por defecto `horizontal`. */
|
|
12
|
+
orientation?: RovingOrientation | undefined;
|
|
13
|
+
/** Vuelta en los extremos. Por defecto `true`. */
|
|
14
|
+
loop?: boolean | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* La parada de Tab cuando el foco está fuera del grupo (por ejemplo, la pestaña elegida). Sin
|
|
17
|
+
* ella, o si devuelve `undefined`, queda la última que tuvo el foco.
|
|
18
|
+
*/
|
|
19
|
+
preferred?: ((stops: HTMLElement[]) => HTMLElement | undefined) | undefined;
|
|
20
|
+
/** Si se pasa, se llama después de mover el foco con teclado: mover el foco activa. */
|
|
21
|
+
activate?: ((stop: HTMLElement, event: KeyboardEvent<HTMLElement>) => void) | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Paradas habilitadas del grupo, en orden del documento. */
|
|
24
|
+
export declare function rovingStops(root: HTMLElement, options: Pick<RovingFocusOptions, 'stop' | 'scope'>): HTMLElement[];
|
|
25
|
+
/**
|
|
26
|
+
* Deja una sola parada con tabIndex 0. `focusInside`: si es `false`, se ignora el elemento
|
|
27
|
+
* enfocado (se llama al salir el foco del grupo, cuando todavía puede figurar como activo).
|
|
28
|
+
*/
|
|
29
|
+
export declare function updateRovingStops(root: HTMLElement, options: RovingFocusOptions, focusInside?: boolean): void;
|
|
30
|
+
export interface RovingFocus {
|
|
31
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
|
|
32
|
+
onFocus: (event: FocusEvent<HTMLElement>) => void;
|
|
33
|
+
onBlur: (event: FocusEvent<HTMLElement>) => void;
|
|
34
|
+
/** Vuelve a elegir la parada (por ejemplo, después de cambiar la pestaña elegida). */
|
|
35
|
+
update: () => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Foco itinerante sobre las paradas de `root`. Devuelve los manejadores para el elemento raíz
|
|
39
|
+
* (`onKeyDown`, `onFocus`, `onBlur`; el uso llama antes a los suyos) y `update`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useRovingFocus(root: RefObject<HTMLElement | null>, options: RovingFocusOptions): RovingFocus;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Módulo interno (no se exporta desde src/index.ts): foco itinerante ("roving tabindex") de los
|
|
2
|
+
// grupos de una sola parada de Tab. Lo usan ChipGroup (ADR-0019), Tabs (ADR-0023) y Toolbar
|
|
3
|
+
// (ADR-0027): patrones APG "Toolbar" y "Tabs". Una parada con `aria-disabled` no es `:disabled`: sigue
|
|
4
|
+
// siendo parada (lo que APG admite en una toolbar).
|
|
5
|
+
//
|
|
6
|
+
// - Una sola parada con tabIndex 0 en el grupo; las demás en -1. Cuál: la enfocada; si el foco está
|
|
7
|
+
// afuera, la que indique `preferred` (la pestaña elegida, como pide APG) o la última que tuvo el
|
|
8
|
+
// foco; si no, la primera habilitada.
|
|
9
|
+
// - Flechas según la orientación (izquierda y derecha en horizontal, arriba y abajo en vertical,
|
|
10
|
+
// las cuatro con `both`), invertidas en RTL las horizontales, con vuelta en los extremos (`loop`),
|
|
11
|
+
// Inicio y Fin, sin pasar por las deshabilitadas (`:disabled`). Con Mayús, Ctrl, Alt o Meta no se
|
|
12
|
+
// capturan, ni fuera de las paradas.
|
|
13
|
+
// - `activate`: si se pasa, mover el foco con teclado también activa la parada (Tabs con
|
|
14
|
+
// activación automática). Sin ella, el foco se mueve sin activar nada (activación manual,
|
|
15
|
+
// ChipGroup, Toolbar): Enter y Espacio son los del elemento.
|
|
16
|
+
//
|
|
17
|
+
// El tabIndex se maneja sobre el DOM, no con estado de React (como @material/web): un
|
|
18
|
+
// MutationObserver cuenta las paradas que se agregan, quitan o deshabilitan sin que cada una se
|
|
19
|
+
// registre, también las de `render`. Sin JavaScript (antes de hidratar), cada parada es una parada
|
|
20
|
+
// de Tab: el grupo sigue usable. Contra: un tabIndex propio en una parada se pisa.
|
|
21
|
+
//
|
|
22
|
+
// Sin 'use client': es un hook que solo importan módulos cliente (ChipGroup, TabList, Toolbar).
|
|
23
|
+
import { useCallback, useLayoutEffect, useRef } from 'react';
|
|
24
|
+
/** Marca de la última parada que tuvo el foco (sobrevive a que el foco salga del grupo). */
|
|
25
|
+
const CURRENT = 'rovingCurrent';
|
|
26
|
+
const ownStops = (root, { stop, scope }) => [...root.querySelectorAll(stop)].filter((el) => el.closest(scope) === root);
|
|
27
|
+
/** Paradas habilitadas del grupo, en orden del documento. */
|
|
28
|
+
export function rovingStops(root, options) {
|
|
29
|
+
return ownStops(root, options).filter((el) => !el.matches(':disabled'));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Deja una sola parada con tabIndex 0. `focusInside`: si es `false`, se ignora el elemento
|
|
33
|
+
* enfocado (se llama al salir el foco del grupo, cuando todavía puede figurar como activo).
|
|
34
|
+
*/
|
|
35
|
+
export function updateRovingStops(root, options, focusInside = true) {
|
|
36
|
+
const all = ownStops(root, options);
|
|
37
|
+
const enabled = all.filter((el) => !el.matches(':disabled'));
|
|
38
|
+
const active = focusInside ? enabled.find((el) => el === document.activeElement) : undefined;
|
|
39
|
+
const current = active ??
|
|
40
|
+
options.preferred?.(enabled) ??
|
|
41
|
+
enabled.find((el) => el.tabIndex === 0 && el.dataset[CURRENT] !== undefined) ??
|
|
42
|
+
enabled[0];
|
|
43
|
+
for (const el of all) {
|
|
44
|
+
el.tabIndex = el === current ? 0 : -1;
|
|
45
|
+
if (el === current)
|
|
46
|
+
el.dataset[CURRENT] = '';
|
|
47
|
+
else
|
|
48
|
+
delete el.dataset[CURRENT];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const KEYS = {
|
|
52
|
+
horizontal: ['ArrowLeft', 'ArrowRight'],
|
|
53
|
+
vertical: ['ArrowUp', 'ArrowDown'],
|
|
54
|
+
both: ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'],
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Foco itinerante sobre las paradas de `root`. Devuelve los manejadores para el elemento raíz
|
|
58
|
+
* (`onKeyDown`, `onFocus`, `onBlur`; el uso llama antes a los suyos) y `update`.
|
|
59
|
+
*/
|
|
60
|
+
export function useRovingFocus(root, options) {
|
|
61
|
+
// Las opciones pueden cambiar en cada render (funciones nuevas); los manejadores leen las últimas.
|
|
62
|
+
const latest = useRef(options);
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
latest.current = options;
|
|
65
|
+
});
|
|
66
|
+
const update = useCallback(() => {
|
|
67
|
+
if (root.current)
|
|
68
|
+
updateRovingStops(root.current, latest.current);
|
|
69
|
+
}, [root]);
|
|
70
|
+
// Al montar y cada vez que cambian las paradas o su `disabled`, una sola parada de Tab.
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
const el = root.current;
|
|
73
|
+
if (!el)
|
|
74
|
+
return;
|
|
75
|
+
updateRovingStops(el, latest.current);
|
|
76
|
+
const observer = new MutationObserver(() => updateRovingStops(el, latest.current));
|
|
77
|
+
observer.observe(el, { childList: true, subtree: true, attributes: true, attributeFilter: ['disabled'] });
|
|
78
|
+
return () => observer.disconnect();
|
|
79
|
+
}, [root]);
|
|
80
|
+
const onFocus = useCallback((event) => {
|
|
81
|
+
if (event.target.matches(latest.current.stop))
|
|
82
|
+
updateRovingStops(event.currentTarget, latest.current);
|
|
83
|
+
}, []);
|
|
84
|
+
const onBlur = useCallback((event) => {
|
|
85
|
+
const next = event.relatedTarget;
|
|
86
|
+
if (latest.current.preferred && !(next instanceof Node && event.currentTarget.contains(next))) {
|
|
87
|
+
updateRovingStops(event.currentTarget, latest.current, false);
|
|
88
|
+
}
|
|
89
|
+
}, []);
|
|
90
|
+
const onKeyDown = useCallback((event) => {
|
|
91
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
92
|
+
return;
|
|
93
|
+
const opts = latest.current;
|
|
94
|
+
const { key } = event;
|
|
95
|
+
const arrows = KEYS[opts.orientation ?? 'horizontal'];
|
|
96
|
+
if (!arrows.includes(key) && key !== 'Home' && key !== 'End')
|
|
97
|
+
return;
|
|
98
|
+
const rootEl = event.currentTarget;
|
|
99
|
+
const stops = rovingStops(rootEl, opts);
|
|
100
|
+
const index = stops.indexOf(event.target);
|
|
101
|
+
if (index === -1 || stops.length < 2)
|
|
102
|
+
return;
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
let next;
|
|
105
|
+
if (key === 'Home')
|
|
106
|
+
next = stops[0];
|
|
107
|
+
else if (key === 'End')
|
|
108
|
+
next = stops[stops.length - 1];
|
|
109
|
+
else {
|
|
110
|
+
// En RTL, la flecha derecha va hacia atrás, como en @material/web (chip-set.ts, tabs.ts).
|
|
111
|
+
const rtl = getComputedStyle(rootEl).direction === 'rtl';
|
|
112
|
+
const forwards = key === 'ArrowDown' ? true : key === 'ArrowUp' ? false : (key === 'ArrowRight') !== rtl;
|
|
113
|
+
const target = index + (forwards ? 1 : -1);
|
|
114
|
+
if (opts.loop === false)
|
|
115
|
+
next = stops[Math.min(Math.max(target, 0), stops.length - 1)];
|
|
116
|
+
else
|
|
117
|
+
next = stops[(target + stops.length) % stops.length];
|
|
118
|
+
}
|
|
119
|
+
if (!next || next === event.target)
|
|
120
|
+
return;
|
|
121
|
+
// focusVisible: el foco llegó por teclado; WebKit no lo marca por sí solo al enfocar por script.
|
|
122
|
+
next.focus({ focusVisible: true });
|
|
123
|
+
opts.activate?.(next, event);
|
|
124
|
+
}, []);
|
|
125
|
+
return { onKeyDown, onFocus, onBlur, update };
|
|
126
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface SettleOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Esperar también las animaciones de los descendientes (`getAnimations({ subtree: true })`). Por
|
|
4
|
+
* defecto solo las del propio elemento. Lo usa el FabMenu, cuya salida son las transiciones de sus
|
|
5
|
+
* elementos escalonadas, sin ninguna en el contenedor (ADR-0033).
|
|
6
|
+
*/
|
|
7
|
+
subtree?: boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Se cumple cuando terminaron las animaciones del elemento, o cuando `active()` da `false`:
|
|
11
|
+
* - Usa `allSettled`: una animación cancelada termina la espera en vez de colgarla.
|
|
12
|
+
* - Al terminar vuelve a consultar: una transición cancelada puede dejar otra en su lugar.
|
|
13
|
+
* - Solo espera las que corren y tienen fin: una animación infinita o en pausa (de quien usa el
|
|
14
|
+
* componente) no detiene la salida.
|
|
15
|
+
* - `active` es la bandera del que espera: si se volvió a abrir durante la salida (las transiciones
|
|
16
|
+
* de salida se reemplazan por las de entrada), da `false` y la espera termina sin seguir a las
|
|
17
|
+
* nuevas. Quien llama vuelve a mirar `active()` antes de ocultar.
|
|
18
|
+
*
|
|
19
|
+
* Sin animaciones (sin transiciones, o una salida pedida antes de que la entrada avance: invertir
|
|
20
|
+
* una transición en progreso 0 no crea ninguna), se cumple enseguida. `getAnimations()` fuerza el
|
|
21
|
+
* cálculo de estilos, así que ya incluye las transiciones que acaba de disparar `data-closing`.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const token = {}
|
|
25
|
+
* closing.current = token
|
|
26
|
+
* el.setAttribute('data-closing', '')
|
|
27
|
+
* void settleAnimations(el, () => closing.current === token).then(() => {
|
|
28
|
+
* if (closing.current !== token) return
|
|
29
|
+
* el.hidePopover()
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function settleAnimations(el: Element, active?: () => boolean, options?: SettleOptions): Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Módulo interno universal (ADR-0003): sin React. No se exporta como API pública.
|
|
2
|
+
//
|
|
3
|
+
// Espera la salida animada de una capa (Snackbar, Tooltip, Menu, Dialog): el componente pone
|
|
4
|
+
// `data-closing`, que dispara las transiciones de salida, y recién al terminar oculta el popover o
|
|
5
|
+
// cierra el diálogo.
|
|
6
|
+
//
|
|
7
|
+
// Antes cada uno esperaba `Promise.all(el.getAnimations().map((a) => a.finished))` e ignoraba el
|
|
8
|
+
// rechazo. Una transición cancelada (por ejemplo, si se activa el movimiento reducido a mitad de la
|
|
9
|
+
// salida, o con `cancel()`) rechaza `finished`: la espera no terminaba nunca y la capa quedaba
|
|
10
|
+
// abierta con `data-closing` (comprobado en los tres motores el 2026-11-26: el Dialog invisible pero
|
|
11
|
+
// modal, con la página inerte; el Menu y el Tooltip abiertos y transparentes, el Tooltip visible en
|
|
12
|
+
// Firefox; el Snackbar con la cola trabada).
|
|
13
|
+
/**
|
|
14
|
+
* Se cumple cuando terminaron las animaciones del elemento, o cuando `active()` da `false`:
|
|
15
|
+
* - Usa `allSettled`: una animación cancelada termina la espera en vez de colgarla.
|
|
16
|
+
* - Al terminar vuelve a consultar: una transición cancelada puede dejar otra en su lugar.
|
|
17
|
+
* - Solo espera las que corren y tienen fin: una animación infinita o en pausa (de quien usa el
|
|
18
|
+
* componente) no detiene la salida.
|
|
19
|
+
* - `active` es la bandera del que espera: si se volvió a abrir durante la salida (las transiciones
|
|
20
|
+
* de salida se reemplazan por las de entrada), da `false` y la espera termina sin seguir a las
|
|
21
|
+
* nuevas. Quien llama vuelve a mirar `active()` antes de ocultar.
|
|
22
|
+
*
|
|
23
|
+
* Sin animaciones (sin transiciones, o una salida pedida antes de que la entrada avance: invertir
|
|
24
|
+
* una transición en progreso 0 no crea ninguna), se cumple enseguida. `getAnimations()` fuerza el
|
|
25
|
+
* cálculo de estilos, así que ya incluye las transiciones que acaba de disparar `data-closing`.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const token = {}
|
|
29
|
+
* closing.current = token
|
|
30
|
+
* el.setAttribute('data-closing', '')
|
|
31
|
+
* void settleAnimations(el, () => closing.current === token).then(() => {
|
|
32
|
+
* if (closing.current !== token) return
|
|
33
|
+
* el.hidePopover()
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export async function settleAnimations(el, active = () => true, options = {}) {
|
|
38
|
+
for (;;) {
|
|
39
|
+
if (!active())
|
|
40
|
+
return;
|
|
41
|
+
const running = el
|
|
42
|
+
.getAnimations({ subtree: options.subtree ?? false })
|
|
43
|
+
.filter((a) => a.playState === 'running' && a.effect?.getComputedTiming().endTime !== Infinity);
|
|
44
|
+
if (running.length === 0)
|
|
45
|
+
return;
|
|
46
|
+
await Promise.allSettled(running.map((a) => a.finished));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { KeyboardEvent, MouseEvent } from 'react';
|
|
2
|
+
export interface TimePeriodProps {
|
|
3
|
+
pm: boolean;
|
|
4
|
+
amLabel: string;
|
|
5
|
+
pmLabel: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
onChange: (pm: boolean, event: KeyboardEvent<HTMLElement> | MouseEvent<HTMLElement>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function TimePeriod({ pm, amLabel, pmLabel, label, disabled, onChange }: TimePeriodProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FocusRing } from '../atoms/FocusRing/FocusRing.js';
|
|
4
|
+
import { Ripple } from '../atoms/Ripple/Ripple.js';
|
|
5
|
+
import { StateLayer } from '../atoms/StateLayer/StateLayer.js';
|
|
6
|
+
export function TimePeriod({ pm, amLabel, pmLabel, label, disabled, onChange }) {
|
|
7
|
+
const handleKeyDown = (e) => {
|
|
8
|
+
if (disabled || e.altKey || e.ctrlKey || e.metaKey)
|
|
9
|
+
return;
|
|
10
|
+
if (!['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key))
|
|
11
|
+
return;
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
const group = e.currentTarget.parentElement;
|
|
14
|
+
const other = group?.querySelector(`[role="radio"]:not([aria-checked="true"])`);
|
|
15
|
+
onChange(!pm, e);
|
|
16
|
+
other?.focus();
|
|
17
|
+
};
|
|
18
|
+
const option = (isPm, text) => {
|
|
19
|
+
const checked = pm === isPm;
|
|
20
|
+
return (_jsxs("button", { type: "button", role: "radio", className: "mk-time-input-period-option", "aria-checked": checked, tabIndex: checked ? 0 : -1, disabled: disabled, onClick: (e) => {
|
|
21
|
+
if (!checked)
|
|
22
|
+
onChange(isPm, e);
|
|
23
|
+
}, onKeyDown: handleKeyDown, children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), text] }));
|
|
24
|
+
};
|
|
25
|
+
return (_jsxs("div", { className: "mk-time-input-period", role: "radiogroup", "aria-label": label, "data-disabled": disabled || undefined, children: [option(false, amLabel), option(true, pmLabel)] }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The clock the time is shown in: `12` (1–12 with AM/PM) or `24` (0–23). */
|
|
2
|
+
export type TimeHourCycle = 12 | 24;
|
|
3
|
+
export interface TimeParts {
|
|
4
|
+
hours: number;
|
|
5
|
+
minutes: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseTime(value: string): TimeParts | null;
|
|
8
|
+
export declare const pad2: (n: number) => string;
|
|
9
|
+
export declare const formatTime: ({ hours, minutes }: TimeParts) => string;
|
|
10
|
+
export declare const displayHour: (hours: number, cycle: TimeHourCycle) => number;
|
|
11
|
+
export declare const toHours24: (shown: number, cycle: TimeHourCycle, pm: boolean) => number;
|
|
12
|
+
export declare const hourRange: (cycle: TimeHourCycle) => {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function localeHourCycle(locale: string): TimeHourCycle;
|
|
17
|
+
export declare function localePeriodLabels(locale: string): {
|
|
18
|
+
am: string;
|
|
19
|
+
pm: string;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare const subscribeToLocale: () => () => void;
|
|
22
|
+
export declare const clientLocale: () => string;
|
|
23
|
+
export declare const serverLocale: () => undefined;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Ayudas de hora compartidas por los modos del time picker (ítem 28b, ADR-0042 y ADR-0043): la entrada
|
|
2
|
+
// por teclado (TimeInput) y la rueda (TimeScroll sobre ScrollField), con el mismo valor, el mismo ciclo
|
|
3
|
+
// de 12 o 24 horas y las mismas etiquetas AM/PM. Universal: sin React ni `window` al
|
|
4
|
+
// cargar (Intl se llama recién al pedir un dato, y se guarda por idioma).
|
|
5
|
+
//
|
|
6
|
+
// El valor es el de `<input type="time">` sin segundos: "HH:mm" en 24 horas, con ceros a la
|
|
7
|
+
// izquierda, o '' si no hay hora. Así es el mismo texto que envía el formulario y el que valida el
|
|
8
|
+
// `<input type="time">` oculto.
|
|
9
|
+
const TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
10
|
+
// "HH:mm" → horas y minutos; `null` si el texto no es una hora válida (también '').
|
|
11
|
+
export function parseTime(value) {
|
|
12
|
+
const match = TIME_RE.exec(value);
|
|
13
|
+
if (!match)
|
|
14
|
+
return null;
|
|
15
|
+
return { hours: Number(match[1]), minutes: Number(match[2]) };
|
|
16
|
+
}
|
|
17
|
+
export const pad2 = (n) => String(n).padStart(2, '0');
|
|
18
|
+
export const formatTime = ({ hours, minutes }) => `${pad2(hours)}:${pad2(minutes)}`;
|
|
19
|
+
// La hora que se muestra: 1–12 en 12 horas (0 y 12 son 12), 0–23 en 24.
|
|
20
|
+
export const displayHour = (hours, cycle) => (cycle === 12 ? hours % 12 || 12 : hours);
|
|
21
|
+
// De la hora mostrada (y el período) a 0–23.
|
|
22
|
+
export const toHours24 = (shown, cycle, pm) => cycle === 12 ? (shown % 12) + (pm ? 12 : 0) : shown;
|
|
23
|
+
export const hourRange = (cycle) => (cycle === 12 ? { min: 1, max: 12 } : { min: 0, max: 23 });
|
|
24
|
+
// Ciclo del idioma: el que usa Intl para una hora sin más opciones. h11 (0–11, Japón con 12 horas) se
|
|
25
|
+
// muestra como 1–12 y h24 (1–24), como 0–23: matekit dibuja solo los dos relojes de Material.
|
|
26
|
+
const cycleCache = new Map();
|
|
27
|
+
export function localeHourCycle(locale) {
|
|
28
|
+
let cycle = cycleCache.get(locale);
|
|
29
|
+
if (cycle === undefined) {
|
|
30
|
+
let resolved;
|
|
31
|
+
try {
|
|
32
|
+
resolved = new Intl.DateTimeFormat(locale, { hour: 'numeric' }).resolvedOptions().hourCycle;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
resolved = undefined;
|
|
36
|
+
}
|
|
37
|
+
cycle = resolved === 'h11' || resolved === 'h12' ? 12 : 24;
|
|
38
|
+
cycleCache.set(locale, cycle);
|
|
39
|
+
}
|
|
40
|
+
return cycle;
|
|
41
|
+
}
|
|
42
|
+
// Nombres de AM y PM del idioma ("a. m." y "p. m." en español), de `formatToParts` sobre una fecha fija
|
|
43
|
+
// en UTC (no depende del día ni de la zona). `null` si el idioma no da un `dayPeriod`.
|
|
44
|
+
const periodCache = new Map();
|
|
45
|
+
export function localePeriodLabels(locale) {
|
|
46
|
+
let labels = periodCache.get(locale);
|
|
47
|
+
if (labels === undefined) {
|
|
48
|
+
labels = null;
|
|
49
|
+
try {
|
|
50
|
+
const format = new Intl.DateTimeFormat(locale, { hour: 'numeric', hourCycle: 'h12', timeZone: 'UTC' });
|
|
51
|
+
const period = (hours) => format.formatToParts(Date.UTC(2000, 0, 1, hours)).find((p) => p.type === 'dayPeriod')?.value;
|
|
52
|
+
const am = period(9);
|
|
53
|
+
const pm = period(21);
|
|
54
|
+
if (am && pm && am !== pm)
|
|
55
|
+
labels = { am, pm };
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
labels = null;
|
|
59
|
+
}
|
|
60
|
+
periodCache.set(locale, labels);
|
|
61
|
+
}
|
|
62
|
+
return labels;
|
|
63
|
+
}
|
|
64
|
+
// El idioma del navegador, para useSyncExternalStore: no cambia durante la vida de la página (un
|
|
65
|
+
// cambio de idioma del sistema recarga), así que la suscripción no hace nada.
|
|
66
|
+
export const subscribeToLocale = () => () => { };
|
|
67
|
+
export const clientLocale = () => Intl.DateTimeFormat().resolvedOptions().locale;
|
|
68
|
+
// En el servidor (y al hidratar) no hay idioma del usuario: el componente usa sus valores fijos.
|
|
69
|
+
export const serverLocale = () => undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Tiempo máximo entre dos teclas de una misma búsqueda (APG sugiere alrededor de medio segundo). */
|
|
2
|
+
export declare const TYPEAHEAD_RESET_MS = 500;
|
|
3
|
+
export interface TypeaheadBuffer {
|
|
4
|
+
text: string;
|
|
5
|
+
time: number;
|
|
6
|
+
}
|
|
7
|
+
/** Un búfer vacío, para guardar en un `useRef` por componente. */
|
|
8
|
+
export declare const createTypeahead: () => TypeaheadBuffer;
|
|
9
|
+
/** Si el búfer tiene una búsqueda en curso (para que un Espacio sea parte del texto y no una elección). */
|
|
10
|
+
export declare function typeaheadActive(buffer: TypeaheadBuffer, now?: number): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Suma `key` al búfer y devuelve el índice del elemento a enfocar (o -1 si ninguno coincide).
|
|
13
|
+
* `texts` son los textos de los elementos en orden y `current` el índice del enfocado (-1 si
|
|
14
|
+
* ninguno). Con una letra repetida busca desde el siguiente; con un texto, desde el actual (sigue
|
|
15
|
+
* en el mismo mientras coincida).
|
|
16
|
+
*/
|
|
17
|
+
export declare function typeaheadMatch(buffer: TypeaheadBuffer, key: string, texts: readonly string[], current: number, now?: number): number;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Módulo interno (no se exporta desde src/index.ts): la búsqueda por letra de las listas con
|
|
2
|
+
// teclado, la de APG para menús y listbox. La usan MenuContent (foco real en los elementos) y Select
|
|
3
|
+
// (opción activa con aria-activedescendant, ADR-0036). Sacada del Menu el 2026-11-29 para no tener
|
|
4
|
+
// dos copias.
|
|
5
|
+
//
|
|
6
|
+
// Caracteres imprimibles escritos seguidos (menos de 500 ms entre uno y otro) forman el texto
|
|
7
|
+
// buscado; una misma letra repetida recorre los que empiezan con ella.
|
|
8
|
+
/** Tiempo máximo entre dos teclas de una misma búsqueda (APG sugiere alrededor de medio segundo). */
|
|
9
|
+
export const TYPEAHEAD_RESET_MS = 500;
|
|
10
|
+
/** Un búfer vacío, para guardar en un `useRef` por componente. */
|
|
11
|
+
export const createTypeahead = () => ({ text: '', time: 0 });
|
|
12
|
+
/** Si el búfer tiene una búsqueda en curso (para que un Espacio sea parte del texto y no una elección). */
|
|
13
|
+
export function typeaheadActive(buffer, now = Date.now()) {
|
|
14
|
+
return buffer.text !== '' && now - buffer.time <= TYPEAHEAD_RESET_MS;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Suma `key` al búfer y devuelve el índice del elemento a enfocar (o -1 si ninguno coincide).
|
|
18
|
+
* `texts` son los textos de los elementos en orden y `current` el índice del enfocado (-1 si
|
|
19
|
+
* ninguno). Con una letra repetida busca desde el siguiente; con un texto, desde el actual (sigue
|
|
20
|
+
* en el mismo mientras coincida).
|
|
21
|
+
*/
|
|
22
|
+
export function typeaheadMatch(buffer, key, texts, current, now = Date.now()) {
|
|
23
|
+
buffer.text = now - buffer.time > TYPEAHEAD_RESET_MS ? key : buffer.text + key;
|
|
24
|
+
buffer.time = now;
|
|
25
|
+
const query = buffer.text.toLocaleLowerCase();
|
|
26
|
+
const repeated = [...query].every((ch) => ch === query[0]);
|
|
27
|
+
const search = repeated ? query.slice(0, 1) : query;
|
|
28
|
+
const start = repeated ? current + 1 : Math.max(current, 0);
|
|
29
|
+
for (let step = 0; step < texts.length; step++) {
|
|
30
|
+
const i = (start + step) % texts.length;
|
|
31
|
+
if (texts[i]?.trim().toLocaleLowerCase().startsWith(search))
|
|
32
|
+
return i;
|
|
33
|
+
}
|
|
34
|
+
return -1;
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HTMLAttributes, Ref } from 'react';
|
|
2
|
+
export interface BadgeProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'aria-label'> {
|
|
3
|
+
/**
|
|
4
|
+
* Text announced by screen readers, for example "3 new notifications" or "New". Required, like
|
|
5
|
+
* the IconButton's `label`, so the badge is never silent by mistake: the visible number alone
|
|
6
|
+
* doesn't say what it counts. It goes as hidden text inside the badge, so it is added to the
|
|
7
|
+
* name of the element that contains it (a link or a button). With `""`, the badge is decorative
|
|
8
|
+
* (for example, if the element's name already says it).
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/** Ref to the badge's `<span>`. */
|
|
12
|
+
ref?: Ref<HTMLSpanElement> | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Material 3 badge: without children it is the small one, a 6 px dot; with children (a short
|
|
16
|
+
* number, "99+") it is the large one, 16 px tall. `error` background and `on-error` text.
|
|
17
|
+
*
|
|
18
|
+
* The visible content is hidden from screen readers; what they announce is `label`.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <Badge label="New" />
|
|
22
|
+
* <Badge label="3 new notifications">3</Badge>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function Badge({ label, className, children, ...props }: BadgeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Material 3 badge: without children it is the small one, a 6 px dot; with children (a short
|
|
4
|
+
* number, "99+") it is the large one, 16 px tall. `error` background and `on-error` text.
|
|
5
|
+
*
|
|
6
|
+
* The visible content is hidden from screen readers; what they announce is `label`.
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <Badge label="New" />
|
|
10
|
+
* <Badge label="3 new notifications">3</Badge>
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function Badge({ label, className, children, ...props }) {
|
|
14
|
+
const large = children !== undefined && children !== null && children !== false && children !== '';
|
|
15
|
+
return (_jsxs("span", { ...(label ? {} : { 'aria-hidden': true }), ...props, className: className ? `mk-badge ${className}` : 'mk-badge', "data-size": large ? 'large' : 'small', children: [large && _jsx("span", { "aria-hidden": "true", children: children }), label && _jsx("span", { className: "mk-badge-label", children: ` ${label}` })] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type ToggleButtonOrLinkProps } from '../../internal/interactive.tsx';
|
|
3
|
+
export type ButtonVariant = 'filled' | 'tonal' | 'outlined' | 'elevated' | 'text';
|
|
4
|
+
export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
5
|
+
export type ButtonShape = 'round' | 'square';
|
|
6
|
+
interface ButtonOwnProps {
|
|
7
|
+
/** Color style. Defaults to `filled`. */
|
|
8
|
+
variant?: ButtonVariant | undefined;
|
|
9
|
+
/** Material 3 Expressive size: 32, 40, 56, 96 or 136 px tall. Defaults to `sm`. */
|
|
10
|
+
size?: ButtonSize | undefined;
|
|
11
|
+
/** Resting shape. When pressed, and when a toggle is selected, it turns square. */
|
|
12
|
+
shape?: ButtonShape | undefined;
|
|
13
|
+
/** Icons and text. */
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Button props: its own plus one of three forms (ADR-0010).
|
|
18
|
+
* - Without `href` or `render`: a `<button type="button">` with its native attributes, `ref` to
|
|
19
|
+
* the `<button>`, `disabled` and `selected`, which makes it a toggle (`aria-pressed`; when
|
|
20
|
+
* undefined, it is a plain button; the `text` style has no toggle version in Material 3).
|
|
21
|
+
* - With `href`: an `<a>` with its attributes (`target`, `download`…) and `ref` to the `<a>`.
|
|
22
|
+
* - With `render`: the router's `Link`.
|
|
23
|
+
* The two link forms don't accept `selected`, `disabled` or `aria-disabled`.
|
|
24
|
+
*/
|
|
25
|
+
export type ButtonProps = ToggleButtonOrLinkProps<ButtonOwnProps>;
|
|
26
|
+
/**
|
|
27
|
+
* Material 3 Expressive button.
|
|
28
|
+
*
|
|
29
|
+
* Icons are passed as children, with no special props: the CSS gives them the button's size and
|
|
30
|
+
* spacing. With `href` or `render` it is a link that looks the same.
|
|
31
|
+
*
|
|
32
|
+
* Customization with CSS variables (inherited; the Toolbar sets them for its buttons):
|
|
33
|
+
* `--mk-button-unselected-container`, `--mk-button-unselected-color`,
|
|
34
|
+
* `--mk-button-selected-container` and `--mk-button-selected-color` change the toggle colors of
|
|
35
|
+
* the `filled` style (the default) when unselected and selected. Disabled keeps its own.
|
|
36
|
+
* `--mk-button-selected-round: 1` keeps the selected toggle round (in any style; by default it
|
|
37
|
+
* turns square).
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <Button>Save</Button>
|
|
41
|
+
* <Button variant="tonal" size="md"><svg …/>Create</Button>
|
|
42
|
+
* <Button variant="outlined" selected={on} onClick={() => setOn(!on)}>Favorite</Button>
|
|
43
|
+
* <Button variant="text" href="/orders/42">View details</Button>
|
|
44
|
+
* <Button render={<Link href="/orders/42" />}>View details</Button>
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function Button(props: ButtonProps): import("react").JSX.Element;
|
|
48
|
+
export {};
|