@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,250 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (ADR-0003): RichTooltip guarda si está visible y lo comparte por contexto
|
|
4
|
+
// con el disparador y el contenido; las partes se registran para que el contenido sepa si tiene
|
|
5
|
+
// subtítulo (su nombre), texto (su descripción) y acciones (que lo vuelven un diálogo no modal).
|
|
6
|
+
// Estado, efectos, contexto y eventos: todas las partes son cliente, como en el Menu.
|
|
7
|
+
//
|
|
8
|
+
// Dos patrones según el contenido (ADR-0021):
|
|
9
|
+
// - Sin acciones: un tooltip (`role="tooltip"`, descripción del disparador), con el mismo
|
|
10
|
+
// comportamiento que el plain (puntero con demora, foco, Escape, uno a la vez).
|
|
11
|
+
// - Con acciones (`RichTooltipActions`): contenido interactivo, que APG no admite en un tooltip.
|
|
12
|
+
// Es un diálogo no modal (`role="dialog"`) que se abre y se cierra con un clic (o Enter y
|
|
13
|
+
// Espacio) en el disparador, como el tooltip persistente de Compose y de material-components-web.
|
|
14
|
+
import { cloneElement, createContext, isValidElement, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
15
|
+
import { cx } from '../../internal/interactive.js';
|
|
16
|
+
import { partOutsideParent, triggerNotElement } from '../../internal/diagnostics.js';
|
|
17
|
+
import { mergeRefs } from '../../internal/merge-refs.js';
|
|
18
|
+
import { useOpenState } from '../../internal/open-state.js';
|
|
19
|
+
import { anchorNameFor, joinList, useCoordinator, usePopover, useTransientTriggers, } from './tooltip-behavior.js';
|
|
20
|
+
const RichTooltipContext = createContext(null);
|
|
21
|
+
function useRichTooltip(part) {
|
|
22
|
+
const ctx = use(RichTooltipContext);
|
|
23
|
+
if (!ctx)
|
|
24
|
+
throw partOutsideParent(part, 'RichTooltip');
|
|
25
|
+
return ctx;
|
|
26
|
+
}
|
|
27
|
+
// Registra una parte mientras está montada.
|
|
28
|
+
function usePart(part, register) {
|
|
29
|
+
useLayoutEffect(() => register(part), [part, register]);
|
|
30
|
+
}
|
|
31
|
+
const TABBABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]';
|
|
32
|
+
// Elementos del contenido alcanzables con Tab, en orden.
|
|
33
|
+
function tabbables(root) {
|
|
34
|
+
return [...root.querySelectorAll(TABBABLE)].filter((el) => el.tabIndex >= 0 && el.checkVisibility());
|
|
35
|
+
}
|
|
36
|
+
// Con acciones: el disparador alterna el diálogo con un clic (Enter y Espacio en un botón también
|
|
37
|
+
// llegan como clic); un clic afuera lo cierra sin mover el foco; Escape lo cierra y, si el foco
|
|
38
|
+
// estaba adentro, lo devuelve al disparador; Tab desde el disparador entra a la primera acción,
|
|
39
|
+
// Mayús+Tab desde la primera vuelve al disparador y Tab desde la última sigue después del
|
|
40
|
+
// disparador (el diálogo se cierra). Si el foco se va a otro lado, se cierra.
|
|
41
|
+
function usePersistentTriggers(enabled, triggerRef, contentRef, setOpen, isOpenNow) {
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const trigger = triggerRef.current;
|
|
44
|
+
const content = contentRef.current;
|
|
45
|
+
if (!enabled || !trigger || !content)
|
|
46
|
+
return;
|
|
47
|
+
const onClick = (e) => {
|
|
48
|
+
if (e.defaultPrevented)
|
|
49
|
+
return;
|
|
50
|
+
setOpen(!isOpenNow(), 'trigger');
|
|
51
|
+
};
|
|
52
|
+
const onPointerDown = (e) => {
|
|
53
|
+
if (!isOpenNow())
|
|
54
|
+
return;
|
|
55
|
+
const target = e.target;
|
|
56
|
+
if (target && (trigger.contains(target) || content.contains(target)))
|
|
57
|
+
return;
|
|
58
|
+
setOpen(false, 'outside');
|
|
59
|
+
};
|
|
60
|
+
const onKeyDown = (e) => {
|
|
61
|
+
if (e.key !== 'Escape' || !isOpenNow())
|
|
62
|
+
return;
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
if (content.contains(document.activeElement))
|
|
66
|
+
trigger.focus();
|
|
67
|
+
setOpen(false, 'escape');
|
|
68
|
+
};
|
|
69
|
+
const onTriggerKeyDown = (e) => {
|
|
70
|
+
if (e.key !== 'Tab' || e.shiftKey || !isOpenNow())
|
|
71
|
+
return;
|
|
72
|
+
const first = tabbables(content)[0];
|
|
73
|
+
if (!first)
|
|
74
|
+
return;
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
first.focus();
|
|
77
|
+
};
|
|
78
|
+
const onContentKeyDown = (e) => {
|
|
79
|
+
if (e.key !== 'Tab')
|
|
80
|
+
return;
|
|
81
|
+
const list = tabbables(content);
|
|
82
|
+
if (e.shiftKey) {
|
|
83
|
+
if (document.activeElement !== list[0])
|
|
84
|
+
return;
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
trigger.focus();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (document.activeElement !== list.at(-1))
|
|
90
|
+
return;
|
|
91
|
+
// Como el Menu: el foco pasa al disparador y el Tab del navegador (sin preventDefault)
|
|
92
|
+
// sigue desde ahí. `inert` saca enseguida al contenido (que puede estar justo después del
|
|
93
|
+
// disparador en el documento) del recorrido, sin esperar la salida animada.
|
|
94
|
+
content.inert = true;
|
|
95
|
+
trigger.focus();
|
|
96
|
+
setOpen(false, 'tab');
|
|
97
|
+
};
|
|
98
|
+
const onFocusOut = (e) => {
|
|
99
|
+
const to = e.relatedTarget;
|
|
100
|
+
// Sin destino (clic en un lugar no enfocable): lo decide el clic afuera.
|
|
101
|
+
if (!to || trigger.contains(to) || content.contains(to))
|
|
102
|
+
return;
|
|
103
|
+
setOpen(false, 'focus-out');
|
|
104
|
+
};
|
|
105
|
+
trigger.addEventListener('click', onClick);
|
|
106
|
+
trigger.addEventListener('keydown', onTriggerKeyDown);
|
|
107
|
+
trigger.addEventListener('focusout', onFocusOut);
|
|
108
|
+
content.addEventListener('keydown', onContentKeyDown);
|
|
109
|
+
content.addEventListener('focusout', onFocusOut);
|
|
110
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
111
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
112
|
+
return () => {
|
|
113
|
+
trigger.removeEventListener('click', onClick);
|
|
114
|
+
trigger.removeEventListener('keydown', onTriggerKeyDown);
|
|
115
|
+
trigger.removeEventListener('focusout', onFocusOut);
|
|
116
|
+
content.removeEventListener('keydown', onContentKeyDown);
|
|
117
|
+
content.removeEventListener('focusout', onFocusOut);
|
|
118
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
119
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
120
|
+
};
|
|
121
|
+
}, [enabled, triggerRef, contentRef, setOpen, isOpenNow]);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Material 3 rich tooltip: a subhead, text and optional actions. It renders no element: it groups
|
|
125
|
+
* the trigger (`RichTooltipTrigger`) and the content (`RichTooltipContent`).
|
|
126
|
+
*
|
|
127
|
+
* ```tsx
|
|
128
|
+
* <RichTooltip>
|
|
129
|
+
* <RichTooltipTrigger><IconButton label="Help"><HelpIcon /></IconButton></RichTooltipTrigger>
|
|
130
|
+
* <RichTooltipContent>
|
|
131
|
+
* <RichTooltipSubhead>Automatic backups</RichTooltipSubhead>
|
|
132
|
+
* <RichTooltipSupporting>They are saved every night to your account.</RichTooltipSupporting>
|
|
133
|
+
* <RichTooltipActions><Button variant="text" size="sm">Configure</Button></RichTooltipActions>
|
|
134
|
+
* </RichTooltipContent>
|
|
135
|
+
* </RichTooltip>
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* - **Without actions** it is a tooltip: it describes the trigger (`aria-describedby`) and shows
|
|
139
|
+
* and hides like the plain one (`Tooltip`).
|
|
140
|
+
* - **With actions** it is a non-modal dialog (`role="dialog"`, named by the subhead): a click on
|
|
141
|
+
* the trigger opens and closes it (`aria-expanded`); Tab from the trigger enters the actions;
|
|
142
|
+
* Escape closes it and returns focus to the trigger; a click outside or moving focus elsewhere
|
|
143
|
+
* closes it.
|
|
144
|
+
*/
|
|
145
|
+
export function RichTooltip({ open, defaultOpen, onOpenChange, children }) {
|
|
146
|
+
const { isOpen, setOpen, isOpenNow } = useOpenState({ open, defaultOpen, onOpenChange });
|
|
147
|
+
const [parts, setParts] = useState({ subhead: 0, supporting: 0, actions: 0 });
|
|
148
|
+
const [triggerId, setTriggerId] = useState(undefined);
|
|
149
|
+
const triggerRef = useRef(null);
|
|
150
|
+
const contentRef = useRef(null);
|
|
151
|
+
const id = useId();
|
|
152
|
+
const persistent = parts.actions > 0;
|
|
153
|
+
const register = useCallback((part) => {
|
|
154
|
+
setParts((p) => ({ ...p, [part]: p[part] + 1 }));
|
|
155
|
+
return () => setParts((p) => ({ ...p, [part]: p[part] - 1 }));
|
|
156
|
+
}, []);
|
|
157
|
+
useCoordinator(isOpen, persistent, setOpen);
|
|
158
|
+
usePopover(isOpen, contentRef, triggerRef);
|
|
159
|
+
useTransientTriggers(!persistent, triggerRef, contentRef, setOpen, isOpenNow);
|
|
160
|
+
usePersistentTriggers(persistent, triggerRef, contentRef, setOpen, isOpenNow);
|
|
161
|
+
const ctx = useMemo(() => ({
|
|
162
|
+
open: isOpen,
|
|
163
|
+
persistent,
|
|
164
|
+
parts,
|
|
165
|
+
register,
|
|
166
|
+
triggerRef,
|
|
167
|
+
contentRef,
|
|
168
|
+
triggerId,
|
|
169
|
+
setTriggerId,
|
|
170
|
+
generatedTriggerId: `${id}trigger`,
|
|
171
|
+
contentId: `${id}tooltip`,
|
|
172
|
+
subheadId: `${id}subhead`,
|
|
173
|
+
supportingId: `${id}supporting`,
|
|
174
|
+
anchorName: anchorNameFor(id),
|
|
175
|
+
}), [id, isOpen, persistent, parts, register, triggerId]);
|
|
176
|
+
return _jsx(RichTooltipContext, { value: ctx, children: children });
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Turns the child into the rich tooltip's trigger, without adding elements: it adds an `id` (if it
|
|
180
|
+
* has none), the `ref`, the `anchor-name` the tooltip is placed next to and, without actions,
|
|
181
|
+
* `aria-describedby`; with actions, `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`.
|
|
182
|
+
* An own `onClick` that calls `preventDefault()` keeps it from opening or closing.
|
|
183
|
+
*/
|
|
184
|
+
export function RichTooltipTrigger({ children }) {
|
|
185
|
+
const ctx = useRichTooltip('RichTooltipTrigger');
|
|
186
|
+
// Sin Children.only: su error genérico de React taparía el de matekit (MK_TRIGGER_NOT_ELEMENT),
|
|
187
|
+
// que salta en los mismos casos (varios hijos, un texto, nada).
|
|
188
|
+
const child = children;
|
|
189
|
+
if (!isValidElement(child)) {
|
|
190
|
+
throw triggerNotElement('RichTooltipTrigger', child);
|
|
191
|
+
}
|
|
192
|
+
const { id: ownId, style, ref } = child.props;
|
|
193
|
+
const id = ownId ?? ctx.generatedTriggerId;
|
|
194
|
+
const { setTriggerId } = ctx;
|
|
195
|
+
useLayoutEffect(() => {
|
|
196
|
+
setTriggerId(id);
|
|
197
|
+
return () => setTriggerId(undefined);
|
|
198
|
+
}, [id, setTriggerId]);
|
|
199
|
+
const mergedRef = useMemo(() => mergeRefs(ref, ctx.triggerRef), [ref, ctx.triggerRef]);
|
|
200
|
+
return cloneElement(child, {
|
|
201
|
+
id,
|
|
202
|
+
ref: mergedRef,
|
|
203
|
+
style: { ...style, anchorName: joinList(', ', style?.anchorName, ctx.anchorName) },
|
|
204
|
+
...(ctx.persistent
|
|
205
|
+
? { 'aria-haspopup': 'dialog', 'aria-expanded': ctx.open, 'aria-controls': ctx.contentId }
|
|
206
|
+
: { 'aria-describedby': joinList(' ', child.props['aria-describedby'], ctx.contentId) }),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The rich tooltip: a popover (`popover="manual"`, in the top layer) above the trigger and
|
|
211
|
+
* centered, or below if it doesn't fit above, within the window. Up to 312 px wide (kit). It is
|
|
212
|
+
* always mounted and hidden while closed (so the description exists even when not visible). Native
|
|
213
|
+
* props, `className`, `style` and `ref` go to the container.
|
|
214
|
+
*/
|
|
215
|
+
export function RichTooltipContent({ className, style, children, ref, ...props }) {
|
|
216
|
+
const ctx = useRichTooltip('RichTooltipContent');
|
|
217
|
+
const mergedRef = useMemo(() => mergeRefs(ref, ctx.contentRef), [ref, ctx.contentRef]);
|
|
218
|
+
const roleProps = ctx.persistent
|
|
219
|
+
? {
|
|
220
|
+
role: 'dialog',
|
|
221
|
+
// Enfocable por script y por clic (no con Tab): un clic en el texto deja el foco adentro y
|
|
222
|
+
// no en el body, así llevar el foco afuera después lo cierra.
|
|
223
|
+
tabIndex: -1,
|
|
224
|
+
'aria-labelledby': ctx.parts.subhead > 0 ? ctx.subheadId : ctx.triggerId,
|
|
225
|
+
'aria-describedby': ctx.parts.supporting > 0 ? ctx.supportingId : undefined,
|
|
226
|
+
}
|
|
227
|
+
: { role: 'tooltip' };
|
|
228
|
+
return (_jsx("div", { ...roleProps, ...props, ref: mergedRef, id: ctx.contentId, popover: "manual", className: cx('mk-tooltip mk-rich-tooltip', className), "data-actions": ctx.persistent ? '' : undefined, style: { ...style, '--_anchor': ctx.anchorName }, children: children }));
|
|
229
|
+
}
|
|
230
|
+
/** Subhead (Title Small). With actions, it is the dialog's name. */
|
|
231
|
+
export function RichTooltipSubhead({ className, ...props }) {
|
|
232
|
+
const ctx = useRichTooltip('RichTooltipSubhead');
|
|
233
|
+
usePart('subhead', ctx.register);
|
|
234
|
+
return _jsx("div", { id: ctx.subheadId, ...props, className: cx('mk-rich-tooltip-subhead', className) });
|
|
235
|
+
}
|
|
236
|
+
/** Supporting text (Body Medium). With actions, it is the dialog's description. */
|
|
237
|
+
export function RichTooltipSupporting({ className, ...props }) {
|
|
238
|
+
const ctx = useRichTooltip('RichTooltipSupporting');
|
|
239
|
+
usePart('supporting', ctx.register);
|
|
240
|
+
return _jsx("div", { id: ctx.supportingId, ...props, className: cx('mk-rich-tooltip-supporting', className) });
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Actions row: text buttons (in the kit, `Button variant="text" size="sm"`). Its presence turns
|
|
244
|
+
* the rich tooltip into a non-modal dialog that opens with a click.
|
|
245
|
+
*/
|
|
246
|
+
export function RichTooltipActions({ className, ...props }) {
|
|
247
|
+
const ctx = useRichTooltip('RichTooltipActions');
|
|
248
|
+
usePart('actions', ctx.register);
|
|
249
|
+
return _jsx("div", { ...props, className: cx('mk-rich-tooltip-actions', className) });
|
|
250
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type CSSProperties, type HTMLAttributes, type ReactElement, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import { type OpenStateProps } from './tooltip-behavior.ts';
|
|
3
|
+
export type { TooltipOpenChangeReason } from './tooltip-behavior.ts';
|
|
4
|
+
/** Trigger props that the tooltip reads or merges. */
|
|
5
|
+
interface TriggerProps {
|
|
6
|
+
label?: string | undefined;
|
|
7
|
+
'aria-label'?: string | undefined;
|
|
8
|
+
'aria-describedby'?: string | undefined;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
style?: CSSProperties | undefined;
|
|
11
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface TooltipProps extends OpenStateProps, Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
15
|
+
/**
|
|
16
|
+
* Text that describes the control, different from its name: it becomes its accessible description
|
|
17
|
+
* (`aria-describedby`), announced after the name. Without `text`, the tooltip shows the trigger's
|
|
18
|
+
* name (its `label`, its `aria-label` or its text) and is not linked: the name already comes from
|
|
19
|
+
* the control itself, so the screen reader doesn't repeat it.
|
|
20
|
+
*/
|
|
21
|
+
text?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The trigger: a single element that passes `ref`, `style` and the `aria-*` props to its
|
|
24
|
+
* interactive element (IconButton, Button, the chips, `Interactive` and native elements do).
|
|
25
|
+
*/
|
|
26
|
+
children: ReactElement<TriggerProps>;
|
|
27
|
+
/** Goes to the trigger, merged with the child's own. */
|
|
28
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Material 3 plain tooltip: a short text about the control it refers to, typically an IconButton.
|
|
32
|
+
* It renders no element around the trigger: it adds the attributes and the `ref` to it, and
|
|
33
|
+
* renders the tooltip (a popover with `role="tooltip"`) right after it.
|
|
34
|
+
*
|
|
35
|
+
* ```tsx
|
|
36
|
+
* <Tooltip><IconButton label="More options"><MoreVertIcon /></IconButton></Tooltip>
|
|
37
|
+
* <Tooltip text="Also saved to the cloud"><Button>Save</Button></Tooltip>
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* - **Name or description:** without `text` it shows the trigger's name (IconButton's `label`,
|
|
41
|
+
* `aria-label` or the text, useful for a chip's truncated text) and stays hidden from screen
|
|
42
|
+
* readers, which already announce that name. With `text`, the tooltip is the trigger's
|
|
43
|
+
* description (`aria-describedby`): don't repeat the name there.
|
|
44
|
+
* - **Shows** with the pointer after 500 ms (or right away if another tooltip is already visible)
|
|
45
|
+
* and with keyboard focus; on touch, with a long press. **Hides** 600 ms after the pointer leaves
|
|
46
|
+
* the trigger and the tooltip (the pointer can move over it), on blur, when the trigger is
|
|
47
|
+
* pressed and with Escape, without moving focus. Only one at a time.
|
|
48
|
+
* - **No interactive content:** for actions, use `RichTooltip` with `RichTooltipActions`.
|
|
49
|
+
* - Native props, `style` and `ref` go to the trigger (merged with its own), so it can be nested in
|
|
50
|
+
* `MenuTrigger`: `<MenuTrigger><Tooltip><IconButton … /></Tooltip></MenuTrigger>`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function Tooltip({ text, open, defaultOpen, onOpenChange, children, ref, ...outer }: TooltipProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (ADR-0003): el tooltip guarda si está visible, escucha el puntero, el foco
|
|
4
|
+
// y el teclado del disparador con demoras (temporizadores) y se coordina con los demás para que
|
|
5
|
+
// haya uno solo a la vez. Todo eso necesita estado, efectos y eventos, así que es cliente, como
|
|
6
|
+
// el Menu. El disparador puede ser universal (IconButton, Button, un chip, Interactive): el
|
|
7
|
+
// tooltip solo le suma atributos y una `ref`.
|
|
8
|
+
//
|
|
9
|
+
// Posicionamiento: CSS anchor positioning con el respaldo compartido con el Menu
|
|
10
|
+
// (src/internal/anchor-position.ts, ADR-0007). Decisiones: ADR-0021.
|
|
11
|
+
import { Children, cloneElement, isValidElement, useId, useMemo, useRef, } from 'react';
|
|
12
|
+
import { mkError, triggerNotElement } from '../../internal/diagnostics.js';
|
|
13
|
+
import { mergeRefs } from '../../internal/merge-refs.js';
|
|
14
|
+
import { useOpenState } from '../../internal/open-state.js';
|
|
15
|
+
import { anchorNameFor, joinList, useCoordinator, usePopover, useTransientTriggers, } from './tooltip-behavior.js';
|
|
16
|
+
// Texto plano de los hijos de primer nivel (`'Texto'` o `[<Icono />, 'Texto']`).
|
|
17
|
+
function plainText(children) {
|
|
18
|
+
return Children.toArray(children)
|
|
19
|
+
.filter((c) => typeof c === 'string' || typeof c === 'number')
|
|
20
|
+
.join('')
|
|
21
|
+
.trim();
|
|
22
|
+
}
|
|
23
|
+
const isHandler = (key) => /^on[A-Z]/.test(key);
|
|
24
|
+
/**
|
|
25
|
+
* Material 3 plain tooltip: a short text about the control it refers to, typically an IconButton.
|
|
26
|
+
* It renders no element around the trigger: it adds the attributes and the `ref` to it, and
|
|
27
|
+
* renders the tooltip (a popover with `role="tooltip"`) right after it.
|
|
28
|
+
*
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <Tooltip><IconButton label="More options"><MoreVertIcon /></IconButton></Tooltip>
|
|
31
|
+
* <Tooltip text="Also saved to the cloud"><Button>Save</Button></Tooltip>
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* - **Name or description:** without `text` it shows the trigger's name (IconButton's `label`,
|
|
35
|
+
* `aria-label` or the text, useful for a chip's truncated text) and stays hidden from screen
|
|
36
|
+
* readers, which already announce that name. With `text`, the tooltip is the trigger's
|
|
37
|
+
* description (`aria-describedby`): don't repeat the name there.
|
|
38
|
+
* - **Shows** with the pointer after 500 ms (or right away if another tooltip is already visible)
|
|
39
|
+
* and with keyboard focus; on touch, with a long press. **Hides** 600 ms after the pointer leaves
|
|
40
|
+
* the trigger and the tooltip (the pointer can move over it), on blur, when the trigger is
|
|
41
|
+
* pressed and with Escape, without moving focus. Only one at a time.
|
|
42
|
+
* - **No interactive content:** for actions, use `RichTooltip` with `RichTooltipActions`.
|
|
43
|
+
* - Native props, `style` and `ref` go to the trigger (merged with its own), so it can be nested in
|
|
44
|
+
* `MenuTrigger`: `<MenuTrigger><Tooltip><IconButton … /></Tooltip></MenuTrigger>`.
|
|
45
|
+
*/
|
|
46
|
+
export function Tooltip({ text, open, defaultOpen, onOpenChange, children, ref, ...outer }) {
|
|
47
|
+
// Sin Children.only: su error genérico de React taparía el de matekit (MK_TRIGGER_NOT_ELEMENT),
|
|
48
|
+
// que salta en los mismos casos (varios hijos, un texto, nada).
|
|
49
|
+
const child = children;
|
|
50
|
+
if (!isValidElement(child)) {
|
|
51
|
+
throw triggerNotElement('Tooltip', child);
|
|
52
|
+
}
|
|
53
|
+
const own = child.props;
|
|
54
|
+
const name = own.label ?? own['aria-label'] ?? outer['aria-label'] ?? plainText(own.children);
|
|
55
|
+
const shown = text ?? name;
|
|
56
|
+
if (!shown) {
|
|
57
|
+
throw mkError('MK_TOOLTIP_NO_TEXT', {
|
|
58
|
+
component: 'Tooltip',
|
|
59
|
+
problem: 'without `text` it shows the trigger name, but the trigger has no `label`, `aria-label` or text of its own',
|
|
60
|
+
fix: 'pass `text` (<Tooltip text="Edit">) or name the trigger (<IconButton label="Edit">)',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const { isOpen, setOpen, isOpenNow } = useOpenState({ open, defaultOpen, onOpenChange });
|
|
64
|
+
const id = useId();
|
|
65
|
+
const contentId = `${id}tooltip`;
|
|
66
|
+
const anchorName = anchorNameFor(id);
|
|
67
|
+
const triggerRef = useRef(null);
|
|
68
|
+
const contentRef = useRef(null);
|
|
69
|
+
useCoordinator(isOpen, false, setOpen);
|
|
70
|
+
usePopover(isOpen, contentRef, triggerRef);
|
|
71
|
+
useTransientTriggers(true, triggerRef, contentRef, setOpen, isOpenNow);
|
|
72
|
+
const mergedRef = useMemo(() => mergeRefs(own.ref, ref, triggerRef), [own.ref, ref]);
|
|
73
|
+
// Las props que llegan al Tooltip (por ejemplo de un MenuTrigger que lo envuelve) son para el
|
|
74
|
+
// disparador y ganan, salvo las que se combinan: manejadores (primero el del hijo), estilo
|
|
75
|
+
// (los nombres de ancla se suman) y aria-describedby.
|
|
76
|
+
const merged = { ...outer };
|
|
77
|
+
for (const [key, value] of Object.entries(outer)) {
|
|
78
|
+
const mine = own[key];
|
|
79
|
+
if (isHandler(key) && typeof value === 'function' && typeof mine === 'function') {
|
|
80
|
+
merged[key] = (...args) => {
|
|
81
|
+
mine(...args);
|
|
82
|
+
value(...args);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const outerStyle = outer.style;
|
|
87
|
+
const style = {
|
|
88
|
+
...own.style,
|
|
89
|
+
...outerStyle,
|
|
90
|
+
anchorName: joinList(', ', own.style?.anchorName, outerStyle?.anchorName, anchorName),
|
|
91
|
+
};
|
|
92
|
+
const trigger = cloneElement(child, {
|
|
93
|
+
...merged,
|
|
94
|
+
ref: mergedRef,
|
|
95
|
+
style,
|
|
96
|
+
'aria-describedby': joinList(' ', own['aria-describedby'], outer['aria-describedby'], text === undefined ? undefined : contentId),
|
|
97
|
+
});
|
|
98
|
+
return (_jsxs(_Fragment, { children: [trigger, _jsx("span", { ref: contentRef, id: contentId, role: "tooltip", "aria-hidden": text === undefined ? true : undefined, popover: "manual", className: "mk-tooltip mk-plain-tooltip", style: { '--_anchor': anchorName }, children: shown })] }));
|
|
99
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import { type PlacementOptions } from '../../internal/anchor-position.ts';
|
|
3
|
+
export declare const SHOW_DELAY_MS = 500;
|
|
4
|
+
export declare const HIDE_DELAY_MS = 600;
|
|
5
|
+
export declare const LONG_PRESS_MS = 500;
|
|
6
|
+
export declare const TOUCH_DURATION_MS = 1500;
|
|
7
|
+
export declare const TOOLTIP_PLACEMENT: PlacementOptions;
|
|
8
|
+
export declare const isWarm: () => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Why a tooltip asked to show or hide (`onOpenChange(open, reason)`).
|
|
11
|
+
*
|
|
12
|
+
* Transient (`Tooltip`, and `RichTooltip` without actions):
|
|
13
|
+
* - `hover`: the pointer rested on the trigger (after the show delay) or left the trigger and the
|
|
14
|
+
* tooltip (after the hide delay);
|
|
15
|
+
* - `focus`: keyboard focus reached the trigger; `focus-out`: focus left it;
|
|
16
|
+
* - `press`: pressing the trigger hides it;
|
|
17
|
+
* - `long-press`: a touch long press shows it; `timeout`: it hides a while after the finger lifts;
|
|
18
|
+
* - `escape`: Escape hides it (also in the persistent one);
|
|
19
|
+
* - `replaced`: another tooltip opened and took its place (also in the persistent one).
|
|
20
|
+
*
|
|
21
|
+
* Persistent (`RichTooltip` with actions):
|
|
22
|
+
* - `trigger`: a click on the trigger toggles it;
|
|
23
|
+
* - `outside`: a click outside the trigger and the tooltip;
|
|
24
|
+
* - `tab`: Tab from the last action left it; `focus-out`: focus went elsewhere.
|
|
25
|
+
*/
|
|
26
|
+
export type TooltipOpenChangeReason = 'hover' | 'focus' | 'focus-out' | 'press' | 'long-press' | 'timeout' | 'escape' | 'replaced' | 'trigger' | 'outside' | 'tab';
|
|
27
|
+
export interface OpenStateProps {
|
|
28
|
+
/** Shown or not, controlled. Without it, the tooltip keeps its own state from `defaultOpen`. */
|
|
29
|
+
open?: boolean | undefined;
|
|
30
|
+
/** Initial state when uncontrolled. Defaults to `false`. */
|
|
31
|
+
defaultOpen?: boolean | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The tooltip asked to show or hide, with the reason (`TooltipOpenChangeReason`): pointer, focus,
|
|
34
|
+
* Escape, a click, another tooltip opening. Controlled, it only changes when `open` does.
|
|
35
|
+
*/
|
|
36
|
+
onOpenChange?: ((open: boolean, reason: TooltipOpenChangeReason) => void) | undefined;
|
|
37
|
+
}
|
|
38
|
+
export type SetTooltipOpen = (open: boolean, reason: TooltipOpenChangeReason) => void;
|
|
39
|
+
export declare function useCoordinator(open: boolean, persistentMode: boolean, setOpen: SetTooltipOpen): void;
|
|
40
|
+
export declare function usePopover(open: boolean, contentRef: RefObject<HTMLElement | null>, triggerRef: RefObject<HTMLElement | null>): void;
|
|
41
|
+
export declare function useTransientTriggers(enabled: boolean, triggerRef: RefObject<HTMLElement | null>, contentRef: RefObject<HTMLElement | null>, setOpen: SetTooltipOpen, isOpenNow: () => boolean): void;
|
|
42
|
+
export declare function joinList(sep: ', ' | ' ', ...items: Array<string | undefined | null | false>): string | undefined;
|
|
43
|
+
export declare const anchorNameFor: (id: string) => string;
|