@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,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long it stays visible: `short` 4 s and `long` 10 s (Compose's `SnackbarDuration.toMillis`),
|
|
3
|
+
* `indefinite` (until it is dismissed or its action is used), or milliseconds. The timer pauses
|
|
4
|
+
* while the pointer is over it, focus is inside it or the tab is hidden.
|
|
5
|
+
*/
|
|
6
|
+
export type SnackbarDuration = 'short' | 'long' | 'indefinite' | number;
|
|
7
|
+
/** Why it went away: the action, the close button or Escape (`dismiss`), the timer or `cancel`. */
|
|
8
|
+
export type SnackbarResult = 'action' | 'dismiss' | 'timeout' | 'cancel';
|
|
9
|
+
export declare const SNACKBAR_DURATION_MS: {
|
|
10
|
+
readonly short: 4000;
|
|
11
|
+
readonly long: 10000;
|
|
12
|
+
};
|
|
13
|
+
export interface SnackbarOptions {
|
|
14
|
+
/** The text. Announced once when it appears (`role="status"` live region). */
|
|
15
|
+
message: string;
|
|
16
|
+
/** Text of the action button (only one, as in Material 3). The promise resolves to `'action'`. */
|
|
17
|
+
action?: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Close button. Defaults to `true` when the duration is `indefinite` (Compose recommends it: it
|
|
20
|
+
* is the way to dismiss it without using the action).
|
|
21
|
+
*/
|
|
22
|
+
dismissible?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Defaults to `short` without an action and `indefinite` with one (Compose, and WCAG 2.2.1: an
|
|
25
|
+
* action that goes away by itself may not leave time to reach it with the keyboard or a screen
|
|
26
|
+
* reader).
|
|
27
|
+
*/
|
|
28
|
+
duration?: SnackbarDuration | undefined;
|
|
29
|
+
/** The action below the text, aligned to the end: for long action texts (kit, Compose). */
|
|
30
|
+
actionOnNewLine?: boolean | undefined;
|
|
31
|
+
/** Name of the close button. Defaults to the host's `closeLabel` ("Close"). */
|
|
32
|
+
closeLabel?: string | undefined;
|
|
33
|
+
/** When aborted, removes it from the screen or the queue; the promise resolves to `'cancel'`. */
|
|
34
|
+
signal?: AbortSignal | undefined;
|
|
35
|
+
}
|
|
36
|
+
/** A snackbar in the queue, with its options resolved. The host renders it. */
|
|
37
|
+
export interface SnackbarEntry {
|
|
38
|
+
/** Unique within the queue (React key). */
|
|
39
|
+
readonly id: number;
|
|
40
|
+
readonly message: string;
|
|
41
|
+
readonly action: string | undefined;
|
|
42
|
+
readonly dismissible: boolean;
|
|
43
|
+
/** In milliseconds; `Infinity` when `indefinite`. */
|
|
44
|
+
readonly duration: number;
|
|
45
|
+
readonly actionOnNewLine: boolean;
|
|
46
|
+
readonly closeLabel: string | undefined;
|
|
47
|
+
/** Removes it from the screen and resolves its promise with `result`. A second call does nothing. */
|
|
48
|
+
close(result: SnackbarResult): void;
|
|
49
|
+
}
|
|
50
|
+
export interface SnackbarQueue {
|
|
51
|
+
/**
|
|
52
|
+
* Shows a snackbar, or queues it behind the ones already there. Resolves when it has gone, with
|
|
53
|
+
* the reason. A plain string is `{ message }`.
|
|
54
|
+
*/
|
|
55
|
+
show(options: SnackbarOptions | string): Promise<SnackbarResult>;
|
|
56
|
+
/** Dismisses the visible one (`'dismiss'`); the next in the queue is shown. */
|
|
57
|
+
dismiss(): void;
|
|
58
|
+
/** Cancels the visible one and those waiting (`'cancel'`). */
|
|
59
|
+
clear(): void;
|
|
60
|
+
/** The one being shown, or `null`. */
|
|
61
|
+
readonly current: SnackbarEntry | null;
|
|
62
|
+
/** How many are waiting behind the visible one. */
|
|
63
|
+
readonly pending: number;
|
|
64
|
+
/**
|
|
65
|
+
* Notifies every time `current` changes (for `useSyncExternalStore`). Returns a function that
|
|
66
|
+
* unsubscribes.
|
|
67
|
+
*/
|
|
68
|
+
subscribe(listener: () => void): () => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a snackbar queue. Each `SnackbarHost` renders one; without `queue`, the host creates its
|
|
72
|
+
* own. Create it inside the React tree (`useState(createSnackbarQueue)`) or per request: a
|
|
73
|
+
* module-level queue would be shared between requests on the server.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const queue = createSnackbarQueue()
|
|
77
|
+
* const result = await queue.show({ message: 'Photo archived', action: 'Undo' })
|
|
78
|
+
* if (result === 'action') restore()
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function createSnackbarQueue(): SnackbarQueue;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Cola de snackbars (ADR-0022): un objeto que crea la app, sin estado de módulo. Universal: no
|
|
2
|
+
// importa React, así que se puede crear y usar en cualquier lado (un manejador, una tienda de
|
|
3
|
+
// estado, una mutación de datos) y pasarle al SnackbarHost que la dibuja.
|
|
4
|
+
//
|
|
5
|
+
// Modelo: SnackbarHostState de Jetpack Compose (SnackbarHost.kt, commit 7ac433e44e): `show`
|
|
6
|
+
// encola y devuelve una promesa que se cumple cuando el snackbar se fue, con el motivo; uno solo a
|
|
7
|
+
// la vez, en orden de llegada. Compose usa un Mutex (cola justa) y devuelve ActionPerformed o
|
|
8
|
+
// Dismissed; acá el motivo distingue además el tiempo cumplido y la cancelación.
|
|
9
|
+
import { mkError } from '../../internal/diagnostics.js';
|
|
10
|
+
export const SNACKBAR_DURATION_MS = { short: 4000, long: 10000 };
|
|
11
|
+
function toMillis(duration) {
|
|
12
|
+
if (duration === 'indefinite')
|
|
13
|
+
return Infinity;
|
|
14
|
+
if (typeof duration === 'number') {
|
|
15
|
+
if (!(duration > 0)) {
|
|
16
|
+
throw mkError('MK_SNACKBAR_DURATION_INVALID', {
|
|
17
|
+
component: 'Snackbar',
|
|
18
|
+
problem: '`duration` in milliseconds must be a positive number',
|
|
19
|
+
fix: "pass milliseconds (duration: 4000), 'short', 'long' or 'indefinite'",
|
|
20
|
+
}, { duration });
|
|
21
|
+
}
|
|
22
|
+
return duration;
|
|
23
|
+
}
|
|
24
|
+
return SNACKBAR_DURATION_MS[duration];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a snackbar queue. Each `SnackbarHost` renders one; without `queue`, the host creates its
|
|
28
|
+
* own. Create it inside the React tree (`useState(createSnackbarQueue)`) or per request: a
|
|
29
|
+
* module-level queue would be shared between requests on the server.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const queue = createSnackbarQueue()
|
|
33
|
+
* const result = await queue.show({ message: 'Photo archived', action: 'Undo' })
|
|
34
|
+
* if (result === 'action') restore()
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function createSnackbarQueue() {
|
|
38
|
+
const waiting = [];
|
|
39
|
+
const listeners = new Set();
|
|
40
|
+
let current = null;
|
|
41
|
+
let nextId = 1;
|
|
42
|
+
const notify = () => {
|
|
43
|
+
for (const listener of [...listeners])
|
|
44
|
+
listener();
|
|
45
|
+
};
|
|
46
|
+
const advance = () => {
|
|
47
|
+
current = waiting.shift() ?? null;
|
|
48
|
+
notify();
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
show(input) {
|
|
52
|
+
const options = typeof input === 'string' ? { message: input } : input;
|
|
53
|
+
const duration = toMillis(options.duration ?? (options.action === undefined ? 'short' : 'indefinite'));
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const { signal } = options;
|
|
56
|
+
if (signal?.aborted) {
|
|
57
|
+
resolve('cancel');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let done = false;
|
|
61
|
+
const onAbort = () => entry.close('cancel');
|
|
62
|
+
const entry = {
|
|
63
|
+
id: nextId++,
|
|
64
|
+
message: options.message,
|
|
65
|
+
action: options.action,
|
|
66
|
+
dismissible: options.dismissible ?? duration === Infinity,
|
|
67
|
+
duration,
|
|
68
|
+
actionOnNewLine: options.actionOnNewLine ?? false,
|
|
69
|
+
closeLabel: options.closeLabel,
|
|
70
|
+
close(result) {
|
|
71
|
+
if (done)
|
|
72
|
+
return;
|
|
73
|
+
done = true;
|
|
74
|
+
signal?.removeEventListener('abort', onAbort);
|
|
75
|
+
resolve(result);
|
|
76
|
+
if (current === entry) {
|
|
77
|
+
advance();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const i = waiting.indexOf(entry);
|
|
81
|
+
if (i >= 0)
|
|
82
|
+
waiting.splice(i, 1);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
86
|
+
if (current) {
|
|
87
|
+
waiting.push(entry);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
current = entry;
|
|
91
|
+
notify();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
dismiss() {
|
|
96
|
+
current?.close('dismiss');
|
|
97
|
+
},
|
|
98
|
+
clear() {
|
|
99
|
+
for (const entry of waiting.splice(0))
|
|
100
|
+
entry.close('cancel');
|
|
101
|
+
current?.close('cancel');
|
|
102
|
+
},
|
|
103
|
+
get current() {
|
|
104
|
+
return current;
|
|
105
|
+
},
|
|
106
|
+
get pending() {
|
|
107
|
+
return waiting.length;
|
|
108
|
+
},
|
|
109
|
+
subscribe(listener) {
|
|
110
|
+
listeners.add(listener);
|
|
111
|
+
return () => listeners.delete(listener);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import { type ButtonProps } from '../../molecules/Button/Button.tsx';
|
|
3
|
+
/** Split button styles (the Button ones, without `text`: neither the kit nor Compose has it). */
|
|
4
|
+
export type SplitButtonVariant = 'filled' | 'tonal' | 'elevated' | 'outlined';
|
|
5
|
+
/** Material 3 Expressive sizes: 32, 40, 56, 96 or 136 px tall, like the Button. */
|
|
6
|
+
export type SplitButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
7
|
+
export interface SplitButtonProps extends HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
/** Color style of both parts. Defaults to `filled`. */
|
|
9
|
+
variant?: SplitButtonVariant | undefined;
|
|
10
|
+
/** Size of both parts. Defaults to `sm`. */
|
|
11
|
+
size?: SplitButtonSize | undefined;
|
|
12
|
+
/** Disables both parts (each one also accepts its own `disabled`). */
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
/** Ref to the `<div>` that groups them. */
|
|
15
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
16
|
+
/** `SplitButtonAction` and a `Menu` with `SplitButtonTrigger` and `MenuContent`. */
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Material 3 Expressive split button: a main action and, joined to it, a button with an arrow that
|
|
21
|
+
* opens a menu of related actions. They are two buttons (two Tab stops); the menu is matekit's
|
|
22
|
+
* `Menu`, written around the trigger.
|
|
23
|
+
*
|
|
24
|
+
* Renders a `<div>` with no role (native props, `className`, `style` and `ref` go there); to group
|
|
25
|
+
* them for a screen reader, pass `role="group"` and a name.
|
|
26
|
+
*
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <SplitButton variant="tonal">
|
|
29
|
+
* <SplitButtonAction onClick={send}><ShareIcon />Send</SplitButtonAction>
|
|
30
|
+
* <Menu>
|
|
31
|
+
* <SplitButtonTrigger label="More send options" />
|
|
32
|
+
* <MenuContent>
|
|
33
|
+
* <MenuItem onSelect={schedule}>Schedule send</MenuItem>
|
|
34
|
+
* <MenuItem onSelect={saveDraft}>Save draft</MenuItem>
|
|
35
|
+
* </MenuContent>
|
|
36
|
+
* </Menu>
|
|
37
|
+
* </SplitButton>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function SplitButton({ variant, size, disabled, className, children, ...props }: SplitButtonProps): import("react").JSX.Element;
|
|
41
|
+
/** The `<button>` form of the Button (no links: the split button is an action and its menu). */
|
|
42
|
+
type ButtonForm = Extract<ButtonProps, {
|
|
43
|
+
href?: undefined;
|
|
44
|
+
render?: undefined;
|
|
45
|
+
}>;
|
|
46
|
+
/** What the split button sets, not the part. */
|
|
47
|
+
type SetByParent = 'variant' | 'size' | 'shape' | 'selected' | 'aria-pressed';
|
|
48
|
+
/** `SplitButtonAction` props: those of a `<button>` Button without style, size, shape or toggle. */
|
|
49
|
+
export type SplitButtonActionProps = Omit<ButtonForm, SetByParent>;
|
|
50
|
+
/**
|
|
51
|
+
* The main (leading) action: a `<button>` Button with the split button's style and size, with a
|
|
52
|
+
* label and an optional icon as children. Native props and `ref` go to the `<button>`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function SplitButtonAction({ className, disabled, ...props }: SplitButtonActionProps): import("react").JSX.Element;
|
|
55
|
+
export interface SplitButtonTriggerProps extends Omit<ButtonForm, SetByParent | 'aria-label' | 'children'> {
|
|
56
|
+
/**
|
|
57
|
+
* Accessible name (becomes `aria-label`): the button only shows the arrow. Defaults to
|
|
58
|
+
* "More options"; with several split buttons on the screen, use one that names the options.
|
|
59
|
+
*/
|
|
60
|
+
label?: string | undefined;
|
|
61
|
+
/** Another icon instead of the arrow (it still rotates when opening). */
|
|
62
|
+
children?: ReactNode;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The menu (trailing) button, inside a `Menu`: a Button with an arrow that opens the menu, with
|
|
66
|
+
* `aria-haspopup="menu"`, `aria-expanded` and the `MenuTrigger` events (Enter, Space and Arrow Down
|
|
67
|
+
* open it and focus the first item; Arrow Up, the last one; Escape and choosing an item return
|
|
68
|
+
* focus here). While open it becomes fully round and the arrow rotates 180°. Native props,
|
|
69
|
+
* `onClick`, `onKeyDown` and `ref` go to the `<button>` (an `onClick` that calls
|
|
70
|
+
* `preventDefault()` doesn't open the menu).
|
|
71
|
+
*/
|
|
72
|
+
export declare function SplitButtonTrigger({ label, className, disabled, children, ...props }: SplitButtonTriggerProps): import("react").JSX.Element;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Organismo cliente (ADR-0032): el estilo, el tamaño y el deshabilitado de todo el split button se
|
|
4
|
+
// reparten por contexto a sus dos partes, que dibujan un Button común (universal) con esos valores.
|
|
5
|
+
// Es lo único cliente propio: el estado abierto, el teclado y el foco son del Menu, que ya es
|
|
6
|
+
// cliente y que el uso escribe alrededor del disparador. Un split button sin menú no tiene sentido,
|
|
7
|
+
// así que el árbol es cliente de todos modos; la forma, los estados y la flecha son CSS
|
|
8
|
+
// (split-button.css), sin estado ni efectos.
|
|
9
|
+
//
|
|
10
|
+
// - Dos paradas de Tab (dos botones), no una barra con flechas: la acción es un botón y el del
|
|
11
|
+
// menú es un "menu button" de WAI-ARIA APG (`aria-haspopup="menu"`, `aria-expanded`; Enter,
|
|
12
|
+
// Espacio y flecha abajo abren en el primero, flecha arriba en el último), como Compose (dos
|
|
13
|
+
// botones independientes en SplitButtonLayout) y labs de @material/web (dos `<button>`).
|
|
14
|
+
// - Forma sobre Group (ADR-0017): exteriores redondas e interiores por tamaño que crecen con hover y
|
|
15
|
+
// presionado, y el del menú redondo entero mientras está abierto (`aria-expanded`, que pone
|
|
16
|
+
// MenuTrigger). Ver split-button.css.
|
|
17
|
+
import { createContext, use, useMemo } from 'react';
|
|
18
|
+
import { Group } from '../../atoms/Group/Group.js';
|
|
19
|
+
import { ExpandMoreIcon } from '../../icons/icons.js';
|
|
20
|
+
import { partOutsideParent } from '../../internal/diagnostics.js';
|
|
21
|
+
import { cx } from '../../internal/interactive.js';
|
|
22
|
+
import { Button } from '../../molecules/Button/Button.js';
|
|
23
|
+
import { MenuTrigger, useMenu } from '../Menu/Menu.js';
|
|
24
|
+
import { splitButtonStrings } from './strings.js';
|
|
25
|
+
const SplitButtonContext = createContext(null);
|
|
26
|
+
function useSplitButton(part) {
|
|
27
|
+
const ctx = use(SplitButtonContext);
|
|
28
|
+
if (!ctx)
|
|
29
|
+
throw partOutsideParent(part, 'SplitButton');
|
|
30
|
+
return ctx;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Material 3 Expressive split button: a main action and, joined to it, a button with an arrow that
|
|
34
|
+
* opens a menu of related actions. They are two buttons (two Tab stops); the menu is matekit's
|
|
35
|
+
* `Menu`, written around the trigger.
|
|
36
|
+
*
|
|
37
|
+
* Renders a `<div>` with no role (native props, `className`, `style` and `ref` go there); to group
|
|
38
|
+
* them for a screen reader, pass `role="group"` and a name.
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <SplitButton variant="tonal">
|
|
42
|
+
* <SplitButtonAction onClick={send}><ShareIcon />Send</SplitButtonAction>
|
|
43
|
+
* <Menu>
|
|
44
|
+
* <SplitButtonTrigger label="More send options" />
|
|
45
|
+
* <MenuContent>
|
|
46
|
+
* <MenuItem onSelect={schedule}>Schedule send</MenuItem>
|
|
47
|
+
* <MenuItem onSelect={saveDraft}>Save draft</MenuItem>
|
|
48
|
+
* </MenuContent>
|
|
49
|
+
* </Menu>
|
|
50
|
+
* </SplitButton>
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function SplitButton({ variant = 'filled', size = 'sm', disabled = false, className, children, ...props }) {
|
|
54
|
+
const ctx = useMemo(() => ({ variant, size, disabled }), [variant, size, disabled]);
|
|
55
|
+
return (_jsx(SplitButtonContext, { value: ctx, children: _jsx(Group, { ...props, className: cx('mk-split-button', className), "data-variant": variant, "data-size": size, children: children }) }));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The main (leading) action: a `<button>` Button with the split button's style and size, with a
|
|
59
|
+
* label and an optional icon as children. Native props and `ref` go to the `<button>`.
|
|
60
|
+
*/
|
|
61
|
+
export function SplitButtonAction({ className, disabled, ...props }) {
|
|
62
|
+
const ctx = useSplitButton('SplitButtonAction');
|
|
63
|
+
return (_jsx(Button, { ...props, variant: ctx.variant, size: ctx.size, disabled: ctx.disabled || disabled, className: cx('mk-split-button-action', className) }));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The menu (trailing) button, inside a `Menu`: a Button with an arrow that opens the menu, with
|
|
67
|
+
* `aria-haspopup="menu"`, `aria-expanded` and the `MenuTrigger` events (Enter, Space and Arrow Down
|
|
68
|
+
* open it and focus the first item; Arrow Up, the last one; Escape and choosing an item return
|
|
69
|
+
* focus here). While open it becomes fully round and the arrow rotates 180°. Native props,
|
|
70
|
+
* `onClick`, `onKeyDown` and `ref` go to the `<button>` (an `onClick` that calls
|
|
71
|
+
* `preventDefault()` doesn't open the menu).
|
|
72
|
+
*/
|
|
73
|
+
export function SplitButtonTrigger({ label = splitButtonStrings.label, className, disabled, children, ...props }) {
|
|
74
|
+
const ctx = useSplitButton('SplitButtonTrigger');
|
|
75
|
+
useMenu('SplitButtonTrigger');
|
|
76
|
+
return (_jsx(MenuTrigger, { children: _jsx(Button, { ...props, variant: ctx.variant, size: ctx.size, disabled: ctx.disabled || disabled, "aria-label": label, className: cx('mk-split-button-trigger', className), children: children ?? _jsx(ExpandMoreIcon, {}) }) }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SplitButtonStrings {
|
|
2
|
+
/**
|
|
3
|
+
* Accessible name of the button that opens the menu (`SplitButtonTrigger` `label`), which only
|
|
4
|
+
* shows an arrow. Prefer one that names the options ("More send options") when there are several
|
|
5
|
+
* on the screen.
|
|
6
|
+
*/
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const splitButtonStrings: SplitButtonStrings;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type LinkElementProps, type RenderElementProps } from '../../atoms/Interactive/Interactive.tsx';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
interface TabLinkOwnProps {
|
|
4
|
+
/**
|
|
5
|
+
* The current page: sets `aria-current="page"` and shows the indicator. The app decides it
|
|
6
|
+
* (comparing with the route). Not needed if the `render` element already sets `aria-current`
|
|
7
|
+
* (React Router's `NavLink`). The same name as the navigation destinations and `ListItemAction`.
|
|
8
|
+
*/
|
|
9
|
+
current?: boolean | undefined;
|
|
10
|
+
/** Icon, label (text or `TabLabel`) and, if needed, a `Badge`. Icon only: `aria-label`. */
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/** With `href`, an `<a>`. */
|
|
14
|
+
export type TabLinkAnchorProps = TabLinkOwnProps & LinkElementProps;
|
|
15
|
+
/** With `render`, the element passed (the router's `Link`), cloned with the classes and the content. */
|
|
16
|
+
export type TabLinkRenderProps = TabLinkOwnProps & RenderElementProps;
|
|
17
|
+
export type TabLinkProps = TabLinkAnchorProps | TabLinkRenderProps;
|
|
18
|
+
/**
|
|
19
|
+
* A `TabNav` link, with the look of a tab.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* // Next.js (App Router): the link can be a Server Component.
|
|
23
|
+
* <TabLink current={pathname === '/account/profile'} render={<Link href="/account/profile" />}>Profile</TabLink>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function TabLink(props: TabLinkProps): import("react").JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Organismo universal (ADR-0003): sin estado, efectos, contexto ni eventos; no lleva 'use client'.
|
|
3
|
+
// Pestaña de navegación entre páginas (ADR-0023): un enlace con el aspecto de una pestaña, no una
|
|
4
|
+
// pestaña APG. Va dentro de `TabNav`. Activo por `aria-current="page"`, como los destinos de
|
|
5
|
+
// NavigationBar (src/internal/navigation-item.tsx); un `<a>` con `href` o el `Link` del enrutador
|
|
6
|
+
// con `render` (ADR-0010, átomo Interactive). Tab recorre los enlaces uno por uno, como en
|
|
7
|
+
// cualquier lista de enlaces (sin foco itinerante ni flechas).
|
|
8
|
+
import { Interactive, } from '../../atoms/Interactive/Interactive.js';
|
|
9
|
+
import { assertRenderElement, cx } from '../../internal/interactive.js';
|
|
10
|
+
import { tabContent, warnIfUnnamed } from './tab-content.js';
|
|
11
|
+
/**
|
|
12
|
+
* A `TabNav` link, with the look of a tab.
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // Next.js (App Router): the link can be a Server Component.
|
|
16
|
+
* <TabLink current={pathname === '/account/profile'} render={<Link href="/account/profile" />}>Profile</TabLink>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function TabLink(props) {
|
|
20
|
+
const { current, className, children, ...rest } = props;
|
|
21
|
+
assertRenderElement('TabLink', rest.render);
|
|
22
|
+
const content = tabContent(children);
|
|
23
|
+
warnIfUnnamed('TabLink', content.hasLabel, rest);
|
|
24
|
+
return (_jsx(Interactive, { ...(current ? { 'aria-current': 'page' } : {}), ...rest, ...content.data, className: cx('mk-tab', className), children: content.children }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type HTMLAttributes, type Ref } from 'react';
|
|
2
|
+
import type { TabBarProps } from './Tabs.tsx';
|
|
3
|
+
export interface TabNavProps extends TabBarProps, HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** Ref to the `<nav>`. */
|
|
5
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Tab bar to navigate between pages: a `<nav>` with `TabLink`s, with the same look as `TabList`
|
|
9
|
+
* (primary or secondary, fixed or scrollable). If the page has more than one `<nav>`, give it a
|
|
10
|
+
* name with `aria-label`.
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <TabNav aria-label="Account">
|
|
14
|
+
* <TabLink href="/account/profile" current>Profile</TabLink>
|
|
15
|
+
* <TabLink href="/account/security">Security</TabLink>
|
|
16
|
+
* </TabNav>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function TabNav({ variant, layout, className, ref, ...rest }: TabNavProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (ADR-0023): solo por el movimiento. La barra de enlaces con aspecto de
|
|
4
|
+
// pestañas (`TabLink`) es un `<nav>` común; sin JavaScript se ve y funciona igual (el indicador es
|
|
5
|
+
// de cada enlace, tab-content.tsx), y el efecto suma el deslizamiento del indicador cuando cambia
|
|
6
|
+
// el `aria-current` (navegación del lado del cliente, con el `Link` del enrutador) y trae el enlace
|
|
7
|
+
// actual a la vista en la scrollable. Los enlaces (`TabLink`) son universales y pueden venir de un
|
|
8
|
+
// Server Component como hijos.
|
|
9
|
+
//
|
|
10
|
+
// No es el patrón APG "Tabs": cada enlace lleva a otra página, así que no hay `tablist`, `tab` ni
|
|
11
|
+
// paneles, y Tab recorre los enlaces uno por uno, como en cualquier lista de enlaces.
|
|
12
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
13
|
+
import { cx } from '../../internal/interactive.js';
|
|
14
|
+
import { mergeRefs } from '../../internal/merge-refs.js';
|
|
15
|
+
import { scrollTabIntoView, slideIndicator } from './tab-motion.js';
|
|
16
|
+
import { useTruncatedLabelWarning } from './tab-fit.js';
|
|
17
|
+
const currentLink = (nav) => [...nav.querySelectorAll('.mk-tab[aria-current]:not([aria-current="false"])')].find((el) => el.closest('.mk-tab-list') === nav) ?? null;
|
|
18
|
+
/**
|
|
19
|
+
* Tab bar to navigate between pages: a `<nav>` with `TabLink`s, with the same look as `TabList`
|
|
20
|
+
* (primary or secondary, fixed or scrollable). If the page has more than one `<nav>`, give it a
|
|
21
|
+
* name with `aria-label`.
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* <TabNav aria-label="Account">
|
|
25
|
+
* <TabLink href="/account/profile" current>Profile</TabLink>
|
|
26
|
+
* <TabLink href="/account/security">Security</TabLink>
|
|
27
|
+
* </TabNav>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function TabNav({ variant = 'primary', layout = 'fixed', className, ref, ...rest }) {
|
|
31
|
+
const navRef = useRef(null);
|
|
32
|
+
const mergedRef = useMemo(() => mergeRefs(ref, navRef), [ref]);
|
|
33
|
+
useTruncatedLabelWarning(navRef, layout, 'TabNav');
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
const nav = navRef.current;
|
|
36
|
+
if (!nav)
|
|
37
|
+
return;
|
|
38
|
+
let previous = currentLink(nav);
|
|
39
|
+
if (previous)
|
|
40
|
+
scrollTabIntoView(nav, previous, false);
|
|
41
|
+
// El aria-current lo puede poner la app (`current`) o el enrutador (NavLink): se observa el DOM.
|
|
42
|
+
const observer = new MutationObserver(() => {
|
|
43
|
+
const link = currentLink(nav);
|
|
44
|
+
if (!link || link === previous)
|
|
45
|
+
return;
|
|
46
|
+
if (previous?.isConnected)
|
|
47
|
+
slideIndicator(previous, link);
|
|
48
|
+
scrollTabIntoView(nav, link, true);
|
|
49
|
+
previous = link;
|
|
50
|
+
});
|
|
51
|
+
observer.observe(nav, { subtree: true, childList: true, attributes: true, attributeFilter: ['aria-current'] });
|
|
52
|
+
return () => observer.disconnect();
|
|
53
|
+
}, []);
|
|
54
|
+
return _jsx("nav", { ...rest, ref: mergedRef, "data-variant": variant, "data-layout": layout, className: cx('mk-tab-list', className) });
|
|
55
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type HTMLAttributes, type KeyboardEvent, type MouseEvent, type ReactNode, type Ref } from 'react';
|
|
2
|
+
export type TabsActivation = 'automatic' | 'manual';
|
|
3
|
+
export type TabsVariant = 'primary' | 'secondary';
|
|
4
|
+
export type TabsLayout = 'fixed' | 'scrollable';
|
|
5
|
+
/**
|
|
6
|
+
* The event that selected another tab: a click or a key on a tab (React events), or the browser's
|
|
7
|
+
* native `beforematch` `Event` when find in page reveals a `findable` panel (`event.type ===
|
|
8
|
+
* 'beforematch'`, `event.target` is the panel).
|
|
9
|
+
*/
|
|
10
|
+
export type TabsChangeEvent = MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLElement> | Event;
|
|
11
|
+
interface TabsBaseProps extends Omit<HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange'> {
|
|
12
|
+
/** `TabList` and the `TabPanel`s. */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* `automatic`: moving focus with the arrow keys selects the tab. `manual`: the arrows only move
|
|
16
|
+
* focus and Enter or Space select (for panels that are slow to show). Defaults to `automatic`.
|
|
17
|
+
*/
|
|
18
|
+
activation?: TabsActivation | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Called when another tab is selected, with its value and the event: a click or a key on a tab,
|
|
21
|
+
* or `beforematch` when find in page reveals a `findable` panel. Controlled, leaving `value` as
|
|
22
|
+
* it is vetoes the change, and a revealed panel is hidden again.
|
|
23
|
+
*/
|
|
24
|
+
onValueChange?: ((value: string, event: TabsChangeEvent) => void) | undefined;
|
|
25
|
+
/** Ref to the `<div>` that contains the list and the panels. */
|
|
26
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
27
|
+
}
|
|
28
|
+
interface ControlledTabs {
|
|
29
|
+
/** Value of the selected tab (controlled). */
|
|
30
|
+
value: string;
|
|
31
|
+
defaultValue?: undefined;
|
|
32
|
+
}
|
|
33
|
+
interface UncontrolledTabs {
|
|
34
|
+
value?: undefined;
|
|
35
|
+
/** Value of the initially selected tab (uncontrolled). */
|
|
36
|
+
defaultValue: string;
|
|
37
|
+
}
|
|
38
|
+
export type TabsProps = TabsBaseProps & (ControlledTabs | UncontrolledTabs);
|
|
39
|
+
/**
|
|
40
|
+
* Content tabs (APG "Tabs" pattern): a list of tabs and one panel per tab, of which the selected
|
|
41
|
+
* tab's panel is shown.
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <Tabs defaultValue="flights">
|
|
45
|
+
* <TabList aria-label="Trip">
|
|
46
|
+
* <Tab value="flights"><FlightIcon />Flights</Tab>
|
|
47
|
+
* <Tab value="hotels"><HotelIcon />Hotels</Tab>
|
|
48
|
+
* </TabList>
|
|
49
|
+
* <TabPanel value="flights">…</TabPanel>
|
|
50
|
+
* <TabPanel value="hotels">…</TabPanel>
|
|
51
|
+
* </Tabs>
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* To navigate between pages (each tab is a URL), use `TabNav` with `TabLink`: they are links, not
|
|
55
|
+
* tabs.
|
|
56
|
+
*/
|
|
57
|
+
export declare function Tabs(props: TabsProps): import("react").JSX.Element;
|
|
58
|
+
/** Bar props, shared by `TabList` and `TabNav`. */
|
|
59
|
+
export interface TabBarProps {
|
|
60
|
+
/**
|
|
61
|
+
* `primary`: below the top app bar, for the main sections; the indicator is as wide as the
|
|
62
|
+
* content. `secondary`: inside the content, to subdivide it; the indicator is as wide as the tab.
|
|
63
|
+
* Defaults to `primary`.
|
|
64
|
+
*/
|
|
65
|
+
variant?: TabsVariant | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* `fixed`: equal-width tabs that fill the bar; a label that does not fit is cut off with
|
|
68
|
+
* an ellipsis, and development builds warn (`MK_TAB_LABEL_TRUNCATED`, measured after layout and on
|
|
69
|
+
* resize). For more than four tabs or long labels, `scrollable`: each tab as wide as its content
|
|
70
|
+
* (at least 90), the bar scrolls horizontally without a scrollbar and the selected tab is brought
|
|
71
|
+
* into view. Defaults to `fixed`.
|
|
72
|
+
*/
|
|
73
|
+
layout?: TabsLayout | undefined;
|
|
74
|
+
}
|
|
75
|
+
export interface TabListProps extends TabBarProps, Omit<HTMLAttributes<HTMLDivElement>, 'role'> {
|
|
76
|
+
/** The tabs (`Tab`). */
|
|
77
|
+
children?: ReactNode;
|
|
78
|
+
/** Ref to the `<div role="tablist">`. */
|
|
79
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Tab list: a `<div role="tablist">` with a `surface` background and a 1 divider at the bottom. A
|
|
83
|
+
* single Tab stop (the selected tab), Arrow Left and Arrow Right (reversed in RTL) with wrapping,
|
|
84
|
+
* Home and End. Give it a name with `aria-label` or `aria-labelledby`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function TabList(props: TabListProps): import("react").JSX.Element;
|
|
87
|
+
/** No `id` or `aria-controls`: the component generates them to relate the tab to its panel. */
|
|
88
|
+
export interface TabProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'role' | 'type' | 'id' | 'aria-controls'> {
|
|
89
|
+
/** The tab's value; the `TabPanel` with the same value is its panel. */
|
|
90
|
+
value: string;
|
|
91
|
+
/**
|
|
92
|
+
* Icon, label (text or `TabLabel`) and, if needed, a `Badge`. Icon only: `aria-label` is
|
|
93
|
+
* required.
|
|
94
|
+
*/
|
|
95
|
+
children?: ReactNode;
|
|
96
|
+
/** Ref to the `<button role="tab">`. */
|
|
97
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Tab: a `<button role="tab">` with `aria-selected` and `aria-controls` (its panel). The accessible
|
|
101
|
+
* name comes from the label (and the badge's `label`); without a visible label, `aria-label`.
|
|
102
|
+
* `disabled` disables it and the arrow keys skip it.
|
|
103
|
+
*/
|
|
104
|
+
export declare function Tab(props: TabProps): import("react").JSX.Element;
|
|
105
|
+
/** No `id` or `aria-labelledby`: the component generates them from its tab. */
|
|
106
|
+
interface TabPanelBaseProps extends Omit<HTMLAttributes<HTMLDivElement>, 'id' | 'aria-labelledby'> {
|
|
107
|
+
/** Value of this panel's tab. */
|
|
108
|
+
value: string;
|
|
109
|
+
/** Ref to the `<div role="tabpanel">`. */
|
|
110
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
111
|
+
}
|
|
112
|
+
interface MountedTabPanel {
|
|
113
|
+
/**
|
|
114
|
+
* Unmounts the content while the tab is not selected (the empty panel stays, hidden). By default
|
|
115
|
+
* the content stays mounted and hidden with `hidden`: it keeps what was typed in a form and the
|
|
116
|
+
* state of its components. For a heavy panel that doesn't need to be kept. Watch out: a
|
|
117
|
+
* `required` field in a hidden, mounted panel blocks form submission without being able to show
|
|
118
|
+
* itself; validate per tab or unmount what is not part of the form. Cannot be combined with
|
|
119
|
+
* `findable`. Defaults to `false`.
|
|
120
|
+
*/
|
|
121
|
+
unmount?: false | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Lets the browser's find in page (Ctrl+F, ⌘F) and links to text fragments find the content while
|
|
124
|
+
* the tab is not selected: the panel is hidden with `hidden="until-found"` instead of `hidden`, and
|
|
125
|
+
* when the browser reveals a match the tab is selected through `onValueChange(value, event)` with
|
|
126
|
+
* the native `beforematch` event. For reference content split into tabs (a long page of tables).
|
|
127
|
+
* The hidden panel leaves the Tab order and is `aria-hidden`. In server-rendered HTML, before
|
|
128
|
+
* hydration, and in browsers without `beforematch`, it falls back to `hidden`. Requires the content
|
|
129
|
+
* to stay mounted, so it cannot be combined with `unmount`. Defaults to `false`.
|
|
130
|
+
*/
|
|
131
|
+
findable?: boolean | undefined;
|
|
132
|
+
}
|
|
133
|
+
interface UnmountedTabPanel {
|
|
134
|
+
/** See `unmount` above: the content is unmounted while the tab is not selected. */
|
|
135
|
+
unmount: true;
|
|
136
|
+
/** An unmounted panel has nothing to find: `findable` requires `unmount` to be `false`. */
|
|
137
|
+
findable?: false | undefined;
|
|
138
|
+
}
|
|
139
|
+
export type TabPanelProps = TabPanelBaseProps & (MountedTabPanel | UnmountedTabPanel);
|
|
140
|
+
/**
|
|
141
|
+
* A tab's panel: a `<div role="tabpanel">` named by its tab (`aria-labelledby`), hidden with
|
|
142
|
+
* `hidden` (or `hidden="until-found"` with `findable`) while the tab is not selected. It is in the
|
|
143
|
+
* Tab order (`tabIndex={0}`, as APG recommends when the panel doesn't start with a focusable element;
|
|
144
|
+
* `tabIndex` changes it).
|
|
145
|
+
*/
|
|
146
|
+
export declare function TabPanel(props: TabPanelProps): import("react").JSX.Element;
|
|
147
|
+
export {};
|