@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,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (excepción al ADR-0003, ADR-0027, como el ChipGroup del ADR-0019): el foco
|
|
4
|
+
// itinerante necesita efectos (un MutationObserver que cuenta las paradas) y manejadores de teclado
|
|
5
|
+
// en la raíz. Aislarlo en una hija oculta, como TopAppBarScroll, obligaría a escuchar el teclado con
|
|
6
|
+
// addEventListener sobre la barra, que corre antes que los manejadores de React de los hijos: la
|
|
7
|
+
// flecha abajo de un MenuTrigger (que abre el menú y cancela el evento) llegaría tarde. Los hijos
|
|
8
|
+
// (IconButton, Button, Menu) siguen siendo lo que son y pueden venir de un Server Component.
|
|
9
|
+
//
|
|
10
|
+
// - Teclado: patrón APG "Toolbar". Una sola parada de Tab para los botones y enlaces de la barra y
|
|
11
|
+
// flechas en su eje (izquierda y derecha, invertidas en RTL; arriba y abajo en la vertical), con
|
|
12
|
+
// vuelta en los extremos, Inicio y Fin (src/internal/roving-focus.ts, ADR-0023). Un campo de
|
|
13
|
+
// texto u otro control que usa las flechas no es parada: conserva su propio Tab.
|
|
14
|
+
// - Deshabilitados: `disabled` los saltea (no se pueden enfocar); `aria-disabled` los deja como
|
|
15
|
+
// parada (APG lo recomienda en una toolbar para que se descubran) y el uso ignora sus clics.
|
|
16
|
+
// - Colores de los hijos: la barra define las variables públicas que leen IconButton y Button
|
|
17
|
+
// (`--mk-icon-button-*`, `--mk-button-*`), con los colores Standard o Vibrant del kit.
|
|
18
|
+
// - Posición: `position: sticky` en el contenedor que se desplaza (como TopAppBar, ADR-0024): la
|
|
19
|
+
// docked abajo a todo el ancho, la floating abajo y centrada o, vertical, a un costado (`side`).
|
|
20
|
+
// Ocultarse al desplazar (`exit-always`), contraerse hacia el FAB al desplazar (`collapse`) y el
|
|
21
|
+
// alto máximo de la vertical (lo visible del contenedor) son la parte cliente ToolbarScroll.
|
|
22
|
+
// - Dentro de un ToolbarLayout contraído, la barra queda `inert` (lee el estado por contexto).
|
|
23
|
+
import { use, useMemo, useRef } from 'react';
|
|
24
|
+
import { cx } from '../../internal/interactive.js';
|
|
25
|
+
import { mergeRefs } from '../../internal/merge-refs.js';
|
|
26
|
+
import { useRovingFocus } from '../../internal/roving-focus.js';
|
|
27
|
+
import { ToolbarLayoutContext } from './ToolbarLayout.js';
|
|
28
|
+
import { ToolbarScroll } from './ToolbarScroll.js';
|
|
29
|
+
// Paradas: botones y enlaces de la barra. No lo son los de un menú, un tooltip o un diálogo que
|
|
30
|
+
// vivan dentro del árbol de la barra (su ancestro más cercano del `scope` no es la raíz), ni los
|
|
31
|
+
// campos de texto, que usan las flechas y conservan su parada de Tab (APG, "Toolbar").
|
|
32
|
+
const STOP = ':is(button, a[href])';
|
|
33
|
+
const SCOPE = '.mk-toolbar, [role="toolbar"], [role="menu"], [popover], dialog';
|
|
34
|
+
/**
|
|
35
|
+
* Material 3 Expressive toolbar: a `<div role="toolbar">` with a required accessible name
|
|
36
|
+
* (`label`, `aria-label` or `aria-labelledby`), a single Tab stop and arrow keys.
|
|
37
|
+
*
|
|
38
|
+
* It goes as the last child of the scrolling container (the window or a pane), except the vertical
|
|
39
|
+
* one, which goes as the first child: `position: sticky` keeps it at the bottom (or on the side)
|
|
40
|
+
* while scrolling.
|
|
41
|
+
*
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <Toolbar label="Formatting" color="vibrant">
|
|
44
|
+
* <IconButton label="Bold" selected={bold} onClick={() => setBold(!bold)}><BoldIcon filled={bold} /></IconButton>
|
|
45
|
+
* <IconButton label="Italic"><ItalicIcon /></IconButton>
|
|
46
|
+
* <Menu>
|
|
47
|
+
* <MenuTrigger><IconButton label="More options"><MoreVertIcon /></IconButton></MenuTrigger>
|
|
48
|
+
* <MenuContent>…</MenuContent>
|
|
49
|
+
* </Menu>
|
|
50
|
+
* </Toolbar>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* With a FAB next to it, both pieces go inside `ToolbarLayout` (floating only).
|
|
54
|
+
*/
|
|
55
|
+
export function Toolbar(props) {
|
|
56
|
+
const { variant = 'floating', color = 'standard', orientation = 'horizontal', side = 'end', scrollBehavior = 'none', label, 'aria-label': ariaLabel, className, children, onKeyDown, onKeyDownCapture, onFocus, ref, ...rest } = props;
|
|
57
|
+
const rootRef = useRef(null);
|
|
58
|
+
const mergedRef = useMemo(() => mergeRefs(ref, rootRef), [ref]);
|
|
59
|
+
const vertical = variant === 'floating' && orientation === 'vertical';
|
|
60
|
+
// Dentro de un ToolbarLayout contraído, la barra no se ve: inerte (sin paradas de Tab ni lectura);
|
|
61
|
+
// el FAB sigue accesible.
|
|
62
|
+
const layout = use(ToolbarLayoutContext);
|
|
63
|
+
const collapsed = layout !== null && !layout.expanded;
|
|
64
|
+
const roving = useRovingFocus(rootRef, { stop: STOP, scope: SCOPE, orientation: vertical ? 'vertical' : 'horizontal' });
|
|
65
|
+
const handleFocus = (event) => {
|
|
66
|
+
onFocus?.(event);
|
|
67
|
+
roving.onFocus(event);
|
|
68
|
+
};
|
|
69
|
+
const handleKeyDown = (event) => {
|
|
70
|
+
onKeyDown?.(event);
|
|
71
|
+
roving.onKeyDown(event);
|
|
72
|
+
};
|
|
73
|
+
// En la vertical, arriba y abajo sobre el disparador de un menú mueven el foco en vez de abrirlo
|
|
74
|
+
// (APG, "Menu Button": abrir con las flechas es opcional; Enter y Espacio lo siguen abriendo). Se
|
|
75
|
+
// resuelve en la captura, antes que el MenuTrigger, que cancela esas flechas para abrir.
|
|
76
|
+
const handleKeyDownCapture = (event) => {
|
|
77
|
+
onKeyDownCapture?.(event);
|
|
78
|
+
const target = event.target;
|
|
79
|
+
if (vertical && (event.key === 'ArrowUp' || event.key === 'ArrowDown') && target.hasAttribute('aria-haspopup')) {
|
|
80
|
+
roving.onKeyDown(event);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return (_jsxs("div", { ...rest, ref: mergedRef, role: "toolbar", "aria-label": label ?? ariaLabel, "aria-orientation": vertical ? 'vertical' : 'horizontal', "data-variant": variant, "data-color": color, "data-side": vertical ? side : undefined, inert: collapsed || undefined, className: cx('mk-toolbar', className), onKeyDown: handleKeyDown, onKeyDownCapture: handleKeyDownCapture, onFocus: handleFocus, children: [children, (scrollBehavior !== 'none' || vertical) && (_jsx(ToolbarScroll, { hide: scrollBehavior === 'exit-always', collapse: scrollBehavior === 'collapse' ? layout : null, measure: vertical }))] }));
|
|
84
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Why the layout asked to expand or collapse (`onExpandedChange(expanded, reason)`): `scroll`
|
|
4
|
+
* (`scrollBehavior="collapse"` on the Toolbar) or `focus` (keyboard focus reaching the FAB while
|
|
5
|
+
* collapsed; the same `focus` as `BottomSheetStateChangeReason` and `TooltipOpenChangeReason`).
|
|
6
|
+
*/
|
|
7
|
+
export type ToolbarLayoutExpandedChangeReason = 'scroll' | 'focus';
|
|
8
|
+
export interface ToolbarLayoutContextValue {
|
|
9
|
+
expanded: boolean;
|
|
10
|
+
requestExpanded: (expanded: boolean, reason: ToolbarLayoutExpandedChangeReason) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const ToolbarLayoutContext: import("react").Context<ToolbarLayoutContextValue | null>;
|
|
13
|
+
export interface ToolbarLayoutProps extends HTMLAttributes<HTMLDivElement> {
|
|
14
|
+
/** A floating `Toolbar` and a `Fab` (size `sm`, 56, as in Compose with the toolbar expanded). */
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
/** Toolbar expanded (controlled). When collapsed, only the FAB shows. */
|
|
17
|
+
expanded?: boolean | undefined;
|
|
18
|
+
/** Toolbar initially expanded (uncontrolled). Defaults to `true`. */
|
|
19
|
+
defaultExpanded?: boolean | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Called when scrolling (`scrollBehavior="collapse"` on the Toolbar) or keyboard focus reaching
|
|
22
|
+
* the FAB while the toolbar is collapsed requests the other state.
|
|
23
|
+
*/
|
|
24
|
+
onExpandedChange?: ((expanded: boolean, reason: ToolbarLayoutExpandedChangeReason) => void) | undefined;
|
|
25
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A floating Toolbar with a FAB next to it. It goes where the toolbar alone would go: the last child
|
|
29
|
+
* of the scrolling container (horizontal) or the first (vertical).
|
|
30
|
+
*
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <ToolbarLayout>
|
|
33
|
+
* <Toolbar label="Editing" scrollBehavior="collapse">…</Toolbar>
|
|
34
|
+
* <Fab label="New" color="secondary-container"><AddIcon /></Fab>
|
|
35
|
+
* </ToolbarLayout>
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* With the toolbar collapsed, keyboard focus reaching the FAB expands it again (so the toolbar's
|
|
39
|
+
* buttons are one Shift+Tab away). When controlled (`expanded`), that is a request:
|
|
40
|
+
* `onExpandedChange(true, 'focus')`. If the app doesn't accept it, the toolbar stays collapsed and
|
|
41
|
+
* inert and its buttons are out of keyboard reach; development builds warn in the console
|
|
42
|
+
* (`MK_TOOLBAR_EXPAND_IGNORED`, once per ToolbarLayout; docs/diagnostics.md).
|
|
43
|
+
*/
|
|
44
|
+
export declare function ToolbarLayout(props: ToolbarLayoutProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Parte de Toolbar (ADR-0027) que ubica una Toolbar floating con su FAB acompañante, como las
|
|
4
|
+
// variantes con `floatingActionButton` de `HorizontalFloatingToolbar` y `VerticalFloatingToolbar` de
|
|
5
|
+
// Compose (FloatingToolbar.kt): las dos piezas en fila (o en columna, con la vertical) a 8 de
|
|
6
|
+
// distancia (`FloatingToolbarFabTokens.BetweenSpace`), centradas en el otro eje, con la posición, el
|
|
7
|
+
// margen y las zonas seguras que la barra tendría sola. El FAB va donde se lo escriba: después de la
|
|
8
|
+
// barra, al final (lo que Compose hace por defecto), o antes, al principio.
|
|
9
|
+
//
|
|
10
|
+
// Es cliente (excepción al ADR-0003) por el estado `expanded` (controlado o no, como el resto de la
|
|
11
|
+
// librería): contraída, la barra se encoge hacia el FAB y el FAB crece de 56 a 80 (`FabSizeRange`),
|
|
12
|
+
// con FastSpatial (`FloatingToolbarDefaults.animationSpec`). La barra lee el estado por contexto y
|
|
13
|
+
// queda inerte mientras está contraída (sin paradas de Tab ni lectura); el FAB sigue accesible.
|
|
14
|
+
//
|
|
15
|
+
// El FAB no es parte de la barra: es su propia parada de Tab, como en Compose, que lo deja fuera de
|
|
16
|
+
// la fila. Con `scrollBehavior="exit-always"` en la Toolbar se esconde el conjunto (lo que Compose
|
|
17
|
+
// recomienda para la barra centrada); con `"collapse"`, se contrae al bajar y se expande al subir (lo
|
|
18
|
+
// que recomienda para la barra a un costado).
|
|
19
|
+
//
|
|
20
|
+
// Docked con FAB: no existe. Ni el kit (configuraciones Docked y Floating, sin FAB en la docked) ni
|
|
21
|
+
// `FlexibleBottomAppBar` de Compose (AppBar.kt, sin parámetro de FAB; el `BottomAppBar` con
|
|
22
|
+
// `floatingActionButton` es el Bottom app bar que la docked reemplaza) lo definen. Para una barra con
|
|
23
|
+
// FAB, usar la floating dentro de ToolbarLayout; si hace falta la docked, el FAB va suelto, encima de
|
|
24
|
+
// ella, como sobre una NavigationBar.
|
|
25
|
+
import { createContext, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
26
|
+
import { isDevelopment } from '../../internal/dev.js';
|
|
27
|
+
import { mkWarn } from '../../internal/diagnostics.js';
|
|
28
|
+
import { cx } from '../../internal/interactive.js';
|
|
29
|
+
// Estado del ToolbarLayout para la Toolbar de adentro (no se exporta desde el índice).
|
|
30
|
+
export const ToolbarLayoutContext = createContext(null);
|
|
31
|
+
/**
|
|
32
|
+
* A floating Toolbar with a FAB next to it. It goes where the toolbar alone would go: the last child
|
|
33
|
+
* of the scrolling container (horizontal) or the first (vertical).
|
|
34
|
+
*
|
|
35
|
+
* ```tsx
|
|
36
|
+
* <ToolbarLayout>
|
|
37
|
+
* <Toolbar label="Editing" scrollBehavior="collapse">…</Toolbar>
|
|
38
|
+
* <Fab label="New" color="secondary-container"><AddIcon /></Fab>
|
|
39
|
+
* </ToolbarLayout>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* With the toolbar collapsed, keyboard focus reaching the FAB expands it again (so the toolbar's
|
|
43
|
+
* buttons are one Shift+Tab away). When controlled (`expanded`), that is a request:
|
|
44
|
+
* `onExpandedChange(true, 'focus')`. If the app doesn't accept it, the toolbar stays collapsed and
|
|
45
|
+
* inert and its buttons are out of keyboard reach; development builds warn in the console
|
|
46
|
+
* (`MK_TOOLBAR_EXPAND_IGNORED`, once per ToolbarLayout; docs/diagnostics.md).
|
|
47
|
+
*/
|
|
48
|
+
export function ToolbarLayout(props) {
|
|
49
|
+
const { className, children, expanded: expandedProp, defaultExpanded = true, onExpandedChange, onFocus, ...rest } = props;
|
|
50
|
+
const [uncontrolled, setUncontrolled] = useState(defaultExpanded);
|
|
51
|
+
const controlled = expandedProp !== undefined;
|
|
52
|
+
const expanded = controlled ? expandedProp : uncontrolled;
|
|
53
|
+
const requestExpanded = useCallback((next, reason) => {
|
|
54
|
+
if (next === expanded)
|
|
55
|
+
return;
|
|
56
|
+
if (!controlled)
|
|
57
|
+
setUncontrolled(next);
|
|
58
|
+
onExpandedChange?.(next, reason);
|
|
59
|
+
}, [expanded, controlled, onExpandedChange]);
|
|
60
|
+
const context = useMemo(() => ({ expanded, requestExpanded }), [expanded, requestExpanded]);
|
|
61
|
+
// Aviso en desarrollo: el pedido de expandir por el foco quedó sin respuesta (controlado). Se mira
|
|
62
|
+
// después de que React aplique lo que la app haga en onExpandedChange (un turno después del evento).
|
|
63
|
+
const latestExpanded = useRef(expanded);
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
latestExpanded.current = expanded;
|
|
66
|
+
});
|
|
67
|
+
// Clave de la deduplicación de mkWarn: una vez por ToolbarLayout montado.
|
|
68
|
+
const instance = useRef({}).current;
|
|
69
|
+
const warnTimer = useRef(undefined);
|
|
70
|
+
useEffect(() => () => clearTimeout(warnTimer.current), []);
|
|
71
|
+
const handleFocus = (event) => {
|
|
72
|
+
onFocus?.(event);
|
|
73
|
+
if (!expanded && event.target.matches(':focus-visible')) {
|
|
74
|
+
requestExpanded(true, 'focus');
|
|
75
|
+
if (controlled && isDevelopment()) {
|
|
76
|
+
clearTimeout(warnTimer.current);
|
|
77
|
+
warnTimer.current = setTimeout(() => {
|
|
78
|
+
if (latestExpanded.current)
|
|
79
|
+
return;
|
|
80
|
+
mkWarn('MK_TOOLBAR_EXPAND_IGNORED', {
|
|
81
|
+
component: 'ToolbarLayout',
|
|
82
|
+
problem: "keyboard focus reached the FAB and requested expanding the toolbar (onExpandedChange(true, 'focus')), but `expanded` is still false: the collapsed toolbar is inert and its buttons cannot be reached with the keyboard",
|
|
83
|
+
fix: "accept the request by updating `expanded` in onExpandedChange (onExpandedChange={(next) => setExpanded(next)}), at least for reason 'focus'",
|
|
84
|
+
}, { expanded: false, reason: 'focus' }, { once: instance });
|
|
85
|
+
}, 0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return (_jsx(ToolbarLayoutContext, { value: context, children: _jsx("div", { ...rest, "data-collapsed": expanded ? undefined : '', className: cx('mk-toolbar-layout', className), onFocus: handleFocus, children: children }) }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolbarLayoutContextValue } from './ToolbarLayout.tsx';
|
|
2
|
+
interface ToolbarScrollProps {
|
|
3
|
+
hide: boolean;
|
|
4
|
+
collapse: ToolbarLayoutContextValue | null;
|
|
5
|
+
measure: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function ToolbarScroll({ hide, collapse, measure }: ToolbarScrollProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Parte cliente de Toolbar ligada al contenedor que se desplaza (ADR-0027): un `<span hidden>`, sin
|
|
4
|
+
// caja ni semántica, que la barra dibuja con `scrollBehavior` o en la vertical. Hace tres cosas:
|
|
5
|
+
//
|
|
6
|
+
// 1. `exit-always` (`hide`): el mismo enfoque que `enter-always` de TopAppBarScroll (ADR-0024),
|
|
7
|
+
// porque depende de la dirección del desplazamiento y CSS no la expone. El corrimiento sigue lo
|
|
8
|
+
// desplazado (baja con lo que se baja y vuelve con lo que se sube, como
|
|
9
|
+
// `ExitAlwaysFloatingToolbarScrollBehavior` de Compose, FloatingToolbar.kt), al terminar de
|
|
10
|
+
// desplazar se acomoda al estado más cercano (`settleFloatingToolbar`) y vuelve cuando el foco
|
|
11
|
+
// entra. Escribe `--_offset` (px, de 0 a `range`) y `--_progress` (de 0 a 1) en la barra o, dentro
|
|
12
|
+
// de `ToolbarLayout`, en el conjunto con el FAB; el CSS los aplica:
|
|
13
|
+
// - Docked y floating horizontal: al `inset-block-end` del `position: sticky`, que la baja hasta
|
|
14
|
+
// sacarla por el borde. No es `translate`: un elemento corrido con `translate` hacia abajo
|
|
15
|
+
// agranda lo que se puede desplazar en Chrome y Firefox (sonda del 2026-11-26), y el inset de un
|
|
16
|
+
// sticky no. Al final del contenido la barra queda en su lugar en el flujo, a la vista.
|
|
17
|
+
// - Floating vertical: hacia el costado se agrandaría el ancho desplazable con cualquier técnica
|
|
18
|
+
// (la misma sonda), así que se corre hasta el borde (su margen) y se desvanece. Con
|
|
19
|
+
// `data-hidden` no recibe el puntero.
|
|
20
|
+
// Con el foco adentro no se esconde: un control enfocado no puede quedar tapado (WCAG 2.4.11).
|
|
21
|
+
// 2. `collapse`: dentro de un ToolbarLayout, pide contraer la barra al bajar 40 px y expandirla al
|
|
22
|
+
// subir 40 px desde el último cambio, como `VerticalNestedScrollExpansionNode` de Compose
|
|
23
|
+
// (`floatingToolbarVerticalNestedScroll`, `ScrollDistanceThreshold`). Con el foco adentro de la
|
|
24
|
+
// barra no la contrae.
|
|
25
|
+
// 3. `measure` (la vertical): escribe el alto visible del contenedor en `--_scrollport`, para que la
|
|
26
|
+
// barra no sea más alta que lo que se ve (el CSS usa `100dvh` hasta que esto corre).
|
|
27
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
28
|
+
import { nearestScroller } from '../../internal/nearest-scroller.js';
|
|
29
|
+
// Sin `scrollend` (Safari, según conocimiento previo), el desplazamiento terminó tras esta pausa.
|
|
30
|
+
const SCROLL_END_FALLBACK_MS = 150;
|
|
31
|
+
// `FloatingToolbarDefaults.ScrollDistanceThreshold` (40 dp).
|
|
32
|
+
const COLLAPSE_THRESHOLD = 40;
|
|
33
|
+
const px = (value) => {
|
|
34
|
+
const n = Number.parseFloat(value);
|
|
35
|
+
return Number.isFinite(n) ? n : 0;
|
|
36
|
+
};
|
|
37
|
+
export function ToolbarScroll({ hide, collapse, measure }) {
|
|
38
|
+
const ref = useRef(null);
|
|
39
|
+
// El estado del ToolbarLayout cambia en cada render: el efecto lee el último.
|
|
40
|
+
const latestCollapse = useRef(collapse);
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
latestCollapse.current = collapse;
|
|
43
|
+
});
|
|
44
|
+
const collapsing = collapse !== null;
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const bar = ref.current?.parentElement;
|
|
47
|
+
if (!bar)
|
|
48
|
+
return;
|
|
49
|
+
const layout = bar.parentElement;
|
|
50
|
+
const target = layout?.classList.contains('mk-toolbar-layout') ? layout : bar;
|
|
51
|
+
const scroller = nearestScroller(target);
|
|
52
|
+
const source = scroller ?? document.scrollingElement ?? document.documentElement;
|
|
53
|
+
const events = scroller ?? window;
|
|
54
|
+
const vertical = bar.getAttribute('aria-orientation') === 'vertical';
|
|
55
|
+
const cleanups = [];
|
|
56
|
+
function readTop() {
|
|
57
|
+
const max = source.scrollHeight - source.clientHeight;
|
|
58
|
+
// Sin valores negativos ni pasados del final (el rebote de Safari).
|
|
59
|
+
return Math.min(Math.max(source.scrollTop, 0), Math.max(max, 0));
|
|
60
|
+
}
|
|
61
|
+
const focusInside = () => target.contains(document.activeElement);
|
|
62
|
+
// --- 3. Alto visible del contenedor ---
|
|
63
|
+
if (measure) {
|
|
64
|
+
const write = () => target.style.setProperty('--_scrollport', `${scroller ? scroller.clientHeight : window.innerHeight}px`);
|
|
65
|
+
write();
|
|
66
|
+
if (scroller) {
|
|
67
|
+
const observer = new ResizeObserver(write);
|
|
68
|
+
observer.observe(scroller);
|
|
69
|
+
cleanups.push(() => observer.disconnect());
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
window.addEventListener('resize', write);
|
|
73
|
+
cleanups.push(() => window.removeEventListener('resize', write));
|
|
74
|
+
}
|
|
75
|
+
cleanups.push(() => target.style.removeProperty('--_scrollport'));
|
|
76
|
+
}
|
|
77
|
+
// --- 2. Contraer hacia el FAB ---
|
|
78
|
+
if (collapsing) {
|
|
79
|
+
let last = readTop();
|
|
80
|
+
// El umbral se ancla donde está el contenedor al montar (un salto grande también cuenta).
|
|
81
|
+
let wasExpanded = latestCollapse.current?.expanded ?? true;
|
|
82
|
+
let threshold = wasExpanded ? last + COLLAPSE_THRESHOLD : last - COLLAPSE_THRESHOLD;
|
|
83
|
+
let frame = 0;
|
|
84
|
+
const update = () => {
|
|
85
|
+
frame = 0;
|
|
86
|
+
const state = latestCollapse.current;
|
|
87
|
+
if (!state)
|
|
88
|
+
return;
|
|
89
|
+
const top = readTop();
|
|
90
|
+
const delta = top - last;
|
|
91
|
+
last = top;
|
|
92
|
+
// Un cambio que no vino de acá (el foco, la app) vuelve a anclar el umbral, como Compose.
|
|
93
|
+
if (wasExpanded !== state.expanded) {
|
|
94
|
+
threshold = state.expanded ? top + COLLAPSE_THRESHOLD : top - COLLAPSE_THRESHOLD;
|
|
95
|
+
wasExpanded = state.expanded;
|
|
96
|
+
}
|
|
97
|
+
if (delta > 0 && state.expanded && top >= threshold && !focusInside()) {
|
|
98
|
+
threshold = top - COLLAPSE_THRESHOLD;
|
|
99
|
+
wasExpanded = false;
|
|
100
|
+
state.requestExpanded(false, 'scroll');
|
|
101
|
+
}
|
|
102
|
+
else if (delta < 0 && !state.expanded && top <= threshold) {
|
|
103
|
+
threshold = top + COLLAPSE_THRESHOLD;
|
|
104
|
+
wasExpanded = true;
|
|
105
|
+
state.requestExpanded(true, 'scroll');
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const onScroll = () => {
|
|
109
|
+
if (!frame)
|
|
110
|
+
frame = requestAnimationFrame(update);
|
|
111
|
+
};
|
|
112
|
+
events.addEventListener('scroll', onScroll, { passive: true });
|
|
113
|
+
cleanups.push(() => {
|
|
114
|
+
cancelAnimationFrame(frame);
|
|
115
|
+
events.removeEventListener('scroll', onScroll);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// --- 1. Ocultar al desplazar ---
|
|
119
|
+
if (hide) {
|
|
120
|
+
let range = 0;
|
|
121
|
+
let offset = 0;
|
|
122
|
+
let last = 0;
|
|
123
|
+
let frame = 0;
|
|
124
|
+
let endTimer;
|
|
125
|
+
const supportsScrollEnd = 'onscrollend' in window;
|
|
126
|
+
// Lo que hay que correr para sacarla del todo: su tamaño más la distancia al borde (el inset
|
|
127
|
+
// del sticky con la zona segura; en la vertical, el margen del costado), como el `offsetLimit`
|
|
128
|
+
// de Compose. El inset se lee con el corrimiento actual y se le suma.
|
|
129
|
+
const measureRange = () => {
|
|
130
|
+
const box = target.getBoundingClientRect();
|
|
131
|
+
const cs = getComputedStyle(target);
|
|
132
|
+
range = vertical
|
|
133
|
+
? box.width + Math.max(px(cs.marginInlineStart), px(cs.marginInlineEnd))
|
|
134
|
+
: box.height + px(cs.insetBlockEnd) + offset;
|
|
135
|
+
};
|
|
136
|
+
const apply = () => {
|
|
137
|
+
target.style.setProperty('--_offset', `${offset}px`);
|
|
138
|
+
target.style.setProperty('--_progress', String(range > 0 ? offset / range : 0));
|
|
139
|
+
if (range > 0 && offset >= range)
|
|
140
|
+
target.dataset['hidden'] = '';
|
|
141
|
+
else
|
|
142
|
+
delete target.dataset['hidden'];
|
|
143
|
+
};
|
|
144
|
+
const update = () => {
|
|
145
|
+
const top = readTop();
|
|
146
|
+
const delta = top - last;
|
|
147
|
+
last = top;
|
|
148
|
+
offset = focusInside() ? 0 : Math.min(Math.max(offset + delta, 0), range);
|
|
149
|
+
apply();
|
|
150
|
+
};
|
|
151
|
+
// Al terminar de desplazar: a la vista o escondida, la más cercana, con la transición de
|
|
152
|
+
// data-settling (instantánea con movimiento reducido).
|
|
153
|
+
const settle = () => {
|
|
154
|
+
if (frame) {
|
|
155
|
+
cancelAnimationFrame(frame);
|
|
156
|
+
frame = 0;
|
|
157
|
+
}
|
|
158
|
+
update();
|
|
159
|
+
if (offset <= 0 || offset >= range)
|
|
160
|
+
return;
|
|
161
|
+
target.dataset['settling'] = '';
|
|
162
|
+
offset = offset / range < 0.5 ? 0 : range;
|
|
163
|
+
apply();
|
|
164
|
+
};
|
|
165
|
+
const onScroll = () => {
|
|
166
|
+
delete target.dataset['settling'];
|
|
167
|
+
if (!frame) {
|
|
168
|
+
frame = requestAnimationFrame(() => {
|
|
169
|
+
frame = 0;
|
|
170
|
+
update();
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (!supportsScrollEnd) {
|
|
174
|
+
clearTimeout(endTimer);
|
|
175
|
+
endTimer = setTimeout(settle, SCROLL_END_FALLBACK_MS);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
// Con el foco adentro, vuelve. Firefox desplaza el contenedor para mostrar el botón enfocado
|
|
179
|
+
// (que estaba fuera, bajo el borde) antes de este evento (comprobado el 2026-11-26; Chrome no):
|
|
180
|
+
// se deshace ese salto, porque la barra vuelve sola.
|
|
181
|
+
const onFocusIn = () => {
|
|
182
|
+
if (offset <= 0)
|
|
183
|
+
return;
|
|
184
|
+
target.dataset['settling'] = '';
|
|
185
|
+
offset = 0;
|
|
186
|
+
apply();
|
|
187
|
+
if (readTop() !== last)
|
|
188
|
+
source.scrollTop = last;
|
|
189
|
+
};
|
|
190
|
+
const resize = new ResizeObserver(() => {
|
|
191
|
+
measureRange();
|
|
192
|
+
offset = Math.min(offset, range);
|
|
193
|
+
apply();
|
|
194
|
+
});
|
|
195
|
+
last = readTop();
|
|
196
|
+
measureRange();
|
|
197
|
+
apply();
|
|
198
|
+
resize.observe(target);
|
|
199
|
+
events.addEventListener('scroll', onScroll, { passive: true });
|
|
200
|
+
if (supportsScrollEnd)
|
|
201
|
+
events.addEventListener('scrollend', settle);
|
|
202
|
+
target.addEventListener('focusin', onFocusIn);
|
|
203
|
+
cleanups.push(() => {
|
|
204
|
+
resize.disconnect();
|
|
205
|
+
cancelAnimationFrame(frame);
|
|
206
|
+
clearTimeout(endTimer);
|
|
207
|
+
events.removeEventListener('scroll', onScroll);
|
|
208
|
+
events.removeEventListener('scrollend', settle);
|
|
209
|
+
target.removeEventListener('focusin', onFocusIn);
|
|
210
|
+
delete target.dataset['settling'];
|
|
211
|
+
delete target.dataset['hidden'];
|
|
212
|
+
for (const name of ['--_offset', '--_progress'])
|
|
213
|
+
target.style.removeProperty(name);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return () => {
|
|
217
|
+
for (const fn of cleanups)
|
|
218
|
+
fn();
|
|
219
|
+
};
|
|
220
|
+
}, [hide, collapsing, measure]);
|
|
221
|
+
return _jsx("span", { ref: ref, hidden: true });
|
|
222
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type CSSProperties, type HTMLAttributes, type ReactElement, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import { type OpenStateProps } from './tooltip-behavior.ts';
|
|
3
|
+
export interface RichTooltipProps extends OpenStateProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Material 3 rich tooltip: a subhead, text and optional actions. It renders no element: it groups
|
|
8
|
+
* the trigger (`RichTooltipTrigger`) and the content (`RichTooltipContent`).
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <RichTooltip>
|
|
12
|
+
* <RichTooltipTrigger><IconButton label="Help"><HelpIcon /></IconButton></RichTooltipTrigger>
|
|
13
|
+
* <RichTooltipContent>
|
|
14
|
+
* <RichTooltipSubhead>Automatic backups</RichTooltipSubhead>
|
|
15
|
+
* <RichTooltipSupporting>They are saved every night to your account.</RichTooltipSupporting>
|
|
16
|
+
* <RichTooltipActions><Button variant="text" size="sm">Configure</Button></RichTooltipActions>
|
|
17
|
+
* </RichTooltipContent>
|
|
18
|
+
* </RichTooltip>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* - **Without actions** it is a tooltip: it describes the trigger (`aria-describedby`) and shows
|
|
22
|
+
* and hides like the plain one (`Tooltip`).
|
|
23
|
+
* - **With actions** it is a non-modal dialog (`role="dialog"`, named by the subhead): a click on
|
|
24
|
+
* the trigger opens and closes it (`aria-expanded`); Tab from the trigger enters the actions;
|
|
25
|
+
* Escape closes it and returns focus to the trigger; a click outside or moving focus elsewhere
|
|
26
|
+
* closes it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function RichTooltip({ open, defaultOpen, onOpenChange, children }: RichTooltipProps): import("react").JSX.Element;
|
|
29
|
+
interface TriggerChildProps {
|
|
30
|
+
id?: string | undefined;
|
|
31
|
+
style?: CSSProperties | undefined;
|
|
32
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
33
|
+
'aria-describedby'?: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface RichTooltipTriggerProps {
|
|
36
|
+
/**
|
|
37
|
+
* The trigger: a single element that passes `id`, `style`, `ref` and the `aria-*` props to its
|
|
38
|
+
* interactive element (IconButton, Button, the chips, `Interactive`). With actions, it must be a
|
|
39
|
+
* button: it opens with its click.
|
|
40
|
+
*/
|
|
41
|
+
children: ReactElement<TriggerChildProps>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Turns the child into the rich tooltip's trigger, without adding elements: it adds an `id` (if it
|
|
45
|
+
* has none), the `ref`, the `anchor-name` the tooltip is placed next to and, without actions,
|
|
46
|
+
* `aria-describedby`; with actions, `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`.
|
|
47
|
+
* An own `onClick` that calls `preventDefault()` keeps it from opening or closing.
|
|
48
|
+
*/
|
|
49
|
+
export declare function RichTooltipTrigger({ children }: RichTooltipTriggerProps): ReactElement<TriggerChildProps, string | import("react").JSXElementConstructor<any>>;
|
|
50
|
+
export interface RichTooltipContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
51
|
+
/** Ref to the container (the popover). */
|
|
52
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The rich tooltip: a popover (`popover="manual"`, in the top layer) above the trigger and
|
|
56
|
+
* centered, or below if it doesn't fit above, within the window. Up to 312 px wide (kit). It is
|
|
57
|
+
* always mounted and hidden while closed (so the description exists even when not visible). Native
|
|
58
|
+
* props, `className`, `style` and `ref` go to the container.
|
|
59
|
+
*/
|
|
60
|
+
export declare function RichTooltipContent({ className, style, children, ref, ...props }: RichTooltipContentProps): import("react").JSX.Element;
|
|
61
|
+
export interface RichTooltipPartProps extends HTMLAttributes<HTMLDivElement> {
|
|
62
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Subhead (Title Small). With actions, it is the dialog's name. */
|
|
65
|
+
export declare function RichTooltipSubhead({ className, ...props }: RichTooltipPartProps): import("react").JSX.Element;
|
|
66
|
+
/** Supporting text (Body Medium). With actions, it is the dialog's description. */
|
|
67
|
+
export declare function RichTooltipSupporting({ className, ...props }: RichTooltipPartProps): import("react").JSX.Element;
|
|
68
|
+
/**
|
|
69
|
+
* Actions row: text buttons (in the kit, `Button variant="text" size="sm"`). Its presence turns
|
|
70
|
+
* the rich tooltip into a non-modal dialog that opens with a click.
|
|
71
|
+
*/
|
|
72
|
+
export declare function RichTooltipActions({ className, ...props }: RichTooltipPartProps): import("react").JSX.Element;
|
|
73
|
+
export {};
|