zabi-components 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1924 -0
- package/README.md +243 -10
- package/THEME.md +149 -332
- package/THEMING.md +1192 -266
- package/dist/atoms/ActionPanel.svelte +15 -5
- package/dist/atoms/Avatar.svelte +104 -0
- package/dist/atoms/Avatar.svelte.d.ts +34 -0
- package/dist/atoms/Badge.svelte +36 -7
- package/dist/atoms/Badge.svelte.d.ts +2 -2
- package/dist/atoms/Button.svelte +177 -27
- package/dist/atoms/Button.svelte.d.ts +30 -2
- package/dist/atoms/Card.svelte +4 -4
- package/dist/atoms/CardHeader.svelte +16 -4
- package/dist/atoms/Checkbox.svelte +48 -21
- package/dist/atoms/Checkbox.svelte.d.ts +4 -2
- package/dist/atoms/CodeBlock.svelte +20 -2
- package/dist/atoms/CodeBlock.svelte.d.ts +4 -0
- package/dist/atoms/ColorPicker.svelte +259 -49
- package/dist/atoms/ColorPicker.svelte.d.ts +3 -0
- package/dist/atoms/Container.svelte +16 -8
- package/dist/atoms/DateField.svelte +107 -0
- package/dist/atoms/DateField.svelte.d.ts +53 -0
- package/dist/atoms/FieldMessages.svelte +69 -0
- package/dist/atoms/FieldMessages.svelte.d.ts +23 -0
- package/dist/atoms/FloatingActionButton.svelte +174 -0
- package/dist/atoms/FloatingActionButton.svelte.d.ts +51 -0
- package/dist/atoms/Heading.svelte +37 -5
- package/dist/atoms/Heading.svelte.d.ts +7 -0
- package/dist/atoms/IconButton.svelte +220 -24
- package/dist/atoms/IconButton.svelte.d.ts +49 -4
- package/dist/atoms/Input.svelte +253 -52
- package/dist/atoms/Input.svelte.d.ts +32 -2
- package/dist/atoms/List.svelte +4 -1
- package/dist/atoms/ListItem.svelte +44 -11
- package/dist/atoms/ListItem.svelte.d.ts +5 -0
- package/dist/atoms/Progress.svelte +27 -8
- package/dist/atoms/Progress.svelte.d.ts +4 -0
- package/dist/atoms/Radio.svelte +19 -3
- package/dist/atoms/Radio.svelte.d.ts +4 -2
- package/dist/atoms/Rating.svelte +494 -0
- package/dist/atoms/Rating.svelte.d.ts +56 -0
- package/dist/atoms/Select.svelte +433 -91
- package/dist/atoms/Select.svelte.d.ts +49 -3
- package/dist/atoms/SelectionControl.svelte +94 -17
- package/dist/atoms/SelectionControl.svelte.d.ts +4 -3
- package/dist/atoms/Skeleton.svelte +1 -1
- package/dist/atoms/Slider.svelte +309 -0
- package/dist/atoms/Slider.svelte.d.ts +40 -0
- package/dist/atoms/Spinner.svelte +57 -0
- package/dist/atoms/Spinner.svelte.d.ts +19 -0
- package/dist/atoms/Table.svelte +151 -6
- package/dist/atoms/Table.svelte.d.ts +15 -3
- package/dist/atoms/TemporalField.svelte +140 -0
- package/dist/atoms/TemporalField.svelte.d.ts +32 -0
- package/dist/atoms/Text.svelte +23 -11
- package/dist/atoms/Text.svelte.d.ts +6 -3
- package/dist/atoms/Textarea.svelte +55 -44
- package/dist/atoms/Textarea.svelte.d.ts +14 -2
- package/dist/atoms/ThemeToggle.svelte +223 -44
- package/dist/atoms/ThemeToggle.svelte.d.ts +26 -3
- package/dist/atoms/TimeField.svelte +108 -0
- package/dist/atoms/TimeField.svelte.d.ts +54 -0
- package/dist/atoms/Toast.svelte +17 -4
- package/dist/atoms/Toast.svelte.d.ts +2 -0
- package/dist/atoms/Toggle.svelte +41 -8
- package/dist/atoms/Toggle.svelte.d.ts +11 -2
- package/dist/atoms/Tooltip.svelte +508 -23
- package/dist/atoms/Tooltip.svelte.d.ts +11 -0
- package/dist/atoms/ZabiStringsProvider.svelte +45 -0
- package/dist/atoms/ZabiStringsProvider.svelte.d.ts +27 -0
- package/dist/atoms/index.d.ts +17 -0
- package/dist/atoms/index.js +12 -0
- package/dist/atoms/selection-control.styles.d.ts +36 -5
- package/dist/atoms/selection-control.styles.js +40 -9
- package/dist/components/atoms/index.d.ts +17 -0
- package/dist/components/atoms/index.d.ts.map +1 -1
- package/dist/components/atoms/selection-control.styles.d.ts +36 -5
- package/dist/components/atoms/selection-control.styles.d.ts.map +1 -1
- package/dist/components/index.d.ts +80 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/molecules/index.d.ts +46 -0
- package/dist/components/molecules/index.d.ts.map +1 -1
- package/dist/components/molecules/toast-store.d.ts +53 -7
- package/dist/components/molecules/toast-store.d.ts.map +1 -1
- package/dist/components/organisms/index.d.ts +5 -0
- package/dist/components/organisms/index.d.ts.map +1 -1
- package/dist/components/types/variants.d.ts +15 -1
- package/dist/components/types/variants.d.ts.map +1 -1
- package/dist/components/util/app-shell.d.ts +28 -0
- package/dist/components/util/app-shell.d.ts.map +1 -0
- package/dist/components/util/avatar.d.ts +36 -0
- package/dist/components/util/avatar.d.ts.map +1 -0
- package/dist/components/util/bottom-sheet.d.ts +30 -0
- package/dist/components/util/bottom-sheet.d.ts.map +1 -0
- package/dist/components/util/bottom-tab-bar.d.ts +35 -0
- package/dist/components/util/bottom-tab-bar.d.ts.map +1 -0
- package/dist/components/util/calendar.d.ts +56 -0
- package/dist/components/util/calendar.d.ts.map +1 -0
- package/dist/components/util/collapsible.d.ts +58 -0
- package/dist/components/util/collapsible.d.ts.map +1 -0
- package/dist/components/util/confirm-dialog.d.ts +12 -0
- package/dist/components/util/confirm-dialog.d.ts.map +1 -0
- package/dist/components/util/date.d.ts +96 -0
- package/dist/components/util/date.d.ts.map +1 -0
- package/dist/components/util/drawer.d.ts +13 -0
- package/dist/components/util/drawer.d.ts.map +1 -0
- package/dist/components/util/dropdown.d.ts +47 -0
- package/dist/components/util/dropdown.d.ts.map +1 -0
- package/dist/components/util/field.d.ts +39 -0
- package/dist/components/util/field.d.ts.map +1 -0
- package/dist/components/util/fit-in-viewport.d.ts +201 -0
- package/dist/components/util/fit-in-viewport.d.ts.map +1 -0
- package/dist/components/util/focus-utils.d.ts +75 -2
- package/dist/components/util/focus-utils.d.ts.map +1 -1
- package/dist/components/util/hydration.d.ts +45 -0
- package/dist/components/util/hydration.d.ts.map +1 -0
- package/dist/components/util/keyboard-inset.d.ts +18 -0
- package/dist/components/util/keyboard-inset.d.ts.map +1 -0
- package/dist/components/util/media-grid.d.ts +51 -0
- package/dist/components/util/media-grid.d.ts.map +1 -0
- package/dist/components/util/media.d.ts +6 -0
- package/dist/components/util/media.d.ts.map +1 -0
- package/dist/components/util/overlay-chrome.d.ts +53 -0
- package/dist/components/util/overlay-chrome.d.ts.map +1 -0
- package/dist/components/util/overlay.d.ts +72 -0
- package/dist/components/util/overlay.d.ts.map +1 -0
- package/dist/components/util/photo.d.ts +215 -0
- package/dist/components/util/photo.d.ts.map +1 -0
- package/dist/components/util/portal.d.ts +23 -0
- package/dist/components/util/portal.d.ts.map +1 -0
- package/dist/components/util/pull-to-refresh.d.ts +27 -0
- package/dist/components/util/pull-to-refresh.d.ts.map +1 -0
- package/dist/components/util/radio-keys.d.ts +25 -0
- package/dist/components/util/radio-keys.d.ts.map +1 -0
- package/dist/components/util/rating.d.ts +23 -0
- package/dist/components/util/rating.d.ts.map +1 -0
- package/dist/components/util/ready-made-strings.d.ts +77 -0
- package/dist/components/util/ready-made-strings.d.ts.map +1 -0
- package/dist/components/util/scroll-padding.d.ts +20 -0
- package/dist/components/util/scroll-padding.d.ts.map +1 -0
- package/dist/components/util/segmented-control.d.ts +16 -0
- package/dist/components/util/segmented-control.d.ts.map +1 -0
- package/dist/components/util/select.d.ts +41 -0
- package/dist/components/util/select.d.ts.map +1 -0
- package/dist/components/util/sheet-drag.d.ts +60 -0
- package/dist/components/util/sheet-drag.d.ts.map +1 -0
- package/dist/components/util/sidebar.d.ts +63 -0
- package/dist/components/util/sidebar.d.ts.map +1 -0
- package/dist/components/util/sortable-list.d.ts +65 -0
- package/dist/components/util/sortable-list.d.ts.map +1 -0
- package/dist/components/util/stepper.d.ts +40 -0
- package/dist/components/util/stepper.d.ts.map +1 -0
- package/dist/components/util/swipeable-list-item.d.ts +36 -0
- package/dist/components/util/swipeable-list-item.d.ts.map +1 -0
- package/dist/components/util/theme-mode.d.ts +80 -0
- package/dist/components/util/theme-mode.d.ts.map +1 -0
- package/dist/components/util/toaster.d.ts +93 -0
- package/dist/components/util/toaster.d.ts.map +1 -0
- package/dist/components/util/tooltip.d.ts +10 -0
- package/dist/components/util/tooltip.d.ts.map +1 -0
- package/dist/components/util/top-navbar.d.ts +11 -0
- package/dist/components/util/top-navbar.d.ts.map +1 -0
- package/dist/components/util/touch-target.d.ts +31 -0
- package/dist/components/util/touch-target.d.ts.map +1 -0
- package/dist/components/util/zabi-strings.d.ts +133 -0
- package/dist/components/util/zabi-strings.d.ts.map +1 -0
- package/dist/create-theme/cli.js +169 -0
- package/dist/create-theme/index.d.ts +176 -0
- package/dist/create-theme/index.js +817 -0
- package/dist/create-theme/lib/ramp-math.js +128 -0
- package/dist/create-theme/lib/resolve.js +141 -0
- package/dist/create-theme/theme-data.js +1116 -0
- package/dist/index.d.ts +80 -2
- package/dist/index.js +57 -2
- package/dist/molecules/Alert.svelte +33 -5
- package/dist/molecules/Alert.svelte.d.ts +2 -0
- package/dist/molecules/AppBar.svelte +415 -0
- package/dist/molecules/AppBar.svelte.d.ts +69 -0
- package/dist/molecules/AvatarGroup.svelte +116 -0
- package/dist/molecules/AvatarGroup.svelte.d.ts +40 -0
- package/dist/molecules/BottomSheet.svelte +540 -0
- package/dist/molecules/BottomSheet.svelte.d.ts +93 -0
- package/dist/molecules/BottomTabBar.svelte +297 -0
- package/dist/molecules/BottomTabBar.svelte.d.ts +64 -0
- package/dist/molecules/Calendar.svelte +597 -0
- package/dist/molecules/Calendar.svelte.d.ts +72 -0
- package/dist/molecules/Collapsible.svelte +243 -0
- package/dist/molecules/Collapsible.svelte.d.ts +44 -0
- package/dist/molecules/CollapsibleGroup.svelte +126 -0
- package/dist/molecules/CollapsibleGroup.svelte.d.ts +14 -0
- package/dist/molecules/ComponentDemo.svelte +16 -4
- package/dist/molecules/ComponentDemo.svelte.d.ts +3 -0
- package/dist/molecules/ConfirmDialog.svelte +253 -0
- package/dist/molecules/ConfirmDialog.svelte.d.ts +55 -0
- package/dist/molecules/ContactForm.svelte +34 -17
- package/dist/molecules/ContactForm.svelte.d.ts +8 -0
- package/dist/molecules/Drawer.svelte +394 -0
- package/dist/molecules/Drawer.svelte.d.ts +55 -0
- package/dist/molecules/Dropdown.svelte +509 -48
- package/dist/molecules/Dropdown.svelte.d.ts +45 -6
- package/dist/molecules/DropdownItem.svelte +122 -0
- package/dist/molecules/DropdownItem.svelte.d.ts +28 -0
- package/dist/molecules/EmptyState.svelte +55 -10
- package/dist/molecules/EmptyState.svelte.d.ts +8 -0
- package/dist/molecules/FormField.svelte +9 -1
- package/dist/molecules/FormField.svelte.d.ts +2 -0
- package/dist/molecules/Header.svelte +1 -1
- package/dist/molecules/ImageUpload.svelte +383 -70
- package/dist/molecules/ImageUpload.svelte.d.ts +47 -2
- package/dist/molecules/MediaGrid.svelte +527 -0
- package/dist/molecules/MediaGrid.svelte.d.ts +77 -0
- package/dist/molecules/Modal.svelte +288 -72
- package/dist/molecules/Modal.svelte.d.ts +51 -2
- package/dist/molecules/NavigationMenuContent.svelte +58 -1
- package/dist/molecules/NavigationMenuItem.svelte +0 -1
- package/dist/molecules/NavigationMenuLink.svelte +1 -1
- package/dist/molecules/NavigationMenuList.svelte +10 -3
- package/dist/molecules/NavigationMenuTrigger.svelte +2 -2
- package/dist/molecules/Page.svelte +32 -2
- package/dist/molecules/Page.svelte.d.ts +11 -0
- package/dist/molecules/PhotoGrid.svelte +433 -0
- package/dist/molecules/PhotoGrid.svelte.d.ts +62 -0
- package/dist/molecules/PhotoViewer.svelte +1116 -0
- package/dist/molecules/PhotoViewer.svelte.d.ts +56 -0
- package/dist/molecules/PropsTable.svelte +22 -10
- package/dist/molecules/PropsTable.svelte.d.ts +3 -0
- package/dist/molecules/PullToRefresh.svelte +263 -0
- package/dist/molecules/PullToRefresh.svelte.d.ts +52 -0
- package/dist/molecules/RadioGroup.svelte +52 -14
- package/dist/molecules/RadioGroup.svelte.d.ts +14 -3
- package/dist/molecules/Section.svelte +1 -1
- package/dist/molecules/SegmentedControl.svelte +323 -0
- package/dist/molecules/SegmentedControl.svelte.d.ts +34 -0
- package/dist/molecules/SidebarBrandHeader.svelte +11 -1
- package/dist/molecules/SidebarBrandHeader.svelte.d.ts +3 -0
- package/dist/molecules/SidebarFooter.svelte +29 -6
- package/dist/molecules/SidebarFooter.svelte.d.ts +3 -0
- package/dist/molecules/SlideUp.svelte +220 -61
- package/dist/molecules/SlideUp.svelte.d.ts +26 -0
- package/dist/molecules/SortableList.svelte +632 -0
- package/dist/molecules/SortableList.svelte.d.ts +69 -0
- package/dist/molecules/Stepper.svelte +548 -0
- package/dist/molecules/Stepper.svelte.d.ts +39 -0
- package/dist/molecules/StickyActionBar.svelte +191 -0
- package/dist/molecules/StickyActionBar.svelte.d.ts +65 -0
- package/dist/molecules/SwipeableListItem.svelte +334 -0
- package/dist/molecules/SwipeableListItem.svelte.d.ts +54 -0
- package/dist/molecules/Tabs.svelte +233 -9
- package/dist/molecules/Tabs.svelte.d.ts +7 -0
- package/dist/molecules/Toaster.svelte +350 -5
- package/dist/molecules/Toaster.svelte.d.ts +95 -2
- package/dist/molecules/ToasterToast.svelte +253 -67
- package/dist/molecules/ToasterToast.svelte.d.ts +9 -0
- package/dist/molecules/UnsavedChangesBar.svelte +212 -0
- package/dist/molecules/UnsavedChangesBar.svelte.d.ts +43 -0
- package/dist/molecules/index.d.ts +46 -0
- package/dist/molecules/index.js +27 -0
- package/dist/molecules/toast-store.d.ts +53 -7
- package/dist/molecules/toast-store.js +21 -0
- package/dist/organisms/AppShell.svelte +196 -0
- package/dist/organisms/AppShell.svelte.d.ts +61 -0
- package/dist/organisms/SidebarAccountPanel.svelte +107 -12
- package/dist/organisms/SidebarAccountPanel.svelte.d.ts +19 -0
- package/dist/organisms/SidebarNavigation.svelte +96 -15
- package/dist/organisms/SidebarNavigation.svelte.d.ts +29 -1
- package/dist/organisms/SidebarPanel.svelte +31 -10
- package/dist/organisms/SidebarShell.svelte +162 -11
- package/dist/organisms/SidebarShell.svelte.d.ts +56 -2
- package/dist/organisms/TopNavbar.svelte +256 -31
- package/dist/organisms/TopNavbar.svelte.d.ts +26 -0
- package/dist/organisms/index.d.ts +5 -0
- package/dist/organisms/index.js +3 -0
- package/dist/types/components.d.ts +4 -0
- package/dist/types/components.d.ts.map +1 -1
- package/dist/types/index.d.ts +605 -25
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/variants.ts +17 -1
- package/dist/util/app-shell.d.ts +27 -0
- package/dist/util/app-shell.js +72 -0
- package/dist/util/avatar.d.ts +35 -0
- package/dist/util/avatar.js +52 -0
- package/dist/util/bottom-sheet.d.ts +29 -0
- package/dist/util/bottom-sheet.js +43 -0
- package/dist/util/bottom-tab-bar.d.ts +34 -0
- package/dist/util/bottom-tab-bar.js +54 -0
- package/dist/util/calendar.d.ts +55 -0
- package/dist/util/calendar.js +74 -0
- package/dist/util/collapsible.d.ts +57 -0
- package/dist/util/collapsible.js +23 -0
- package/dist/util/confirm-dialog.d.ts +11 -0
- package/dist/util/confirm-dialog.js +2 -0
- package/dist/util/date.d.ts +95 -0
- package/dist/util/date.js +237 -0
- package/dist/util/drawer.d.ts +12 -0
- package/dist/util/drawer.js +7 -0
- package/dist/util/dropdown.d.ts +46 -0
- package/dist/util/dropdown.js +21 -0
- package/dist/util/field.d.ts +38 -0
- package/dist/util/field.js +38 -0
- package/dist/util/fit-in-viewport.d.ts +200 -0
- package/dist/util/fit-in-viewport.js +399 -0
- package/dist/util/focus-utils.d.ts +75 -2
- package/dist/util/focus-utils.js +182 -9
- package/dist/util/hydration.d.ts +44 -0
- package/dist/util/hydration.js +58 -0
- package/dist/util/keyboard-inset.d.ts +17 -0
- package/dist/util/keyboard-inset.js +53 -0
- package/dist/util/media-grid.d.ts +50 -0
- package/dist/util/media-grid.js +81 -0
- package/dist/util/media.d.ts +5 -0
- package/dist/util/media.js +10 -0
- package/dist/util/overlay-chrome.d.ts +52 -0
- package/dist/util/overlay-chrome.js +56 -0
- package/dist/util/overlay.d.ts +71 -0
- package/dist/util/overlay.js +240 -0
- package/dist/util/photo.d.ts +214 -0
- package/dist/util/photo.js +206 -0
- package/dist/util/portal.d.ts +22 -0
- package/dist/util/portal.js +50 -0
- package/dist/util/pull-to-refresh.d.ts +26 -0
- package/dist/util/pull-to-refresh.js +30 -0
- package/dist/util/radio-keys.d.ts +24 -0
- package/dist/util/radio-keys.js +49 -0
- package/dist/util/rating.d.ts +22 -0
- package/dist/util/rating.js +26 -0
- package/dist/util/ready-made-strings.d.ts +76 -0
- package/dist/util/ready-made-strings.js +67 -0
- package/dist/util/scroll-padding.d.ts +19 -0
- package/dist/util/scroll-padding.js +44 -0
- package/dist/util/segmented-control.d.ts +15 -0
- package/dist/util/segmented-control.js +1 -0
- package/dist/util/select.d.ts +40 -0
- package/dist/util/select.js +63 -0
- package/dist/util/sheet-drag.d.ts +59 -0
- package/dist/util/sheet-drag.js +241 -0
- package/dist/util/sidebar.d.ts +62 -0
- package/dist/util/sidebar.js +38 -0
- package/dist/util/sortable-list.d.ts +64 -0
- package/dist/util/sortable-list.js +53 -0
- package/dist/util/stepper.d.ts +39 -0
- package/dist/util/stepper.js +38 -0
- package/dist/util/swipeable-list-item.d.ts +35 -0
- package/dist/util/swipeable-list-item.js +32 -0
- package/dist/util/theme-mode.d.ts +79 -0
- package/dist/util/theme-mode.js +121 -0
- package/dist/util/toaster.d.ts +92 -0
- package/dist/util/toaster.js +75 -0
- package/dist/util/tooltip.d.ts +9 -0
- package/dist/util/tooltip.js +18 -0
- package/dist/util/top-navbar.d.ts +10 -0
- package/dist/util/top-navbar.js +5 -0
- package/dist/util/touch-target.d.ts +30 -0
- package/dist/util/touch-target.js +30 -0
- package/dist/util/zabi-strings.d.ts +132 -0
- package/dist/util/zabi-strings.js +105 -0
- package/dist/zabi-components-colors.css +5 -2
- package/dist/zabi-components-theme-dark-only.css +543 -241
- package/dist/zabi-components-theme-dark.css +543 -241
- package/dist/zabi-components-theme-only.css +1584 -367
- package/dist/zabi-components-theme.css +1584 -367
- package/dist/zabi-components.css +3885 -518
- package/docs/lucide-icons.md +40 -17
- package/docs/theme-imports.md +81 -11
- package/package.json +35 -8
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Types and pure helpers for `Stepper`. Kept out of the component so they can be tested without a DOM. */
|
|
2
|
+
/** One step: a label, and optionally a line under it. A plain string is a step with only a label. */
|
|
3
|
+
export interface StepperStep {
|
|
4
|
+
label: string;
|
|
5
|
+
/** A short line under the label in the full layout, and under the current step's name in the compact one. */
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
/** A step as the `steps` prop takes it. */
|
|
9
|
+
export type StepperItem = string | StepperStep;
|
|
10
|
+
/** Where a step is in the flow. */
|
|
11
|
+
export type StepperStepState = "completed" | "current" | "upcoming";
|
|
12
|
+
export type StepperLayout = "auto" | "full" | "compact";
|
|
13
|
+
/**
|
|
14
|
+
* Every built-in string. Pass a partial object to `strings` to translate.
|
|
15
|
+
* `step` is counted from 1 in all of them.
|
|
16
|
+
*/
|
|
17
|
+
export interface StepperStrings {
|
|
18
|
+
/** The visible start of the compact line: "Step 2 of 3". */
|
|
19
|
+
position: (step: number, total: number) => string;
|
|
20
|
+
/**
|
|
21
|
+
* What a screen reader reads for a step, and the name of its button when
|
|
22
|
+
* the step is one: "Step 1 of 3: Details, completed".
|
|
23
|
+
*/
|
|
24
|
+
stepLabel: (step: number, total: number, label: string, state: StepperStepState) => string;
|
|
25
|
+
/** Read out, politely, when the current step changes: "Step 2 of 3: Ratings". */
|
|
26
|
+
announcement: (step: number, total: number, label: string) => string;
|
|
27
|
+
}
|
|
28
|
+
export declare const STEPPER_STRINGS: StepperStrings;
|
|
29
|
+
/** Strings and objects alike, as objects. */
|
|
30
|
+
export declare function normalizeSteps(steps: readonly StepperItem[] | null | undefined): StepperStep[];
|
|
31
|
+
/**
|
|
32
|
+
* The index of the step that is shown as current: `current` as a whole number
|
|
33
|
+
* held within the steps. Below the first step it is the first, past the last
|
|
34
|
+
* it is the last, and something that is not a number is the first. `-1` when
|
|
35
|
+
* there are no steps.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clampStep(current: number | null | undefined, total: number): number;
|
|
38
|
+
/** The state of the step at `index` when the step at `current` is the current one. */
|
|
39
|
+
export declare function stepState(index: number, current: number): StepperStepState;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Types and pure helpers for `Stepper`. Kept out of the component so they can be tested without a DOM. */
|
|
2
|
+
const STATE_WORDS = {
|
|
3
|
+
completed: "completed",
|
|
4
|
+
current: "current",
|
|
5
|
+
upcoming: "upcoming",
|
|
6
|
+
};
|
|
7
|
+
export const STEPPER_STRINGS = {
|
|
8
|
+
position: (step, total) => `Step ${step} of ${total}`,
|
|
9
|
+
stepLabel: (step, total, label, state) => `Step ${step} of ${total}: ${label}, ${STATE_WORDS[state]}`,
|
|
10
|
+
announcement: (step, total, label) => `Step ${step} of ${total}: ${label}`,
|
|
11
|
+
};
|
|
12
|
+
/** Strings and objects alike, as objects. */
|
|
13
|
+
export function normalizeSteps(steps) {
|
|
14
|
+
return (steps ?? []).map((step) => (typeof step === "string" ? { label: step } : step));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The index of the step that is shown as current: `current` as a whole number
|
|
18
|
+
* held within the steps. Below the first step it is the first, past the last
|
|
19
|
+
* it is the last, and something that is not a number is the first. `-1` when
|
|
20
|
+
* there are no steps.
|
|
21
|
+
*/
|
|
22
|
+
export function clampStep(current, total) {
|
|
23
|
+
if (total <= 0)
|
|
24
|
+
return -1;
|
|
25
|
+
if (current === null || current === undefined || Number.isNaN(current))
|
|
26
|
+
return 0;
|
|
27
|
+
if (current === Infinity)
|
|
28
|
+
return total - 1;
|
|
29
|
+
if (current === -Infinity)
|
|
30
|
+
return 0;
|
|
31
|
+
return Math.max(0, Math.min(total - 1, Math.trunc(current)));
|
|
32
|
+
}
|
|
33
|
+
/** The state of the step at `index` when the step at `current` is the current one. */
|
|
34
|
+
export function stepState(index, current) {
|
|
35
|
+
if (index < current)
|
|
36
|
+
return "completed";
|
|
37
|
+
return index === current ? "current" : "upcoming";
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Component } from "svelte";
|
|
2
|
+
/** Public types and shared state for `SwipeableListItem`. */
|
|
3
|
+
/** One action behind a row, such as Delete. */
|
|
4
|
+
export interface SwipeableListItemAction {
|
|
5
|
+
id: string;
|
|
6
|
+
/** The button's text, and its accessible name. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Drawn above the label. */
|
|
9
|
+
icon?: Component<{
|
|
10
|
+
size?: number;
|
|
11
|
+
class?: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** `danger` for an action that destroys something. */
|
|
14
|
+
tone?: "default" | "danger";
|
|
15
|
+
/** Runs when the button is pressed. The row closes afterwards. */
|
|
16
|
+
onselect: () => void;
|
|
17
|
+
}
|
|
18
|
+
/** The words a `SwipeableListItem` says by itself. */
|
|
19
|
+
export interface SwipeableListItemStrings {
|
|
20
|
+
/** Accessible name of the button that opens the row's actions, and of the group they are in. */
|
|
21
|
+
actions: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const DEFAULT_SWIPEABLE_LIST_ITEM_STRINGS: SwipeableListItemStrings;
|
|
24
|
+
/**
|
|
25
|
+
* Says that a row has opened: every other open row in the same list closes.
|
|
26
|
+
* Returns what to call when this row closes or goes away.
|
|
27
|
+
*/
|
|
28
|
+
export declare function registerOpenRow(root: HTMLElement, close: () => void): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Where a swipe ends: open or closed. A flick decides by its direction,
|
|
31
|
+
* whatever the distance; otherwise the row goes to whichever is nearer.
|
|
32
|
+
* `revealed` and `width` are px of the actions; `velocity` is px per ms,
|
|
33
|
+
* positive towards revealing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function settleSwipe(revealed: number, width: number, velocity: number, flick: number): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const DEFAULT_SWIPEABLE_LIST_ITEM_STRINGS = {
|
|
2
|
+
actions: "Actions",
|
|
3
|
+
};
|
|
4
|
+
/** What groups rows: the nearest list around a row. Rows with none are each on their own. */
|
|
5
|
+
const LIST = 'ul, ol, [role="list"], [role="listbox"]';
|
|
6
|
+
/** The rows that are open now. */
|
|
7
|
+
const openRows = new Set();
|
|
8
|
+
/**
|
|
9
|
+
* Says that a row has opened: every other open row in the same list closes.
|
|
10
|
+
* Returns what to call when this row closes or goes away.
|
|
11
|
+
*/
|
|
12
|
+
export function registerOpenRow(root, close) {
|
|
13
|
+
const list = root.closest(LIST);
|
|
14
|
+
for (const other of [...openRows]) {
|
|
15
|
+
if (other.root !== root && list && other.root.closest(LIST) === list)
|
|
16
|
+
other.close();
|
|
17
|
+
}
|
|
18
|
+
const entry = { root, close };
|
|
19
|
+
openRows.add(entry);
|
|
20
|
+
return () => openRows.delete(entry);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Where a swipe ends: open or closed. A flick decides by its direction,
|
|
24
|
+
* whatever the distance; otherwise the row goes to whichever is nearer.
|
|
25
|
+
* `revealed` and `width` are px of the actions; `velocity` is px per ms,
|
|
26
|
+
* positive towards revealing.
|
|
27
|
+
*/
|
|
28
|
+
export function settleSwipe(revealed, width, velocity, flick) {
|
|
29
|
+
if (Math.abs(velocity) > flick)
|
|
30
|
+
return velocity > 0;
|
|
31
|
+
return revealed > width / 2;
|
|
32
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's theme mode, read and written in one place.
|
|
3
|
+
*
|
|
4
|
+
* The theme is switched on `<html>`: `data-theme="auto" | "light" | "dark"`,
|
|
5
|
+
* or the older `dark` class (THEMING.md, "Light, dark and auto"). ThemeToggle
|
|
6
|
+
* uses these helpers, and so can an app that renders a control of its own, a
|
|
7
|
+
* SegmentedControl with three options for instance: both then read and write
|
|
8
|
+
* the same attribute, and ThemeToggle follows whatever the other one sets.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is safe to call on the server: without a document the
|
|
11
|
+
* readers return the default and the writers do nothing.
|
|
12
|
+
*/
|
|
13
|
+
/** `"auto"` follows the system; the other two are a choice. */
|
|
14
|
+
export type ThemeMode = "auto" | "light" | "dark";
|
|
15
|
+
/** The modes in the order a three-way ThemeToggle steps through them. */
|
|
16
|
+
export declare const THEME_MODES: readonly ThemeMode[];
|
|
17
|
+
/** Where the choice is kept in `localStorage` unless a key is given. The key ThemeToggle has always used. */
|
|
18
|
+
export declare const DEFAULT_THEME_STORAGE_KEY = "theme";
|
|
19
|
+
/** The texts ThemeToggle builds its accessible name from. Pass any of them as `labels`. */
|
|
20
|
+
export interface ThemeToggleLabels {
|
|
21
|
+
/** What `"auto"` is called, with three modes. Default `"system"`. */
|
|
22
|
+
auto: string;
|
|
23
|
+
/** Default `"light"`. */
|
|
24
|
+
light: string;
|
|
25
|
+
/** Default `"dark"`. */
|
|
26
|
+
dark: string;
|
|
27
|
+
/**
|
|
28
|
+
* The name with three modes, from the current mode's word and the next
|
|
29
|
+
* one's. Default: "Theme: system. Switch to light".
|
|
30
|
+
*/
|
|
31
|
+
describe: (current: string, next: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* The name with two modes. It does not change: the button is a switch, and
|
|
34
|
+
* `aria-pressed` says whether dark is on. Default "Dark mode".
|
|
35
|
+
*/
|
|
36
|
+
darkMode: string;
|
|
37
|
+
/** The name before the button mounts, when the mode is not known yet. Default "Theme toggle". */
|
|
38
|
+
beforeMount: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function isThemeMode(value: unknown): value is ThemeMode;
|
|
41
|
+
/**
|
|
42
|
+
* The mode the page is in. `data-theme` says it outright; a page without the
|
|
43
|
+
* attribute is dark with the `dark` class and light without it (such a page
|
|
44
|
+
* does not follow the system, so it is never `"auto"`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function getThemeMode(): ThemeMode;
|
|
47
|
+
/** Whether the page is dark right now: by the class, by `data-theme="dark"`, or by `auto` on a dark system. */
|
|
48
|
+
export declare function isThemeDark(): boolean;
|
|
49
|
+
export interface SetThemeModeOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Where to keep the choice in `localStorage`. Default `"theme"`; `null`
|
|
52
|
+
* keeps nothing (an app that stores the choice in its own backend).
|
|
53
|
+
*/
|
|
54
|
+
storageKey?: string | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Puts the page in `mode` by writing `data-theme` on `<html>`, and remembers
|
|
58
|
+
* it. A leftover `dark` class and an inline `color-scheme` are removed: either
|
|
59
|
+
* would hold the page dark, or its native controls, under another mode. The
|
|
60
|
+
* theme sets `color-scheme` for each value of the attribute.
|
|
61
|
+
*/
|
|
62
|
+
export declare function setThemeMode(mode: ThemeMode, options?: SetThemeModeOptions): void;
|
|
63
|
+
/** The stored choice, or `null` when there is none, it is not a mode, or `storageKey` is `null`. */
|
|
64
|
+
export declare function getStoredThemeMode(storageKey?: string | null): ThemeMode | null;
|
|
65
|
+
/** Remembers `mode` under `storageKey` (default `"theme"`); `null` keeps nothing. */
|
|
66
|
+
export declare function storeThemeMode(mode: ThemeMode, storageKey?: string | null): void;
|
|
67
|
+
/**
|
|
68
|
+
* A script for `<head>` that applies the stored mode before the first paint,
|
|
69
|
+
* so a returning visitor does not see the other theme flash by. Returns the
|
|
70
|
+
* source as a string; it has no dependencies and can be inlined as it is.
|
|
71
|
+
*
|
|
72
|
+
* It writes to whichever mechanism the page uses, as ThemeToggle does:
|
|
73
|
+
* `data-theme` when `<html>` already has the attribute or the stored mode is
|
|
74
|
+
* `"auto"`, and the `dark` class otherwise. With nothing stored it does
|
|
75
|
+
* nothing, and the markup's own `data-theme` (or its absence) stands.
|
|
76
|
+
*
|
|
77
|
+
* The key is written into the script as a JSON string, so any key is safe.
|
|
78
|
+
*/
|
|
79
|
+
export declare function themeInitScript(storageKey?: string): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's theme mode, read and written in one place.
|
|
3
|
+
*
|
|
4
|
+
* The theme is switched on `<html>`: `data-theme="auto" | "light" | "dark"`,
|
|
5
|
+
* or the older `dark` class (THEMING.md, "Light, dark and auto"). ThemeToggle
|
|
6
|
+
* uses these helpers, and so can an app that renders a control of its own, a
|
|
7
|
+
* SegmentedControl with three options for instance: both then read and write
|
|
8
|
+
* the same attribute, and ThemeToggle follows whatever the other one sets.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is safe to call on the server: without a document the
|
|
11
|
+
* readers return the default and the writers do nothing.
|
|
12
|
+
*/
|
|
13
|
+
/** The modes in the order a three-way ThemeToggle steps through them. */
|
|
14
|
+
export const THEME_MODES = ["auto", "light", "dark"];
|
|
15
|
+
/** Where the choice is kept in `localStorage` unless a key is given. The key ThemeToggle has always used. */
|
|
16
|
+
export const DEFAULT_THEME_STORAGE_KEY = "theme";
|
|
17
|
+
export function isThemeMode(value) {
|
|
18
|
+
return value === "auto" || value === "light" || value === "dark";
|
|
19
|
+
}
|
|
20
|
+
function root() {
|
|
21
|
+
return typeof document === "undefined" ? undefined : document.documentElement;
|
|
22
|
+
}
|
|
23
|
+
function storage() {
|
|
24
|
+
try {
|
|
25
|
+
return typeof localStorage === "undefined" ? undefined : localStorage;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Reading `localStorage` throws where storage is blocked.
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The mode the page is in. `data-theme` says it outright; a page without the
|
|
34
|
+
* attribute is dark with the `dark` class and light without it (such a page
|
|
35
|
+
* does not follow the system, so it is never `"auto"`).
|
|
36
|
+
*/
|
|
37
|
+
export function getThemeMode() {
|
|
38
|
+
const html = root();
|
|
39
|
+
if (!html)
|
|
40
|
+
return "light";
|
|
41
|
+
const attribute = html.getAttribute("data-theme");
|
|
42
|
+
if (isThemeMode(attribute))
|
|
43
|
+
return attribute;
|
|
44
|
+
return html.classList.contains("dark") ? "dark" : "light";
|
|
45
|
+
}
|
|
46
|
+
/** Whether the page is dark right now: by the class, by `data-theme="dark"`, or by `auto` on a dark system. */
|
|
47
|
+
export function isThemeDark() {
|
|
48
|
+
const html = root();
|
|
49
|
+
if (!html)
|
|
50
|
+
return false;
|
|
51
|
+
// The class brings the dark tokens whatever the attribute says.
|
|
52
|
+
if (html.classList.contains("dark"))
|
|
53
|
+
return true;
|
|
54
|
+
const mode = getThemeMode();
|
|
55
|
+
if (mode === "auto") {
|
|
56
|
+
return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-color-scheme: dark)").matches;
|
|
57
|
+
}
|
|
58
|
+
return mode === "dark";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Puts the page in `mode` by writing `data-theme` on `<html>`, and remembers
|
|
62
|
+
* it. A leftover `dark` class and an inline `color-scheme` are removed: either
|
|
63
|
+
* would hold the page dark, or its native controls, under another mode. The
|
|
64
|
+
* theme sets `color-scheme` for each value of the attribute.
|
|
65
|
+
*/
|
|
66
|
+
export function setThemeMode(mode, options = {}) {
|
|
67
|
+
if (!isThemeMode(mode))
|
|
68
|
+
return;
|
|
69
|
+
const html = root();
|
|
70
|
+
if (!html)
|
|
71
|
+
return;
|
|
72
|
+
html.setAttribute("data-theme", mode);
|
|
73
|
+
html.classList.remove("dark");
|
|
74
|
+
html.style.removeProperty("color-scheme");
|
|
75
|
+
storeThemeMode(mode, options.storageKey);
|
|
76
|
+
}
|
|
77
|
+
/** The stored choice, or `null` when there is none, it is not a mode, or `storageKey` is `null`. */
|
|
78
|
+
export function getStoredThemeMode(storageKey = DEFAULT_THEME_STORAGE_KEY) {
|
|
79
|
+
if (storageKey === null)
|
|
80
|
+
return null;
|
|
81
|
+
try {
|
|
82
|
+
const stored = storage()?.getItem(storageKey);
|
|
83
|
+
return isThemeMode(stored) ? stored : null;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Remembers `mode` under `storageKey` (default `"theme"`); `null` keeps nothing. */
|
|
90
|
+
export function storeThemeMode(mode, storageKey = DEFAULT_THEME_STORAGE_KEY) {
|
|
91
|
+
if (storageKey === null)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
storage()?.setItem(storageKey, mode);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Storage full or blocked: the page is still switched.
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A script for `<head>` that applies the stored mode before the first paint,
|
|
102
|
+
* so a returning visitor does not see the other theme flash by. Returns the
|
|
103
|
+
* source as a string; it has no dependencies and can be inlined as it is.
|
|
104
|
+
*
|
|
105
|
+
* It writes to whichever mechanism the page uses, as ThemeToggle does:
|
|
106
|
+
* `data-theme` when `<html>` already has the attribute or the stored mode is
|
|
107
|
+
* `"auto"`, and the `dark` class otherwise. With nothing stored it does
|
|
108
|
+
* nothing, and the markup's own `data-theme` (or its absence) stands.
|
|
109
|
+
*
|
|
110
|
+
* The key is written into the script as a JSON string, so any key is safe.
|
|
111
|
+
*/
|
|
112
|
+
export function themeInitScript(storageKey = DEFAULT_THEME_STORAGE_KEY) {
|
|
113
|
+
const key = JSON.stringify(String(storageKey)).replace(/</g, "\\u003c");
|
|
114
|
+
return ("(function(){try{" +
|
|
115
|
+
`var m=localStorage.getItem(${key});` +
|
|
116
|
+
'if(m!=="auto"&&m!=="light"&&m!=="dark")return;' +
|
|
117
|
+
"var r=document.documentElement;" +
|
|
118
|
+
'if(r.hasAttribute("data-theme")||m==="auto"){r.setAttribute("data-theme",m);r.classList.remove("dark")}' +
|
|
119
|
+
'else{r.classList.toggle("dark",m==="dark")}' +
|
|
120
|
+
"}catch(e){}})();");
|
|
121
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every word a `Toaster` says by itself. An app in another language passes
|
|
3
|
+
* its own through `strings`; what it leaves out stays as it is here.
|
|
4
|
+
*/
|
|
5
|
+
export interface ToasterStrings {
|
|
6
|
+
/** Accessible name of the region the toasts are in. */
|
|
7
|
+
regionLabel: string;
|
|
8
|
+
/**
|
|
9
|
+
* What a toast says when it was pushed with neither a `title` nor a
|
|
10
|
+
* `message`, by type. A toast with a message shows the message.
|
|
11
|
+
*/
|
|
12
|
+
successTitle: string;
|
|
13
|
+
errorTitle: string;
|
|
14
|
+
warningTitle: string;
|
|
15
|
+
infoTitle: string;
|
|
16
|
+
/** The time a toast has left, while its timer runs. */
|
|
17
|
+
closesIn: (seconds: number) => string;
|
|
18
|
+
/** The same, while a pointer, a finger or focus holds the timer. */
|
|
19
|
+
pausedClosesIn: (seconds: number) => string;
|
|
20
|
+
/** The button that stops the timer; shown with `showCountdown`. */
|
|
21
|
+
stop: string;
|
|
22
|
+
/** The button under a toast's opened details, which closes them again. */
|
|
23
|
+
okay: string;
|
|
24
|
+
/** Accessible name of the button that opens a toast's details. */
|
|
25
|
+
expand: string;
|
|
26
|
+
/** The same button, once they are open. */
|
|
27
|
+
collapse: string;
|
|
28
|
+
/** Accessible name of the button that dismisses a toast. */
|
|
29
|
+
dismiss: string;
|
|
30
|
+
/**
|
|
31
|
+
* Read after a toast's text when it has an action, so a screen reader
|
|
32
|
+
* user hears that there is one. `label` is the action's own.
|
|
33
|
+
*/
|
|
34
|
+
actionAvailable: (label: string) => string;
|
|
35
|
+
}
|
|
36
|
+
export declare const DEFAULT_TOASTER_STRINGS: ToasterStrings;
|
|
37
|
+
/**
|
|
38
|
+
* The three lengths a toast can be given by name, in milliseconds.
|
|
39
|
+
*
|
|
40
|
+
* `short` (3 s) is for a few words that need no reading time ("Saved").
|
|
41
|
+
* Anything a person has to read is `medium` (7 s) or `long` (14 s). What
|
|
42
|
+
* they have to act on, and an error, should stay: `"persistent"`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const TOAST_DURATIONS: {
|
|
45
|
+
readonly short: 3000;
|
|
46
|
+
readonly medium: 7000;
|
|
47
|
+
readonly long: 14000;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* How long a toast stays: one of the named lengths, `"persistent"` (until it
|
|
51
|
+
* is dismissed), or a number of milliseconds, where `0` is persistent too.
|
|
52
|
+
*/
|
|
53
|
+
export type ToastDuration = keyof typeof TOAST_DURATIONS | "persistent" | number;
|
|
54
|
+
/**
|
|
55
|
+
* A toast with more visible text than this (title and message together) gets
|
|
56
|
+
* `long` when the app gave it no duration.
|
|
57
|
+
*/
|
|
58
|
+
export declare const TOAST_LONG_TEXT_LENGTH = 120;
|
|
59
|
+
/**
|
|
60
|
+
* And one with more than this stays until it is dismissed: `long` was
|
|
61
|
+
* measured as too short to read it in, and nothing longer has a name.
|
|
62
|
+
*/
|
|
63
|
+
export declare const TOAST_PERSISTENT_TEXT_LENGTH = 240;
|
|
64
|
+
/**
|
|
65
|
+
* How long a toast stays, in milliseconds; `0` is until it is dismissed.
|
|
66
|
+
*
|
|
67
|
+
* What the app said for the toast wins, whatever the toast is. When it said
|
|
68
|
+
* nothing: an error stays, and so does a toast with an action, since the user
|
|
69
|
+
* has to be able to reach the button. So does a text longer than
|
|
70
|
+
* `TOAST_PERSISTENT_TEXT_LENGTH`, whatever the Toaster's default. Everything
|
|
71
|
+
* else gets the Toaster's `defaultDuration`, or `medium` without one; a text
|
|
72
|
+
* longer than `TOAST_LONG_TEXT_LENGTH` gets `long`, unless the default is
|
|
73
|
+
* longer still.
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolveToastDuration(toast: {
|
|
76
|
+
duration?: ToastDuration;
|
|
77
|
+
type: string;
|
|
78
|
+
hasAction: boolean;
|
|
79
|
+
textLength: number;
|
|
80
|
+
}, defaultDuration?: ToastDuration): number;
|
|
81
|
+
/**
|
|
82
|
+
* The least a toast has left when a finger that held it lifts, in seconds.
|
|
83
|
+
* As long as `short`: holding a short toast starts it again, in effect.
|
|
84
|
+
*/
|
|
85
|
+
export declare const TOAST_SECONDS_AFTER_HOLD = 3;
|
|
86
|
+
/** What `onpausechange` of a `Toaster` is called with. */
|
|
87
|
+
export interface ToastPauseChange {
|
|
88
|
+
/** The id of the toast, as `pushToast` returned it. */
|
|
89
|
+
id: string;
|
|
90
|
+
/** True while a pointer is over the toast, a finger is on it, or focus is inside it. */
|
|
91
|
+
paused: boolean;
|
|
92
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const DEFAULT_TOASTER_STRINGS = {
|
|
2
|
+
regionLabel: "Notifications",
|
|
3
|
+
successTitle: "Changes saved",
|
|
4
|
+
errorTitle: "Something went wrong",
|
|
5
|
+
warningTitle: "Please review",
|
|
6
|
+
infoTitle: "Notice",
|
|
7
|
+
closesIn: (seconds) => `This message will close in ${seconds} ${seconds === 1 ? "second" : "seconds"}.`,
|
|
8
|
+
pausedClosesIn: (seconds) => `Paused — closes in ${seconds} ${seconds === 1 ? "second" : "seconds"}.`,
|
|
9
|
+
stop: "Click to stop",
|
|
10
|
+
okay: "Okay",
|
|
11
|
+
expand: "Expand details",
|
|
12
|
+
collapse: "Collapse details",
|
|
13
|
+
dismiss: "Dismiss notification",
|
|
14
|
+
actionAvailable: (label) => `${label} available.`,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The three lengths a toast can be given by name, in milliseconds.
|
|
18
|
+
*
|
|
19
|
+
* `short` (3 s) is for a few words that need no reading time ("Saved").
|
|
20
|
+
* Anything a person has to read is `medium` (7 s) or `long` (14 s). What
|
|
21
|
+
* they have to act on, and an error, should stay: `"persistent"`.
|
|
22
|
+
*/
|
|
23
|
+
export const TOAST_DURATIONS = { short: 3000, medium: 7000, long: 14000 };
|
|
24
|
+
/**
|
|
25
|
+
* A toast with more visible text than this (title and message together) gets
|
|
26
|
+
* `long` when the app gave it no duration.
|
|
27
|
+
*/
|
|
28
|
+
export const TOAST_LONG_TEXT_LENGTH = 120;
|
|
29
|
+
/**
|
|
30
|
+
* And one with more than this stays until it is dismissed: `long` was
|
|
31
|
+
* measured as too short to read it in, and nothing longer has a name.
|
|
32
|
+
*/
|
|
33
|
+
export const TOAST_PERSISTENT_TEXT_LENGTH = 240;
|
|
34
|
+
/** The milliseconds of a duration, `0` for one that stays; `undefined` for what is not a duration. */
|
|
35
|
+
function toastDurationMs(duration) {
|
|
36
|
+
if (duration === "persistent")
|
|
37
|
+
return 0;
|
|
38
|
+
if (typeof duration === "string") {
|
|
39
|
+
return Object.prototype.hasOwnProperty.call(TOAST_DURATIONS, duration)
|
|
40
|
+
? TOAST_DURATIONS[duration]
|
|
41
|
+
: undefined;
|
|
42
|
+
}
|
|
43
|
+
if (typeof duration !== "number" || Number.isNaN(duration))
|
|
44
|
+
return undefined;
|
|
45
|
+
return duration <= 0 ? 0 : duration;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* How long a toast stays, in milliseconds; `0` is until it is dismissed.
|
|
49
|
+
*
|
|
50
|
+
* What the app said for the toast wins, whatever the toast is. When it said
|
|
51
|
+
* nothing: an error stays, and so does a toast with an action, since the user
|
|
52
|
+
* has to be able to reach the button. So does a text longer than
|
|
53
|
+
* `TOAST_PERSISTENT_TEXT_LENGTH`, whatever the Toaster's default. Everything
|
|
54
|
+
* else gets the Toaster's `defaultDuration`, or `medium` without one; a text
|
|
55
|
+
* longer than `TOAST_LONG_TEXT_LENGTH` gets `long`, unless the default is
|
|
56
|
+
* longer still.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveToastDuration(toast, defaultDuration) {
|
|
59
|
+
const said = toastDurationMs(toast.duration);
|
|
60
|
+
if (said !== undefined)
|
|
61
|
+
return said;
|
|
62
|
+
if (toast.type === "error" || toast.hasAction)
|
|
63
|
+
return 0;
|
|
64
|
+
if (toast.textLength > TOAST_PERSISTENT_TEXT_LENGTH)
|
|
65
|
+
return 0;
|
|
66
|
+
const base = toastDurationMs(defaultDuration) ?? TOAST_DURATIONS.medium;
|
|
67
|
+
if (base === 0 || toast.textLength <= TOAST_LONG_TEXT_LENGTH)
|
|
68
|
+
return base;
|
|
69
|
+
return Math.max(base, TOAST_DURATIONS.long);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The least a toast has left when a finger that held it lifts, in seconds.
|
|
73
|
+
* As long as `short`: holding a short toast starts it again, in effect.
|
|
74
|
+
*/
|
|
75
|
+
export const TOAST_SECONDS_AFTER_HOLD = 3;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tooltip at a time. A tooltip that opens closes the one that was open: a
|
|
3
|
+
* mouse resting on one trigger while Tab moves focus to another would
|
|
4
|
+
* otherwise show both, one of them stale.
|
|
5
|
+
*/
|
|
6
|
+
/** Called by a tooltip as it opens, with what closes it. Closes any other. */
|
|
7
|
+
export declare function claimOpenTooltip(close: () => void): void;
|
|
8
|
+
/** Called by a tooltip as it closes or goes. */
|
|
9
|
+
export declare function releaseOpenTooltip(close: () => void): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tooltip at a time. A tooltip that opens closes the one that was open: a
|
|
3
|
+
* mouse resting on one trigger while Tab moves focus to another would
|
|
4
|
+
* otherwise show both, one of them stale.
|
|
5
|
+
*/
|
|
6
|
+
/** The tooltip that is open, as the function that closes it. */
|
|
7
|
+
let closeOpen = null;
|
|
8
|
+
/** Called by a tooltip as it opens, with what closes it. Closes any other. */
|
|
9
|
+
export function claimOpenTooltip(close) {
|
|
10
|
+
if (closeOpen && closeOpen !== close)
|
|
11
|
+
closeOpen();
|
|
12
|
+
closeOpen = close;
|
|
13
|
+
}
|
|
14
|
+
/** Called by a tooltip as it closes or goes. */
|
|
15
|
+
export function releaseOpenTooltip(close) {
|
|
16
|
+
if (closeOpen === close)
|
|
17
|
+
closeOpen = null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The words `TopNavbar` says by itself. Pass any of them as `strings`. */
|
|
2
|
+
export interface TopNavbarStrings {
|
|
3
|
+
/** Accessible name of the phone menu's button while the menu is closed. */
|
|
4
|
+
openMenu: string;
|
|
5
|
+
/** The same button, while the menu is open. */
|
|
6
|
+
closeMenu: string;
|
|
7
|
+
/** Read after the label of a link that opens in a new tab. */
|
|
8
|
+
opensInNewTab: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_TOP_NAVBAR_STRINGS: TopNavbarStrings;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Touch targets: 44 by 44px on a coarse pointer, nothing changed on a fine one.
|
|
3
|
+
*
|
|
4
|
+
* There are two ways to get there, and which one a control takes depends on
|
|
5
|
+
* what stands beside it.
|
|
6
|
+
*
|
|
7
|
+
* 1. The control itself grows: `pointer-coarse:min-h-11` (and `min-w-11` for a
|
|
8
|
+
* square one), written where the size is. Button, IconButton, Input and
|
|
9
|
+
* Select do this at `sm` and `md`, so a row of them still lines up; so does
|
|
10
|
+
* any control that has a neighbour close by (the handle and the move
|
|
11
|
+
* buttons of a SortableList row). `scripts/check-control-geometry.js` holds
|
|
12
|
+
* the shared controls to it.
|
|
13
|
+
*
|
|
14
|
+
* 2. The control keeps its size and an invisible layer around it takes the
|
|
15
|
+
* touch: `TOUCH_HIT_AREA` below. Only for a control that stands alone, with
|
|
16
|
+
* nothing pressable within about 10px: a close button in the corner of an
|
|
17
|
+
* Alert or in the header of a Modal, the switch of a Toggle. The layer
|
|
18
|
+
* reaches past the visible box, so beside another control it would cover
|
|
19
|
+
* that control's edge and a tap there would fire the wrong one. An `xs`
|
|
20
|
+
* IconButton had such a layer and lost it for that reason. A Toggle is
|
|
21
|
+
* stacked in settings lists, so its row is 44px tall on a coarse pointer:
|
|
22
|
+
* the layer of one switch then never reaches the switch above or below.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* An invisible hit area of at least 44 by 44px, centred on the element, on a
|
|
26
|
+
* coarse pointer only. The element must be positioned (`relative`, `absolute`
|
|
27
|
+
* or `fixed`; `pointer-coarse:relative` where it was not positioned before, so
|
|
28
|
+
* a fine pointer sees no change) and must not clip its overflow.
|
|
29
|
+
*/
|
|
30
|
+
export declare const TOUCH_HIT_AREA = "pointer-coarse:before:absolute pointer-coarse:before:top-1/2 pointer-coarse:before:left-1/2 pointer-coarse:before:size-full pointer-coarse:before:min-h-11 pointer-coarse:before:min-w-11 pointer-coarse:before:-translate-x-1/2 pointer-coarse:before:-translate-y-1/2 pointer-coarse:before:content-['']";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Touch targets: 44 by 44px on a coarse pointer, nothing changed on a fine one.
|
|
3
|
+
*
|
|
4
|
+
* There are two ways to get there, and which one a control takes depends on
|
|
5
|
+
* what stands beside it.
|
|
6
|
+
*
|
|
7
|
+
* 1. The control itself grows: `pointer-coarse:min-h-11` (and `min-w-11` for a
|
|
8
|
+
* square one), written where the size is. Button, IconButton, Input and
|
|
9
|
+
* Select do this at `sm` and `md`, so a row of them still lines up; so does
|
|
10
|
+
* any control that has a neighbour close by (the handle and the move
|
|
11
|
+
* buttons of a SortableList row). `scripts/check-control-geometry.js` holds
|
|
12
|
+
* the shared controls to it.
|
|
13
|
+
*
|
|
14
|
+
* 2. The control keeps its size and an invisible layer around it takes the
|
|
15
|
+
* touch: `TOUCH_HIT_AREA` below. Only for a control that stands alone, with
|
|
16
|
+
* nothing pressable within about 10px: a close button in the corner of an
|
|
17
|
+
* Alert or in the header of a Modal, the switch of a Toggle. The layer
|
|
18
|
+
* reaches past the visible box, so beside another control it would cover
|
|
19
|
+
* that control's edge and a tap there would fire the wrong one. An `xs`
|
|
20
|
+
* IconButton had such a layer and lost it for that reason. A Toggle is
|
|
21
|
+
* stacked in settings lists, so its row is 44px tall on a coarse pointer:
|
|
22
|
+
* the layer of one switch then never reaches the switch above or below.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* An invisible hit area of at least 44 by 44px, centred on the element, on a
|
|
26
|
+
* coarse pointer only. The element must be positioned (`relative`, `absolute`
|
|
27
|
+
* or `fixed`; `pointer-coarse:relative` where it was not positioned before, so
|
|
28
|
+
* a fine pointer sees no change) and must not clip its overflow.
|
|
29
|
+
*/
|
|
30
|
+
export const TOUCH_HIT_AREA = "pointer-coarse:before:absolute pointer-coarse:before:top-1/2 pointer-coarse:before:left-1/2 pointer-coarse:before:size-full pointer-coarse:before:min-h-11 pointer-coarse:before:min-w-11 pointer-coarse:before:-translate-x-1/2 pointer-coarse:before:-translate-y-1/2 pointer-coarse:before:content-['']";
|