@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,223 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (excepción al ADR-0003 registrada en el ADR-0023, como el RadioGroup del
|
|
4
|
+
// ADR-0012 y el ChipGroup del ADR-0019): las pestañas necesitan estado (la elegida), contexto (la
|
|
5
|
+
// reparten a Tab y TabPanel), efectos (el indicador y el desplazamiento) y teclado.
|
|
6
|
+
//
|
|
7
|
+
// Patrón APG "Tabs" (https://www.w3.org/WAI/ARIA/apg/patterns/tabs/):
|
|
8
|
+
// - `TabList` es el `role="tablist"`, `Tab` un `<button role="tab">` con `aria-selected` y
|
|
9
|
+
// `aria-controls`, `TabPanel` el `role="tabpanel"` con `aria-labelledby`. Los `id` salen de
|
|
10
|
+
// `useId` y el valor de cada pestaña.
|
|
11
|
+
// - Una sola parada de Tab en la lista (la pestaña elegida, también al volver con Mayús+Tab) y
|
|
12
|
+
// flechas izquierda y derecha con vuelta, Inicio y Fin, RTL, sin pasar por las deshabilitadas:
|
|
13
|
+
// el foco itinerante compartido con ChipGroup (src/internal/roving-focus.ts).
|
|
14
|
+
// - Activación automática por defecto (mover el foco con las flechas elige la pestaña; APG la
|
|
15
|
+
// recomienda cuando mostrar el panel es inmediato) o manual (`activation="manual"`: las flechas
|
|
16
|
+
// solo mueven el foco; Enter o Espacio, los del botón, eligen).
|
|
17
|
+
// - Los paneles que no están elegidos quedan montados y ocultos con `hidden` (conservan el estado
|
|
18
|
+
// de un formulario, el desplazamiento y lo que cargaron); `unmount` en un TabPanel desmonta su
|
|
19
|
+
// contenido mientras está oculto (para un panel pesado), pero deja el elemento del panel para que
|
|
20
|
+
// `aria-controls` siga apuntando a algo.
|
|
21
|
+
// - `findable` en un TabPanel montado lo oculta con `hidden="until-found"` en lugar de `hidden`: la
|
|
22
|
+
// búsqueda en la página del navegador encuentra su texto, y al revelarlo (`beforematch`) las Tabs
|
|
23
|
+
// eligen esa pestaña con el evento nativo. React 19 escribe `hidden` como booleano (`hidden=""`,
|
|
24
|
+
// también en el HTML del servidor), así que el valor `until-found` se pone en un efecto de layout,
|
|
25
|
+
// después de cada commit en que el panel queda oculto. Actualización de 2026-11-29 del ADR-0023.
|
|
26
|
+
//
|
|
27
|
+
// Estado como el RadioGroup (ADR-0012): `value` (controlado) o `defaultValue` (no controlado), uno
|
|
28
|
+
// de los dos obligatorio (sin JavaScript tiene que haber una elegida y no hay de dónde sacarla), y
|
|
29
|
+
// `onValueChange(value, event)`.
|
|
30
|
+
import { createContext, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
31
|
+
import { cx } from '../../internal/interactive.js';
|
|
32
|
+
import { partOutsideParent } from '../../internal/diagnostics.js';
|
|
33
|
+
import { mergeRefs } from '../../internal/merge-refs.js';
|
|
34
|
+
import { useRovingFocus } from '../../internal/roving-focus.js';
|
|
35
|
+
import { tabContent, warnIfUnnamed } from './tab-content.js';
|
|
36
|
+
import { scrollTabIntoView, slideIndicator } from './tab-motion.js';
|
|
37
|
+
import { useTruncatedLabelWarning } from './tab-fit.js';
|
|
38
|
+
const TabsContext = createContext(null);
|
|
39
|
+
function useTabsContext(name) {
|
|
40
|
+
const ctx = use(TabsContext);
|
|
41
|
+
if (!ctx)
|
|
42
|
+
throw partOutsideParent(name, 'Tabs');
|
|
43
|
+
return ctx;
|
|
44
|
+
}
|
|
45
|
+
// Un `id` válido a partir del valor (sin espacios, que romperían las listas de `aria-controls`).
|
|
46
|
+
const idPart = (value) => encodeURIComponent(value);
|
|
47
|
+
/**
|
|
48
|
+
* Content tabs (APG "Tabs" pattern): a list of tabs and one panel per tab, of which the selected
|
|
49
|
+
* tab's panel is shown.
|
|
50
|
+
*
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <Tabs defaultValue="flights">
|
|
53
|
+
* <TabList aria-label="Trip">
|
|
54
|
+
* <Tab value="flights"><FlightIcon />Flights</Tab>
|
|
55
|
+
* <Tab value="hotels"><HotelIcon />Hotels</Tab>
|
|
56
|
+
* </TabList>
|
|
57
|
+
* <TabPanel value="flights">…</TabPanel>
|
|
58
|
+
* <TabPanel value="hotels">…</TabPanel>
|
|
59
|
+
* </Tabs>
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* To navigate between pages (each tab is a URL), use `TabNav` with `TabLink`: they are links, not
|
|
63
|
+
* tabs.
|
|
64
|
+
*/
|
|
65
|
+
export function Tabs(props) {
|
|
66
|
+
const { value: valueProp, defaultValue, onValueChange, activation = 'automatic', className, ...rest } = props;
|
|
67
|
+
const baseId = useId();
|
|
68
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue ?? '');
|
|
69
|
+
const controlled = valueProp !== undefined;
|
|
70
|
+
const value = controlled ? valueProp : uncontrolled;
|
|
71
|
+
const select = useCallback((next, event) => {
|
|
72
|
+
if (next === value)
|
|
73
|
+
return;
|
|
74
|
+
if (!controlled)
|
|
75
|
+
setUncontrolled(next);
|
|
76
|
+
onValueChange?.(next, event);
|
|
77
|
+
}, [value, controlled, onValueChange]);
|
|
78
|
+
const context = useMemo(() => ({
|
|
79
|
+
value,
|
|
80
|
+
activation,
|
|
81
|
+
tabId: (v) => `${baseId}tab-${idPart(v)}`,
|
|
82
|
+
panelId: (v) => `${baseId}panel-${idPart(v)}`,
|
|
83
|
+
select,
|
|
84
|
+
}), [value, activation, baseId, select]);
|
|
85
|
+
return (_jsx(TabsContext, { value: context, children: _jsx("div", { ...rest, className: cx('mk-tabs', className) }) }));
|
|
86
|
+
}
|
|
87
|
+
const ROVING = { stop: '[role="tab"]', scope: '[role="tablist"]' };
|
|
88
|
+
// Pestaña elegida de la lista (sin las de una lista anidada).
|
|
89
|
+
const selectedTab = (list) => [...list.querySelectorAll('[role="tab"][aria-selected="true"]')].find((el) => el.closest('[role="tablist"]') === list) ??
|
|
90
|
+
null;
|
|
91
|
+
/**
|
|
92
|
+
* Tab list: a `<div role="tablist">` with a `surface` background and a 1 divider at the bottom. A
|
|
93
|
+
* single Tab stop (the selected tab), Arrow Left and Arrow Right (reversed in RTL) with wrapping,
|
|
94
|
+
* Home and End. Give it a name with `aria-label` or `aria-labelledby`.
|
|
95
|
+
*/
|
|
96
|
+
export function TabList(props) {
|
|
97
|
+
const { variant = 'primary', layout = 'fixed', className, onKeyDown, onFocus, onBlur, ref, ...rest } = props;
|
|
98
|
+
const { value, activation, select } = useTabsContext('TabList');
|
|
99
|
+
const listRef = useRef(null);
|
|
100
|
+
const mergedRef = useMemo(() => mergeRefs(ref, listRef), [ref]);
|
|
101
|
+
useTruncatedLabelWarning(listRef, layout, 'TabList');
|
|
102
|
+
const roving = useRovingFocus(listRef, {
|
|
103
|
+
...ROVING,
|
|
104
|
+
preferred: (stops) => stops.find((el) => el.getAttribute('aria-selected') === 'true'),
|
|
105
|
+
activate: activation === 'automatic'
|
|
106
|
+
? (tab, event) => {
|
|
107
|
+
const next = tab.dataset['tabValue'];
|
|
108
|
+
if (next !== undefined)
|
|
109
|
+
select(next, event);
|
|
110
|
+
}
|
|
111
|
+
: undefined,
|
|
112
|
+
});
|
|
113
|
+
// Al cambiar la elegida: el indicador se desliza desde la anterior, la nueva se trae a la vista y
|
|
114
|
+
// pasa a ser la parada de Tab (si el foco no está en otra de la lista).
|
|
115
|
+
const previous = useRef(null);
|
|
116
|
+
const { update } = roving;
|
|
117
|
+
useLayoutEffect(() => {
|
|
118
|
+
const list = listRef.current;
|
|
119
|
+
if (!list)
|
|
120
|
+
return;
|
|
121
|
+
const tab = selectedTab(list);
|
|
122
|
+
if (tab && previous.current && previous.current !== tab && previous.current.isConnected)
|
|
123
|
+
slideIndicator(previous.current, tab);
|
|
124
|
+
if (tab)
|
|
125
|
+
scrollTabIntoView(list, tab, previous.current !== null);
|
|
126
|
+
previous.current = tab;
|
|
127
|
+
update();
|
|
128
|
+
}, [value, update]);
|
|
129
|
+
return (_jsx("div", { ...rest, ref: mergedRef, role: "tablist", "data-variant": variant, "data-layout": layout, className: cx('mk-tab-list', className), onKeyDown: (event) => {
|
|
130
|
+
onKeyDown?.(event);
|
|
131
|
+
roving.onKeyDown(event);
|
|
132
|
+
}, onFocus: (event) => {
|
|
133
|
+
onFocus?.(event);
|
|
134
|
+
roving.onFocus(event);
|
|
135
|
+
}, onBlur: (event) => {
|
|
136
|
+
onBlur?.(event);
|
|
137
|
+
roving.onBlur(event);
|
|
138
|
+
} }));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Tab: a `<button role="tab">` with `aria-selected` and `aria-controls` (its panel). The accessible
|
|
142
|
+
* name comes from the label (and the badge's `label`); without a visible label, `aria-label`.
|
|
143
|
+
* `disabled` disables it and the arrow keys skip it.
|
|
144
|
+
*/
|
|
145
|
+
export function Tab(props) {
|
|
146
|
+
const { value, children, className, onClick, ...rest } = props;
|
|
147
|
+
const ctx = useTabsContext('Tab');
|
|
148
|
+
const selected = ctx.value === value;
|
|
149
|
+
const content = tabContent(children);
|
|
150
|
+
warnIfUnnamed('Tab', content.hasLabel, rest);
|
|
151
|
+
return (_jsx("button", { ...rest, id: ctx.tabId(value), "aria-controls": ctx.panelId(value), type: "button", role: "tab", "aria-selected": selected, "data-tab-value": value, ...content.data, className: cx('mk-tab', className), onClick: (event) => {
|
|
152
|
+
onClick?.(event);
|
|
153
|
+
if (!event.defaultPrevented)
|
|
154
|
+
ctx.select(value, event);
|
|
155
|
+
}, children: content.children }));
|
|
156
|
+
}
|
|
157
|
+
// `hidden="until-found"` sirve solo si el navegador avisa la revelación (`beforematch`): sin el
|
|
158
|
+
// evento, la pestaña no se elegiría y el panel quedaría visible sin estar elegido.
|
|
159
|
+
const supportsUntilFound = () => typeof HTMLElement !== 'undefined' && 'onbeforematch' in HTMLElement.prototype;
|
|
160
|
+
/**
|
|
161
|
+
* A tab's panel: a `<div role="tabpanel">` named by its tab (`aria-labelledby`), hidden with
|
|
162
|
+
* `hidden` (or `hidden="until-found"` with `findable`) while the tab is not selected. It is in the
|
|
163
|
+
* Tab order (`tabIndex={0}`, as APG recommends when the panel doesn't start with a focusable element;
|
|
164
|
+
* `tabIndex` changes it).
|
|
165
|
+
*/
|
|
166
|
+
export function TabPanel(props) {
|
|
167
|
+
const { value, unmount = false, findable = false, children, className, tabIndex = 0, ref, ...rest } = props;
|
|
168
|
+
const ctx = useTabsContext('TabPanel');
|
|
169
|
+
const selected = ctx.value === value;
|
|
170
|
+
// Un panel desmontado no tiene nada que encontrar (los tipos ya lo impiden; desde JavaScript,
|
|
171
|
+
// `unmount` gana).
|
|
172
|
+
const untilFound = findable && !unmount;
|
|
173
|
+
const panelRef = useRef(null);
|
|
174
|
+
const mergedRef = useMemo(() => mergeRefs(ref, panelRef), [ref]);
|
|
175
|
+
// React escribe `hidden=""` cuando la prop pasa a verdadera; acá se cambia por `until-found` en
|
|
176
|
+
// el mismo commit, antes de pintar. Si el panel sigue oculto y React no lo toca, el atributo queda.
|
|
177
|
+
// La limpieza vuelve a `hidden=""` solo si el atributo sigue en `until-found` (dejar `findable`
|
|
178
|
+
// con el panel oculto); si React o el navegador ya lo sacaron (elegido o revelado), no hace nada.
|
|
179
|
+
useLayoutEffect(() => {
|
|
180
|
+
const el = panelRef.current;
|
|
181
|
+
if (!el || !untilFound || selected || !supportsUntilFound())
|
|
182
|
+
return;
|
|
183
|
+
el.setAttribute('hidden', 'until-found');
|
|
184
|
+
return () => {
|
|
185
|
+
if (el.getAttribute('hidden') === 'until-found')
|
|
186
|
+
el.setAttribute('hidden', '');
|
|
187
|
+
};
|
|
188
|
+
}, [untilFound, selected]);
|
|
189
|
+
// El último estado para el oyente nativo, que se registra una vez por panel.
|
|
190
|
+
const latest = useRef({ select: ctx.select, selected });
|
|
191
|
+
useLayoutEffect(() => {
|
|
192
|
+
latest.current = { select: ctx.select, selected };
|
|
193
|
+
});
|
|
194
|
+
// El navegador avisa con `beforematch` (que burbujea) antes de sacar el atributo: se elige la
|
|
195
|
+
// pestaña por el camino normal. Si después de la tarea la pestaña no quedó elegida (controlada y
|
|
196
|
+
// vetada), el panel vuelve a ocultarse: React no lo haría, su prop `hidden` no cambió.
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
const el = panelRef.current;
|
|
199
|
+
if (!el || !untilFound)
|
|
200
|
+
return;
|
|
201
|
+
let timer;
|
|
202
|
+
const onBeforeMatch = (event) => {
|
|
203
|
+
if (event.target !== el)
|
|
204
|
+
return; // el de un panel anidado
|
|
205
|
+
latest.current.select(value, event);
|
|
206
|
+
clearTimeout(timer);
|
|
207
|
+
timer = setTimeout(() => {
|
|
208
|
+
if (!latest.current.selected && el.isConnected && !el.hasAttribute('hidden'))
|
|
209
|
+
el.setAttribute('hidden', 'until-found');
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
el.addEventListener('beforematch', onBeforeMatch);
|
|
213
|
+
return () => {
|
|
214
|
+
el.removeEventListener('beforematch', onBeforeMatch);
|
|
215
|
+
clearTimeout(timer);
|
|
216
|
+
};
|
|
217
|
+
}, [untilFound, value]);
|
|
218
|
+
const hiddenFindable = untilFound && !selected;
|
|
219
|
+
return (_jsx("div", { ...rest, ref: mergedRef,
|
|
220
|
+
// Con `until-found` el panel conserva su caja (`content-visibility: hidden` oculta solo el
|
|
221
|
+
// contenido): sin esto quedaría en el orden de Tab y en el árbol de accesibilidad, vacío.
|
|
222
|
+
tabIndex: hiddenFindable ? -1 : tabIndex, "aria-hidden": hiddenFindable ? true : rest['aria-hidden'], id: ctx.panelId(value), "aria-labelledby": ctx.tabId(value), role: "tabpanel", hidden: !selected, className: cx('mk-tab-panel', className), children: unmount && !selected ? null : children }));
|
|
223
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
export interface TabLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
/** Ref to the `<span>`. */
|
|
4
|
+
ref?: Ref<HTMLSpanElement> | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A tab's label, for when it is not just text (formatted text or a translation component). Plain
|
|
8
|
+
* text is already wrapped on its own: `<Tab value="a">Flights</Tab>`. It stays on one line; in
|
|
9
|
+
* fixed tabs, if it doesn't fit, it is cut off with an ellipsis and the accessible name is still
|
|
10
|
+
* the full text.
|
|
11
|
+
*/
|
|
12
|
+
export declare function TabLabel({ className, ...props }: TabLabelProps): import("react").JSX.Element;
|
|
13
|
+
interface TabContent {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
data: {
|
|
16
|
+
'data-icon'?: '';
|
|
17
|
+
'data-label'?: '';
|
|
18
|
+
};
|
|
19
|
+
hasLabel: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function tabContent(children: ReactNode): TabContent;
|
|
22
|
+
export declare function warnIfUnnamed(name: string, hasLabel: boolean, props: Record<string, unknown>): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Módulo universal (ADR-0003): sin estado, efectos, contexto ni eventos; no lleva 'use client'.
|
|
3
|
+
// Contenido de una pestaña, compartido por Tab (pestañas APG) y TabLink (enlaces): `TabLabel`, el
|
|
4
|
+
// reparto de los hijos en icono, etiqueta e insignia, el indicador y los átomos (ADR-0023).
|
|
5
|
+
//
|
|
6
|
+
// Los casos simples se escriben corto, como el Button y los chips:
|
|
7
|
+
// `<Tab value="vuelos"><FlightIcon />Vuelos</Tab>`. El texto suelto se envuelve en la etiqueta
|
|
8
|
+
// (`.mk-tab-label`), que necesita ser un elemento para recortarse con puntos suspensivos; `TabLabel` sirve cuando la etiqueta no es solo texto (un componente de traducción).
|
|
9
|
+
// Una `Badge` va sobre la esquina del icono (con su texto para lectores después de la etiqueta) o,
|
|
10
|
+
// sin icono, después de la etiqueta. Cualquier otro elemento es el icono.
|
|
11
|
+
//
|
|
12
|
+
// El indicador es de cada pestaña y se ve solo en la elegida (como @material/web, tab.ts): así está
|
|
13
|
+
// en su lugar sin JavaScript (antes de hidratar o en un Server Component) y sigue a la pestaña
|
|
14
|
+
// cuando cambia el ancho sin medir nada. El desplazamiento entre pestañas lo anima tab-motion.ts.
|
|
15
|
+
// En la primary va dentro del contenido (`position: relative`) y mide su ancho; en la secondary,
|
|
16
|
+
// el contenido no está posicionado y el indicador mide el ancho de la pestaña (tabs.css).
|
|
17
|
+
import { Children, cloneElement, Fragment, isValidElement } from 'react';
|
|
18
|
+
import { FocusRing } from '../../atoms/FocusRing/FocusRing.js';
|
|
19
|
+
import { Ripple } from '../../atoms/Ripple/Ripple.js';
|
|
20
|
+
import { StateLayer } from '../../atoms/StateLayer/StateLayer.js';
|
|
21
|
+
import { Badge } from '../../molecules/Badge/Badge.js';
|
|
22
|
+
import { mkWarn } from '../../internal/diagnostics.js';
|
|
23
|
+
import { cx } from '../../internal/interactive.js';
|
|
24
|
+
/**
|
|
25
|
+
* A tab's label, for when it is not just text (formatted text or a translation component). Plain
|
|
26
|
+
* text is already wrapped on its own: `<Tab value="a">Flights</Tab>`. It stays on one line; in
|
|
27
|
+
* fixed tabs, if it doesn't fit, it is cut off with an ellipsis and the accessible name is still
|
|
28
|
+
* the full text.
|
|
29
|
+
*/
|
|
30
|
+
export function TabLabel({ className, ...props }) {
|
|
31
|
+
return _jsx("span", { ...props, className: cx('mk-tab-label', className) });
|
|
32
|
+
}
|
|
33
|
+
const isLabel = (el) => el.type === TabLabel;
|
|
34
|
+
// Hijos en una lista plana: los de un fragmento (`<>{icono}{texto}</>`) cuentan como propios.
|
|
35
|
+
const flatten = (children, prefix = '') => Children.toArray(children).flatMap((child) => {
|
|
36
|
+
if (!isValidElement(child))
|
|
37
|
+
return [child];
|
|
38
|
+
const key = `${prefix}${String(child.key)}`;
|
|
39
|
+
if (child.type === Fragment)
|
|
40
|
+
return flatten(child.props.children, `${key}/`);
|
|
41
|
+
return [prefix ? cloneElement(child, { key }) : child];
|
|
42
|
+
});
|
|
43
|
+
const isBadge = (el) => el.type === Badge;
|
|
44
|
+
// Reparte los hijos de una pestaña en icono, etiqueta e insignia, con el indicador y los átomos.
|
|
45
|
+
export function tabContent(children) {
|
|
46
|
+
const icon = [];
|
|
47
|
+
const label = [];
|
|
48
|
+
const badge = [];
|
|
49
|
+
let text = [];
|
|
50
|
+
const flushText = () => {
|
|
51
|
+
if (text.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
label.push(_jsx("span", { className: "mk-tab-label", children: text.join('') }, `label-${label.length}`));
|
|
54
|
+
text = [];
|
|
55
|
+
};
|
|
56
|
+
for (const child of flatten(children)) {
|
|
57
|
+
if (typeof child === 'string' || typeof child === 'number') {
|
|
58
|
+
text.push(child);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
flushText();
|
|
62
|
+
if (!isValidElement(child))
|
|
63
|
+
continue;
|
|
64
|
+
if (isLabel(child))
|
|
65
|
+
label.push(child);
|
|
66
|
+
else if (isBadge(child))
|
|
67
|
+
badge.push(child);
|
|
68
|
+
else
|
|
69
|
+
icon.push(child);
|
|
70
|
+
}
|
|
71
|
+
flushText();
|
|
72
|
+
const hasIcon = icon.length > 0;
|
|
73
|
+
// Con icono, la insignia se dibuja sobre él, pero su texto para lectores va después de la
|
|
74
|
+
// etiqueta ("Favoritos 3 nuevos" y no "3 nuevos Favoritos"): la insignia sobre el icono queda
|
|
75
|
+
// decorativa (`label=""`) y su texto, oculto a la vista, después de la etiqueta.
|
|
76
|
+
const badgeText = [];
|
|
77
|
+
if (hasIcon) {
|
|
78
|
+
for (const [i, el] of badge.entries()) {
|
|
79
|
+
if (!isValidElement(el))
|
|
80
|
+
continue;
|
|
81
|
+
if (el.props.label)
|
|
82
|
+
badgeText.push(_jsx("span", { className: "mk-badge-label", children: ` ${el.props.label}` }, `badge-${i}`));
|
|
83
|
+
badge[i] = cloneElement(el, { label: '' });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const hasLabel = label.length > 0;
|
|
87
|
+
return {
|
|
88
|
+
children: (_jsxs(_Fragment, { children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), _jsxs("span", { className: "mk-tab-content", children: [hasIcon ? (_jsxs("span", { className: "mk-tab-icon", children: [icon, badge] })) : null, label, hasIcon ? badgeText : badge, _jsx("span", { className: "mk-tab-indicator", "aria-hidden": "true" })] })] })),
|
|
89
|
+
data: { ...(hasIcon ? { 'data-icon': '' } : {}), ...(hasLabel ? { 'data-label': '' } : {}) },
|
|
90
|
+
hasLabel,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Una pestaña sin etiqueta visible (solo icono) necesita nombre accesible. No se puede pedir en los
|
|
94
|
+
// tipos (los hijos no dicen si son un icono o un texto), así que se avisa por consola, como un aviso
|
|
95
|
+
// de React: es un error de accesibilidad del uso, no del componente. Solo en desarrollo y una vez
|
|
96
|
+
// por componente (`MK_TAB_UNNAMED`; este módulo es universal: sin instancia, se deduplica por texto).
|
|
97
|
+
export function warnIfUnnamed(name, hasLabel, props) {
|
|
98
|
+
if (hasLabel || props['aria-label'] || props['aria-labelledby'])
|
|
99
|
+
return;
|
|
100
|
+
mkWarn('MK_TAB_UNNAMED', {
|
|
101
|
+
component: name,
|
|
102
|
+
problem: 'a tab without a visible label (icon only) has no accessible name',
|
|
103
|
+
fix: `add aria-label (<${name} aria-label="Home"><HomeIcon /></${name}>) or aria-labelledby; if the label is a component, wrap it in <TabLabel>`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { TabsLayout } from './Tabs.tsx';
|
|
3
|
+
export declare function truncatedLabels(list: HTMLElement): HTMLElement[];
|
|
4
|
+
export declare function useTruncatedLabelWarning(listRef: RefObject<HTMLElement | null>, layout: TabsLayout, component: 'TabList' | 'TabNav'): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Aviso de etiquetas recortadas en la barra fija (MK_TAB_LABEL_TRUNCATED), compartido por TabList y
|
|
2
|
+
// TabNav (ADR-0023, actualización del 2026-11-28). Un hook: solo lo usan las dos barras, que son
|
|
3
|
+
// cliente.
|
|
4
|
+
//
|
|
5
|
+
// En `layout="fixed"` las pestañas se reparten el ancho y la etiqueta que no entra se recorta con
|
|
6
|
+
// puntos suspensivos (tabs.css): el nombre accesible queda completo, pero quien mira no puede leerla.
|
|
7
|
+
// Se mide en el cliente: una etiqueta está recortada si su contenido es más ancho que su caja
|
|
8
|
+
// (`scrollWidth > clientWidth`). Los dos son enteros redondeados y cada motor redondea a su manera
|
|
9
|
+
// (Firefox ubica en subpíxeles): se pide más de 1 px de diferencia para que una etiqueta que entra
|
|
10
|
+
// justa no avise. Una barra de 0 de ancho (oculta, en un panel con `display: none`) no cuenta.
|
|
11
|
+
//
|
|
12
|
+
// Cuándo: un cuadro después de cada cambio de tamaño de la barra (ResizeObserver, que también avisa
|
|
13
|
+
// al empezar a observar) y cuando terminan de cargar las fuentes (`document.fonts.ready`: una fuente
|
|
14
|
+
// web cambia el ancho del texto sin cambiar el de la barra). Una vez por instancia; después de avisar
|
|
15
|
+
// deja de observar. Solo en desarrollo.
|
|
16
|
+
import { useEffect, useRef } from 'react';
|
|
17
|
+
import { isDevelopment } from '../../internal/dev.js';
|
|
18
|
+
import { mkWarn } from '../../internal/diagnostics.js';
|
|
19
|
+
// Diferencia mínima, en px, entre el contenido y la caja para contar una etiqueta como recortada.
|
|
20
|
+
const TOLERANCE = 1;
|
|
21
|
+
// Etiquetas de esta barra (sin las de una barra anidada) recortadas por el ancho.
|
|
22
|
+
export function truncatedLabels(list) {
|
|
23
|
+
// Una barra oculta mide 0 (y sus etiquetas también): no hay nada que recortar a la vista. Una
|
|
24
|
+
// etiqueta de 0 en una barra visible sí cuenta: es el recorte total (muchas pestañas en poco ancho).
|
|
25
|
+
if (list.clientWidth === 0)
|
|
26
|
+
return [];
|
|
27
|
+
return [...list.querySelectorAll('.mk-tab-label')].filter((label) => label.closest('.mk-tab-list') === list && label.scrollWidth - label.clientWidth > TOLERANCE);
|
|
28
|
+
}
|
|
29
|
+
export function useTruncatedLabelWarning(listRef, layout, component) {
|
|
30
|
+
const warned = useRef({});
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const list = listRef.current;
|
|
33
|
+
if (!list || layout !== 'fixed' || !isDevelopment() || typeof ResizeObserver === 'undefined')
|
|
34
|
+
return;
|
|
35
|
+
let done = false;
|
|
36
|
+
let frame = 0;
|
|
37
|
+
const check = () => {
|
|
38
|
+
frame = 0;
|
|
39
|
+
if (done)
|
|
40
|
+
return;
|
|
41
|
+
const clipped = truncatedLabels(list);
|
|
42
|
+
if (clipped.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
done = true;
|
|
45
|
+
observer.disconnect();
|
|
46
|
+
mkWarn('MK_TAB_LABEL_TRUNCATED', {
|
|
47
|
+
component,
|
|
48
|
+
problem: 'with layout="fixed", some tab labels do not fit and are cut off with an ellipsis, so they cannot be read on screen',
|
|
49
|
+
fix: `use layout="scrollable" (<${component} layout="scrollable">), or shorten the labels or use fewer tabs`,
|
|
50
|
+
}, { labels: clipped.map((label) => label.textContent ?? ''), width: list.clientWidth }, { once: warned.current });
|
|
51
|
+
};
|
|
52
|
+
const schedule = () => {
|
|
53
|
+
if (!done && !frame)
|
|
54
|
+
frame = requestAnimationFrame(check);
|
|
55
|
+
};
|
|
56
|
+
const observer = new ResizeObserver(schedule);
|
|
57
|
+
observer.observe(list);
|
|
58
|
+
void document.fonts?.ready.then(schedule);
|
|
59
|
+
return () => {
|
|
60
|
+
done = true;
|
|
61
|
+
observer.disconnect();
|
|
62
|
+
cancelAnimationFrame(frame);
|
|
63
|
+
};
|
|
64
|
+
}, [listRef, layout, component]);
|
|
65
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Movimiento de la barra de pestañas, compartido por TabList y TabNav (ADR-0023): el indicador que
|
|
2
|
+
// se desliza de la pestaña anterior a la nueva y la pestaña elegida traída a la vista en la
|
|
3
|
+
// scrollable. Sin estado ni React: funciones sobre el DOM que llaman los efectos de los dos.
|
|
4
|
+
//
|
|
5
|
+
// Indicador (técnica elegida con una sonda en Chrome, Firefox y WebKit el 2026-11-26): cada
|
|
6
|
+
// pestaña tiene el suyo (tab-content.tsx) y, al cambiar, el de la nueva se anima desde el lugar y
|
|
7
|
+
// el ancho del anterior con la Web Animations API (FLIP, como @material/web tabs/internal/tab.ts,
|
|
8
|
+
// commit dba9f5fe40, pero con `translate` y `width` en lugar de `scaleX`, para no deformar las
|
|
9
|
+
// esquinas redondeadas del primary). Descartado CSS anchor positioning con transición: existe en los tres, pero Firefox no
|
|
10
|
+
// anima al cambiar de ancla (salta), y el indicador quedaría sin lugar antes de hidratar.
|
|
11
|
+
//
|
|
12
|
+
// Resorte DefaultSpatial (Compose TabRow.kt, commit c61c795a52: tabIndicatorAnimationSpec =
|
|
13
|
+
// MotionSchemeKeyTokens.DefaultSpatial), leído de los tokens. Con movimiento reducido su duración
|
|
14
|
+
// es 0 (tokens/motion.css): el indicador aparece en su lugar con un fundido corto (FastEffects),
|
|
15
|
+
// sin desplazarse, como @material/web con `shouldReduceMotion()`.
|
|
16
|
+
const INDICATOR = '.mk-tab-indicator';
|
|
17
|
+
// Duración en ms de un token de movimiento (`440ms` o `0.44s`).
|
|
18
|
+
function duration(style, token) {
|
|
19
|
+
const raw = style.getPropertyValue(token).trim();
|
|
20
|
+
const value = Number.parseFloat(raw);
|
|
21
|
+
if (!Number.isFinite(value))
|
|
22
|
+
return 0;
|
|
23
|
+
return raw.endsWith('ms') ? value : value * 1000;
|
|
24
|
+
}
|
|
25
|
+
// Anima el indicador de `to` desde donde está el de `from` (o lo hace aparecer, sin `from`).
|
|
26
|
+
export function slideIndicator(from, to) {
|
|
27
|
+
const target = to.querySelector(INDICATOR);
|
|
28
|
+
if (!target)
|
|
29
|
+
return;
|
|
30
|
+
const source = from?.querySelector(INDICATOR) ?? null;
|
|
31
|
+
// Se mide antes de cancelar: si el anterior estaba a mitad de camino, se sale desde ahí.
|
|
32
|
+
const a = source?.getBoundingClientRect();
|
|
33
|
+
for (const animation of [...target.getAnimations(), ...(source?.getAnimations() ?? [])]) {
|
|
34
|
+
if (animation instanceof CSSTransition || animation instanceof CSSAnimation)
|
|
35
|
+
continue;
|
|
36
|
+
animation.cancel();
|
|
37
|
+
}
|
|
38
|
+
const b = target.getBoundingClientRect();
|
|
39
|
+
const style = getComputedStyle(target);
|
|
40
|
+
const spatial = duration(style, '--md-sys-motion-spring-default-spatial-duration');
|
|
41
|
+
if (a && a.width > 0 && b.width > 0 && spatial > 0) {
|
|
42
|
+
target.animate([{ translate: `${a.left - b.left}px 0`, width: `${a.width}px`, offset: 0 }], {
|
|
43
|
+
duration: spatial,
|
|
44
|
+
easing: style.getPropertyValue('--md-sys-motion-spring-default-spatial-easing').trim() || 'ease',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
target.animate([{ opacity: 0, offset: 0 }], {
|
|
49
|
+
duration: duration(style, '--md-sys-motion-spring-fast-effects-duration'),
|
|
50
|
+
easing: style.getPropertyValue('--md-sys-motion-spring-fast-effects-easing').trim() || 'ease',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Trae la pestaña a la vista dentro de la barra, lo más centrada que se pueda (Compose,
|
|
55
|
+
// ScrollableTabData.calculateTabOffset). Desplaza solo la barra (`scrollTo` en ella, no
|
|
56
|
+
// `scrollIntoView`, que también movería la página en vertical). `smooth`: con desplazamiento
|
|
57
|
+
// suave, salvo movimiento reducido.
|
|
58
|
+
export function scrollTabIntoView(list, tab, smooth) {
|
|
59
|
+
if (list.scrollWidth <= list.clientWidth)
|
|
60
|
+
return;
|
|
61
|
+
const l = list.getBoundingClientRect();
|
|
62
|
+
const t = tab.getBoundingClientRect();
|
|
63
|
+
const delta = t.left + t.width / 2 - (l.left + l.width / 2);
|
|
64
|
+
if (Math.abs(delta) < 1)
|
|
65
|
+
return;
|
|
66
|
+
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
67
|
+
list.scrollTo({ left: list.scrollLeft + delta, behavior: smooth && !reduce ? 'smooth' : 'instant' });
|
|
68
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type DialogProps } from '../Dialog/Dialog.tsx';
|
|
2
|
+
export interface TimePickerDialogProps extends Omit<DialogProps, 'view' | 'alert'> {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* The time picker dialog of Material 3 (the kit's "Keyboard picker", Compose `TimePickerDialog`): a
|
|
6
|
+
* `Dialog` as wide as its time input, with a small title. It takes the `Dialog` parts and props (`open`,
|
|
7
|
+
* `onClose(reason)`); keep the chosen time in your own state and commit it on OK.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <TimePickerDialog open={open} onClose={() => setOpen(false)}>
|
|
11
|
+
* <DialogHeadline>Enter time</DialogHeadline>
|
|
12
|
+
* <DialogContent>
|
|
13
|
+
* <TimeInput value={draft} onValueChange={setDraft} />
|
|
14
|
+
* </DialogContent>
|
|
15
|
+
* <DialogActions>
|
|
16
|
+
* <Button variant="text" onClick={() => setOpen(false)}>Cancel</Button>
|
|
17
|
+
* <Button variant="text" onClick={() => { setTime(draft); setOpen(false) }}>OK</Button>
|
|
18
|
+
* </DialogActions>
|
|
19
|
+
* </TimePickerDialog>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The `DialogHeadline` takes the kit's header style (Label Medium, `on-surface-variant`) and names the
|
|
23
|
+
* dialog. Focus starts on the hour field. It takes a `TimeScroll` (the wheel) the same way; to offer both
|
|
24
|
+
* modes, keep one draft and put an `IconButton` that switches them at the start of `DialogActions`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function TimePickerDialog({ className, ...props }: TimePickerDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Organismo universal (ADR-0003, ADR-0042): sin estado, efectos, contexto ni eventos propios; el ciclo
|
|
3
|
+
// modal es el del Dialog (cliente), que se renderiza con la clase del time picker. Las partes son las
|
|
4
|
+
// del Dialog (DialogHeadline, DialogContent, DialogActions): el time picker de Compose
|
|
5
|
+
// (TimePickerDialog) es también un diálogo con título, contenido y acciones, y el aspecto distinto
|
|
6
|
+
// (título en Label Medium, ancho del contenido) se resuelve en time-picker-dialog.css. La rueda
|
|
7
|
+
// (TimeScroll) va adentro del mismo diálogo; el botón que cambia de modo lo compone la app en las acciones
|
|
8
|
+
// (ADR-0043).
|
|
9
|
+
import { Dialog } from '../Dialog/Dialog.js';
|
|
10
|
+
/**
|
|
11
|
+
* The time picker dialog of Material 3 (the kit's "Keyboard picker", Compose `TimePickerDialog`): a
|
|
12
|
+
* `Dialog` as wide as its time input, with a small title. It takes the `Dialog` parts and props (`open`,
|
|
13
|
+
* `onClose(reason)`); keep the chosen time in your own state and commit it on OK.
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <TimePickerDialog open={open} onClose={() => setOpen(false)}>
|
|
17
|
+
* <DialogHeadline>Enter time</DialogHeadline>
|
|
18
|
+
* <DialogContent>
|
|
19
|
+
* <TimeInput value={draft} onValueChange={setDraft} />
|
|
20
|
+
* </DialogContent>
|
|
21
|
+
* <DialogActions>
|
|
22
|
+
* <Button variant="text" onClick={() => setOpen(false)}>Cancel</Button>
|
|
23
|
+
* <Button variant="text" onClick={() => { setTime(draft); setOpen(false) }}>OK</Button>
|
|
24
|
+
* </DialogActions>
|
|
25
|
+
* </TimePickerDialog>
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The `DialogHeadline` takes the kit's header style (Label Medium, `on-surface-variant`) and names the
|
|
29
|
+
* dialog. Focus starts on the hour field. It takes a `TimeScroll` (the wheel) the same way; to offer both
|
|
30
|
+
* modes, keep one draft and put an `IconButton` that switches them at the start of `DialogActions`.
|
|
31
|
+
*/
|
|
32
|
+
export function TimePickerDialog({ className, ...props }) {
|
|
33
|
+
return _jsx(Dialog, { ...props, className: className ? `mk-time-picker-dialog ${className}` : 'mk-time-picker-dialog' });
|
|
34
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import type { AccessibleNameProps } from '../../internal/accessible-name.ts';
|
|
3
|
+
/** `docked`: at the bottom, full width (replaces the Bottom app bar). `floating`: a floating pill. */
|
|
4
|
+
export type ToolbarVariant = 'docked' | 'floating';
|
|
5
|
+
/** Kit colors: `standard` (Surface Container) or `vibrant` (Primary Container). */
|
|
6
|
+
export type ToolbarColor = 'standard' | 'vibrant';
|
|
7
|
+
export type ToolbarOrientation = 'horizontal' | 'vertical';
|
|
8
|
+
/** Side of the vertical floating toolbar: the start or the end of the line (left or right in LTR). */
|
|
9
|
+
export type ToolbarSide = 'start' | 'end';
|
|
10
|
+
/**
|
|
11
|
+
* What the toolbar does when its container scrolls:
|
|
12
|
+
* - `none` (the default): it always stays in view.
|
|
13
|
+
* - `exit-always`: it leaves when scrolling down and comes back as soon as you scroll up, like
|
|
14
|
+
* Compose's `exitAlwaysScrollBehavior` (`FloatingToolbarDefaults` and `BottomAppBarDefaults`). It
|
|
15
|
+
* also comes back when focus enters the toolbar. Needs JavaScript (the scroll direction).
|
|
16
|
+
* - `collapse`: inside a `ToolbarLayout`, the toolbar collapses into its FAB after scrolling down
|
|
17
|
+
* 40 px and expands after scrolling up 40 px, like Compose's `floatingToolbarVerticalNestedScroll`
|
|
18
|
+
* (`ScrollDistanceThreshold`). It requests the change from the `ToolbarLayout`
|
|
19
|
+
* (`onExpandedChange` with `'scroll'`). Outside a `ToolbarLayout` it does nothing.
|
|
20
|
+
*/
|
|
21
|
+
export type ToolbarScrollBehavior = 'none' | 'exit-always' | 'collapse';
|
|
22
|
+
interface ToolbarBaseProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'color' | 'aria-label' | 'aria-labelledby' | 'aria-orientation'> {
|
|
23
|
+
/** Colors. Defaults to `standard`. */
|
|
24
|
+
color?: ToolbarColor | undefined;
|
|
25
|
+
/** Hiding on scroll. Defaults to `none`. */
|
|
26
|
+
scrollBehavior?: ToolbarScrollBehavior | undefined;
|
|
27
|
+
/** IconButton, Button (toggles too), a MenuTrigger for more actions, Tooltip… */
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
/** Ref to the `<div role="toolbar">`. */
|
|
30
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Vertical exists only in the floating toolbar (neither the kit nor Compose has a vertical docked
|
|
34
|
+
* one), and `side` only in the vertical one. The docked toolbar has no companion FAB (neither the kit
|
|
35
|
+
* nor Compose's `FlexibleBottomAppBar` defines one; see `ToolbarLayout`).
|
|
36
|
+
*/
|
|
37
|
+
type ToolbarShapeProps = {
|
|
38
|
+
/** Defaults to `floating`. */
|
|
39
|
+
variant?: ToolbarVariant | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* `horizontal`: at the bottom, centered. `vertical` (floating only): on one side. Defaults to
|
|
42
|
+
* `horizontal`.
|
|
43
|
+
*/
|
|
44
|
+
orientation?: 'horizontal' | undefined;
|
|
45
|
+
side?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
variant?: 'floating' | undefined;
|
|
48
|
+
orientation: 'vertical';
|
|
49
|
+
/** Side: `end` (on the right in LTR) or `start`. Defaults to `end`. */
|
|
50
|
+
side?: ToolbarSide | undefined;
|
|
51
|
+
};
|
|
52
|
+
export type ToolbarProps = ToolbarBaseProps & ToolbarShapeProps & AccessibleNameProps;
|
|
53
|
+
/**
|
|
54
|
+
* Material 3 Expressive toolbar: a `<div role="toolbar">` with a required accessible name
|
|
55
|
+
* (`label`, `aria-label` or `aria-labelledby`), a single Tab stop and arrow keys.
|
|
56
|
+
*
|
|
57
|
+
* It goes as the last child of the scrolling container (the window or a pane), except the vertical
|
|
58
|
+
* one, which goes as the first child: `position: sticky` keeps it at the bottom (or on the side)
|
|
59
|
+
* while scrolling.
|
|
60
|
+
*
|
|
61
|
+
* ```tsx
|
|
62
|
+
* <Toolbar label="Formatting" color="vibrant">
|
|
63
|
+
* <IconButton label="Bold" selected={bold} onClick={() => setBold(!bold)}><BoldIcon filled={bold} /></IconButton>
|
|
64
|
+
* <IconButton label="Italic"><ItalicIcon /></IconButton>
|
|
65
|
+
* <Menu>
|
|
66
|
+
* <MenuTrigger><IconButton label="More options"><MoreVertIcon /></IconButton></MenuTrigger>
|
|
67
|
+
* <MenuContent>…</MenuContent>
|
|
68
|
+
* </Menu>
|
|
69
|
+
* </Toolbar>
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* With a FAB next to it, both pieces go inside `ToolbarLayout` (floating only).
|
|
73
|
+
*/
|
|
74
|
+
export declare function Toolbar(props: ToolbarProps): import("react").JSX.Element;
|
|
75
|
+
export {};
|