@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,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { chipElement } from './chip-element.js';
|
|
3
|
+
import { useChipGroupContext } from './ChipGroup.js';
|
|
4
|
+
/**
|
|
5
|
+
* Filter chip: a toggle that filters content ("Vegan", "Free shipping"). When selected, it is
|
|
6
|
+
* filled in `secondary-container` and shows a check mark at the start.
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <FilterChip selected={vegan} onClick={() => setVegan(!vegan)}>Vegan</FilterChip>
|
|
10
|
+
* <ChipGroup aria-label="Diet" selectionMode="multiple" defaultValue={['vegan']}>
|
|
11
|
+
* <FilterChip value="vegan">Vegan</FilterChip>
|
|
12
|
+
* <FilterChip value="gluten-free">Gluten-free</FilterChip>
|
|
13
|
+
* </ChipGroup>
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Your own `onClick` is called before the group is notified; with `event.preventDefault()`, the
|
|
17
|
+
* group doesn't change the selection.
|
|
18
|
+
*/
|
|
19
|
+
export function FilterChip(props) {
|
|
20
|
+
const { variant = 'outlined', selected: selectedProp, value, onClick, className, children, ...rest } = props;
|
|
21
|
+
const group = useChipGroupContext();
|
|
22
|
+
const fromGroup = selectedProp === undefined && value !== undefined && group !== null && group.selectionMode !== 'none';
|
|
23
|
+
const selected = selectedProp ?? (fromGroup ? group.value.includes(value) : false);
|
|
24
|
+
const handleClick = (event) => {
|
|
25
|
+
onClick?.(event);
|
|
26
|
+
if (fromGroup && !event.defaultPrevented)
|
|
27
|
+
group.toggle(value, event);
|
|
28
|
+
};
|
|
29
|
+
return chipElement({ name: 'FilterChip', type: 'filter', variant, selected, checkWhenSelected: true, className, children }, { ...rest, value, onClick: handleClick });
|
|
30
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type CSSProperties, type HTMLAttributes, type KeyboardEvent, type MouseEvent, type ReactNode, type Ref } from 'react';
|
|
2
|
+
export type InputChipRemoveEvent = KeyboardEvent<HTMLElement> | MouseEvent<HTMLButtonElement>;
|
|
3
|
+
interface InputChipOwnProps {
|
|
4
|
+
/** Optional icon or `ChipAvatar` and the text: `<ChipAvatar><img alt="" src="…" /></ChipAvatar>Ana`. */
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* Called when removing the chip is requested (remove button, Delete or Backspace). You remove it
|
|
8
|
+
* from your list; the chip doesn't hide itself.
|
|
9
|
+
*/
|
|
10
|
+
onRemove: (event: InputChipRemoveEvent) => void;
|
|
11
|
+
/**
|
|
12
|
+
* First part of the remove button's name, followed by the chip's label ("Remove Ana"). Defaults
|
|
13
|
+
* to "Remove". If the chip has an `aria-label`, that is used instead of the label.
|
|
14
|
+
*/
|
|
15
|
+
removeLabel?: string | undefined;
|
|
16
|
+
/** Disables both actions. */
|
|
17
|
+
disabled?: boolean | undefined;
|
|
18
|
+
/** Class of the chip's container. */
|
|
19
|
+
className?: string | undefined;
|
|
20
|
+
/** Style of the chip's container. */
|
|
21
|
+
style?: CSSProperties | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The primary action is a `<button>` (selectable with `selected`). */
|
|
24
|
+
interface InputChipButtonProps extends InputChipOwnProps, Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof InputChipOwnProps> {
|
|
25
|
+
removeOnly?: false | undefined;
|
|
26
|
+
/** Selected: `aria-pressed` on the primary action and the `secondary-container` fill. */
|
|
27
|
+
selected?: boolean | undefined;
|
|
28
|
+
/** Ref to the primary `<button>`. */
|
|
29
|
+
ref?: Ref<HTMLButtonElement> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** No primary action: the chip can only be removed (the label is text). */
|
|
32
|
+
interface InputChipRemoveOnlyProps extends InputChipOwnProps, Omit<HTMLAttributes<HTMLSpanElement>, keyof InputChipOwnProps> {
|
|
33
|
+
removeOnly: true;
|
|
34
|
+
selected?: undefined;
|
|
35
|
+
/** Ref to the label's `<span>`. */
|
|
36
|
+
ref?: Ref<HTMLSpanElement> | undefined;
|
|
37
|
+
}
|
|
38
|
+
export type InputChipProps = InputChipButtonProps | InputChipRemoveOnlyProps;
|
|
39
|
+
/**
|
|
40
|
+
* Input chip: a piece of data the user entered (a recipient, a tag), with a button to remove it.
|
|
41
|
+
* You manage the list:
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <ChipGroup aria-label="Recipients">
|
|
45
|
+
* {people.map((p) => (
|
|
46
|
+
* <InputChip key={p.id} onRemove={() => setPeople((l) => l.filter((x) => x !== p))}>
|
|
47
|
+
* <ChipAvatar><img alt="" src={p.photo} /></ChipAvatar>{p.name}
|
|
48
|
+
* </InputChip>
|
|
49
|
+
* ))}
|
|
50
|
+
* </ChipGroup>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* With `removeOnly`, the label is not a button (it can only be removed). Native props and the
|
|
54
|
+
* `ref` go to the primary action; `className` and `style`, to the container.
|
|
55
|
+
*
|
|
56
|
+
* After removal, if focus was lost with the chip, it moves to the next chip, or the previous one
|
|
57
|
+
* if it was the last, or to the group if no chips are left; focus you move in `onRemove` is kept.
|
|
58
|
+
*/
|
|
59
|
+
export declare function InputChip(props: InputChipProps): import("react").JSX.Element;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Molécula interactiva (excepción al ADR-0003, ADR-0019): escucha Supr y Retroceso y, después de
|
|
4
|
+
// que el uso quita el chip, mueve el foco al chip vecino. Eso necesita eventos y una referencia
|
|
5
|
+
// al DOM, que solo existen en el cliente.
|
|
6
|
+
//
|
|
7
|
+
// Dos acciones en un mismo chip, como el input chip de @material/web (chips/internal/
|
|
8
|
+
// input-chip.ts y trailing-icons.ts): la principal (un `<button>`, o solo texto con `removeOnly`)
|
|
9
|
+
// y el botón de quitar, con nombre "Remove <etiqueta>" (por defecto) armado con aria-labelledby. El contenedor
|
|
10
|
+
// (`<span>`) dibuja el chip y no es interactivo: no hay controles anidados.
|
|
11
|
+
//
|
|
12
|
+
// Quitar (ADR-0019): el chip avisa con `onRemove(event)` y el uso saca el elemento de su lista
|
|
13
|
+
// (controlado; el chip no se esconde solo). Con Supr o Retroceso sobre cualquiera de las dos
|
|
14
|
+
// acciones (como React Aria TagGroup, useTag.ts; @material/web no lo tiene) o con el botón. Si el
|
|
15
|
+
// chip desaparece y el foco se perdió con él, va al chip siguiente, o al anterior si era el
|
|
16
|
+
// último, o al grupo si no quedan chips. Si el uso movió el foco en `onRemove` (por ejemplo a su
|
|
17
|
+
// campo de texto), se respeta.
|
|
18
|
+
import { useId, useRef, } from 'react';
|
|
19
|
+
import { FocusRing } from '../../atoms/FocusRing/FocusRing.js';
|
|
20
|
+
import { Ripple } from '../../atoms/Ripple/Ripple.js';
|
|
21
|
+
import { StateLayer } from '../../atoms/StateLayer/StateLayer.js';
|
|
22
|
+
import { CloseIcon } from '../../icons/icons.js';
|
|
23
|
+
import { cx } from '../../internal/interactive.js';
|
|
24
|
+
import { chipContent, chipDataAttributes } from './chip-content.js';
|
|
25
|
+
import { inputChipStrings } from './strings.js';
|
|
26
|
+
const FOCUSABLE = '[data-chip-stop]:not(:disabled)';
|
|
27
|
+
// El primer elemento enfocable del chip vecino (siguiente, o anterior si no hay), o el grupo.
|
|
28
|
+
function focusTargetAfterRemoving(chip) {
|
|
29
|
+
const group = chip.closest('.mk-chip-group');
|
|
30
|
+
const scope = group ?? chip.parentElement;
|
|
31
|
+
if (!scope)
|
|
32
|
+
return null;
|
|
33
|
+
const chips = [...scope.querySelectorAll('[data-chip]')].filter((el) => (el.closest('.mk-chip-group') ?? scope) === (group ?? scope));
|
|
34
|
+
const firstStop = (el) => (el.matches(FOCUSABLE) ? el : el.querySelector(FOCUSABLE));
|
|
35
|
+
const index = chips.indexOf(chip);
|
|
36
|
+
for (const candidate of [...chips.slice(index + 1), ...chips.slice(0, index).reverse()]) {
|
|
37
|
+
const stop = firstStop(candidate);
|
|
38
|
+
if (stop)
|
|
39
|
+
return stop;
|
|
40
|
+
}
|
|
41
|
+
if (group) {
|
|
42
|
+
if (!group.hasAttribute('tabindex'))
|
|
43
|
+
group.tabIndex = -1;
|
|
44
|
+
return group;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const focusLost = () => document.activeElement === null || document.activeElement === document.body;
|
|
49
|
+
/**
|
|
50
|
+
* Input chip: a piece of data the user entered (a recipient, a tag), with a button to remove it.
|
|
51
|
+
* You manage the list:
|
|
52
|
+
*
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <ChipGroup aria-label="Recipients">
|
|
55
|
+
* {people.map((p) => (
|
|
56
|
+
* <InputChip key={p.id} onRemove={() => setPeople((l) => l.filter((x) => x !== p))}>
|
|
57
|
+
* <ChipAvatar><img alt="" src={p.photo} /></ChipAvatar>{p.name}
|
|
58
|
+
* </InputChip>
|
|
59
|
+
* ))}
|
|
60
|
+
* </ChipGroup>
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* With `removeOnly`, the label is not a button (it can only be removed). Native props and the
|
|
64
|
+
* `ref` go to the primary action; `className` and `style`, to the container.
|
|
65
|
+
*
|
|
66
|
+
* After removal, if focus was lost with the chip, it moves to the next chip, or the previous one
|
|
67
|
+
* if it was the last, or to the group if no chips are left; focus you move in `onRemove` is kept.
|
|
68
|
+
*/
|
|
69
|
+
export function InputChip(props) {
|
|
70
|
+
const { children, onRemove, removeLabel = inputChipStrings.removeLabel, disabled = false, className, style, removeOnly, selected, onKeyDown, ...rest } = props;
|
|
71
|
+
const rootRef = useRef(null);
|
|
72
|
+
const labelId = useId();
|
|
73
|
+
const removeId = useId();
|
|
74
|
+
const content = chipContent(children, { check: selected === true, labelId });
|
|
75
|
+
const ariaLabel = rest['aria-label'];
|
|
76
|
+
const remove = (event) => {
|
|
77
|
+
const chip = rootRef.current;
|
|
78
|
+
if (disabled || !chip)
|
|
79
|
+
return;
|
|
80
|
+
const target = focusTargetAfterRemoving(chip);
|
|
81
|
+
onRemove(event);
|
|
82
|
+
// React aplica la actualización de un evento discreto al terminar el evento; se revisa en una
|
|
83
|
+
// microtarea y, por si el uso la difiere (una transición), en los dos cuadros siguientes.
|
|
84
|
+
const settle = (frames) => {
|
|
85
|
+
if (!chip.isConnected) {
|
|
86
|
+
if (focusLost() && target?.isConnected)
|
|
87
|
+
target.focus({ focusVisible: event.type === 'keydown' });
|
|
88
|
+
}
|
|
89
|
+
else if (frames > 0) {
|
|
90
|
+
requestAnimationFrame(() => settle(frames - 1));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
queueMicrotask(() => settle(2));
|
|
94
|
+
};
|
|
95
|
+
const handleKeyDown = (event) => {
|
|
96
|
+
;
|
|
97
|
+
onKeyDown?.(event);
|
|
98
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey)
|
|
99
|
+
return;
|
|
100
|
+
if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
remove(event);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const primary = removeOnly ? (_jsx("span", { ...rest, className: "mk-input-chip-primary", onKeyDown: handleKeyDown, children: content.content })) : (_jsxs("button", { ...rest, ...(selected === undefined ? {} : { 'aria-pressed': selected }), type: rest.type ?? 'button', disabled: disabled, className: "mk-input-chip-primary", "data-chip-stop": "", onKeyDown: handleKeyDown, children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), content.content] }));
|
|
106
|
+
return (_jsxs("span", { ref: rootRef, className: cx('mk-input-chip', className), style: style, "data-chip": "input", "data-selected": selected ? '' : undefined, "data-disabled": disabled ? '' : undefined, "data-remove-only": removeOnly ? '' : undefined, ...chipDataAttributes(content), children: [primary, _jsx("span", { id: removeId, hidden: true, children: ariaLabel ? `${removeLabel} ${ariaLabel}` : removeLabel }), _jsxs("button", { type: "button", className: "mk-input-chip-remove", "data-chip-stop": "", "aria-labelledby": ariaLabel ? removeId : `${removeId} ${labelId}`, disabled: disabled, onClick: remove, onKeyDown: handleKeyDown, children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), _jsx(CloseIcon, {})] })] }));
|
|
107
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ToggleButtonOrLinkProps } from '../../internal/interactive.tsx';
|
|
3
|
+
import type { ChipVariant } from './chip-content.tsx';
|
|
4
|
+
interface SuggestionChipOwnProps {
|
|
5
|
+
/** `outlined` or `elevated`. Defaults to `outlined`. */
|
|
6
|
+
variant?: ChipVariant | undefined;
|
|
7
|
+
/** An optional icon and the text. */
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* SuggestionChip props: its own plus one of the three forms of ADR-0010. Only the `<button>`
|
|
12
|
+
* accepts `selected` (toggle) and `disabled`.
|
|
13
|
+
*/
|
|
14
|
+
export type SuggestionChipProps = ToggleButtonOrLinkProps<SuggestionChipOwnProps>;
|
|
15
|
+
/**
|
|
16
|
+
* Suggestion chip: a suggested reply or search the user picks ("Sounds good").
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <SuggestionChip onClick={() => reply('Sure')}>Sure</SuggestionChip>
|
|
20
|
+
* <SuggestionChip href="/search?q=empanadas">Empanadas</SuggestionChip>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function SuggestionChip(props: SuggestionChipProps): import("react").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Molécula universal (ADR-0003): sin estado, efectos ni contexto; no lleva 'use client'.
|
|
2
|
+
// Como AssistChip (ver su comentario): botón, `href` o `render` (ADR-0010). El kit también tiene
|
|
3
|
+
// el suggestion seleccionado (Compose no): con `selected`, y solo como `<button>`, es un toggle
|
|
4
|
+
// con `aria-pressed`, como el Button.
|
|
5
|
+
import { chipElement } from './chip-element.js';
|
|
6
|
+
/**
|
|
7
|
+
* Suggestion chip: a suggested reply or search the user picks ("Sounds good").
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <SuggestionChip onClick={() => reply('Sure')}>Sure</SuggestionChip>
|
|
11
|
+
* <SuggestionChip href="/search?q=empanadas">Empanadas</SuggestionChip>
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function SuggestionChip(props) {
|
|
15
|
+
const { variant = 'outlined', selected, className, children, ...rest } = props;
|
|
16
|
+
return chipElement({ name: 'SuggestionChip', type: 'suggestion', variant, selected, checkWhenSelected: false, className, children }, rest);
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
export type ChipVariant = 'outlined' | 'elevated';
|
|
3
|
+
export interface ChipLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
/** Ref to the `<span>`. */
|
|
5
|
+
ref?: Ref<HTMLSpanElement> | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The chip's label, for when it isn't plain text (formatted text or a translation component).
|
|
9
|
+
* Plain text is already wrapped automatically: `<FilterChip>Vegan</FilterChip>`. If it doesn't
|
|
10
|
+
* fit, it is truncated with an ellipsis; the accessible name is still the full text.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ChipLabel({ className, ...props }: ChipLabelProps): import("react").JSX.Element;
|
|
13
|
+
export interface ChipAvatarProps extends HTMLAttributes<HTMLSpanElement> {
|
|
14
|
+
/** Ref to the `<span>`. */
|
|
15
|
+
ref?: Ref<HTMLSpanElement> | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The input chip's avatar: a 24 px circle with an image (`<img alt="">`, decorative if the name
|
|
19
|
+
* is already in the label) or initials. It goes before the label and makes the chip round, as in
|
|
20
|
+
* the kit. When selected, it shows a check mark instead.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ChipAvatar({ className, ...props }: ChipAvatarProps): import("react").JSX.Element;
|
|
23
|
+
export interface ChipContent {
|
|
24
|
+
content: ReactNode;
|
|
25
|
+
leading: boolean;
|
|
26
|
+
trailing: boolean;
|
|
27
|
+
avatar: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface ChipContentOptions {
|
|
30
|
+
check?: boolean | undefined;
|
|
31
|
+
labelId?: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export declare function chipContent(children: ReactNode, { check, labelId }?: ChipContentOptions): ChipContent;
|
|
34
|
+
export declare const chipDataAttributes: (c: ChipContent) => {
|
|
35
|
+
'data-leading': string | undefined;
|
|
36
|
+
'data-trailing': string | undefined;
|
|
37
|
+
'data-avatar': string | undefined;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Módulo universal (ADR-0003): sin estado, efectos, contexto ni eventos; no lleva 'use client'.
|
|
3
|
+
// Partes de los chips (ChipLabel, ChipAvatar) y el reparto del contenido en inicio, etiqueta y
|
|
4
|
+
// final, compartidos por los cuatro tipos (ADR-0019).
|
|
5
|
+
//
|
|
6
|
+
// Los casos simples se escriben como el Button: `<AssistChip><EventIcon />Agendar</AssistChip>`.
|
|
7
|
+
// El texto suelto se envuelve en la etiqueta (`.mk-chip-label`), que necesita ser un elemento para
|
|
8
|
+
// recortarse con puntos suspensivos (un texto suelto en un flex no admite overflow ni
|
|
9
|
+
// text-overflow). Los elementos antes de la etiqueta son el inicio (icono o `ChipAvatar`) y los de
|
|
10
|
+
// después, el final (un icono de desplegable en el filter). La configuración resultante va en
|
|
11
|
+
// atributos `data-*` del chip, que el CSS usa para los rellenos del kit; así no depende de
|
|
12
|
+
// selectores frágiles sobre hermanos.
|
|
13
|
+
import { Children, cloneElement, isValidElement, } from 'react';
|
|
14
|
+
import { CheckIcon } from '../../icons/icons.js';
|
|
15
|
+
import { cx } from '../../internal/interactive.js';
|
|
16
|
+
/**
|
|
17
|
+
* The chip's label, for when it isn't plain text (formatted text or a translation component).
|
|
18
|
+
* Plain text is already wrapped automatically: `<FilterChip>Vegan</FilterChip>`. If it doesn't
|
|
19
|
+
* fit, it is truncated with an ellipsis; the accessible name is still the full text.
|
|
20
|
+
*/
|
|
21
|
+
export function ChipLabel({ className, ...props }) {
|
|
22
|
+
return _jsx("span", { ...props, className: cx('mk-chip-label', className) });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The input chip's avatar: a 24 px circle with an image (`<img alt="">`, decorative if the name
|
|
26
|
+
* is already in the label) or initials. It goes before the label and makes the chip round, as in
|
|
27
|
+
* the kit. When selected, it shows a check mark instead.
|
|
28
|
+
*/
|
|
29
|
+
export function ChipAvatar({ className, ...props }) {
|
|
30
|
+
return _jsx("span", { ...props, className: cx('mk-chip-avatar', className) });
|
|
31
|
+
}
|
|
32
|
+
const isLabel = (el) => el.type === ChipLabel;
|
|
33
|
+
const isAvatar = (el) => el.type === ChipAvatar;
|
|
34
|
+
// Reparte los hijos de un chip en inicio, etiqueta y final, con los atributos para el CSS.
|
|
35
|
+
export function chipContent(children, { check = false, labelId } = {}) {
|
|
36
|
+
const leading = [];
|
|
37
|
+
const label = [];
|
|
38
|
+
const trailing = [];
|
|
39
|
+
let text = [];
|
|
40
|
+
let labelSeen = false;
|
|
41
|
+
const flushText = () => {
|
|
42
|
+
if (text.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
const first = !labelSeen;
|
|
45
|
+
label.push(_jsx("span", { className: "mk-chip-label", id: first ? labelId : undefined, children: text.join('') }, `label-${label.length}`));
|
|
46
|
+
labelSeen = true;
|
|
47
|
+
text = [];
|
|
48
|
+
};
|
|
49
|
+
for (const child of Children.toArray(children)) {
|
|
50
|
+
if (typeof child === 'string' || typeof child === 'number') {
|
|
51
|
+
text.push(child);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
flushText();
|
|
55
|
+
if (!isValidElement(child))
|
|
56
|
+
continue;
|
|
57
|
+
if (isLabel(child)) {
|
|
58
|
+
label.push(labelSeen || labelId === undefined ? child : cloneElement(child, { id: labelId }));
|
|
59
|
+
labelSeen = true;
|
|
60
|
+
}
|
|
61
|
+
else if (labelSeen) {
|
|
62
|
+
trailing.push(child);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
leading.push(child);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
flushText();
|
|
69
|
+
const avatarEl = leading.find((el) => isValidElement(el) && isAvatar(el));
|
|
70
|
+
const checkIcon = _jsx(CheckIcon, { className: "mk-chip-check" }, "check");
|
|
71
|
+
let start = null;
|
|
72
|
+
if (avatarEl) {
|
|
73
|
+
// El avatar seleccionado conserva su círculo (el chip no cambia de ancho ni de forma) y muestra
|
|
74
|
+
// la marca en lugar de la imagen.
|
|
75
|
+
start = check ? cloneElement(avatarEl, { 'data-checked': '' }, checkIcon) : avatarEl;
|
|
76
|
+
}
|
|
77
|
+
else if (check) {
|
|
78
|
+
start = _jsx("span", { className: "mk-chip-leading", children: checkIcon }, "leading");
|
|
79
|
+
}
|
|
80
|
+
else if (leading.length > 0) {
|
|
81
|
+
start = _jsx("span", { className: "mk-chip-leading", children: leading }, "leading");
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
content: (_jsxs(_Fragment, { children: [start, label, trailing.length > 0 ? _jsx("span", { className: "mk-chip-trailing", children: trailing }, "trailing") : null] })),
|
|
85
|
+
leading: start !== null,
|
|
86
|
+
trailing: trailing.length > 0,
|
|
87
|
+
avatar: avatarEl !== undefined,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Atributos de configuración del chip, para los rellenos y la forma (chip.css).
|
|
91
|
+
export const chipDataAttributes = (c) => ({
|
|
92
|
+
'data-leading': c.leading ? '' : undefined,
|
|
93
|
+
'data-trailing': c.trailing ? '' : undefined,
|
|
94
|
+
'data-avatar': c.avatar ? '' : undefined,
|
|
95
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type ChipVariant } from './chip-content.tsx';
|
|
3
|
+
export type ChipType = 'assist' | 'filter' | 'suggestion';
|
|
4
|
+
interface ChipElementOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
type: ChipType;
|
|
7
|
+
variant: ChipVariant;
|
|
8
|
+
selected: boolean | undefined;
|
|
9
|
+
checkWhenSelected: boolean;
|
|
10
|
+
className: string | undefined;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function chipElement({ name, type, variant, selected, checkWhenSelected, className, children }: ChipElementOptions, rest: Record<string, unknown>): import("react").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FocusRing } from '../../atoms/FocusRing/FocusRing.js';
|
|
3
|
+
import { Ripple } from '../../atoms/Ripple/Ripple.js';
|
|
4
|
+
import { StateLayer } from '../../atoms/StateLayer/StateLayer.js';
|
|
5
|
+
import { Interactive } from '../../atoms/Interactive/Interactive.js';
|
|
6
|
+
import { assertRenderElement, cx } from '../../internal/interactive.js';
|
|
7
|
+
import { chipContent, chipDataAttributes } from './chip-content.js';
|
|
8
|
+
export function chipElement({ name, type, variant, selected, checkWhenSelected, className, children }, rest) {
|
|
9
|
+
const content = chipContent(children, { check: checkWhenSelected && selected === true });
|
|
10
|
+
assertRenderElement(name, rest.render);
|
|
11
|
+
return (_jsxs(Interactive
|
|
12
|
+
// Antes de las props del uso: un aria-pressed propio gana, como en el Button.
|
|
13
|
+
, { ...(selected === undefined ? {} : { 'aria-pressed': selected }), ...rest, "data-chip": type, "data-chip-stop": "", "data-variant": variant, ...chipDataAttributes(content), className: cx('mk-chip', className), children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), content.content] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type ButtonElementProps, type LinkElementProps, type RenderElementProps } from '../../atoms/Interactive/Interactive.tsx';
|
|
3
|
+
/**
|
|
4
|
+
* Color role: an `X` container with `on-X` icon and text. The three `*-container` are the classic
|
|
5
|
+
* ones; `primary`, `secondary` and `tertiary` are the stronger tones Expressive adds. A color, not
|
|
6
|
+
* a style, so the prop is `color` (ADR-0034).
|
|
7
|
+
*/
|
|
8
|
+
export type FabColor = 'primary-container' | 'secondary-container' | 'tertiary-container' | 'primary' | 'secondary' | 'tertiary';
|
|
9
|
+
/**
|
|
10
|
+
* Material 3 Expressive size: `sm` 56, `md` 80 and `lg` 96 px tall. In the kit, the 56 FAB is
|
|
11
|
+
* called "Default" and the 56 extended FAB "Small"; here both are `sm`, because a collapsed
|
|
12
|
+
* extended FAB looks the same as the FAB of its size. The small 40 px FAB is obsolete in
|
|
13
|
+
* Expressive and not included.
|
|
14
|
+
*/
|
|
15
|
+
export type FabSize = 'sm' | 'md' | 'lg';
|
|
16
|
+
interface FabOwnProps {
|
|
17
|
+
/** Color role (`FabColor`). Defaults to `primary-container`. */
|
|
18
|
+
color?: FabColor | undefined;
|
|
19
|
+
/** Size: 56, 80 or 96 px. Defaults to `sm` (56). */
|
|
20
|
+
size?: FabSize | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Lower elevation (level 1 at rest and 2 on hover, instead of 3 and 4), for when the FAB sits on
|
|
23
|
+
* a surface that is already elevated. Comes from Compose (`loweredElevation`); the kit does not
|
|
24
|
+
* have it.
|
|
25
|
+
*/
|
|
26
|
+
lowered?: boolean | undefined;
|
|
27
|
+
disabled?: never;
|
|
28
|
+
}
|
|
29
|
+
type WithElement<Own> = (Own & Omit<LinkElementProps, keyof Own>) | (Own & Omit<ButtonElementProps, keyof Own | 'disabled'>) | (Own & Omit<RenderElementProps, keyof Own>);
|
|
30
|
+
interface FabContentProps extends FabOwnProps {
|
|
31
|
+
/** Accessible name (becomes `aria-label`). Required: the FAB has no visible text. */
|
|
32
|
+
label: string;
|
|
33
|
+
'aria-label'?: never;
|
|
34
|
+
/** The icon. */
|
|
35
|
+
children?: ReactNode;
|
|
36
|
+
}
|
|
37
|
+
export type FabProps = WithElement<FabContentProps>;
|
|
38
|
+
interface ExtendedFabContentProps extends FabOwnProps {
|
|
39
|
+
/**
|
|
40
|
+
* With `false`, collapses to an icon-only FAB; the text hides with an animation but is still the
|
|
41
|
+
* accessible name. Defaults to `true`.
|
|
42
|
+
*/
|
|
43
|
+
expanded?: boolean | undefined;
|
|
44
|
+
/** The icon, first, and the text: `<AddIcon />Create`. */
|
|
45
|
+
children?: ReactNode;
|
|
46
|
+
}
|
|
47
|
+
export type ExtendedFabProps = WithElement<ExtendedFabContentProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Material 3 Expressive floating action button (FAB): the screen's primary action, icon only. A
|
|
50
|
+
* `<button type="button">`, an `<a>` with `href`, or the `render` element.
|
|
51
|
+
*
|
|
52
|
+
* **It does not position itself.** The app places it (for example, `position: fixed` in the
|
|
53
|
+
* bottom-right corner, 16 px from the edges, plus the system safe area); the playground shows it
|
|
54
|
+
* floating in the corner of a frame. That way it also works inside a NavigationRail or any
|
|
55
|
+
* container.
|
|
56
|
+
*
|
|
57
|
+
* ```tsx
|
|
58
|
+
* <Fab label="Write"><EditIcon /></Fab>
|
|
59
|
+
* <Fab label="New" size="lg" color="tertiary" render={<Link href="/new" />}><AddIcon /></Fab>
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function Fab(props: FabProps): import("react").JSX.Element;
|
|
63
|
+
/**
|
|
64
|
+
* Material 3 Expressive extended FAB: icon and text, like a Button. The text is the accessible
|
|
65
|
+
* name, also when collapsed. The icon goes first (it is the one left visible when collapsing).
|
|
66
|
+
*
|
|
67
|
+
* With `expanded={false}` it collapses to a FAB of the same size, with the spatial spring and the
|
|
68
|
+
* text fading out; with `prefers-reduced-motion`, the width changes without animating.
|
|
69
|
+
*
|
|
70
|
+
* **It does not position itself**, like `Fab`: the app places it.
|
|
71
|
+
*
|
|
72
|
+
* ```tsx
|
|
73
|
+
* <ExtendedFab><EditIcon />Write</ExtendedFab>
|
|
74
|
+
* <ExtendedFab expanded={!scrolled} size="md" href="/new"><AddIcon />New</ExtendedFab>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function ExtendedFab(props: ExtendedFabProps): import("react").JSX.Element;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FocusRing } from '../../atoms/FocusRing/FocusRing.js';
|
|
3
|
+
import { Ripple } from '../../atoms/Ripple/Ripple.js';
|
|
4
|
+
import { StateLayer } from '../../atoms/StateLayer/StateLayer.js';
|
|
5
|
+
import { Interactive, } from '../../atoms/Interactive/Interactive.js';
|
|
6
|
+
import { assertRenderElement, cx } from '../../internal/interactive.js';
|
|
7
|
+
// Atributos que lee fab.css.
|
|
8
|
+
const dataAttributes = (color, size, lowered, expanded) => ({
|
|
9
|
+
'data-color': color,
|
|
10
|
+
'data-size': size,
|
|
11
|
+
'data-lowered': lowered ? '' : undefined,
|
|
12
|
+
'data-expanded': expanded === undefined ? undefined : String(expanded),
|
|
13
|
+
});
|
|
14
|
+
const atoms = (_jsxs(_Fragment, { children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {})] }));
|
|
15
|
+
/**
|
|
16
|
+
* Material 3 Expressive floating action button (FAB): the screen's primary action, icon only. A
|
|
17
|
+
* `<button type="button">`, an `<a>` with `href`, or the `render` element.
|
|
18
|
+
*
|
|
19
|
+
* **It does not position itself.** The app places it (for example, `position: fixed` in the
|
|
20
|
+
* bottom-right corner, 16 px from the edges, plus the system safe area); the playground shows it
|
|
21
|
+
* floating in the corner of a frame. That way it also works inside a NavigationRail or any
|
|
22
|
+
* container.
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <Fab label="Write"><EditIcon /></Fab>
|
|
26
|
+
* <Fab label="New" size="lg" color="tertiary" render={<Link href="/new" />}><AddIcon /></Fab>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function Fab(props) {
|
|
30
|
+
const { label, color = 'primary-container', size = 'sm', lowered, className, children, ...rest } = props;
|
|
31
|
+
assertRenderElement('Fab', rest.render);
|
|
32
|
+
return (_jsxs(Interactive, { ...rest, "aria-label": label, ...dataAttributes(color, size, lowered), className: cx('mk-fab', className), children: [atoms, children] }));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Material 3 Expressive extended FAB: icon and text, like a Button. The text is the accessible
|
|
36
|
+
* name, also when collapsed. The icon goes first (it is the one left visible when collapsing).
|
|
37
|
+
*
|
|
38
|
+
* With `expanded={false}` it collapses to a FAB of the same size, with the spatial spring and the
|
|
39
|
+
* text fading out; with `prefers-reduced-motion`, the width changes without animating.
|
|
40
|
+
*
|
|
41
|
+
* **It does not position itself**, like `Fab`: the app places it.
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <ExtendedFab><EditIcon />Write</ExtendedFab>
|
|
45
|
+
* <ExtendedFab expanded={!scrolled} size="md" href="/new"><AddIcon />New</ExtendedFab>
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function ExtendedFab(props) {
|
|
49
|
+
const { expanded = true, color = 'primary-container', size = 'sm', lowered, className, children, ...rest } = props;
|
|
50
|
+
assertRenderElement('ExtendedFab', rest.render);
|
|
51
|
+
return (_jsxs(Interactive, { ...rest, ...dataAttributes(color, size, lowered, expanded), className: cx('mk-extended-fab', className), children: [atoms, _jsx("span", { className: "mk-extended-fab-content", children: _jsx("span", { className: "mk-extended-fab-label", children: children }) })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type ToggleButtonOrLinkProps } from '../../internal/interactive.tsx';
|
|
3
|
+
export type IconButtonVariant = 'standard' | 'filled' | 'tonal' | 'outlined';
|
|
4
|
+
export type IconButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
5
|
+
export type IconButtonWidth = 'narrow' | 'default' | 'wide';
|
|
6
|
+
export type IconButtonShape = 'round' | 'square';
|
|
7
|
+
interface IconButtonOwnProps {
|
|
8
|
+
/** Accessible name (becomes `aria-label`). Required: the button has no visible text. */
|
|
9
|
+
label: string;
|
|
10
|
+
'aria-label'?: never;
|
|
11
|
+
/** Color style. Defaults to `standard` (no container). */
|
|
12
|
+
variant?: IconButtonVariant | undefined;
|
|
13
|
+
/** Material 3 Expressive size: 32, 40, 56, 96 or 136 px tall. Defaults to `sm`. */
|
|
14
|
+
size?: IconButtonSize | undefined;
|
|
15
|
+
/** Container width: narrower, equal to the height, or wider. Defaults to `default` (equal to the height). */
|
|
16
|
+
width?: IconButtonWidth | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Resting shape. When pressed it becomes squarer; when a toggle is selected, round becomes
|
|
19
|
+
* square and square becomes round. Defaults to `round`.
|
|
20
|
+
*/
|
|
21
|
+
shape?: IconButtonShape | undefined;
|
|
22
|
+
/** The icon. */
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* IconButton props: its own plus one of three forms (ADR-0010), like `ButtonProps`.
|
|
27
|
+
* - Without `href` or `render`: a `<button type="button">` with `ref` to the `<button>`, `disabled`
|
|
28
|
+
* and `selected`, which makes it a toggle (`aria-pressed`; when undefined, a plain button).
|
|
29
|
+
* - With `href`: an `<a>` (`ref` to the `<a>`). With `render`: the router's `Link`.
|
|
30
|
+
* The two link forms do not accept `selected`, `disabled` or `aria-disabled`.
|
|
31
|
+
*/
|
|
32
|
+
export type IconButtonProps = ToggleButtonOrLinkProps<IconButtonOwnProps>;
|
|
33
|
+
/**
|
|
34
|
+
* Material 3 Expressive icon button.
|
|
35
|
+
*
|
|
36
|
+
* The icon is the child; the component sizes it with `--mk-icon-size` (20 to 40 px depending on
|
|
37
|
+
* the size). `label` is the name screen readers announce. With `href` or `render` it is a link
|
|
38
|
+
* that looks the same (an icon that opens another page).
|
|
39
|
+
*
|
|
40
|
+
* Customization with CSS variables:
|
|
41
|
+
* - `--mk-icon-button-color`: icon color of the unselected `standard` style (defaults to
|
|
42
|
+
* `on-surface-variant`). Inherited: set on a container, it affects the buttons inside.
|
|
43
|
+
* Selected and disabled keep their colors.
|
|
44
|
+
* - `--mk-icon-button-selected-container` and `--mk-icon-button-selected-color`: background
|
|
45
|
+
* (defaults to none) and icon color (`primary`) of the selected `standard` toggle. Also
|
|
46
|
+
* inherited; the Toolbar sets them for its buttons.
|
|
47
|
+
* - `--mk-icon-button-selected-round`: `1` keeps the selected toggle round (by default it turns
|
|
48
|
+
* square); the Toolbar uses it, as in the kit.
|
|
49
|
+
*
|
|
50
|
+
* ```tsx
|
|
51
|
+
* <IconButton label="Search"><SearchIcon /></IconButton>
|
|
52
|
+
* <IconButton variant="filled" width="wide" label="Favorite" selected={fav} onClick={() => setFav(!fav)}>
|
|
53
|
+
* <StarIcon filled={fav} />
|
|
54
|
+
* </IconButton>
|
|
55
|
+
* <IconButton label="Settings" render={<Link href="/settings" />}><SettingsIcon /></IconButton>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function IconButton(props: IconButtonProps): import("react").JSX.Element;
|
|
59
|
+
export {};
|