@matekit/react 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/LICENSE +202 -0
- package/NOTICE +56 -0
- package/README.md +115 -2
- package/dist/atoms/Divider/Divider.d.ts +49 -0
- package/dist/atoms/Divider/Divider.js +29 -0
- package/dist/atoms/FocusRing/FocusRing.d.ts +16 -0
- package/dist/atoms/FocusRing/FocusRing.js +16 -0
- package/dist/atoms/Group/Group.d.ts +38 -0
- package/dist/atoms/Group/Group.js +34 -0
- package/dist/atoms/Icon/Icon.d.ts +23 -0
- package/dist/atoms/Icon/Icon.js +19 -0
- package/dist/atoms/Interactive/Interactive.d.ts +98 -0
- package/dist/atoms/Interactive/Interactive.js +87 -0
- package/dist/atoms/Ripple/Ripple.d.ts +14 -0
- package/dist/atoms/Ripple/Ripple.js +63 -0
- package/dist/atoms/Shape/Shape.d.ts +24 -0
- package/dist/atoms/Shape/Shape.js +19 -0
- package/dist/atoms/Shape/shapes.d.ts +8 -0
- package/dist/atoms/Shape/shapes.js +40 -0
- package/dist/atoms/Stack/Stack.d.ts +58 -0
- package/dist/atoms/Stack/Stack.js +33 -0
- package/dist/atoms/StateLayer/StateLayer.d.ts +17 -0
- package/dist/atoms/StateLayer/StateLayer.js +17 -0
- package/dist/atoms/index.d.ts +10 -0
- package/dist/atoms/index.js +10 -0
- package/dist/fonts/roboto-flex/OFL.txt +93 -0
- package/dist/fonts/roboto-flex/roboto-flex-cyrillic-ext.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-cyrillic.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-greek.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-latin-ext.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-latin.woff2 +0 -0
- package/dist/fonts/roboto-flex/roboto-flex-vietnamese.woff2 +0 -0
- package/dist/icons/icons.d.ts +89 -0
- package/dist/icons/icons.js +186 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +12 -0
- package/dist/internal/accessible-name.d.ts +17 -0
- package/dist/internal/accessible-name.js +33 -0
- package/dist/internal/anchor-position.d.ts +99 -0
- package/dist/internal/anchor-position.js +159 -0
- package/dist/internal/anchored-drag.d.ts +25 -0
- package/dist/internal/anchored-drag.js +106 -0
- package/dist/internal/dev.d.ts +2 -0
- package/dist/internal/dev.js +18 -0
- package/dist/internal/diagnostics.d.ts +46 -0
- package/dist/internal/diagnostics.js +125 -0
- package/dist/internal/group-label.d.ts +22 -0
- package/dist/internal/group-label.js +50 -0
- package/dist/internal/interactive.d.ts +28 -0
- package/dist/internal/interactive.js +18 -0
- package/dist/internal/layout-element.d.ts +21 -0
- package/dist/internal/layout-element.js +33 -0
- package/dist/internal/merge-refs.d.ts +13 -0
- package/dist/internal/merge-refs.js +35 -0
- package/dist/internal/modal-dialog.d.ts +63 -0
- package/dist/internal/modal-dialog.js +267 -0
- package/dist/internal/navigation-count.d.ts +38 -0
- package/dist/internal/navigation-count.js +60 -0
- package/dist/internal/navigation-item.d.ts +14 -0
- package/dist/internal/navigation-item.js +17 -0
- package/dist/internal/nearest-scroller.d.ts +4 -0
- package/dist/internal/nearest-scroller.js +17 -0
- package/dist/internal/open-state.d.ts +15 -0
- package/dist/internal/open-state.js +42 -0
- package/dist/internal/roving-focus.d.ts +41 -0
- package/dist/internal/roving-focus.js +126 -0
- package/dist/internal/settle-animations.d.ts +33 -0
- package/dist/internal/settle-animations.js +48 -0
- package/dist/internal/time-period.d.ts +10 -0
- package/dist/internal/time-period.js +26 -0
- package/dist/internal/time.d.ts +23 -0
- package/dist/internal/time.js +69 -0
- package/dist/internal/typeahead.d.ts +17 -0
- package/dist/internal/typeahead.js +35 -0
- package/dist/molecules/Badge/Badge.d.ts +25 -0
- package/dist/molecules/Badge/Badge.js +16 -0
- package/dist/molecules/Button/Button.d.ts +48 -0
- package/dist/molecules/Button/Button.js +34 -0
- package/dist/molecules/Card/Card.d.ts +159 -0
- package/dist/molecules/Card/Card.js +119 -0
- package/dist/molecules/Checkbox/Checkbox.d.ts +26 -0
- package/dist/molecules/Checkbox/Checkbox.js +40 -0
- package/dist/molecules/Chip/AssistChip.d.ts +23 -0
- package/dist/molecules/Chip/AssistChip.js +22 -0
- package/dist/molecules/Chip/ChipGroup.d.ts +85 -0
- package/dist/molecules/Chip/ChipGroup.js +92 -0
- package/dist/molecules/Chip/FilterChip.d.ts +33 -0
- package/dist/molecules/Chip/FilterChip.js +30 -0
- package/dist/molecules/Chip/InputChip.d.ts +60 -0
- package/dist/molecules/Chip/InputChip.js +107 -0
- package/dist/molecules/Chip/SuggestionChip.d.ts +24 -0
- package/dist/molecules/Chip/SuggestionChip.js +17 -0
- package/dist/molecules/Chip/chip-content.d.ts +39 -0
- package/dist/molecules/Chip/chip-content.js +95 -0
- package/dist/molecules/Chip/chip-element.d.ts +14 -0
- package/dist/molecules/Chip/chip-element.js +14 -0
- package/dist/molecules/Chip/strings.d.ts +8 -0
- package/dist/molecules/Chip/strings.js +5 -0
- package/dist/molecules/Fab/Fab.d.ts +78 -0
- package/dist/molecules/Fab/Fab.js +52 -0
- package/dist/molecules/IconButton/IconButton.d.ts +59 -0
- package/dist/molecules/IconButton/IconButton.js +36 -0
- package/dist/molecules/LoadingIndicator/LoadingIndicator.d.ts +38 -0
- package/dist/molecules/LoadingIndicator/LoadingIndicator.js +25 -0
- package/dist/molecules/LoadingIndicator/determinate.d.ts +3 -0
- package/dist/molecules/LoadingIndicator/determinate.js +47 -0
- package/dist/molecules/LoadingIndicator/loading-indicator-data.d.ts +21 -0
- package/dist/molecules/LoadingIndicator/loading-indicator-data.js +72 -0
- package/dist/molecules/ProgressIndicator/CircularProgressIndicator.d.ts +35 -0
- package/dist/molecules/ProgressIndicator/CircularProgressIndicator.js +30 -0
- package/dist/molecules/ProgressIndicator/LinearProgressIndicator.d.ts +43 -0
- package/dist/molecules/ProgressIndicator/LinearProgressIndicator.js +28 -0
- package/dist/molecules/ProgressIndicator/circular-wavy-data.d.ts +5 -0
- package/dist/molecules/ProgressIndicator/circular-wavy-data.js +19 -0
- package/dist/molecules/ProgressIndicator/progress.d.ts +24 -0
- package/dist/molecules/ProgressIndicator/progress.js +60 -0
- package/dist/molecules/RadioButton/RadioButton.d.ts +27 -0
- package/dist/molecules/RadioButton/RadioButton.js +70 -0
- package/dist/molecules/RadioButton/RadioGroup.d.ts +73 -0
- package/dist/molecules/RadioButton/RadioGroup.js +82 -0
- package/dist/molecules/ScrollField/ScrollField.d.ts +61 -0
- package/dist/molecules/ScrollField/ScrollField.js +352 -0
- package/dist/molecules/Slider/RangeSlider.d.ts +60 -0
- package/dist/molecules/Slider/RangeSlider.js +169 -0
- package/dist/molecules/Slider/Slider.d.ts +54 -0
- package/dist/molecules/Slider/Slider.js +71 -0
- package/dist/molecules/Slider/slider-shared.d.ts +26 -0
- package/dist/molecules/Slider/slider-shared.js +98 -0
- package/dist/molecules/Switch/Switch.d.ts +22 -0
- package/dist/molecules/Switch/Switch.js +20 -0
- package/dist/molecules/TextField/TextField.d.ts +83 -0
- package/dist/molecules/TextField/TextField.js +146 -0
- package/dist/molecules/TextField/TextFieldSlots.d.ts +22 -0
- package/dist/molecules/TextField/TextFieldSlots.js +24 -0
- package/dist/molecules/TimeInput/TimeInput.d.ts +108 -0
- package/dist/molecules/TimeInput/TimeInput.js +347 -0
- package/dist/molecules/TimeInput/strings.d.ts +13 -0
- package/dist/molecules/TimeInput/strings.js +10 -0
- package/dist/molecules/TimeScroll/TimeScroll.d.ts +106 -0
- package/dist/molecules/TimeScroll/TimeScroll.js +213 -0
- package/dist/molecules/TimeScroll/strings.d.ts +13 -0
- package/dist/molecules/TimeScroll/strings.js +12 -0
- package/dist/molecules/index.d.ts +27 -0
- package/dist/molecules/index.js +25 -0
- package/dist/organisms/BottomSheet/BottomSheet.d.ts +128 -0
- package/dist/organisms/BottomSheet/BottomSheet.js +432 -0
- package/dist/organisms/BottomSheet/BottomSheetSlots.d.ts +17 -0
- package/dist/organisms/BottomSheet/BottomSheetSlots.js +16 -0
- package/dist/organisms/BottomSheet/StandardBottomSheet.d.ts +37 -0
- package/dist/organisms/BottomSheet/StandardBottomSheet.js +206 -0
- package/dist/organisms/BottomSheet/bottom-sheet-context.d.ts +31 -0
- package/dist/organisms/BottomSheet/bottom-sheet-context.js +12 -0
- package/dist/organisms/BottomSheet/sheet-drag.d.ts +1 -0
- package/dist/organisms/BottomSheet/sheet-drag.js +4 -0
- package/dist/organisms/BottomSheet/strings.d.ts +9 -0
- package/dist/organisms/BottomSheet/strings.js +8 -0
- package/dist/organisms/ButtonGroup/ButtonGroup.d.ts +97 -0
- package/dist/organisms/ButtonGroup/ButtonGroup.js +242 -0
- package/dist/organisms/ButtonGroup/ButtonGroupItem.d.ts +36 -0
- package/dist/organisms/ButtonGroup/ButtonGroupItem.js +47 -0
- package/dist/organisms/Dialog/Dialog.d.ts +186 -0
- package/dist/organisms/Dialog/Dialog.js +193 -0
- package/dist/organisms/Dialog/DialogSlots.d.ts +60 -0
- package/dist/organisms/Dialog/DialogSlots.js +54 -0
- package/dist/organisms/Dialog/strings.d.ts +5 -0
- package/dist/organisms/Dialog/strings.js +5 -0
- package/dist/organisms/FabMenu/FabMenu.d.ts +104 -0
- package/dist/organisms/FabMenu/FabMenu.js +142 -0
- package/dist/organisms/FabMenu/strings.d.ts +9 -0
- package/dist/organisms/FabMenu/strings.js +5 -0
- package/dist/organisms/List/List.d.ts +190 -0
- package/dist/organisms/List/List.js +148 -0
- package/dist/organisms/Menu/Menu.d.ts +313 -0
- package/dist/organisms/Menu/Menu.js +865 -0
- package/dist/organisms/Menu/MenuSlots.d.ts +35 -0
- package/dist/organisms/Menu/MenuSlots.js +36 -0
- package/dist/organisms/NavigationBar/NavigationBar.d.ts +96 -0
- package/dist/organisms/NavigationBar/NavigationBar.js +77 -0
- package/dist/organisms/NavigationRail/ModalNavigationRail.d.ts +105 -0
- package/dist/organisms/NavigationRail/ModalNavigationRail.js +272 -0
- package/dist/organisms/NavigationRail/NavigationRail.d.ts +148 -0
- package/dist/organisms/NavigationRail/NavigationRail.js +114 -0
- package/dist/organisms/NavigationRail/NavigationRailSection.d.ts +54 -0
- package/dist/organisms/NavigationRail/NavigationRailSection.js +96 -0
- package/dist/organisms/NavigationRail/strings.d.ts +7 -0
- package/dist/organisms/NavigationRail/strings.js +7 -0
- package/dist/organisms/NavigationSuite/NavigationSuite.d.ts +109 -0
- package/dist/organisms/NavigationSuite/NavigationSuite.js +86 -0
- package/dist/organisms/PaneScaffold/PaneScaffold.d.ts +118 -0
- package/dist/organisms/PaneScaffold/PaneScaffold.js +132 -0
- package/dist/organisms/Search/Search.d.ts +213 -0
- package/dist/organisms/Search/Search.js +783 -0
- package/dist/organisms/Search/SearchSlots.d.ts +18 -0
- package/dist/organisms/Search/SearchSlots.js +19 -0
- package/dist/organisms/Search/strings.d.ts +21 -0
- package/dist/organisms/Search/strings.js +12 -0
- package/dist/organisms/Select/Select.d.ts +186 -0
- package/dist/organisms/Select/Select.js +597 -0
- package/dist/organisms/Select/SelectSlots.d.ts +12 -0
- package/dist/organisms/Select/SelectSlots.js +12 -0
- package/dist/organisms/SideSheet/SideSheet.d.ts +88 -0
- package/dist/organisms/SideSheet/SideSheet.js +109 -0
- package/dist/organisms/SideSheet/SideSheetSlots.d.ts +35 -0
- package/dist/organisms/SideSheet/SideSheetSlots.js +37 -0
- package/dist/organisms/SideSheet/strings.d.ts +7 -0
- package/dist/organisms/SideSheet/strings.js +6 -0
- package/dist/organisms/Snackbar/Snackbar.d.ts +46 -0
- package/dist/organisms/Snackbar/Snackbar.js +36 -0
- package/dist/organisms/Snackbar/SnackbarHost.d.ts +57 -0
- package/dist/organisms/Snackbar/SnackbarHost.js +221 -0
- package/dist/organisms/Snackbar/snackbar-queue.d.ts +81 -0
- package/dist/organisms/Snackbar/snackbar-queue.js +114 -0
- package/dist/organisms/Snackbar/strings.d.ts +8 -0
- package/dist/organisms/Snackbar/strings.js +5 -0
- package/dist/organisms/SplitButton/SplitButton.d.ts +73 -0
- package/dist/organisms/SplitButton/SplitButton.js +77 -0
- package/dist/organisms/SplitButton/strings.d.ts +9 -0
- package/dist/organisms/SplitButton/strings.js +5 -0
- package/dist/organisms/Tabs/TabLink.d.ts +27 -0
- package/dist/organisms/Tabs/TabLink.js +25 -0
- package/dist/organisms/Tabs/TabNav.d.ts +19 -0
- package/dist/organisms/Tabs/TabNav.js +55 -0
- package/dist/organisms/Tabs/Tabs.d.ts +147 -0
- package/dist/organisms/Tabs/Tabs.js +223 -0
- package/dist/organisms/Tabs/tab-content.d.ts +23 -0
- package/dist/organisms/Tabs/tab-content.js +105 -0
- package/dist/organisms/Tabs/tab-fit.d.ts +4 -0
- package/dist/organisms/Tabs/tab-fit.js +65 -0
- package/dist/organisms/Tabs/tab-motion.d.ts +2 -0
- package/dist/organisms/Tabs/tab-motion.js +68 -0
- package/dist/organisms/TimePickerDialog/TimePickerDialog.d.ts +26 -0
- package/dist/organisms/TimePickerDialog/TimePickerDialog.js +34 -0
- package/dist/organisms/Toolbar/Toolbar.d.ts +75 -0
- package/dist/organisms/Toolbar/Toolbar.js +84 -0
- package/dist/organisms/Toolbar/ToolbarLayout.d.ts +44 -0
- package/dist/organisms/Toolbar/ToolbarLayout.js +90 -0
- package/dist/organisms/Toolbar/ToolbarScroll.d.ts +8 -0
- package/dist/organisms/Toolbar/ToolbarScroll.js +222 -0
- package/dist/organisms/Tooltip/RichTooltip.d.ts +73 -0
- package/dist/organisms/Tooltip/RichTooltip.js +250 -0
- package/dist/organisms/Tooltip/Tooltip.d.ts +52 -0
- package/dist/organisms/Tooltip/Tooltip.js +99 -0
- package/dist/organisms/Tooltip/tooltip-behavior.d.ts +43 -0
- package/dist/organisms/Tooltip/tooltip-behavior.js +307 -0
- package/dist/organisms/TopAppBar/TopAppBar.d.ts +107 -0
- package/dist/organisms/TopAppBar/TopAppBar.js +78 -0
- package/dist/organisms/TopAppBar/TopAppBarScroll.d.ts +7 -0
- package/dist/organisms/TopAppBar/TopAppBarScroll.js +155 -0
- package/dist/organisms/index.d.ts +36 -0
- package/dist/organisms/index.js +36 -0
- package/dist/palettes/blue.css +275 -0
- package/dist/palettes/green.css +275 -0
- package/dist/palettes/index.css +823 -0
- package/dist/palettes/orange.css +275 -0
- package/dist/shapes.css +115 -0
- package/dist/strings/index.d.ts +35 -0
- package/dist/strings/index.js +39 -0
- package/dist/styles-no-fonts.css +12025 -0
- package/dist/styles.css +12123 -0
- package/dist/stylesheet.d.ts +2 -0
- package/dist/tokens/breakpoints.d.ts +33 -0
- package/dist/tokens/breakpoints.js +31 -0
- package/dist/tokens/space.d.ts +26 -0
- package/dist/tokens/space.js +26 -0
- package/package.json +110 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { partOutsideParent } from '../../internal/diagnostics.js';
|
|
4
|
+
import { Button } from '../../molecules/Button/Button.js';
|
|
5
|
+
import { IconButton } from '../../molecules/IconButton/IconButton.js';
|
|
6
|
+
import { useButtonGroupContext } from './ButtonGroup.js';
|
|
7
|
+
function useItem(part, value, onClick) {
|
|
8
|
+
const ctx = useButtonGroupContext();
|
|
9
|
+
if (!ctx)
|
|
10
|
+
throw partOutsideParent(part, 'ButtonGroup');
|
|
11
|
+
return {
|
|
12
|
+
connected: ctx.variant === 'connected',
|
|
13
|
+
// Sin selección en el grupo, es un botón común (sin aria-pressed).
|
|
14
|
+
selected: ctx.selectionMode === 'none' ? undefined : ctx.value.includes(value),
|
|
15
|
+
onClick: (event) => {
|
|
16
|
+
onClick?.(event);
|
|
17
|
+
if (!event.defaultPrevented)
|
|
18
|
+
ctx.toggle(value, event);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Text (and icon) button of a `ButtonGroup` that handles selection: selected according to the
|
|
24
|
+
* group's `value` (`aria-pressed`). In the connected variant it defaults to `tonal` (the kit's
|
|
25
|
+
* colors); in the standard one, to the Button's default style.
|
|
26
|
+
*
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <ButtonGroupItem value="week"><CalendarIcon />Week</ButtonGroupItem>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function ButtonGroupItem({ value, variant, onClick, ...props }) {
|
|
32
|
+
const item = useItem('ButtonGroupItem', value, onClick);
|
|
33
|
+
return (_jsx(Button, { ...props, value: value, variant: variant ?? (item.connected ? 'tonal' : undefined), selected: item.selected, onClick: item.onClick }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Icon button of a `ButtonGroup` that handles selection (`label` is required, as in IconButton). In
|
|
37
|
+
* the connected variant it defaults to `tonal`; in the standard one, to the IconButton's default
|
|
38
|
+
* style.
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <ButtonGroupIconItem value="bold" label="Bold"><BoldIcon /></ButtonGroupIconItem>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function ButtonGroupIconItem({ value, variant, onClick, ...props }) {
|
|
45
|
+
const item = useItem('ButtonGroupIconItem', value, onClick);
|
|
46
|
+
return (_jsx(IconButton, { ...props, value: value, variant: variant ?? (item.connected ? 'tonal' : undefined), selected: item.selected, onClick: item.onClick }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type DialogHTMLAttributes, type HTMLAttributes, type Ref } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Why a dialog asks to close (`onClose(reason)`):
|
|
4
|
+
* - `close-button`: `DialogClose` (the close button of a full-screen dialog's header);
|
|
5
|
+
* - `escape`: Escape, or the platform's close request (Android back), including the second
|
|
6
|
+
* Escape in a row that Chrome does not let the page cancel;
|
|
7
|
+
* - `scrim`: a click on the scrim (with `closeOnScrimClick`);
|
|
8
|
+
* - `native`: the `<dialog>` closed itself without matekit: a `<form method="dialog">`, a
|
|
9
|
+
* `command="close"` button or a call to `close()`.
|
|
10
|
+
*/
|
|
11
|
+
export type DialogCloseReason = 'close-button' | 'escape' | 'scrim' | 'native';
|
|
12
|
+
/**
|
|
13
|
+
* How the dialog is presented (`view`):
|
|
14
|
+
* - `basic`: the basic dialog, centered over a scrim;
|
|
15
|
+
* - `full-screen`: it fills the window, for long forms or tasks on small screens;
|
|
16
|
+
* - `auto`: full screen in a compact window (narrower than 600 px or shorter than 480 px, the same
|
|
17
|
+
* breakpoints as `NavigationSuite`), basic otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export type DialogView = 'basic' | 'full-screen' | 'auto';
|
|
20
|
+
export interface DialogProps extends Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open' | 'onClose'> {
|
|
21
|
+
/**
|
|
22
|
+
* Open (modal) or closed. Controlled: the app opens the dialog (it has no trigger of its own) and
|
|
23
|
+
* the dialog only changes when `open` changes.
|
|
24
|
+
*/
|
|
25
|
+
open?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* A **close request**, with the reason (`DialogCloseReason`): `DialogClose`, Escape, the scrim or a
|
|
28
|
+
* native close.
|
|
29
|
+
* The dialog does not close by itself: the app decides by passing `open={false}`, or refuses by
|
|
30
|
+
* keeping `open` (the dialog stays open and modal), for example to confirm before discarding a
|
|
31
|
+
* form only when the reason is `'scrim'`.
|
|
32
|
+
*/
|
|
33
|
+
onClose?: ((reason: DialogCloseReason) => void) | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Whether a click on the scrim asks to close (`onClose('scrim')`). Defaults to `true`, as in
|
|
36
|
+
* Compose (`DialogProperties.dismissOnClickOutside`) and `@material/web`. With `false`, only
|
|
37
|
+
* Escape or the actions close it; useful for alerts that demand an answer.
|
|
38
|
+
*/
|
|
39
|
+
closeOnScrimClick?: boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Alert dialog (`role="alertdialog"`): an important message that demands an answer, such as a
|
|
42
|
+
* destructive confirmation. Same as `type="alert"` in `@material/web`. Put the message in
|
|
43
|
+
* `DialogSupporting` so it is announced with the headline (APG: an alert dialog is described by its
|
|
44
|
+
* message).
|
|
45
|
+
*/
|
|
46
|
+
alert?: boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Presentation (`DialogView`). `full-screen` fills the window (`surface`, square corners, no
|
|
49
|
+
* scrim) and slides up from the bottom, for long forms or tasks on small screens: put a
|
|
50
|
+
* `DialogHeader` first, with `DialogClose`, the `DialogHeadline` and the confirming action (a
|
|
51
|
+
* `text` `Button`). `auto` is full screen only in a compact window (narrower than 600 px or
|
|
52
|
+
* shorter than 480 px, like `NavigationSuite`); otherwise it is a basic dialog with the same
|
|
53
|
+
* header, 560 px wide by default. The switch is a CSS media query, so the server HTML and the
|
|
54
|
+
* client HTML are the same.
|
|
55
|
+
*
|
|
56
|
+
* Defaults to `basic`.
|
|
57
|
+
*/
|
|
58
|
+
view?: DialogView | undefined;
|
|
59
|
+
/** Ref to the native `<dialog>`. */
|
|
60
|
+
ref?: Ref<HTMLDialogElement> | undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Material 3 modal dialog, on the native `<dialog>` opened with `showModal()`: focus is trapped,
|
|
64
|
+
* the rest of the page is inert and the scrim is the `::backdrop`.
|
|
65
|
+
*
|
|
66
|
+
* ```tsx
|
|
67
|
+
* const [open, setOpen] = useState(false)
|
|
68
|
+
*
|
|
69
|
+
* <Dialog open={open} onClose={() => setOpen(false)}>
|
|
70
|
+
* <DialogIcon><DeleteIcon /></DialogIcon>
|
|
71
|
+
* <DialogHeadline>Delete file?</DialogHeadline>
|
|
72
|
+
* <DialogContent>
|
|
73
|
+
* <DialogSupporting>This cannot be undone.</DialogSupporting>
|
|
74
|
+
* </DialogContent>
|
|
75
|
+
* <DialogActions>
|
|
76
|
+
* <Button variant="text" onClick={() => setOpen(false)}>Cancel</Button>
|
|
77
|
+
* <Button variant="text" onClick={remove}>Delete</Button>
|
|
78
|
+
* </DialogActions>
|
|
79
|
+
* </Dialog>
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* - **Open and close:** the app opens it with `open`; the dialog asks to close with `onClose(reason)`
|
|
83
|
+
* (Escape, scrim, a native close; see `DialogCloseReason`) and the app decides. It has no trigger
|
|
84
|
+
* of its own, so it reports a close request, not an open state (`onOpenChange` is for components
|
|
85
|
+
* with a trigger part, like `Menu`). To refuse, do not change `open`:
|
|
86
|
+
*
|
|
87
|
+
* ```tsx
|
|
88
|
+
* <Dialog
|
|
89
|
+
* open={open}
|
|
90
|
+
* onClose={(reason) => {
|
|
91
|
+
* // A stray click on the scrim must not lose the form: ask first.
|
|
92
|
+
* if (reason === 'scrim' && dirty) setConfirming(true)
|
|
93
|
+
* else setOpen(false)
|
|
94
|
+
* }}
|
|
95
|
+
* >
|
|
96
|
+
* ```
|
|
97
|
+
* - **Name:** from `DialogHeadline` (`aria-labelledby`), without passing ids. Without a headline,
|
|
98
|
+
* pass `aria-label` or `aria-labelledby`; with none of them, development builds warn
|
|
99
|
+
* (`MK_SURFACE_UNNAMED`) once the dialog opens.
|
|
100
|
+
* - **Description:** only what you ask for. `DialogSupporting` (the supporting text, usually inside
|
|
101
|
+
* `DialogContent`) becomes the `aria-describedby`, read together with the name on open; or pass
|
|
102
|
+
* your own `aria-describedby`. `DialogContent` alone is not a description: a list or a form in it
|
|
103
|
+
* would be read in full before the user can act.
|
|
104
|
+
* - **Focus:** on open, the browser focuses the first focusable element (or the dialog, if there
|
|
105
|
+
* is none); mark another one with `data-autofocus`. React's `autoFocus` does not work here: React
|
|
106
|
+
* does not write the attribute, it calls `focus()` on mount, while the dialog is still closed. On
|
|
107
|
+
* close, focus returns to the element that had it before opening.
|
|
108
|
+
* - **Animated exit:** with `open={false}` the dialog animates out and only then calls `close()`.
|
|
109
|
+
* Keep the `Dialog` mounted and change `open` to see it; unmounted, it disappears at once.
|
|
110
|
+
* - While open, the page does not scroll (`overflow: hidden` on `<html>`, in CSS).
|
|
111
|
+
* - **Full screen:** `view="full-screen"` (or `view="auto"`, only in compact windows), with a
|
|
112
|
+
* `DialogHeader`:
|
|
113
|
+
*
|
|
114
|
+
* ```tsx
|
|
115
|
+
* <Dialog view="auto" open={open} onClose={() => setOpen(false)}>
|
|
116
|
+
* <DialogHeader>
|
|
117
|
+
* <DialogClose />
|
|
118
|
+
* <DialogHeadline>New event</DialogHeadline>
|
|
119
|
+
* <Button variant="text" type="submit" form="new-event">Save</Button>
|
|
120
|
+
* </DialogHeader>
|
|
121
|
+
* <DialogContent>
|
|
122
|
+
* <form id="new-event" onSubmit={save}>…</form>
|
|
123
|
+
* </DialogContent>
|
|
124
|
+
* </Dialog>
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* The header stays fixed while the content scrolls under it, and turns `surface-container` once
|
|
128
|
+
* there is content beneath. With `viewport-fit=cover` in the viewport meta tag, the dialog keeps
|
|
129
|
+
* its content inside the safe areas (`env(safe-area-inset-*)`). With
|
|
130
|
+
* `interactive-widget=resizes-content`, it shrinks above the on-screen keyboard; otherwise the
|
|
131
|
+
* browser pans to the focused field.
|
|
132
|
+
*
|
|
133
|
+
* Native props and `ref` reach the `<dialog>`; so do `className` and `style` (it is the visible
|
|
134
|
+
* container). Default width 312 px (`--mk-dialog-width`), between 280 and 560.
|
|
135
|
+
*/
|
|
136
|
+
export declare function Dialog({ open, onClose, closeOnScrimClick, alert, view, className, children, ref, onCancel, onClick, onKeyDown, onPointerDown, ...props }: DialogProps): import("react").JSX.Element;
|
|
137
|
+
export interface DialogHeadlineProps extends HTMLAttributes<HTMLHeadingElement> {
|
|
138
|
+
/** Ref to the `<h2>`. */
|
|
139
|
+
ref?: Ref<HTMLHeadingElement> | undefined;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Dialog headline (Headline Small, `on-surface`), in an `<h2>`. It is the dialog's accessible name
|
|
143
|
+
* (`aria-labelledby`). With `DialogIcon`, it is centered.
|
|
144
|
+
*/
|
|
145
|
+
export declare function DialogHeadline({ id, className, ...props }: DialogHeadlineProps): import("react").JSX.Element;
|
|
146
|
+
export interface DialogSupportingProps extends HTMLAttributes<HTMLDivElement> {
|
|
147
|
+
/** Ref to the text container. */
|
|
148
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Supporting text of the dialog (the kit's "supporting text", Compose's `text`): the message that
|
|
152
|
+
* explains the headline. It is the dialog's accessible description (`aria-describedby`), so a screen
|
|
153
|
+
* reader reads it with the name on open. Place it inside `DialogContent` (it scrolls with it):
|
|
154
|
+
*
|
|
155
|
+
* ```tsx
|
|
156
|
+
* <DialogContent>
|
|
157
|
+
* <DialogSupporting>This cannot be undone.</DialogSupporting>
|
|
158
|
+
* </DialogContent>
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* Before a list or a form, it describes just the intro, not the controls:
|
|
162
|
+
*
|
|
163
|
+
* ```tsx
|
|
164
|
+
* <DialogContent>
|
|
165
|
+
* <DialogSupporting>Choose where to save the copy.</DialogSupporting>
|
|
166
|
+
* <List>…</List>
|
|
167
|
+
* </DialogContent>
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* One per dialog. With your own `aria-describedby` on the `Dialog`, that one wins.
|
|
171
|
+
*/
|
|
172
|
+
export declare function DialogSupporting({ id, className, ...props }: DialogSupportingProps): import("react").JSX.Element;
|
|
173
|
+
export interface DialogCloseProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'aria-label'> {
|
|
174
|
+
/** The button's accessible name (its `aria-label`). Defaults to "Close". */
|
|
175
|
+
label?: string | undefined;
|
|
176
|
+
'aria-label'?: never;
|
|
177
|
+
/** Ref to the `<button>`. */
|
|
178
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Close button (standard icon button with `close`, `on-surface`), the first item of a full-screen
|
|
182
|
+
* dialog's `DialogHeader`. It asks the `Dialog` to close (`onClose('close-button')`), unless its own
|
|
183
|
+
* `onClick` calls `preventDefault()`. Like every close request, the app can refuse it, for example to
|
|
184
|
+
* ask before discarding a form with changes.
|
|
185
|
+
*/
|
|
186
|
+
export declare function DialogClose({ label, className, onClick, ...props }: DialogCloseProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Organismo interactivo (ADR-0003): el <dialog> nativo solo queda modal (foco atrapado, fondo
|
|
4
|
+
// inerte, ::backdrop como scrim) si se abre con showModal(), que es una llamada del navegador;
|
|
5
|
+
// además escucha Escape (cancel) y el clic en el fondo, y espera el fin de la animación de
|
|
6
|
+
// salida antes de close(). Todo eso necesita efectos y eventos en el cliente.
|
|
7
|
+
//
|
|
8
|
+
// El título y el texto de apoyo comparten ids con el <dialog> para aria-labelledby y
|
|
9
|
+
// aria-describedby; esos ids viajan por contexto, así que DialogHeadline y DialogSupporting también
|
|
10
|
+
// son cliente (mismo patrón que TextFieldLabel y TextFieldSupporting). DialogIcon, DialogContent y
|
|
11
|
+
// DialogActions no necesitan nada de eso y son universales: están en DialogSlots.tsx.
|
|
12
|
+
//
|
|
13
|
+
// Pantalla completa (ítem 24b del plan, ADR-0041): `view` solo escribe data-view; el cambio de
|
|
14
|
+
// presentación es CSS (dialog.css), también el de `auto` por el tamaño de la ventana, así el HTML del servidor y el del cliente son iguales (sin desajuste al hidratar).
|
|
15
|
+
// DialogClose pide cerrar por contexto ('close-button'), como SideSheetClose: es cliente y vive acá;
|
|
16
|
+
// DialogHeader, la barra, es universal (DialogSlots.tsx).
|
|
17
|
+
//
|
|
18
|
+
// Descripción (ADR-0035): solo DialogSupporting (o el aria-describedby de la app) describe el
|
|
19
|
+
// diálogo. Antes lo hacía todo DialogContent, y con una lista o un formulario adentro el lector leía
|
|
20
|
+
// todo al abrir.
|
|
21
|
+
import { createContext, use, useId, useMemo, useState, } from 'react';
|
|
22
|
+
import { IconButton } from '../../molecules/IconButton/IconButton.js';
|
|
23
|
+
import { CloseIcon } from '../../icons/icons.js';
|
|
24
|
+
import { useModalDialog, useRegisteredId } from '../../internal/modal-dialog.js';
|
|
25
|
+
import { partOutsideParent } from '../../internal/diagnostics.js';
|
|
26
|
+
import { dialogStrings } from './strings.js';
|
|
27
|
+
const DialogContext = createContext(null);
|
|
28
|
+
function useDialog(part) {
|
|
29
|
+
const ctx = use(DialogContext);
|
|
30
|
+
if (!ctx)
|
|
31
|
+
throw partOutsideParent(part, 'Dialog');
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
|
|
35
|
+
/**
|
|
36
|
+
* Material 3 modal dialog, on the native `<dialog>` opened with `showModal()`: focus is trapped,
|
|
37
|
+
* the rest of the page is inert and the scrim is the `::backdrop`.
|
|
38
|
+
*
|
|
39
|
+
* ```tsx
|
|
40
|
+
* const [open, setOpen] = useState(false)
|
|
41
|
+
*
|
|
42
|
+
* <Dialog open={open} onClose={() => setOpen(false)}>
|
|
43
|
+
* <DialogIcon><DeleteIcon /></DialogIcon>
|
|
44
|
+
* <DialogHeadline>Delete file?</DialogHeadline>
|
|
45
|
+
* <DialogContent>
|
|
46
|
+
* <DialogSupporting>This cannot be undone.</DialogSupporting>
|
|
47
|
+
* </DialogContent>
|
|
48
|
+
* <DialogActions>
|
|
49
|
+
* <Button variant="text" onClick={() => setOpen(false)}>Cancel</Button>
|
|
50
|
+
* <Button variant="text" onClick={remove}>Delete</Button>
|
|
51
|
+
* </DialogActions>
|
|
52
|
+
* </Dialog>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* - **Open and close:** the app opens it with `open`; the dialog asks to close with `onClose(reason)`
|
|
56
|
+
* (Escape, scrim, a native close; see `DialogCloseReason`) and the app decides. It has no trigger
|
|
57
|
+
* of its own, so it reports a close request, not an open state (`onOpenChange` is for components
|
|
58
|
+
* with a trigger part, like `Menu`). To refuse, do not change `open`:
|
|
59
|
+
*
|
|
60
|
+
* ```tsx
|
|
61
|
+
* <Dialog
|
|
62
|
+
* open={open}
|
|
63
|
+
* onClose={(reason) => {
|
|
64
|
+
* // A stray click on the scrim must not lose the form: ask first.
|
|
65
|
+
* if (reason === 'scrim' && dirty) setConfirming(true)
|
|
66
|
+
* else setOpen(false)
|
|
67
|
+
* }}
|
|
68
|
+
* >
|
|
69
|
+
* ```
|
|
70
|
+
* - **Name:** from `DialogHeadline` (`aria-labelledby`), without passing ids. Without a headline,
|
|
71
|
+
* pass `aria-label` or `aria-labelledby`; with none of them, development builds warn
|
|
72
|
+
* (`MK_SURFACE_UNNAMED`) once the dialog opens.
|
|
73
|
+
* - **Description:** only what you ask for. `DialogSupporting` (the supporting text, usually inside
|
|
74
|
+
* `DialogContent`) becomes the `aria-describedby`, read together with the name on open; or pass
|
|
75
|
+
* your own `aria-describedby`. `DialogContent` alone is not a description: a list or a form in it
|
|
76
|
+
* would be read in full before the user can act.
|
|
77
|
+
* - **Focus:** on open, the browser focuses the first focusable element (or the dialog, if there
|
|
78
|
+
* is none); mark another one with `data-autofocus`. React's `autoFocus` does not work here: React
|
|
79
|
+
* does not write the attribute, it calls `focus()` on mount, while the dialog is still closed. On
|
|
80
|
+
* close, focus returns to the element that had it before opening.
|
|
81
|
+
* - **Animated exit:** with `open={false}` the dialog animates out and only then calls `close()`.
|
|
82
|
+
* Keep the `Dialog` mounted and change `open` to see it; unmounted, it disappears at once.
|
|
83
|
+
* - While open, the page does not scroll (`overflow: hidden` on `<html>`, in CSS).
|
|
84
|
+
* - **Full screen:** `view="full-screen"` (or `view="auto"`, only in compact windows), with a
|
|
85
|
+
* `DialogHeader`:
|
|
86
|
+
*
|
|
87
|
+
* ```tsx
|
|
88
|
+
* <Dialog view="auto" open={open} onClose={() => setOpen(false)}>
|
|
89
|
+
* <DialogHeader>
|
|
90
|
+
* <DialogClose />
|
|
91
|
+
* <DialogHeadline>New event</DialogHeadline>
|
|
92
|
+
* <Button variant="text" type="submit" form="new-event">Save</Button>
|
|
93
|
+
* </DialogHeader>
|
|
94
|
+
* <DialogContent>
|
|
95
|
+
* <form id="new-event" onSubmit={save}>…</form>
|
|
96
|
+
* </DialogContent>
|
|
97
|
+
* </Dialog>
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* The header stays fixed while the content scrolls under it, and turns `surface-container` once
|
|
101
|
+
* there is content beneath. With `viewport-fit=cover` in the viewport meta tag, the dialog keeps
|
|
102
|
+
* its content inside the safe areas (`env(safe-area-inset-*)`). With
|
|
103
|
+
* `interactive-widget=resizes-content`, it shrinks above the on-screen keyboard; otherwise the
|
|
104
|
+
* browser pans to the focused field.
|
|
105
|
+
*
|
|
106
|
+
* Native props and `ref` reach the `<dialog>`; so do `className` and `style` (it is the visible
|
|
107
|
+
* container). Default width 312 px (`--mk-dialog-width`), between 280 and 560.
|
|
108
|
+
*/
|
|
109
|
+
export function Dialog({ open = false, onClose, closeOnScrimClick = true, alert = false, view = 'basic', className, children, ref, onCancel, onClick, onKeyDown, onPointerDown, ...props }) {
|
|
110
|
+
// El ciclo de vida modal (showModal, Escape, scrim, Tab, salida animada, devolución del foco)
|
|
111
|
+
// es la base común de src/internal/modal-dialog.ts (ADR-0025).
|
|
112
|
+
// Controlado: Escape, el scrim y el cierre nativo piden cerrar con su motivo (ADR-0034).
|
|
113
|
+
const { setRef, requestClose, dialogProps } = useModalDialog({
|
|
114
|
+
open,
|
|
115
|
+
onRequestClose: onClose,
|
|
116
|
+
closeOnScrimClick,
|
|
117
|
+
ref,
|
|
118
|
+
contentSelector: '.mk-dialog-content',
|
|
119
|
+
unnamed: {
|
|
120
|
+
component: 'Dialog',
|
|
121
|
+
fix: 'add a <DialogHeadline>, or pass aria-label (<Dialog aria-label="Delete file">) or aria-labelledby',
|
|
122
|
+
},
|
|
123
|
+
onCancel,
|
|
124
|
+
onClick,
|
|
125
|
+
onKeyDown,
|
|
126
|
+
onPointerDown,
|
|
127
|
+
});
|
|
128
|
+
const generatedId = useId();
|
|
129
|
+
const [headlineId, setHeadlineId] = useState(undefined);
|
|
130
|
+
const [supportingId, setSupportingId] = useState(undefined);
|
|
131
|
+
const ctx = useMemo(() => ({
|
|
132
|
+
headlineId: `${generatedId}headline`,
|
|
133
|
+
supportingId: `${generatedId}supporting`,
|
|
134
|
+
setHeadlineId,
|
|
135
|
+
setSupportingId,
|
|
136
|
+
requestClose,
|
|
137
|
+
}),
|
|
138
|
+
// requestClose cambia con onClose.
|
|
139
|
+
[generatedId, onClose]);
|
|
140
|
+
const labelledBy = props['aria-labelledby'] ?? headlineId;
|
|
141
|
+
const describedBy = props['aria-describedby'] ?? supportingId;
|
|
142
|
+
return (_jsx(DialogContext, { value: ctx, children: _jsx("dialog", { role: alert ? 'alertdialog' : undefined, ...props, ...dialogProps, ref: setRef, className: cx('mk-dialog', className), "data-view": view === 'basic' ? undefined : view, "aria-labelledby": labelledBy || undefined, "aria-describedby": describedBy || undefined, children: children }) }));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Dialog headline (Headline Small, `on-surface`), in an `<h2>`. It is the dialog's accessible name
|
|
146
|
+
* (`aria-labelledby`). With `DialogIcon`, it is centered.
|
|
147
|
+
*/
|
|
148
|
+
export function DialogHeadline({ id, className, ...props }) {
|
|
149
|
+
const ctx = useDialog('DialogHeadline');
|
|
150
|
+
const ownId = useRegisteredId(id, ctx.headlineId, ctx.setHeadlineId);
|
|
151
|
+
return _jsx("h2", { ...props, id: ownId, className: cx('mk-dialog-headline', className) });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Supporting text of the dialog (the kit's "supporting text", Compose's `text`): the message that
|
|
155
|
+
* explains the headline. It is the dialog's accessible description (`aria-describedby`), so a screen
|
|
156
|
+
* reader reads it with the name on open. Place it inside `DialogContent` (it scrolls with it):
|
|
157
|
+
*
|
|
158
|
+
* ```tsx
|
|
159
|
+
* <DialogContent>
|
|
160
|
+
* <DialogSupporting>This cannot be undone.</DialogSupporting>
|
|
161
|
+
* </DialogContent>
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* Before a list or a form, it describes just the intro, not the controls:
|
|
165
|
+
*
|
|
166
|
+
* ```tsx
|
|
167
|
+
* <DialogContent>
|
|
168
|
+
* <DialogSupporting>Choose where to save the copy.</DialogSupporting>
|
|
169
|
+
* <List>…</List>
|
|
170
|
+
* </DialogContent>
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* One per dialog. With your own `aria-describedby` on the `Dialog`, that one wins.
|
|
174
|
+
*/
|
|
175
|
+
export function DialogSupporting({ id, className, ...props }) {
|
|
176
|
+
const ctx = useDialog('DialogSupporting');
|
|
177
|
+
const ownId = useRegisteredId(id, ctx.supportingId, ctx.setSupportingId);
|
|
178
|
+
return _jsx("div", { ...props, id: ownId, className: cx('mk-dialog-supporting', className) });
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Close button (standard icon button with `close`, `on-surface`), the first item of a full-screen
|
|
182
|
+
* dialog's `DialogHeader`. It asks the `Dialog` to close (`onClose('close-button')`), unless its own
|
|
183
|
+
* `onClick` calls `preventDefault()`. Like every close request, the app can refuse it, for example to
|
|
184
|
+
* ask before discarding a form with changes.
|
|
185
|
+
*/
|
|
186
|
+
export function DialogClose({ label = dialogStrings.closeLabel, className, onClick, ...props }) {
|
|
187
|
+
const ctx = useDialog('DialogClose');
|
|
188
|
+
return (_jsx(IconButton, { ...props, label: label, className: cx('mk-dialog-close', className), onClick: (e) => {
|
|
189
|
+
onClick?.(e);
|
|
190
|
+
if (!e.defaultPrevented)
|
|
191
|
+
ctx.requestClose('close-button');
|
|
192
|
+
}, children: _jsx(CloseIcon, {}) }));
|
|
193
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { HTMLAttributes, Ref } from 'react';
|
|
2
|
+
export interface DialogIconProps extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
ref?: Ref<HTMLSpanElement> | undefined;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Optional icon above the headline: 24 px, `secondary` color. With an icon, the icon and the
|
|
7
|
+
* headline are centered (the body text stays start-aligned, as in Compose).
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <DialogIcon><DeleteIcon /></DialogIcon>
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function DialogIcon({ className, ...props }: DialogIconProps): import("react").JSX.Element;
|
|
14
|
+
export interface DialogContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
15
|
+
/** Ref to the content container. */
|
|
16
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Body of the dialog (Body Medium, `on-surface-variant`): text, a list, a form. If it does not fit
|
|
20
|
+
* on screen, only this part scrolls: the headline and the actions stay fixed. It is **not** the
|
|
21
|
+
* dialog's description: for that, put the message in `DialogSupporting` inside it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function DialogContent({ className, ...props }: DialogContentProps): import("react").JSX.Element;
|
|
24
|
+
export interface DialogActionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
25
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The dialog's actions, aligned to the end with 8 px between them; if they do not fit in one row,
|
|
29
|
+
* they wrap to the next. Use `text` style `Button`s. The confirming action goes last.
|
|
30
|
+
*
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <DialogActions>
|
|
33
|
+
* <Button variant="text" onClick={cancel}>Cancel</Button>
|
|
34
|
+
* <Button variant="text" onClick={confirm}>OK</Button>
|
|
35
|
+
* </DialogActions>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function DialogActions({ className, ...props }: DialogActionsProps): import("react").JSX.Element;
|
|
39
|
+
export interface DialogHeaderProps extends HTMLAttributes<HTMLDivElement> {
|
|
40
|
+
/** Ref to the header container. */
|
|
41
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The header bar of a full-screen dialog (`view="full-screen"`, or `auto`): 56 px high, with `DialogClose` at the
|
|
45
|
+
* start, the `DialogHeadline` (Title Large) and the confirming action at the end, usually a `text`
|
|
46
|
+
* `Button` ("Save"). It stays fixed while `DialogContent` scrolls under it.
|
|
47
|
+
*
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <DialogHeader>
|
|
50
|
+
* <DialogClose />
|
|
51
|
+
* <DialogHeadline>New event</DialogHeadline>
|
|
52
|
+
* <Button variant="text" onClick={save}>Save</Button>
|
|
53
|
+
* </DialogHeader>
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* The order is also the focus order: close, then the action, then the content. On open, focus goes
|
|
57
|
+
* to the close button (the first focusable element); mark the first field with `data-autofocus` to
|
|
58
|
+
* start there instead.
|
|
59
|
+
*/
|
|
60
|
+
export declare function DialogHeader({ className, ...props }: DialogHeaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Optional icon above the headline: 24 px, `secondary` color. With an icon, the icon and the
|
|
4
|
+
* headline are centered (the body text stays start-aligned, as in Compose).
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* <DialogIcon><DeleteIcon /></DialogIcon>
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export function DialogIcon({ className, ...props }) {
|
|
11
|
+
return _jsx("span", { ...props, className: className ? `mk-dialog-icon ${className}` : 'mk-dialog-icon' });
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Body of the dialog (Body Medium, `on-surface-variant`): text, a list, a form. If it does not fit
|
|
15
|
+
* on screen, only this part scrolls: the headline and the actions stay fixed. It is **not** the
|
|
16
|
+
* dialog's description: for that, put the message in `DialogSupporting` inside it.
|
|
17
|
+
*/
|
|
18
|
+
export function DialogContent({ className, ...props }) {
|
|
19
|
+
return _jsx("div", { ...props, className: className ? `mk-dialog-content ${className}` : 'mk-dialog-content' });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The dialog's actions, aligned to the end with 8 px between them; if they do not fit in one row,
|
|
23
|
+
* they wrap to the next. Use `text` style `Button`s. The confirming action goes last.
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <DialogActions>
|
|
27
|
+
* <Button variant="text" onClick={cancel}>Cancel</Button>
|
|
28
|
+
* <Button variant="text" onClick={confirm}>OK</Button>
|
|
29
|
+
* </DialogActions>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function DialogActions({ className, ...props }) {
|
|
33
|
+
return _jsx("div", { ...props, className: className ? `mk-dialog-actions ${className}` : 'mk-dialog-actions' });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The header bar of a full-screen dialog (`view="full-screen"`, or `auto`): 56 px high, with `DialogClose` at the
|
|
37
|
+
* start, the `DialogHeadline` (Title Large) and the confirming action at the end, usually a `text`
|
|
38
|
+
* `Button` ("Save"). It stays fixed while `DialogContent` scrolls under it.
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <DialogHeader>
|
|
42
|
+
* <DialogClose />
|
|
43
|
+
* <DialogHeadline>New event</DialogHeadline>
|
|
44
|
+
* <Button variant="text" onClick={save}>Save</Button>
|
|
45
|
+
* </DialogHeader>
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* The order is also the focus order: close, then the action, then the content. On open, focus goes
|
|
49
|
+
* to the close button (the first focusable element); mark the first field with `data-autofocus` to
|
|
50
|
+
* start there instead.
|
|
51
|
+
*/
|
|
52
|
+
export function DialogHeader({ className, ...props }) {
|
|
53
|
+
return _jsx("div", { ...props, className: className ? `mk-dialog-header ${className}` : 'mk-dialog-header' });
|
|
54
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import type { ButtonElementProps } from '../../atoms/Interactive/Interactive.tsx';
|
|
3
|
+
import { type FabColor, type FabSize } from '../../molecules/Fab/Fab.tsx';
|
|
4
|
+
import { type MenuItemProps, type MenuProps } from '../Menu/Menu.tsx';
|
|
5
|
+
/**
|
|
6
|
+
* The kit's color sets, named like `FabColor` after the color of the closed FAB: the closed FAB
|
|
7
|
+
* and the items in `X-container` with `on-X-container`; open, the close button in `X` with `on-X`.
|
|
8
|
+
*/
|
|
9
|
+
export type FabMenuColor = Extract<FabColor, 'primary-container' | 'secondary-container' | 'tertiary-container'>;
|
|
10
|
+
export interface FabMenuItemDelay {
|
|
11
|
+
enter: number;
|
|
12
|
+
exit: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function fabMenuStagger(count: number): FabMenuItemDelay[];
|
|
15
|
+
export interface FabMenuProps extends MenuProps {
|
|
16
|
+
/**
|
|
17
|
+
* Color set of the FAB and the items, named after the closed FAB's color, the same values as
|
|
18
|
+
* `Fab`'s `color` (`FabMenuColor`). Defaults to `primary-container`.
|
|
19
|
+
*/
|
|
20
|
+
color?: FabMenuColor | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Material 3 Expressive FAB menu: a FAB that morphs into the close button and shows a column of
|
|
24
|
+
* actions above it, aligned to its end edge. It is matekit's `Menu` (the WAI-ARIA APG "menu button"
|
|
25
|
+
* pattern) with another presentation: it renders no element, it groups the FAB (`FabMenuTrigger`)
|
|
26
|
+
* and the column (`FabMenuContent`). It takes the `Menu` props (`open`, `defaultOpen`,
|
|
27
|
+
* `onOpenChange(open, reason)` with `MenuOpenChangeReason`).
|
|
28
|
+
*
|
|
29
|
+
* **It does not position itself**, like `Fab`: the app places the `FabMenuTrigger` (for example in
|
|
30
|
+
* the bottom end corner, 16 px from the edges); the column appears in the top layer, 8 px above the
|
|
31
|
+
* FAB.
|
|
32
|
+
*
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <FabMenu color="tertiary-container">
|
|
35
|
+
* <FabMenuTrigger label="Create"><AddIcon /></FabMenuTrigger>
|
|
36
|
+
* <FabMenuContent>
|
|
37
|
+
* <FabMenuItem onSelect={newNote}><EditIcon />Note</FabMenuItem>
|
|
38
|
+
* <FabMenuItem onSelect={newList}><CheckIcon />List</FabMenuItem>
|
|
39
|
+
* </FabMenuContent>
|
|
40
|
+
* </FabMenu>
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* - **Keyboard** (the Menu's): on the FAB, Enter, Space and Down Arrow open it and focus the first
|
|
44
|
+
* item (the top one); Up Arrow, the last one (closest to the FAB). Inside, arrows with wrap-around,
|
|
45
|
+
* Home, End and typeahead; Escape closes and returns focus to the FAB; Tab closes and moves on.
|
|
46
|
+
* - A click on the open FAB, or outside the column, closes it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function FabMenu({ color, children, ...props }: FabMenuProps): import("react").JSX.Element;
|
|
49
|
+
export interface FabMenuTriggerProps extends Omit<ButtonElementProps, 'aria-label' | 'disabled' | 'aria-haspopup' | 'aria-expanded' | 'aria-controls'> {
|
|
50
|
+
/**
|
|
51
|
+
* Accessible name of the FAB (becomes `aria-label`), which also names the menu. Defaults to
|
|
52
|
+
* "More actions"; prefer one that names the actions ("Create"). It does not change on open:
|
|
53
|
+
* `aria-expanded` announces the state.
|
|
54
|
+
*/
|
|
55
|
+
label?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Size of the closed FAB: `sm` 56, `md` 80 or `lg` 96 px, the FAB sizes (`FabSize`), which are
|
|
58
|
+
* not the `Button` sizes (`xs`…`xl`, other heights: a FAB `sm` is as tall as a Button `md`). Open,
|
|
59
|
+
* the close button is always 56 and sits at the top-end corner of the FAB's place, which does not
|
|
60
|
+
* change. Defaults to `sm`.
|
|
61
|
+
*/
|
|
62
|
+
size?: FabSize | undefined;
|
|
63
|
+
/** Lower elevation, as in `Fab` (`lowered`). */
|
|
64
|
+
lowered?: boolean | undefined;
|
|
65
|
+
/** The closed FAB's icon (`<AddIcon />`); when open, it crossfades with the close icon. */
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The FAB that opens and closes the menu, inside a `FabMenu`: a `Fab` `<button>` with
|
|
70
|
+
* `aria-haspopup="menu"`, `aria-expanded`, `aria-controls` and the `MenuTrigger` events. Closed it is
|
|
71
|
+
* a regular FAB in `X-container`; open it morphs (FastSpatial spring) into the kit's close button:
|
|
72
|
+
* 56 × 56, round, in `X` with `on-X` and the 20 px close icon. `size` takes the FAB sizes (`sm`/`md`/
|
|
73
|
+
* `lg` = 56/80/96), not the `Button` ones. Native props, `onClick`, `onKeyDown`, `className`, `style`
|
|
74
|
+
* and `ref` reach the `<button>` (an `onClick` with `preventDefault()` does not open the menu).
|
|
75
|
+
*/
|
|
76
|
+
export declare function FabMenuTrigger({ label, size, lowered, className, children, ...props }: FabMenuTriggerProps): import("react").JSX.Element;
|
|
77
|
+
export interface FabMenuContentProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'color'> {
|
|
78
|
+
/** Ref to the container (`role="menu"`, a popover). */
|
|
79
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
80
|
+
/** The `FabMenuItem`s, from the top down to the FAB. */
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The column of actions: the Menu's `MenuContent` (`role="menu"`, a popover in the top layer named
|
|
85
|
+
* after the FAB), with no background or shadow, placed above the FAB and aligned to its end edge
|
|
86
|
+
* (CSS anchor positioning), with 4 px between items and 8 to the FAB. Each item appears staggered,
|
|
87
|
+
* from the FAB upwards, growing from the end edge.
|
|
88
|
+
*
|
|
89
|
+
* The items must be direct children (the stagger counts the children). Native props, `className`,
|
|
90
|
+
* `style` and `ref` reach the container.
|
|
91
|
+
*/
|
|
92
|
+
export declare function FabMenuContent({ className, children, ...props }: FabMenuContentProps): import("react").JSX.Element;
|
|
93
|
+
/** `FabMenuItem` props: those of a regular `MenuItem` (an action, no selection). */
|
|
94
|
+
export type FabMenuItemProps = Omit<Extract<MenuItemProps, {
|
|
95
|
+
type?: 'item' | undefined;
|
|
96
|
+
}>, 'type' | 'selected'>;
|
|
97
|
+
/**
|
|
98
|
+
* An action of the FAB menu: a `MenuItem` (`role="menuitem"`, out of the Tab order) shaped as a
|
|
99
|
+
* 56 px pill, in `X-container` with `on-X-container`, a 24 px icon and a Title Medium label, written
|
|
100
|
+
* as children (`<EditIcon />Note`). Choosing it calls `onSelect` and closes the menu; `disabled`
|
|
101
|
+
* announces it and keeps it focusable without activating it (APG), dimmed. Native props and `ref`
|
|
102
|
+
* reach the `<button>`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function FabMenuItem({ className, style, ...props }: FabMenuItemProps): import("react").JSX.Element;
|