@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,88 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type DialogHTMLAttributes, type HTMLAttributes, type Ref } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Why a side sheet asks to close (`onClose(reason)`):
|
|
4
|
+
* - `close-button`: `SideSheetClose`;
|
|
5
|
+
* - `escape`, `scrim`, `native` (modal only): Escape or the platform's close request, a click on
|
|
6
|
+
* the scrim, or the `<dialog>` closing itself (`<form method="dialog">`, `close()`), as in `Dialog`.
|
|
7
|
+
*/
|
|
8
|
+
export type SideSheetCloseReason = 'close-button' | 'escape' | 'scrim' | 'native';
|
|
9
|
+
interface SideSheetCommonProps {
|
|
10
|
+
/**
|
|
11
|
+
* A **close request**, with the reason (`SideSheetCloseReason`): `SideSheetClose` and, in the
|
|
12
|
+
* modal, Escape, the scrim or a native close. The sheet does not close by itself: the app decides
|
|
13
|
+
* by passing `open={false}`, or refuses by keeping `open` (the sheet stays open and, if modal,
|
|
14
|
+
* modal), for example to confirm before discarding a form only when the reason is `'scrim'`.
|
|
15
|
+
*/
|
|
16
|
+
onClose?: ((reason: SideSheetCloseReason) => void) | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface SideSheetModalProps extends SideSheetCommonProps, Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open' | 'onClose'> {
|
|
19
|
+
/** Modal: over the content, from the end edge, with a scrim and trapped focus. Defaults to `true`. */
|
|
20
|
+
modal?: true | undefined;
|
|
21
|
+
/** Open (modal) or closed, controlled by the app (the sheet has no trigger of its own). Defaults to closed. */
|
|
22
|
+
open?: boolean | undefined;
|
|
23
|
+
/** Whether a click on the scrim asks to close. Defaults to `true`. */
|
|
24
|
+
closeOnScrimClick?: boolean | undefined;
|
|
25
|
+
/** Ref to the native `<dialog>`. */
|
|
26
|
+
ref?: Ref<HTMLDialogElement> | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface SideSheetStandardProps extends SideSheetCommonProps, HTMLAttributes<HTMLElement> {
|
|
29
|
+
/** Standard: in the page flow, beside the content, with no scrim or trapped focus. */
|
|
30
|
+
modal: false;
|
|
31
|
+
/** Shown or hidden (`hidden`), controlled by the app. Defaults to shown. */
|
|
32
|
+
open?: boolean | undefined;
|
|
33
|
+
closeOnScrimClick?: never;
|
|
34
|
+
/** Ref to the `<aside>`. */
|
|
35
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
36
|
+
}
|
|
37
|
+
export type SideSheetProps = SideSheetModalProps | SideSheetStandardProps;
|
|
38
|
+
/**
|
|
39
|
+
* Material 3 side sheet: secondary content or controls along the end edge of the window.
|
|
40
|
+
*
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <SideSheet open={open} onClose={() => setOpen(false)}>
|
|
43
|
+
* <SideSheetHeader>
|
|
44
|
+
* <SideSheetTitle>Filters</SideSheetTitle>
|
|
45
|
+
* <SideSheetClose />
|
|
46
|
+
* </SideSheetHeader>
|
|
47
|
+
* <SideSheetContent>…</SideSheetContent>
|
|
48
|
+
* <SideSheetActions>
|
|
49
|
+
* <Button onClick={apply}>Apply</Button>
|
|
50
|
+
* <Button variant="outlined" onClick={() => setOpen(false)}>Cancel</Button>
|
|
51
|
+
* </SideSheetActions>
|
|
52
|
+
* </SideSheet>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* - **Modal** (the default): a `<dialog>` with `showModal()`, like `Dialog` (trapped focus, inert
|
|
56
|
+
* page, scrim, Escape and a click on the scrim ask to close with `onClose(reason)`, animated exit,
|
|
57
|
+
* focus returned). It enters from the end edge (the left one in RTL), full height, with a 16
|
|
58
|
+
* radius on the content side. 320 px wide (`--mk-side-sheet-width`), and in a narrow window it
|
|
59
|
+
* leaves at least 48 px of scrim to tap and close.
|
|
60
|
+
* - **Standard** (`modal={false}`): an `<aside>` (complementary region) in the page flow, with no
|
|
61
|
+
* radius and a divider on the content side (the start: it goes at the end of the row). With
|
|
62
|
+
* `open={false}` it is hidden, and `SideSheetClose` asks for that as in the modal.
|
|
63
|
+
* - **Name:** from `SideSheetTitle` (`aria-labelledby`); without a title, pass `aria-label` or
|
|
64
|
+
* `aria-labelledby`. A modal sheet with none of them warns in development (`MK_SURFACE_UNNAMED`)
|
|
65
|
+
* once it opens. There is no description by default: point `aria-describedby` at a paragraph of
|
|
66
|
+
* your own if the sheet needs one.
|
|
67
|
+
*
|
|
68
|
+
* Native props and `ref` reach the `<dialog>` or the `<aside>`; so do `className` and `style`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function SideSheet(props: SideSheetProps): import("react").JSX.Element;
|
|
71
|
+
export interface SideSheetTitleProps extends HTMLAttributes<HTMLHeadingElement> {
|
|
72
|
+
/** Ref to the `<h2>`. */
|
|
73
|
+
ref?: Ref<HTMLHeadingElement> | undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The sheet's title (Title Large, `on-surface-variant`), in an `<h2>`. It is the sheet's accessible name. */
|
|
76
|
+
export declare function SideSheetTitle({ id, className, ...props }: SideSheetTitleProps): import("react").JSX.Element;
|
|
77
|
+
export interface SideSheetCloseProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'aria-label'> {
|
|
78
|
+
/** The button's accessible name (its `aria-label`). Defaults to "Close". */
|
|
79
|
+
label?: string | undefined;
|
|
80
|
+
'aria-label'?: never;
|
|
81
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Close button of the header (standard icon button with `close`): asks the `SideSheet` to close
|
|
85
|
+
* (`onClose('close-button')`), unless its own `onClick` calls `preventDefault()`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function SideSheetClose({ label, className, onClick, ...props }: SideSheetCloseProps): import("react").JSX.Element;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (ADR-0003, ADR-0025): el side sheet modal es un <dialog> abierto con
|
|
4
|
+
// showModal() (efecto) con la misma base que el Dialog y el BottomSheet
|
|
5
|
+
// (src/internal/modal-dialog.ts). El standard no lo necesita, pero comparte las partes: el título
|
|
6
|
+
// registra su id para aria-labelledby y el botón de cerrar pide cerrar, los dos por contexto,
|
|
7
|
+
// así que SideSheetTitle y SideSheetClose son cliente. El resto de las partes son universales
|
|
8
|
+
// (SideSheetSlots.tsx).
|
|
9
|
+
import { createContext, use, useId, useMemo, useState, } from 'react';
|
|
10
|
+
import { IconButton } from '../../molecules/IconButton/IconButton.js';
|
|
11
|
+
import { CloseIcon } from '../../icons/icons.js';
|
|
12
|
+
import { useModalDialog, useRegisteredId } from '../../internal/modal-dialog.js';
|
|
13
|
+
import { partOutsideParent } from '../../internal/diagnostics.js';
|
|
14
|
+
import { sideSheetStrings } from './strings.js';
|
|
15
|
+
const SideSheetContext = createContext(null);
|
|
16
|
+
function useSideSheet(part) {
|
|
17
|
+
const ctx = use(SideSheetContext);
|
|
18
|
+
if (!ctx)
|
|
19
|
+
throw partOutsideParent(part, 'SideSheet');
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
|
|
23
|
+
/**
|
|
24
|
+
* Material 3 side sheet: secondary content or controls along the end edge of the window.
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <SideSheet open={open} onClose={() => setOpen(false)}>
|
|
28
|
+
* <SideSheetHeader>
|
|
29
|
+
* <SideSheetTitle>Filters</SideSheetTitle>
|
|
30
|
+
* <SideSheetClose />
|
|
31
|
+
* </SideSheetHeader>
|
|
32
|
+
* <SideSheetContent>…</SideSheetContent>
|
|
33
|
+
* <SideSheetActions>
|
|
34
|
+
* <Button onClick={apply}>Apply</Button>
|
|
35
|
+
* <Button variant="outlined" onClick={() => setOpen(false)}>Cancel</Button>
|
|
36
|
+
* </SideSheetActions>
|
|
37
|
+
* </SideSheet>
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* - **Modal** (the default): a `<dialog>` with `showModal()`, like `Dialog` (trapped focus, inert
|
|
41
|
+
* page, scrim, Escape and a click on the scrim ask to close with `onClose(reason)`, animated exit,
|
|
42
|
+
* focus returned). It enters from the end edge (the left one in RTL), full height, with a 16
|
|
43
|
+
* radius on the content side. 320 px wide (`--mk-side-sheet-width`), and in a narrow window it
|
|
44
|
+
* leaves at least 48 px of scrim to tap and close.
|
|
45
|
+
* - **Standard** (`modal={false}`): an `<aside>` (complementary region) in the page flow, with no
|
|
46
|
+
* radius and a divider on the content side (the start: it goes at the end of the row). With
|
|
47
|
+
* `open={false}` it is hidden, and `SideSheetClose` asks for that as in the modal.
|
|
48
|
+
* - **Name:** from `SideSheetTitle` (`aria-labelledby`); without a title, pass `aria-label` or
|
|
49
|
+
* `aria-labelledby`. A modal sheet with none of them warns in development (`MK_SURFACE_UNNAMED`)
|
|
50
|
+
* once it opens. There is no description by default: point `aria-describedby` at a paragraph of
|
|
51
|
+
* your own if the sheet needs one.
|
|
52
|
+
*
|
|
53
|
+
* Native props and `ref` reach the `<dialog>` or the `<aside>`; so do `className` and `style`.
|
|
54
|
+
*/
|
|
55
|
+
export function SideSheet(props) {
|
|
56
|
+
return props.modal === false ? _jsx(StandardSideSheet, { ...props }) : _jsx(ModalSideSheet, { ...props });
|
|
57
|
+
}
|
|
58
|
+
function useTitle() {
|
|
59
|
+
const generatedId = useId();
|
|
60
|
+
const [titleId, setTitleId] = useState(undefined);
|
|
61
|
+
return { fallback: `${generatedId}title`, titleId, setTitleId };
|
|
62
|
+
}
|
|
63
|
+
function ModalSideSheet({ modal: _modal, open = false, onClose, closeOnScrimClick = true, className, children, ref, onCancel, onClick, onKeyDown, onPointerDown, ...props }) {
|
|
64
|
+
const { setRef, requestClose, dialogProps } = useModalDialog({
|
|
65
|
+
open,
|
|
66
|
+
onRequestClose: onClose,
|
|
67
|
+
closeOnScrimClick,
|
|
68
|
+
ref,
|
|
69
|
+
contentSelector: '.mk-side-sheet-content',
|
|
70
|
+
unnamed: {
|
|
71
|
+
component: 'SideSheet',
|
|
72
|
+
fix: 'add a <SideSheetTitle>, or pass aria-label (<SideSheet aria-label="Filters">) or aria-labelledby',
|
|
73
|
+
},
|
|
74
|
+
onCancel,
|
|
75
|
+
onClick,
|
|
76
|
+
onKeyDown,
|
|
77
|
+
onPointerDown,
|
|
78
|
+
});
|
|
79
|
+
const title = useTitle();
|
|
80
|
+
const ctx = useMemo(() => ({ titleId: title.fallback, setTitleId: title.setTitleId, requestClose }),
|
|
81
|
+
// requestClose cambia con onClose.
|
|
82
|
+
[title.fallback, title.setTitleId, onClose]);
|
|
83
|
+
const labelledBy = props['aria-labelledby'] ?? title.titleId;
|
|
84
|
+
return (_jsx(SideSheetContext, { value: ctx, children: _jsx("dialog", { ...props, ...dialogProps, ref: setRef, className: cx('mk-side-sheet mk-side-sheet-modal', className), "aria-labelledby": labelledBy || undefined, children: children }) }));
|
|
85
|
+
}
|
|
86
|
+
function StandardSideSheet({ modal: _modal, open = true, onClose, className, children, ...props }) {
|
|
87
|
+
const title = useTitle();
|
|
88
|
+
const ctx = useMemo(() => ({ titleId: title.fallback, setTitleId: title.setTitleId, requestClose: (reason) => onClose?.(reason) }), [title.fallback, title.setTitleId, onClose]);
|
|
89
|
+
const labelledBy = props['aria-labelledby'] ?? title.titleId;
|
|
90
|
+
return (_jsx(SideSheetContext, { value: ctx, children: _jsx("aside", { ...props, hidden: !open || props.hidden, className: cx('mk-side-sheet mk-side-sheet-standard', className), "aria-labelledby": labelledBy || undefined, children: children }) }));
|
|
91
|
+
}
|
|
92
|
+
/** The sheet's title (Title Large, `on-surface-variant`), in an `<h2>`. It is the sheet's accessible name. */
|
|
93
|
+
export function SideSheetTitle({ id, className, ...props }) {
|
|
94
|
+
const ctx = useSideSheet('SideSheetTitle');
|
|
95
|
+
const ownId = useRegisteredId(id, ctx.titleId, ctx.setTitleId);
|
|
96
|
+
return _jsx("h2", { ...props, id: ownId, className: cx('mk-side-sheet-title', className) });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Close button of the header (standard icon button with `close`): asks the `SideSheet` to close
|
|
100
|
+
* (`onClose('close-button')`), unless its own `onClick` calls `preventDefault()`.
|
|
101
|
+
*/
|
|
102
|
+
export function SideSheetClose({ label = sideSheetStrings.closeLabel, className, onClick, ...props }) {
|
|
103
|
+
const ctx = useSideSheet('SideSheetClose');
|
|
104
|
+
return (_jsx(IconButton, { ...props, label: label, className: cx('mk-side-sheet-close', className), onClick: (e) => {
|
|
105
|
+
onClick?.(e);
|
|
106
|
+
if (!e.defaultPrevented)
|
|
107
|
+
ctx.requestClose('close-button');
|
|
108
|
+
}, children: _jsx(CloseIcon, {}) }));
|
|
109
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HTMLAttributes, Ref } from 'react';
|
|
2
|
+
import { type IconButtonProps } from '../../molecules/IconButton/IconButton.tsx';
|
|
3
|
+
export interface SideSheetPartProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The 76 header: an optional `SideSheetBack`, `SideSheetTitle` and `SideSheetClose`, in that order.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <SideSheetHeader>
|
|
11
|
+
* <SideSheetBack onClick={back} />
|
|
12
|
+
* <SideSheetTitle>Details</SideSheetTitle>
|
|
13
|
+
* <SideSheetClose />
|
|
14
|
+
* </SideSheetHeader>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function SideSheetHeader({ className, ...props }: SideSheetPartProps): import("react").JSX.Element;
|
|
18
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
19
|
+
export type SideSheetBackProps = DistributiveOmit<IconButtonProps, 'label' | 'children' | 'width'> & {
|
|
20
|
+
/** The button's accessible name. Defaults to "Back". */
|
|
21
|
+
label?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The header's back button (a narrow standard icon button with `arrow_back`, which points right in
|
|
25
|
+
* RTL). What it does is up to its `onClick`, or `href`/`render` if it is a link.
|
|
26
|
+
*/
|
|
27
|
+
export declare function SideSheetBack({ label, className, ...props }: SideSheetBackProps): import("react").JSX.Element;
|
|
28
|
+
/** Free content, with no padding of its own; the only part that scrolls. */
|
|
29
|
+
export declare function SideSheetContent({ className, ...props }: SideSheetPartProps): import("react").JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* Actions at the bottom, with a divider above: small `Button`s (for example one filled and one
|
|
32
|
+
* outlined), aligned to the start with 8 between them.
|
|
33
|
+
*/
|
|
34
|
+
export declare function SideSheetActions({ className, ...props }: SideSheetPartProps): import("react").JSX.Element;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { IconButton } from '../../molecules/IconButton/IconButton.js';
|
|
3
|
+
import { ArrowBackIcon } from '../../icons/icons.js';
|
|
4
|
+
import { sideSheetStrings } from './strings.js';
|
|
5
|
+
const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
|
|
6
|
+
/**
|
|
7
|
+
* The 76 header: an optional `SideSheetBack`, `SideSheetTitle` and `SideSheetClose`, in that order.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <SideSheetHeader>
|
|
11
|
+
* <SideSheetBack onClick={back} />
|
|
12
|
+
* <SideSheetTitle>Details</SideSheetTitle>
|
|
13
|
+
* <SideSheetClose />
|
|
14
|
+
* </SideSheetHeader>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function SideSheetHeader({ className, ...props }) {
|
|
18
|
+
return _jsx("div", { ...props, className: cx('mk-side-sheet-header', className) });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The header's back button (a narrow standard icon button with `arrow_back`, which points right in
|
|
22
|
+
* RTL). What it does is up to its `onClick`, or `href`/`render` if it is a link.
|
|
23
|
+
*/
|
|
24
|
+
export function SideSheetBack({ label = sideSheetStrings.backLabel, className, ...props }) {
|
|
25
|
+
return (_jsx(IconButton, { ...props, label: label, width: "narrow", className: cx('mk-side-sheet-back', className), children: _jsx(ArrowBackIcon, {}) }));
|
|
26
|
+
}
|
|
27
|
+
/** Free content, with no padding of its own; the only part that scrolls. */
|
|
28
|
+
export function SideSheetContent({ className, ...props }) {
|
|
29
|
+
return _jsx("div", { ...props, className: cx('mk-side-sheet-content', className) });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Actions at the bottom, with a divider above: small `Button`s (for example one filled and one
|
|
33
|
+
* outlined), aligned to the start with 8 between them.
|
|
34
|
+
*/
|
|
35
|
+
export function SideSheetActions({ className, ...props }) {
|
|
36
|
+
return _jsx("div", { ...props, className: cx('mk-side-sheet-actions', className) });
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode, Ref } from 'react';
|
|
2
|
+
export interface SnackbarProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
/**
|
|
4
|
+
* The action below the text, aligned to the end (the kit's "longer action", Compose's
|
|
5
|
+
* `actionOnNewLine`). It is a decision of whoever writes the text, not a measurement: Compose
|
|
6
|
+
* doesn't decide it on its own either. Defaults to `false`.
|
|
7
|
+
*/
|
|
8
|
+
actionOnNewLine?: boolean | undefined;
|
|
9
|
+
/** Ref to the snackbar's `<div>`. */
|
|
10
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Material 3 snackbar: the container (radius 4, Inverse Surface, elevation 3). Children:
|
|
14
|
+
* `SnackbarMessage`, and optionally `SnackbarAction` and `SnackbarClose`, in that order.
|
|
15
|
+
*
|
|
16
|
+
* To show transient messages, use `SnackbarHost` and its queue (`useSnackbar().show(…)`), which
|
|
17
|
+
* adds the top layer, the live region, the duration and focus handling. This component only draws.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <Snackbar>
|
|
21
|
+
* <SnackbarMessage>Photo archived</SnackbarMessage>
|
|
22
|
+
* <SnackbarAction>Undo</SnackbarAction>
|
|
23
|
+
* <SnackbarClose />
|
|
24
|
+
* </Snackbar>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function Snackbar({ actionOnNewLine, className, ...rest }: SnackbarProps): import("react").JSX.Element;
|
|
28
|
+
export interface SnackbarMessageProps extends HTMLAttributes<HTMLDivElement> {
|
|
29
|
+
children?: ReactNode;
|
|
30
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The snackbar text (Body Medium, Inverse On Surface). Material recommends up to two lines. */
|
|
33
|
+
export declare function SnackbarMessage({ className, ...rest }: SnackbarMessageProps): import("react").JSX.Element;
|
|
34
|
+
export interface SnackbarActionProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
35
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
36
|
+
}
|
|
37
|
+
/** The action: a text button in Inverse Primary. Only one per snackbar. */
|
|
38
|
+
export declare function SnackbarAction({ className, ...rest }: SnackbarActionProps): import("react").JSX.Element;
|
|
39
|
+
export interface SnackbarCloseProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'aria-label'> {
|
|
40
|
+
/** Accessible name of the button (its `aria-label`). Defaults to "Close". */
|
|
41
|
+
label?: string | undefined;
|
|
42
|
+
'aria-label'?: never;
|
|
43
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
44
|
+
}
|
|
45
|
+
/** The close button: a 24 `close` icon in a 40 circle, in a 48 target at the end. */
|
|
46
|
+
export declare function SnackbarClose({ label, className, ...rest }: SnackbarCloseProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../../internal/interactive.js';
|
|
3
|
+
import { Button } from '../../molecules/Button/Button.js';
|
|
4
|
+
import { IconButton } from '../../molecules/IconButton/IconButton.js';
|
|
5
|
+
import { CloseIcon } from '../../icons/icons.js';
|
|
6
|
+
import { snackbarStrings } from './strings.js';
|
|
7
|
+
/**
|
|
8
|
+
* Material 3 snackbar: the container (radius 4, Inverse Surface, elevation 3). Children:
|
|
9
|
+
* `SnackbarMessage`, and optionally `SnackbarAction` and `SnackbarClose`, in that order.
|
|
10
|
+
*
|
|
11
|
+
* To show transient messages, use `SnackbarHost` and its queue (`useSnackbar().show(…)`), which
|
|
12
|
+
* adds the top layer, the live region, the duration and focus handling. This component only draws.
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <Snackbar>
|
|
16
|
+
* <SnackbarMessage>Photo archived</SnackbarMessage>
|
|
17
|
+
* <SnackbarAction>Undo</SnackbarAction>
|
|
18
|
+
* <SnackbarClose />
|
|
19
|
+
* </Snackbar>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function Snackbar({ actionOnNewLine, className, ...rest }) {
|
|
23
|
+
return (_jsx("div", { ...rest, className: cx('mk-snackbar', className), "data-action-on-new-line": actionOnNewLine ? '' : undefined }));
|
|
24
|
+
}
|
|
25
|
+
/** The snackbar text (Body Medium, Inverse On Surface). Material recommends up to two lines. */
|
|
26
|
+
export function SnackbarMessage({ className, ...rest }) {
|
|
27
|
+
return _jsx("div", { ...rest, className: cx('mk-snackbar-message', className) });
|
|
28
|
+
}
|
|
29
|
+
/** The action: a text button in Inverse Primary. Only one per snackbar. */
|
|
30
|
+
export function SnackbarAction({ className, ...rest }) {
|
|
31
|
+
return _jsx(Button, { ...rest, variant: "text", className: cx('mk-snackbar-action', className) });
|
|
32
|
+
}
|
|
33
|
+
/** The close button: a 24 `close` icon in a 40 circle, in a 48 target at the end. */
|
|
34
|
+
export function SnackbarClose({ label = snackbarStrings.closeLabel, className, ...rest }) {
|
|
35
|
+
return (_jsx(IconButton, { ...rest, label: label, className: cx('mk-snackbar-close', className), children: _jsx(CloseIcon, {}) }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import { type SnackbarQueue } from './snackbar-queue.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The queue of the nearest `SnackbarHost` wrapping the component. With nested hosts (one per pane,
|
|
5
|
+
* one inside a Dialog), the nearest one wins.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const snackbar = useSnackbar()
|
|
9
|
+
* const onArchive = async () => {
|
|
10
|
+
* archive()
|
|
11
|
+
* if ((await snackbar.show({ message: 'Photo archived', action: 'Undo' })) === 'action') restore()
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function useSnackbar(): SnackbarQueue;
|
|
16
|
+
export type SnackbarAlign = 'center' | 'start';
|
|
17
|
+
export interface SnackbarHostProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
18
|
+
/**
|
|
19
|
+
* The queue it renders. When undefined, the host creates its own. One queue, one host: two hosts
|
|
20
|
+
* with the same queue would show the same snackbar twice.
|
|
21
|
+
*/
|
|
22
|
+
queue?: SnackbarQueue | undefined;
|
|
23
|
+
/** The content that can call `useSnackbar()`. It can include Server Components. */
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
/** Name of the close button when the snackbar has no `closeLabel`. Defaults to "Close". */
|
|
26
|
+
closeLabel?: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Bottom and centered (as in Compose) or bottom at the start, which Material allows in wide
|
|
29
|
+
* windows. Below 600 px it always takes the window width minus the margins. Defaults to
|
|
30
|
+
* `center`.
|
|
31
|
+
*/
|
|
32
|
+
align?: SnackbarAlign | undefined;
|
|
33
|
+
/** Goes to the visible snackbar (the popover). So do `className`, `style` and the native props. */
|
|
34
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Shows the snackbars of a queue, one at a time, in the top layer (Popover), at the bottom of the
|
|
38
|
+
* window. Mount it once (for example in the layout, wrapping the app); the components inside show
|
|
39
|
+
* messages with `useSnackbar().show(…)`, which returns a promise with the result.
|
|
40
|
+
*
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <SnackbarHost>
|
|
43
|
+
* <App />
|
|
44
|
+
* </SnackbarHost>
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* - **Announcement:** a live region (`role="status"`) that always exists in the host receives the
|
|
48
|
+
* text when the snackbar appears, so it is announced once in every screen reader.
|
|
49
|
+
* - **Focus:** it doesn't move when the snackbar appears. F6 moves focus to the action (or the close
|
|
50
|
+
* button) and F6 again moves it back; Tab also reaches it, because the snackbar sits in document
|
|
51
|
+
* order where the host is. When it goes away with focus inside, focus returns to where it was.
|
|
52
|
+
* - **Timer:** pauses with the pointer over it, focus inside it or the tab hidden. Escape dismisses
|
|
53
|
+
* it when focus is inside.
|
|
54
|
+
* - **Position:** `--mk-snackbar-offset` raises it (for example, by the height of a NavigationBar
|
|
55
|
+
* or a FAB).
|
|
56
|
+
*/
|
|
57
|
+
export declare function SnackbarHost({ queue: given, children, closeLabel, align, ref, onPointerEnter, onPointerLeave, onFocus, onBlur, onKeyDown, ...rest }: SnackbarHostProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (ADR-0003): el host lee la cola (useSyncExternalStore), muestra y oculta el
|
|
4
|
+
// popover con su salida animada, lleva el tiempo con temporizadores que se detienen con el puntero,
|
|
5
|
+
// el foco y la pestaña oculta, anuncia el mensaje en una región viva y maneja Escape, F6 y la
|
|
6
|
+
// vuelta del foco. Todo eso necesita estado, efectos y eventos. Las partes visuales (Snackbar.tsx)
|
|
7
|
+
// y la cola (snackbar-queue.ts) son universales. Decisiones: ADR-0022.
|
|
8
|
+
import { createContext, use, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
9
|
+
import { mkError } from '../../internal/diagnostics.js';
|
|
10
|
+
import { mergeRefs } from '../../internal/merge-refs.js';
|
|
11
|
+
import { settleAnimations } from '../../internal/settle-animations.js';
|
|
12
|
+
import { Snackbar, SnackbarAction, SnackbarClose, SnackbarMessage } from './Snackbar.js';
|
|
13
|
+
import { createSnackbarQueue } from './snackbar-queue.js';
|
|
14
|
+
import { snackbarStrings } from './strings.js';
|
|
15
|
+
const SnackbarContext = createContext(null);
|
|
16
|
+
/**
|
|
17
|
+
* The queue of the nearest `SnackbarHost` wrapping the component. With nested hosts (one per pane,
|
|
18
|
+
* one inside a Dialog), the nearest one wins.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const snackbar = useSnackbar()
|
|
22
|
+
* const onArchive = async () => {
|
|
23
|
+
* archive()
|
|
24
|
+
* if ((await snackbar.show({ message: 'Photo archived', action: 'Undo' })) === 'action') restore()
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function useSnackbar() {
|
|
29
|
+
const queue = use(SnackbarContext);
|
|
30
|
+
if (!queue) {
|
|
31
|
+
throw mkError('MK_SNACKBAR_HOST_MISSING', {
|
|
32
|
+
component: 'useSnackbar',
|
|
33
|
+
problem: 'found no <SnackbarHost> wrapping the component',
|
|
34
|
+
fix: 'wrap the app (or the section) in <SnackbarHost>; if the host lives elsewhere in the tree, create the queue with createSnackbarQueue(), pass it to the host with `queue` and use it directly instead of useSnackbar()',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return queue;
|
|
38
|
+
}
|
|
39
|
+
// El snackbar contiene al elemento (o es él).
|
|
40
|
+
const holds = (el, node) => !!el && node instanceof Node && el.contains(node);
|
|
41
|
+
/**
|
|
42
|
+
* Shows the snackbars of a queue, one at a time, in the top layer (Popover), at the bottom of the
|
|
43
|
+
* window. Mount it once (for example in the layout, wrapping the app); the components inside show
|
|
44
|
+
* messages with `useSnackbar().show(…)`, which returns a promise with the result.
|
|
45
|
+
*
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <SnackbarHost>
|
|
48
|
+
* <App />
|
|
49
|
+
* </SnackbarHost>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* - **Announcement:** a live region (`role="status"`) that always exists in the host receives the
|
|
53
|
+
* text when the snackbar appears, so it is announced once in every screen reader.
|
|
54
|
+
* - **Focus:** it doesn't move when the snackbar appears. F6 moves focus to the action (or the close
|
|
55
|
+
* button) and F6 again moves it back; Tab also reaches it, because the snackbar sits in document
|
|
56
|
+
* order where the host is. When it goes away with focus inside, focus returns to where it was.
|
|
57
|
+
* - **Timer:** pauses with the pointer over it, focus inside it or the tab hidden. Escape dismisses
|
|
58
|
+
* it when focus is inside.
|
|
59
|
+
* - **Position:** `--mk-snackbar-offset` raises it (for example, by the height of a NavigationBar
|
|
60
|
+
* or a FAB).
|
|
61
|
+
*/
|
|
62
|
+
export function SnackbarHost({ queue: given, children, closeLabel = snackbarStrings.closeLabel, align = 'center', ref, onPointerEnter, onPointerLeave, onFocus, onBlur, onKeyDown, ...rest }) {
|
|
63
|
+
const [own] = useState(createSnackbarQueue);
|
|
64
|
+
const queue = given ?? own;
|
|
65
|
+
const current = useSyncExternalStore(queue.subscribe, () => queue.current, () => null);
|
|
66
|
+
// El que se dibuja: sigue siendo el anterior mientras sale, aunque la cola ya avanzó.
|
|
67
|
+
const [shown, setShown] = useState(null);
|
|
68
|
+
const [announcement, setAnnouncement] = useState(null);
|
|
69
|
+
const [hovered, setHovered] = useState(false);
|
|
70
|
+
const [focusWithin, setFocusWithin] = useState(false);
|
|
71
|
+
const [pageHidden, setPageHidden] = useState(false);
|
|
72
|
+
const leaving = shown !== null && current !== shown;
|
|
73
|
+
const elRef = useRef(null);
|
|
74
|
+
const mergedRef = useMemo(() => mergeRefs(ref, elRef), [ref]);
|
|
75
|
+
// Dónde estaba el foco antes de entrar al snackbar, para devolverlo.
|
|
76
|
+
const returnTo = useRef(null);
|
|
77
|
+
const timing = useRef({ id: 0, remaining: 0 });
|
|
78
|
+
// Pasar al siguiente: si no hay ninguno dibujado, se dibuja el de la cola.
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (shown === null && current !== null)
|
|
81
|
+
setShown(current);
|
|
82
|
+
}, [shown, current]);
|
|
83
|
+
// Mostrar el popover. Al cambiar de snackbar se reinician puntero y foco (el elemento es el mismo).
|
|
84
|
+
useLayoutEffect(() => {
|
|
85
|
+
const el = elRef.current;
|
|
86
|
+
if (!el || !shown)
|
|
87
|
+
return;
|
|
88
|
+
el.removeAttribute('data-closing');
|
|
89
|
+
el.inert = false;
|
|
90
|
+
if (!el.matches(':popover-open'))
|
|
91
|
+
el.showPopover();
|
|
92
|
+
setHovered(el.matches(':hover'));
|
|
93
|
+
setFocusWithin(el.matches(':focus-within'));
|
|
94
|
+
}, [shown]);
|
|
95
|
+
// Salida: el foco vuelve a donde estaba, la animación (data-closing) y recién ahí se oculta.
|
|
96
|
+
useLayoutEffect(() => {
|
|
97
|
+
const el = elRef.current;
|
|
98
|
+
if (!el || !leaving)
|
|
99
|
+
return;
|
|
100
|
+
if (el.contains(document.activeElement)) {
|
|
101
|
+
const target = returnTo.current;
|
|
102
|
+
if (target?.isConnected)
|
|
103
|
+
target.focus({ preventScroll: true });
|
|
104
|
+
else
|
|
105
|
+
document.activeElement?.blur();
|
|
106
|
+
}
|
|
107
|
+
returnTo.current = null;
|
|
108
|
+
el.setAttribute('data-closing', '');
|
|
109
|
+
el.inert = true;
|
|
110
|
+
let active = true;
|
|
111
|
+
void settleAnimations(el, () => active).then(() => {
|
|
112
|
+
if (!active)
|
|
113
|
+
return;
|
|
114
|
+
el.removeAttribute('data-closing');
|
|
115
|
+
if (el.matches(':popover-open'))
|
|
116
|
+
el.hidePopover();
|
|
117
|
+
setShown(null);
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
active = false;
|
|
121
|
+
};
|
|
122
|
+
}, [leaving]);
|
|
123
|
+
// Región viva: el texto llega un cuadro después de mostrarse, a una región que ya existía. Se
|
|
124
|
+
// vacía al irse, así el mismo mensaje dos veces seguidas también es un cambio que se anuncia.
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (!shown) {
|
|
127
|
+
setAnnouncement(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const frame = requestAnimationFrame(() => setAnnouncement(shown));
|
|
131
|
+
return () => cancelAnimationFrame(frame);
|
|
132
|
+
}, [shown]);
|
|
133
|
+
// Pestaña oculta: el tiempo no corre mientras nadie puede leerlo.
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!shown)
|
|
136
|
+
return;
|
|
137
|
+
const update = () => setPageHidden(document.visibilityState === 'hidden');
|
|
138
|
+
update();
|
|
139
|
+
document.addEventListener('visibilitychange', update);
|
|
140
|
+
return () => document.removeEventListener('visibilitychange', update);
|
|
141
|
+
}, [shown]);
|
|
142
|
+
// Tiempo: corre mientras está visible y nada lo detiene; al detenerse, guarda lo que falta.
|
|
143
|
+
const paused = hovered || focusWithin || pageHidden;
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!shown || leaving || shown.duration === Infinity)
|
|
146
|
+
return;
|
|
147
|
+
const t = timing.current;
|
|
148
|
+
if (t.id !== shown.id) {
|
|
149
|
+
t.id = shown.id;
|
|
150
|
+
t.remaining = shown.duration;
|
|
151
|
+
}
|
|
152
|
+
if (paused)
|
|
153
|
+
return;
|
|
154
|
+
const started = Date.now();
|
|
155
|
+
const timer = setTimeout(() => shown.close('timeout'), t.remaining);
|
|
156
|
+
return () => {
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
t.remaining = Math.max(0, t.remaining - (Date.now() - started));
|
|
159
|
+
};
|
|
160
|
+
}, [shown, leaving, paused]);
|
|
161
|
+
// F6: entra a la acción (o al cerrar) desde cualquier lugar de la página, y sale devolviendo el
|
|
162
|
+
// foco. Con varios hosts, el primero que lo atiende (preventDefault) gana.
|
|
163
|
+
const interactive = !!shown && !leaving && (shown.action !== undefined || shown.dismissible);
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (!interactive)
|
|
166
|
+
return;
|
|
167
|
+
const onF6 = (e) => {
|
|
168
|
+
if (e.key !== 'F6' || e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey)
|
|
169
|
+
return;
|
|
170
|
+
const el = elRef.current;
|
|
171
|
+
if (!el)
|
|
172
|
+
return;
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
if (el.contains(document.activeElement)) {
|
|
175
|
+
const target = returnTo.current;
|
|
176
|
+
if (target?.isConnected)
|
|
177
|
+
target.focus();
|
|
178
|
+
else
|
|
179
|
+
document.activeElement?.blur();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const first = el.querySelector('button');
|
|
183
|
+
// focusVisible: el anillo de foco también en WebKit, que no lo pone con focus() por script.
|
|
184
|
+
first?.focus({ focusVisible: true });
|
|
185
|
+
};
|
|
186
|
+
document.addEventListener('keydown', onF6);
|
|
187
|
+
return () => document.removeEventListener('keydown', onF6);
|
|
188
|
+
}, [interactive]);
|
|
189
|
+
const handlers = {
|
|
190
|
+
onPointerEnter: (e) => {
|
|
191
|
+
onPointerEnter?.(e);
|
|
192
|
+
setHovered(true);
|
|
193
|
+
},
|
|
194
|
+
onPointerLeave: (e) => {
|
|
195
|
+
onPointerLeave?.(e);
|
|
196
|
+
setHovered(false);
|
|
197
|
+
},
|
|
198
|
+
onFocus: (e) => {
|
|
199
|
+
onFocus?.(e);
|
|
200
|
+
if (!holds(elRef.current, e.relatedTarget)) {
|
|
201
|
+
returnTo.current = e.relatedTarget instanceof HTMLElement ? e.relatedTarget : null;
|
|
202
|
+
}
|
|
203
|
+
setFocusWithin(true);
|
|
204
|
+
},
|
|
205
|
+
onBlur: (e) => {
|
|
206
|
+
onBlur?.(e);
|
|
207
|
+
if (!holds(elRef.current, e.relatedTarget))
|
|
208
|
+
setFocusWithin(false);
|
|
209
|
+
},
|
|
210
|
+
onKeyDown: (e) => {
|
|
211
|
+
onKeyDown?.(e);
|
|
212
|
+
if (e.key !== 'Escape' || e.defaultPrevented || !shown || leaving)
|
|
213
|
+
return;
|
|
214
|
+
// Solo el snackbar: un Dialog que contiene al host no se cierra con este Escape.
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
e.stopPropagation();
|
|
217
|
+
shown.close('dismiss');
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
return (_jsxs(SnackbarContext, { value: queue, children: [children, _jsx("div", { className: "mk-snackbar-announcer", role: "status", "aria-live": "polite", "aria-atomic": "true", children: announcement && (_jsxs(_Fragment, { children: [_jsx("span", { children: announcement.message }), announcement.action !== undefined && _jsxs("span", { children: [" ", announcement.action] })] })) }), _jsx(Snackbar, { ...rest, ...handlers, ref: mergedRef, popover: "manual", "data-align": align, actionOnNewLine: shown?.actionOnNewLine, children: shown && (_jsxs(_Fragment, { children: [_jsx(SnackbarMessage, { children: shown.message }), shown.action !== undefined && (_jsx(SnackbarAction, { onClick: () => shown.close('action'), children: shown.action })), shown.dismissible && (_jsx(SnackbarClose, { label: shown.closeLabel ?? closeLabel, onClick: () => shown.close('dismiss') }))] })) })] }));
|
|
221
|
+
}
|