@matekit/react 0.0.0-stage → 0.1.0
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 +71 -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 +106 -0
- package/dist/organisms/PaneScaffold/PaneScaffold.js +120 -0
- package/dist/organisms/Search/Search.d.ts +207 -0
- package/dist/organisms/Search/Search.js +754 -0
- package/dist/organisms/Search/SearchSlots.d.ts +16 -0
- package/dist/organisms/Search/SearchSlots.js +17 -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 +11991 -0
- package/dist/styles.css +12089 -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,307 @@
|
|
|
1
|
+
// Comportamiento compartido por Tooltip y RichTooltip (ADR-0021): estado abierto (controlado o
|
|
2
|
+
// no), el popover con su salida animada, los disparadores del tooltip pasajero (puntero con
|
|
3
|
+
// demora, foco de teclado, Escape, presionar, pulsación larga en táctil) y el coordinador que deja
|
|
4
|
+
// un solo tooltip pasajero visible a la vez. Módulo de hooks sin componentes: solo lo importan
|
|
5
|
+
// Tooltip.tsx y RichTooltip.tsx, que son cliente.
|
|
6
|
+
//
|
|
7
|
+
// Tiempos (ver tooltip.css y docs/research/07-jetpack-compose.md § Tooltip):
|
|
8
|
+
// - SHOW_DELAY_MS y HIDE_DELAY_MS: material-components-web, packages/mdc-tooltip/constants.ts
|
|
9
|
+
// (numbers.SHOW_DELAY_MS = 500 y HIDE_DELAY_MS = 600, commit 817002c296). Compose muestra y oculta
|
|
10
|
+
// con el mouse sin demora (internal/BasicTooltip.kt, PointerEventType.Enter/Exit, commit
|
|
11
|
+
// 5a2d24b9bd); en web, sin demora cada pasada del puntero por una barra de iconos abre un
|
|
12
|
+
// tooltip, y la demora de salida es la que deja cruzar la separación de 4 px hasta el tooltip
|
|
13
|
+
// (WCAG 1.4.13).
|
|
14
|
+
// - LONG_PRESS_MS: la demora de MDC en touchstart (500); Compose usa la pulsación larga del sistema.
|
|
15
|
+
// - TOUCH_DURATION_MS: BasicTooltipDefaults.TooltipDuration (1500, internal/BasicTooltip.kt).
|
|
16
|
+
// - Foco de teclado: aparece enseguida (Compose, onFocusChanged) y queda mientras dure el foco
|
|
17
|
+
// (Compose lo cierra a los 1500 ms; WCAG 1.4.13 pide que persista).
|
|
18
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
|
|
19
|
+
import { followAnchor, placeNextTo } from '../../internal/anchor-position.js';
|
|
20
|
+
import { settleAnimations } from '../../internal/settle-animations.js';
|
|
21
|
+
export const SHOW_DELAY_MS = 500;
|
|
22
|
+
export const HIDE_DELAY_MS = 600;
|
|
23
|
+
export const LONG_PRESS_MS = 500;
|
|
24
|
+
export const TOUCH_DURATION_MS = 1500;
|
|
25
|
+
// Separación con el ancla: GapTrigger de PlainTooltipTokens.kt (Space50 = 4). Igual en tooltip.css.
|
|
26
|
+
const GAP = 4;
|
|
27
|
+
// Arriba y centrado, y abajo si arriba no entra (TooltipAnchorPosition.Above de Compose).
|
|
28
|
+
export const TOOLTIP_PLACEMENT = { side: 'top', align: 'center', gap: GAP };
|
|
29
|
+
let transient = null;
|
|
30
|
+
let persistent = null;
|
|
31
|
+
// Hay un tooltip pasajero visible (o esperando su demora de salida): el siguiente aparece ya.
|
|
32
|
+
export const isWarm = () => transient !== null;
|
|
33
|
+
// Un tooltip pasajero se muestra: cierra el pasajero anterior. No cierra un rich con acciones
|
|
34
|
+
// abierto: ese lo cerró la persona con un clic y se cierra solo con Escape, otro clic o el foco.
|
|
35
|
+
function claimTransient(owner) {
|
|
36
|
+
if (transient && transient !== owner)
|
|
37
|
+
transient.close();
|
|
38
|
+
transient = owner;
|
|
39
|
+
}
|
|
40
|
+
// Un rich con acciones se abre: cierra cualquier otro tooltip, pasajero o con acciones.
|
|
41
|
+
function claimPersistent(owner) {
|
|
42
|
+
if (transient && transient !== owner)
|
|
43
|
+
transient.close();
|
|
44
|
+
if (persistent && persistent !== owner)
|
|
45
|
+
persistent.close();
|
|
46
|
+
transient = null;
|
|
47
|
+
persistent = owner;
|
|
48
|
+
}
|
|
49
|
+
function release(owner) {
|
|
50
|
+
if (transient === owner)
|
|
51
|
+
transient = null;
|
|
52
|
+
if (persistent === owner)
|
|
53
|
+
persistent = null;
|
|
54
|
+
}
|
|
55
|
+
// Registra el tooltip en el coordinador mientras está abierto: al abrirse cierra el anterior
|
|
56
|
+
// (pasajero, o cualquiera si `persistent`), y al cerrarse libera el lugar.
|
|
57
|
+
export function useCoordinator(open, persistentMode, setOpen) {
|
|
58
|
+
const owner = useRef({ close: () => setOpen(false, 'replaced') });
|
|
59
|
+
owner.current.close = () => setOpen(false, 'replaced');
|
|
60
|
+
useLayoutEffect(() => {
|
|
61
|
+
if (!open)
|
|
62
|
+
return;
|
|
63
|
+
const o = owner.current;
|
|
64
|
+
if (persistentMode)
|
|
65
|
+
claimPersistent(o);
|
|
66
|
+
else
|
|
67
|
+
claimTransient(o);
|
|
68
|
+
return () => release(o);
|
|
69
|
+
}, [open, persistentMode]);
|
|
70
|
+
}
|
|
71
|
+
// --- Popover: mostrar, ubicar y ocultar después de la salida ---
|
|
72
|
+
// Muestra el popover (capa superior) al abrir y lo ubica junto al disparador; al cerrar pone
|
|
73
|
+
// `data-closing` (la salida en tooltip.css) y lo oculta cuando terminan las transiciones. Mismo
|
|
74
|
+
// patrón que Menu y Dialog. Sin anchor positioning, lo sigue al desplazarse la página.
|
|
75
|
+
export function usePopover(open, contentRef, triggerRef) {
|
|
76
|
+
const closing = useRef(null);
|
|
77
|
+
const place = useCallback(() => {
|
|
78
|
+
const content = contentRef.current;
|
|
79
|
+
const trigger = triggerRef.current;
|
|
80
|
+
if (content && trigger)
|
|
81
|
+
placeNextTo(content, trigger, TOOLTIP_PLACEMENT);
|
|
82
|
+
}, [contentRef, triggerRef]);
|
|
83
|
+
useLayoutEffect(() => {
|
|
84
|
+
const el = contentRef.current;
|
|
85
|
+
if (!el)
|
|
86
|
+
return;
|
|
87
|
+
if (open) {
|
|
88
|
+
closing.current = null;
|
|
89
|
+
el.removeAttribute('data-closing');
|
|
90
|
+
el.inert = false;
|
|
91
|
+
if (!el.matches(':popover-open')) {
|
|
92
|
+
el.showPopover();
|
|
93
|
+
place();
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!el.matches(':popover-open') || closing.current)
|
|
98
|
+
return;
|
|
99
|
+
const token = {};
|
|
100
|
+
closing.current = token;
|
|
101
|
+
el.setAttribute('data-closing', '');
|
|
102
|
+
// Espera la salida (src/internal/settle-animations.ts). Si se volvió a abrir, `closing` ya no es
|
|
103
|
+
// esta ficha: la espera termina y no se oculta.
|
|
104
|
+
void settleAnimations(el, () => closing.current === token).then(() => {
|
|
105
|
+
if (closing.current !== token)
|
|
106
|
+
return;
|
|
107
|
+
closing.current = null;
|
|
108
|
+
el.removeAttribute('data-closing');
|
|
109
|
+
if (el.matches(':popover-open'))
|
|
110
|
+
el.hidePopover();
|
|
111
|
+
});
|
|
112
|
+
}, [open, contentRef, place]);
|
|
113
|
+
useLayoutEffect(() => () => {
|
|
114
|
+
closing.current = null;
|
|
115
|
+
}, []);
|
|
116
|
+
// Siempre, no solo sin anchor positioning: si el centrado del navegador falló (placeNextTo) la
|
|
117
|
+
// posición es calculada y hay que seguir al disparador. Un tooltip abierto dura poco.
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!open)
|
|
120
|
+
return;
|
|
121
|
+
return followAnchor(place, false);
|
|
122
|
+
}, [open, place]);
|
|
123
|
+
}
|
|
124
|
+
// --- Disparadores del tooltip pasajero (plain, y rich sin acciones) ---
|
|
125
|
+
const isTouch = (e) => e.pointerType === 'touch';
|
|
126
|
+
// Escucha el disparador y el tooltip, con eventos nativos (así funciona con cualquier elemento que
|
|
127
|
+
// pase la `ref`, sin pedirle que reparta manejadores):
|
|
128
|
+
// - Puntero (mouse o lápiz) sobre el disparador: aparece tras SHOW_DELAY_MS, o enseguida si ya hay
|
|
129
|
+
// otro tooltip visible. Al salir del disparador o del tooltip, se oculta tras HIDE_DELAY_MS si el
|
|
130
|
+
// puntero no volvió a ninguno de los dos (se puede pasar el puntero sobre el tooltip).
|
|
131
|
+
// - Foco de teclado (`:focus-visible`): aparece enseguida y queda mientras dure el foco.
|
|
132
|
+
// - Presionar el disparador lo oculta y no vuelve hasta que el puntero salga y entre de nuevo.
|
|
133
|
+
// - Escape lo oculta sin mover el foco ni el puntero; no vuelve hasta salir y entrar o reenfocar.
|
|
134
|
+
// - Táctil: pulsación larga de LONG_PRESS_MS (sin el menú contextual ni el clic al soltar);
|
|
135
|
+
// se oculta TOUCH_DURATION_MS después de levantar el dedo. Un toque común no lo muestra.
|
|
136
|
+
export function useTransientTriggers(enabled, triggerRef, contentRef, setOpen, isOpenNow) {
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
const trigger = triggerRef.current;
|
|
139
|
+
const content = contentRef.current;
|
|
140
|
+
if (!enabled || !trigger || !content)
|
|
141
|
+
return;
|
|
142
|
+
let showTimer;
|
|
143
|
+
let hideTimer;
|
|
144
|
+
let pressTimer;
|
|
145
|
+
let hovered = false;
|
|
146
|
+
let focused = false;
|
|
147
|
+
// Tras presionar o Escape: no vuelve a aparecer por el puntero hasta que salga y entre.
|
|
148
|
+
let suppressed = false;
|
|
149
|
+
let longPressed = false;
|
|
150
|
+
let eatClick;
|
|
151
|
+
const clearTimers = () => {
|
|
152
|
+
clearTimeout(showTimer);
|
|
153
|
+
clearTimeout(hideTimer);
|
|
154
|
+
};
|
|
155
|
+
const show = (reason) => {
|
|
156
|
+
clearTimers();
|
|
157
|
+
setOpen(true, reason);
|
|
158
|
+
};
|
|
159
|
+
const hide = (reason) => {
|
|
160
|
+
clearTimers();
|
|
161
|
+
setOpen(false, reason);
|
|
162
|
+
};
|
|
163
|
+
const scheduleHide = () => {
|
|
164
|
+
clearTimers();
|
|
165
|
+
if (!isOpenNow())
|
|
166
|
+
return;
|
|
167
|
+
hideTimer = setTimeout(() => {
|
|
168
|
+
if (!hovered && !focused)
|
|
169
|
+
setOpen(false, 'hover');
|
|
170
|
+
}, HIDE_DELAY_MS);
|
|
171
|
+
};
|
|
172
|
+
const stopEatingClick = () => {
|
|
173
|
+
if (eatClick)
|
|
174
|
+
trigger.removeEventListener('click', eatClick, true);
|
|
175
|
+
eatClick = undefined;
|
|
176
|
+
};
|
|
177
|
+
const onTriggerEnter = (e) => {
|
|
178
|
+
if (isTouch(e))
|
|
179
|
+
return;
|
|
180
|
+
hovered = true;
|
|
181
|
+
if (suppressed)
|
|
182
|
+
return;
|
|
183
|
+
clearTimeout(hideTimer);
|
|
184
|
+
if (isOpenNow())
|
|
185
|
+
return;
|
|
186
|
+
clearTimeout(showTimer);
|
|
187
|
+
if (isWarm())
|
|
188
|
+
show('hover');
|
|
189
|
+
else
|
|
190
|
+
showTimer = setTimeout(() => show('hover'), SHOW_DELAY_MS);
|
|
191
|
+
};
|
|
192
|
+
const onLeave = (e) => {
|
|
193
|
+
if (isTouch(e))
|
|
194
|
+
return;
|
|
195
|
+
hovered = false;
|
|
196
|
+
if (e.currentTarget === trigger)
|
|
197
|
+
suppressed = false;
|
|
198
|
+
if (!focused)
|
|
199
|
+
scheduleHide();
|
|
200
|
+
else
|
|
201
|
+
clearTimeout(showTimer);
|
|
202
|
+
};
|
|
203
|
+
const onContentEnter = (e) => {
|
|
204
|
+
if (isTouch(e))
|
|
205
|
+
return;
|
|
206
|
+
hovered = true;
|
|
207
|
+
clearTimeout(hideTimer);
|
|
208
|
+
};
|
|
209
|
+
const onFocusIn = (e) => {
|
|
210
|
+
const target = e.target;
|
|
211
|
+
if (!target.matches(':focus-visible'))
|
|
212
|
+
return;
|
|
213
|
+
focused = true;
|
|
214
|
+
suppressed = false;
|
|
215
|
+
show('focus');
|
|
216
|
+
};
|
|
217
|
+
const onFocusOut = (e) => {
|
|
218
|
+
if (content.contains(e.relatedTarget))
|
|
219
|
+
return;
|
|
220
|
+
focused = false;
|
|
221
|
+
suppressed = false;
|
|
222
|
+
if (!hovered)
|
|
223
|
+
hide('focus-out');
|
|
224
|
+
};
|
|
225
|
+
const onPointerDown = (e) => {
|
|
226
|
+
stopEatingClick();
|
|
227
|
+
hide('press');
|
|
228
|
+
suppressed = true;
|
|
229
|
+
if (!isTouch(e))
|
|
230
|
+
return;
|
|
231
|
+
longPressed = false;
|
|
232
|
+
clearTimeout(pressTimer);
|
|
233
|
+
pressTimer = setTimeout(() => {
|
|
234
|
+
longPressed = true;
|
|
235
|
+
setOpen(true, 'long-press');
|
|
236
|
+
}, LONG_PRESS_MS);
|
|
237
|
+
};
|
|
238
|
+
const onPointerEnd = (e) => {
|
|
239
|
+
if (!isTouch(e))
|
|
240
|
+
return;
|
|
241
|
+
clearTimeout(pressTimer);
|
|
242
|
+
if (!longPressed)
|
|
243
|
+
return;
|
|
244
|
+
longPressed = false;
|
|
245
|
+
suppressed = false;
|
|
246
|
+
hideTimer = setTimeout(() => setOpen(false, 'timeout'), TOUCH_DURATION_MS);
|
|
247
|
+
// Como Compose (consume el "up" de la pulsación larga): soltar no activa el disparador.
|
|
248
|
+
if (e.type === 'pointerup') {
|
|
249
|
+
eatClick = (click) => {
|
|
250
|
+
click.preventDefault();
|
|
251
|
+
click.stopPropagation();
|
|
252
|
+
stopEatingClick();
|
|
253
|
+
};
|
|
254
|
+
trigger.addEventListener('click', eatClick, true);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const onContextMenu = (e) => {
|
|
258
|
+
// La pulsación larga abre el menú contextual del navegador: con el tooltip, no.
|
|
259
|
+
if (longPressed || isOpenNow())
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
};
|
|
262
|
+
const onKeyDown = (e) => {
|
|
263
|
+
if (e.key !== 'Escape' || !isOpenNow())
|
|
264
|
+
return;
|
|
265
|
+
// Solo el tooltip: un Dialog o un Menu que lo contengan no se cierran con este Escape.
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
e.stopPropagation();
|
|
268
|
+
suppressed = true;
|
|
269
|
+
hide('escape');
|
|
270
|
+
};
|
|
271
|
+
trigger.addEventListener('pointerenter', onTriggerEnter);
|
|
272
|
+
trigger.addEventListener('pointerleave', onLeave);
|
|
273
|
+
trigger.addEventListener('focusin', onFocusIn);
|
|
274
|
+
trigger.addEventListener('focusout', onFocusOut);
|
|
275
|
+
trigger.addEventListener('pointerdown', onPointerDown);
|
|
276
|
+
trigger.addEventListener('pointerup', onPointerEnd);
|
|
277
|
+
trigger.addEventListener('pointercancel', onPointerEnd);
|
|
278
|
+
trigger.addEventListener('contextmenu', onContextMenu);
|
|
279
|
+
content.addEventListener('pointerenter', onContentEnter);
|
|
280
|
+
content.addEventListener('pointerleave', onLeave);
|
|
281
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
282
|
+
return () => {
|
|
283
|
+
clearTimers();
|
|
284
|
+
clearTimeout(pressTimer);
|
|
285
|
+
stopEatingClick();
|
|
286
|
+
trigger.removeEventListener('pointerenter', onTriggerEnter);
|
|
287
|
+
trigger.removeEventListener('pointerleave', onLeave);
|
|
288
|
+
trigger.removeEventListener('focusin', onFocusIn);
|
|
289
|
+
trigger.removeEventListener('focusout', onFocusOut);
|
|
290
|
+
trigger.removeEventListener('pointerdown', onPointerDown);
|
|
291
|
+
trigger.removeEventListener('pointerup', onPointerEnd);
|
|
292
|
+
trigger.removeEventListener('pointercancel', onPointerEnd);
|
|
293
|
+
trigger.removeEventListener('contextmenu', onContextMenu);
|
|
294
|
+
content.removeEventListener('pointerenter', onContentEnter);
|
|
295
|
+
content.removeEventListener('pointerleave', onLeave);
|
|
296
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
297
|
+
};
|
|
298
|
+
}, [enabled, triggerRef, contentRef, setOpen, isOpenNow]);
|
|
299
|
+
}
|
|
300
|
+
// --- Utilidades de las partes ---
|
|
301
|
+
// Une listas separadas por espacios o comas (ids de `aria-describedby`, nombres de ancla).
|
|
302
|
+
export function joinList(sep, ...items) {
|
|
303
|
+
const parts = items.filter((x) => typeof x === 'string' && x.trim() !== '');
|
|
304
|
+
return parts.length ? parts.join(sep) : undefined;
|
|
305
|
+
}
|
|
306
|
+
// `anchor-name` tiene que ser un <dashed-ident>: sin los caracteres que pone useId.
|
|
307
|
+
export const anchorNameFor = (id) => `--mk-tooltip-${id.replace(/[^a-zA-Z0-9_-]/g, '')}`;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode, Ref } from 'react';
|
|
2
|
+
import { type LayoutRenderedProps } from '../../internal/layout-element.tsx';
|
|
3
|
+
/** Kit size: small (64), medium (112, or 136 with a subtitle) and large (120, or 152). */
|
|
4
|
+
export type TopAppBarSize = 'sm' | 'md' | 'lg';
|
|
5
|
+
/**
|
|
6
|
+
* What the bar does when the content scrolls (Compose's three, `TopAppBarDefaults`):
|
|
7
|
+
* - `pinned`: it stays fixed at the top and turns `surface-container` when there is content
|
|
8
|
+
* under it.
|
|
9
|
+
* - `enter-always`: it leaves when scrolling down and comes back as soon as you scroll up. The
|
|
10
|
+
* small one hides entirely; the medium and large ones collapse to the small height (as in
|
|
11
|
+
* Compose). Needs JavaScript (the direction).
|
|
12
|
+
* - `exit-until-collapsed`: the medium and large ones collapse to the small height when scrolling
|
|
13
|
+
* down and expand only when back at the top; the small one scrolls away with the content.
|
|
14
|
+
* - `none`: neither fixed nor changing color (for example, outside a scrolling container).
|
|
15
|
+
*/
|
|
16
|
+
export type TopAppBarScrollBehavior = 'pinned' | 'enter-always' | 'exit-until-collapsed' | 'none';
|
|
17
|
+
export interface TopAppBarProps extends HTMLAttributes<HTMLElement> {
|
|
18
|
+
/** Size. Defaults to `sm`. */
|
|
19
|
+
size?: TopAppBarSize | undefined;
|
|
20
|
+
/** Centers the title and the subtitle (in the medium and large ones, the expanded ones too). */
|
|
21
|
+
centered?: boolean | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Behavior on scroll. Defaults to `pinned` for the small one and `exit-until-collapsed` for the
|
|
24
|
+
* medium and large ones (what Material shows for each).
|
|
25
|
+
*/
|
|
26
|
+
scrollBehavior?: TopAppBarScrollBehavior | undefined;
|
|
27
|
+
/** Ref to the `<header>` (or to the `render` element). */
|
|
28
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The element rendered instead of the `<header>`, for example `render={<div />}`. It is cloned
|
|
31
|
+
* with the bar's class, attributes and children; its own props win.
|
|
32
|
+
*/
|
|
33
|
+
render?: ReactElement<LayoutRenderedProps> | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Material 3 Expressive top app bar: title, optional subtitle, navigation icon and actions.
|
|
37
|
+
*
|
|
38
|
+
* It goes as the **first child of the scrolling element**: the window (in the `<body>` or a
|
|
39
|
+
* `<main>` that doesn't scroll) or an element with `overflow: auto`, such as a pane. No wiring
|
|
40
|
+
* needed: it uses the nearest scrolling container (the same as CSS `scroll(nearest)`). There can't
|
|
41
|
+
* be another element with `overflow` other than `visible` between the bar and that container
|
|
42
|
+
* (`position: sticky` and the timeline would attach to that one).
|
|
43
|
+
*
|
|
44
|
+
* It is a `<header>`: in the `<body>` it is the page's `banner` region; inside `<main>`,
|
|
45
|
+
* `<article>` or another section, it is just the header of that part (no region role).
|
|
46
|
+
*
|
|
47
|
+
* ```tsx
|
|
48
|
+
* <main style={{ height: '100dvh', overflow: 'auto' }}>
|
|
49
|
+
* <TopAppBar size="md">
|
|
50
|
+
* <TopAppBarLeading><IconButton label="Back" href="/"><ArrowBackIcon /></IconButton></TopAppBarLeading>
|
|
51
|
+
* <TopAppBarTitle>Inbox</TopAppBarTitle>
|
|
52
|
+
* <TopAppBarSubtitle>3 unread</TopAppBarSubtitle>
|
|
53
|
+
* <TopAppBarActions>
|
|
54
|
+
* <IconButton label="Search"><SearchIcon /></IconButton>
|
|
55
|
+
* <MenuTrigger>…</MenuTrigger>
|
|
56
|
+
* </TopAppBarActions>
|
|
57
|
+
* </TopAppBar>
|
|
58
|
+
* …content…
|
|
59
|
+
* </main>
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Customization with CSS variables: `--mk-top-app-bar-z-index` (defaults to 1, above the content
|
|
63
|
+
* scrolling under it).
|
|
64
|
+
*/
|
|
65
|
+
export declare function TopAppBar({ size, centered, scrollBehavior, className, style, children, ...rest }: TopAppBarProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
66
|
+
export interface TopAppBarPartProps extends HTMLAttributes<HTMLDivElement> {
|
|
67
|
+
/** Ref to the part's element. */
|
|
68
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The start of the bar: usually a navigation `IconButton` (back, menu) with `label`. It can also
|
|
72
|
+
* be an avatar or a logo.
|
|
73
|
+
*/
|
|
74
|
+
export declare function TopAppBarLeading({ className, ...props }: TopAppBarPartProps): import("react").JSX.Element;
|
|
75
|
+
/**
|
|
76
|
+
* The actions at the end: `IconButton`s with `label` (and `Tooltip` if the name needs to show). On
|
|
77
|
+
* small screens, up to three visible and the rest in a more-options `Menu`
|
|
78
|
+
* (`<MenuTrigger><IconButton label="More options"><MoreVertIcon /></IconButton></MenuTrigger>`).
|
|
79
|
+
*/
|
|
80
|
+
export declare function TopAppBarActions({ className, ...props }: TopAppBarPartProps): import("react").JSX.Element;
|
|
81
|
+
export interface TopAppBarTitleProps extends HTMLAttributes<HTMLHeadingElement> {
|
|
82
|
+
/** Heading level. Defaults to `1`: the bar usually carries the page title. */
|
|
83
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
|
84
|
+
/** The title: text, or an image with `alt` (the small bar's logo image). */
|
|
85
|
+
children?: ReactNode;
|
|
86
|
+
/** Ref to the heading. */
|
|
87
|
+
ref?: Ref<HTMLHeadingElement> | undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The title. In the small bar it stays on one line with an ellipsis (the heading keeps the full
|
|
91
|
+
* text for screen readers); in the medium and large ones it takes the lines it needs and the bar
|
|
92
|
+
* grows (Expressive's "flexible" bars).
|
|
93
|
+
*
|
|
94
|
+
* In the medium and large ones the text is repeated in a copy shown in the collapsed bar (like
|
|
95
|
+
* Compose, which crossfades two titles); the copy is hidden from accessibility (`aria-hidden` and
|
|
96
|
+
* `inert`), so the title is read once. That's why the children shouldn't carry an `id`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function TopAppBarTitle({ level, className, children, ...props }: TopAppBarTitleProps): import("react").JSX.Element;
|
|
99
|
+
export interface TopAppBarSubtitleProps extends HTMLAttributes<HTMLParagraphElement> {
|
|
100
|
+
/** Ref to the paragraph. */
|
|
101
|
+
ref?: Ref<HTMLParagraphElement> | undefined;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The subtitle, below the title (a `<p>`). Like the title, it has a copy, hidden from
|
|
105
|
+
* accessibility, in the collapsed bar.
|
|
106
|
+
*/
|
|
107
|
+
export declare function TopAppBarSubtitle({ className, children, ...props }: TopAppBarSubtitleProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../../internal/interactive.js';
|
|
3
|
+
import { layoutElement } from '../../internal/layout-element.js';
|
|
4
|
+
import { TopAppBarScroll } from './TopAppBarScroll.js';
|
|
5
|
+
/**
|
|
6
|
+
* Material 3 Expressive top app bar: title, optional subtitle, navigation icon and actions.
|
|
7
|
+
*
|
|
8
|
+
* It goes as the **first child of the scrolling element**: the window (in the `<body>` or a
|
|
9
|
+
* `<main>` that doesn't scroll) or an element with `overflow: auto`, such as a pane. No wiring
|
|
10
|
+
* needed: it uses the nearest scrolling container (the same as CSS `scroll(nearest)`). There can't
|
|
11
|
+
* be another element with `overflow` other than `visible` between the bar and that container
|
|
12
|
+
* (`position: sticky` and the timeline would attach to that one).
|
|
13
|
+
*
|
|
14
|
+
* It is a `<header>`: in the `<body>` it is the page's `banner` region; inside `<main>`,
|
|
15
|
+
* `<article>` or another section, it is just the header of that part (no region role).
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <main style={{ height: '100dvh', overflow: 'auto' }}>
|
|
19
|
+
* <TopAppBar size="md">
|
|
20
|
+
* <TopAppBarLeading><IconButton label="Back" href="/"><ArrowBackIcon /></IconButton></TopAppBarLeading>
|
|
21
|
+
* <TopAppBarTitle>Inbox</TopAppBarTitle>
|
|
22
|
+
* <TopAppBarSubtitle>3 unread</TopAppBarSubtitle>
|
|
23
|
+
* <TopAppBarActions>
|
|
24
|
+
* <IconButton label="Search"><SearchIcon /></IconButton>
|
|
25
|
+
* <MenuTrigger>…</MenuTrigger>
|
|
26
|
+
* </TopAppBarActions>
|
|
27
|
+
* </TopAppBar>
|
|
28
|
+
* …content…
|
|
29
|
+
* </main>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Customization with CSS variables: `--mk-top-app-bar-z-index` (defaults to 1, above the content
|
|
33
|
+
* scrolling under it).
|
|
34
|
+
*/
|
|
35
|
+
export function TopAppBar({ size = 'sm', centered = false, scrollBehavior, className, style, children, ...rest }) {
|
|
36
|
+
const behavior = scrollBehavior ?? (size === 'sm' ? 'pinned' : 'exit-until-collapsed');
|
|
37
|
+
return layoutElement('TopAppBar', cx('mk-top-app-bar', className), style, {
|
|
38
|
+
...rest,
|
|
39
|
+
'data-size': size,
|
|
40
|
+
'data-centered': centered ? '' : undefined,
|
|
41
|
+
'data-scroll-behavior': behavior,
|
|
42
|
+
}, _jsxs(_Fragment, { children: [children, behavior !== 'none' && _jsx(TopAppBarScroll, { behavior: behavior, size: size })] }), 'header');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The start of the bar: usually a navigation `IconButton` (back, menu) with `label`. It can also
|
|
46
|
+
* be an avatar or a logo.
|
|
47
|
+
*/
|
|
48
|
+
export function TopAppBarLeading({ className, ...props }) {
|
|
49
|
+
return _jsx("div", { ...props, className: cx('mk-top-app-bar-leading', className) });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The actions at the end: `IconButton`s with `label` (and `Tooltip` if the name needs to show). On
|
|
53
|
+
* small screens, up to three visible and the rest in a more-options `Menu`
|
|
54
|
+
* (`<MenuTrigger><IconButton label="More options"><MoreVertIcon /></IconButton></MenuTrigger>`).
|
|
55
|
+
*/
|
|
56
|
+
export function TopAppBarActions({ className, ...props }) {
|
|
57
|
+
return _jsx("div", { ...props, className: cx('mk-top-app-bar-actions', className) });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The title. In the small bar it stays on one line with an ellipsis (the heading keeps the full
|
|
61
|
+
* text for screen readers); in the medium and large ones it takes the lines it needs and the bar
|
|
62
|
+
* grows (Expressive's "flexible" bars).
|
|
63
|
+
*
|
|
64
|
+
* In the medium and large ones the text is repeated in a copy shown in the collapsed bar (like
|
|
65
|
+
* Compose, which crossfades two titles); the copy is hidden from accessibility (`aria-hidden` and
|
|
66
|
+
* `inert`), so the title is read once. That's why the children shouldn't carry an `id`.
|
|
67
|
+
*/
|
|
68
|
+
export function TopAppBarTitle({ level = 1, className, children, ...props }) {
|
|
69
|
+
const Tag = `h${level}`;
|
|
70
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tag, { ...props, className: cx('mk-top-app-bar-title', className), children: children }), _jsx("span", { className: "mk-top-app-bar-collapsed-title", "aria-hidden": "true", inert: true, children: children })] }));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The subtitle, below the title (a `<p>`). Like the title, it has a copy, hidden from
|
|
74
|
+
* accessibility, in the collapsed bar.
|
|
75
|
+
*/
|
|
76
|
+
export function TopAppBarSubtitle({ className, children, ...props }) {
|
|
77
|
+
return (_jsxs(_Fragment, { children: [_jsx("p", { ...props, className: cx('mk-top-app-bar-subtitle', className), children: children }), _jsx("span", { className: "mk-top-app-bar-collapsed-subtitle", "aria-hidden": "true", inert: true, children: children })] }));
|
|
78
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TopAppBarScrollBehavior, TopAppBarSize } from './TopAppBar.tsx';
|
|
2
|
+
interface TopAppBarScrollProps {
|
|
3
|
+
behavior: Exclude<TopAppBarScrollBehavior, 'none'>;
|
|
4
|
+
size: TopAppBarSize;
|
|
5
|
+
}
|
|
6
|
+
export declare function TopAppBarScroll({ behavior, size }: TopAppBarScrollProps): import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Parte cliente de TopAppBar (ADR-0024): usa un efecto y eventos de desplazamiento. La barra es
|
|
4
|
+
// universal y dibuja esta parte como hija (un `<span hidden>`, sin caja ni semántica), así que el
|
|
5
|
+
// JavaScript queda aislado acá. Hace tres cosas, y ninguna es necesaria para que la barra se vea
|
|
6
|
+
// bien al cargar (arriba de todo, plana y expandida):
|
|
7
|
+
//
|
|
8
|
+
// 1. Mide el alto real de la barra (`--_height`). El CSS lo calcula con los tokens para un título
|
|
9
|
+
// de una línea; con varias (medium y large "flexible"), el colapso necesita el alto de verdad.
|
|
10
|
+
// 2. Respaldo donde no existen las animaciones por desplazamiento (`animation-timeline: scroll()`):
|
|
11
|
+
// marca la barra con `data-scroll-driver="script"` y escribe el avance en `--_progress` y
|
|
12
|
+
// `--_tint`, que el CSS convierte en la misma animación detenida en ese punto.
|
|
13
|
+
// 3. `enter-always` en todos los motores: depende de la dirección del desplazamiento, que CSS no
|
|
14
|
+
// expone. Lleva la cuenta del corrimiento (`--_offset`) como `enterAlwaysScrollBehavior` de
|
|
15
|
+
// Compose (AppBar.kt): baja con lo que se desplaza hacia abajo, sube con lo que se desplaza hacia
|
|
16
|
+
// arriba, y al terminar de desplazar se acomoda al estado más cercano.
|
|
17
|
+
import { useEffect, useRef } from 'react';
|
|
18
|
+
import { nearestScroller } from '../../internal/nearest-scroller.js';
|
|
19
|
+
// Sin `scrollend` (Safari, según conocimiento previo), el desplazamiento terminó tras esta pausa.
|
|
20
|
+
const SCROLL_END_FALLBACK_MS = 150;
|
|
21
|
+
const clamp01 = (n) => Math.min(1, Math.max(0, n));
|
|
22
|
+
// Un número de una variable CSS en px (`--_keep: 64px`), o el respaldo.
|
|
23
|
+
function cssPx(el, name, fallback) {
|
|
24
|
+
const value = Number.parseFloat(getComputedStyle(el).getPropertyValue(name));
|
|
25
|
+
return Number.isFinite(value) ? value : fallback;
|
|
26
|
+
}
|
|
27
|
+
export function TopAppBarScroll({ behavior, size }) {
|
|
28
|
+
const ref = useRef(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const bar = ref.current?.parentElement;
|
|
31
|
+
if (!bar)
|
|
32
|
+
return;
|
|
33
|
+
const scroller = nearestScroller(bar);
|
|
34
|
+
const doc = document.scrollingElement ?? document.documentElement;
|
|
35
|
+
const source = scroller ?? doc;
|
|
36
|
+
const target = scroller ?? window;
|
|
37
|
+
// 1. Alto real: lo que se colapsa es el alto menos lo que queda visible (--_keep).
|
|
38
|
+
let height = bar.getBoundingClientRect().height;
|
|
39
|
+
const resize = new ResizeObserver(([entry]) => {
|
|
40
|
+
const box = entry?.borderBoxSize[0];
|
|
41
|
+
height = box ? box.blockSize : bar.getBoundingClientRect().height;
|
|
42
|
+
bar.style.setProperty('--_height', `${height}px`);
|
|
43
|
+
update();
|
|
44
|
+
});
|
|
45
|
+
const script = behavior === 'enter-always' || !CSS.supports('animation-timeline: scroll()');
|
|
46
|
+
if (script)
|
|
47
|
+
bar.dataset['scrollDriver'] = 'script';
|
|
48
|
+
const keep = cssPx(bar, '--_keep', size === 'sm' ? 0 : 64);
|
|
49
|
+
const tintDistance = cssPx(bar, '--_tint-distance', 16);
|
|
50
|
+
let last = 0;
|
|
51
|
+
let offset = 0;
|
|
52
|
+
let progress = 0;
|
|
53
|
+
let frame = 0;
|
|
54
|
+
let endTimer;
|
|
55
|
+
const supportsScrollEnd = 'onscrollend' in window;
|
|
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
|
+
function update() {
|
|
62
|
+
if (!script)
|
|
63
|
+
return;
|
|
64
|
+
const top = readTop();
|
|
65
|
+
const delta = top - last;
|
|
66
|
+
last = top;
|
|
67
|
+
const range = Math.max(height - keep, 0);
|
|
68
|
+
const overlap = clamp01(top / tintDistance);
|
|
69
|
+
let tint = overlap;
|
|
70
|
+
if (behavior === 'enter-always') {
|
|
71
|
+
offset = Math.min(Math.max(offset + delta, 0), range);
|
|
72
|
+
progress = range > 0 ? offset / range : 0;
|
|
73
|
+
bar?.style.setProperty('--_offset', `${offset}px`);
|
|
74
|
+
// Compose: el small cambia de color cuando hay contenido debajo; el medium y el large,
|
|
75
|
+
// con lo que se colapsaron (TwoRowsTopAppBar usa collapsedFraction).
|
|
76
|
+
if (size !== 'sm')
|
|
77
|
+
tint = progress;
|
|
78
|
+
}
|
|
79
|
+
else if (behavior === 'exit-until-collapsed') {
|
|
80
|
+
progress = range > 0 ? clamp01(top / range) : 0;
|
|
81
|
+
if (size !== 'sm')
|
|
82
|
+
tint = progress;
|
|
83
|
+
}
|
|
84
|
+
bar?.style.setProperty('--_progress', String(progress));
|
|
85
|
+
bar?.style.setProperty('--_tint', String(tint));
|
|
86
|
+
}
|
|
87
|
+
// Acomodar enter-always al terminar: expandida o colapsada, la más cercana (settleAppBar de
|
|
88
|
+
// Compose), con la transición de data-settling (instantánea con movimiento reducido).
|
|
89
|
+
function settle() {
|
|
90
|
+
// scrollend puede llegar antes del cuadro que aplica el último desplazamiento: aplicarlo ya.
|
|
91
|
+
if (frame) {
|
|
92
|
+
cancelAnimationFrame(frame);
|
|
93
|
+
frame = 0;
|
|
94
|
+
}
|
|
95
|
+
update();
|
|
96
|
+
const range = Math.max(height - keep, 0);
|
|
97
|
+
if (offset <= 0 || offset >= range)
|
|
98
|
+
return;
|
|
99
|
+
if (bar)
|
|
100
|
+
bar.dataset['settling'] = '';
|
|
101
|
+
offset = progress < 0.5 ? 0 : range;
|
|
102
|
+
last = readTop();
|
|
103
|
+
// update() suma el delta (0): con offset ya acomodado, escribe las variables.
|
|
104
|
+
update();
|
|
105
|
+
}
|
|
106
|
+
function onScroll() {
|
|
107
|
+
if (bar)
|
|
108
|
+
delete bar.dataset['settling'];
|
|
109
|
+
if (!frame) {
|
|
110
|
+
frame = requestAnimationFrame(() => {
|
|
111
|
+
frame = 0;
|
|
112
|
+
update();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (behavior === 'enter-always' && !supportsScrollEnd) {
|
|
116
|
+
clearTimeout(endTimer);
|
|
117
|
+
endTimer = setTimeout(settle, SCROLL_END_FALLBACK_MS);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Con el foco adentro (Tab hacia una acción), la barra escondida vuelve.
|
|
121
|
+
function onFocusIn() {
|
|
122
|
+
if (offset <= 0)
|
|
123
|
+
return;
|
|
124
|
+
if (bar)
|
|
125
|
+
bar.dataset['settling'] = '';
|
|
126
|
+
offset = 0;
|
|
127
|
+
last = readTop();
|
|
128
|
+
update();
|
|
129
|
+
}
|
|
130
|
+
last = readTop();
|
|
131
|
+
resize.observe(bar);
|
|
132
|
+
if (script) {
|
|
133
|
+
target.addEventListener('scroll', onScroll, { passive: true });
|
|
134
|
+
if (behavior === 'enter-always') {
|
|
135
|
+
if (supportsScrollEnd)
|
|
136
|
+
target.addEventListener('scrollend', settle);
|
|
137
|
+
bar.addEventListener('focusin', onFocusIn);
|
|
138
|
+
}
|
|
139
|
+
update();
|
|
140
|
+
}
|
|
141
|
+
return () => {
|
|
142
|
+
resize.disconnect();
|
|
143
|
+
cancelAnimationFrame(frame);
|
|
144
|
+
clearTimeout(endTimer);
|
|
145
|
+
target.removeEventListener('scroll', onScroll);
|
|
146
|
+
target.removeEventListener('scrollend', settle);
|
|
147
|
+
bar.removeEventListener('focusin', onFocusIn);
|
|
148
|
+
delete bar.dataset['scrollDriver'];
|
|
149
|
+
delete bar.dataset['settling'];
|
|
150
|
+
for (const name of ['--_height', '--_offset', '--_progress', '--_tint'])
|
|
151
|
+
bar.style.removeProperty(name);
|
|
152
|
+
};
|
|
153
|
+
}, [behavior, size]);
|
|
154
|
+
return _jsx("span", { ref: ref, hidden: true });
|
|
155
|
+
}
|