@slashsuite/ui-react 0.12.1 → 0.13.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/MIGRATING.md +386 -8
- package/README.md +89 -44
- package/agent-docs/components/app-shell.md +9 -6
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/badge.md +2 -1
- package/agent-docs/components/body-text.md +26 -15
- package/agent-docs/components/bottom-sheet.md +27 -17
- package/agent-docs/components/breadcrumbs.md +10 -6
- package/agent-docs/components/button.md +2 -2
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +4 -3
- package/agent-docs/components/card-grid.md +15 -7
- package/agent-docs/components/card.md +33 -18
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/chat-composer.md +4 -3
- package/agent-docs/components/checkbox.md +11 -5
- package/agent-docs/components/cluster.md +10 -8
- package/agent-docs/components/code-example.md +2 -2
- package/agent-docs/components/code.md +7 -5
- package/agent-docs/components/colour-scheme-toggle.md +12 -6
- package/agent-docs/components/colour-swatch.md +41 -0
- package/agent-docs/components/combobox.md +88 -0
- package/agent-docs/components/confirm-dialog.md +98 -0
- package/agent-docs/components/container.md +2 -1
- package/agent-docs/components/copy-button.md +7 -5
- package/agent-docs/components/copy-line.md +6 -5
- package/agent-docs/components/date-field.md +14 -11
- package/agent-docs/components/date-range-picker.md +16 -9
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/dialog.md +22 -68
- package/agent-docs/components/disclosure.md +4 -0
- package/agent-docs/components/docs-layout.md +10 -6
- package/agent-docs/components/drawer.md +13 -4
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +4 -1
- package/agent-docs/components/field-dialog.md +6 -5
- package/agent-docs/components/field.md +10 -7
- package/agent-docs/components/fieldset.md +4 -4
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +4 -1
- package/agent-docs/components/form-row.md +7 -7
- package/agent-docs/components/full-bleed-layout.md +0 -2
- package/agent-docs/components/headings.md +13 -7
- package/agent-docs/components/hero.md +11 -2
- package/agent-docs/components/icon-button.md +1 -3
- package/agent-docs/components/icon.md +6 -13
- package/agent-docs/components/image.md +24 -14
- package/agent-docs/components/input.md +8 -7
- package/agent-docs/components/key-value-list.md +4 -1
- package/agent-docs/components/lightbox.md +1 -1
- package/agent-docs/components/list-layout.md +5 -7
- package/agent-docs/components/list-row.md +37 -34
- package/agent-docs/components/loading.md +2 -2
- package/agent-docs/components/markdown.md +13 -13
- package/agent-docs/components/media-tile.md +8 -4
- package/agent-docs/components/menu.md +19 -12
- package/agent-docs/components/meta-list.md +2 -2
- package/agent-docs/components/morph.md +11 -5
- package/agent-docs/components/navigation-progress.md +2 -2
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +19 -8
- package/agent-docs/components/page-fade.md +2 -1
- package/agent-docs/components/pill.md +7 -6
- package/agent-docs/components/popover.md +63 -0
- package/agent-docs/components/price.md +49 -0
- package/agent-docs/components/product-tile.md +78 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +1 -1
- package/agent-docs/components/radio-group.md +9 -6
- package/agent-docs/components/scroll-strip.md +3 -3
- package/agent-docs/components/segmented-control.md +4 -2
- package/agent-docs/components/select.md +8 -3
- package/agent-docs/components/show.md +2 -2
- package/agent-docs/components/side-column.md +13 -9
- package/agent-docs/components/sidebar-layout.md +1 -1
- package/agent-docs/components/site-footer.md +4 -4
- package/agent-docs/components/site-search.md +21 -9
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +15 -10
- package/agent-docs/components/stack.md +3 -3
- package/agent-docs/components/stacked-bar.md +7 -4
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +13 -6
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/switch.md +4 -4
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +35 -24
- package/agent-docs/components/tabs.md +24 -26
- package/agent-docs/components/text-link.md +12 -7
- package/agent-docs/components/textarea.md +4 -2
- package/agent-docs/components/toast.md +19 -14
- package/agent-docs/components/video.md +7 -2
- package/agent-docs/llms.txt +22 -3
- package/dist/AppShell.d.ts +25 -9
- package/dist/AppShell.js +67 -33
- package/dist/AppShellMenu.d.ts +31 -18
- package/dist/AppShellMenu.js +72 -45
- package/dist/ArticleLayout.d.ts +36 -0
- package/dist/ArticleLayout.js +27 -0
- package/dist/Audio.d.ts +16 -0
- package/dist/Audio.js +11 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/Badge.js +3 -2
- package/dist/BottomSheet.d.ts +17 -6
- package/dist/BottomSheet.js +62 -11
- package/dist/Breadcrumbs.d.ts +8 -6
- package/dist/Breadcrumbs.js +17 -7
- package/dist/Button.d.ts +1 -0
- package/dist/Button.js +4 -3
- package/dist/CallToAction.d.ts +25 -0
- package/dist/CallToAction.js +17 -0
- package/dist/Callout.d.ts +2 -2
- package/dist/Callout.js +2 -2
- package/dist/Card.d.ts +88 -31
- package/dist/Card.js +55 -92
- package/dist/CardBody.d.ts +2 -0
- package/dist/CardBody.js +33 -3
- package/dist/CardGrid.d.ts +32 -4
- package/dist/CardGrid.js +42 -8
- package/dist/CardParts.d.ts +7 -1
- package/dist/CardParts.js +7 -2
- package/dist/CartButton.d.ts +33 -0
- package/dist/CartButton.js +18 -0
- package/dist/ChatComposer.d.ts +10 -4
- package/dist/ChatComposer.js +35 -13
- package/dist/Checkbox.d.ts +21 -3
- package/dist/Checkbox.js +66 -20
- package/dist/Chevron.js +1 -1
- package/dist/Cluster.d.ts +28 -15
- package/dist/Cluster.js +21 -4
- package/dist/Code.d.ts +15 -3
- package/dist/Code.js +23 -3
- package/dist/CodeBlock.d.ts +4 -4
- package/dist/CodeBlock.js +2 -2
- package/dist/CodeBody.d.ts +1 -1
- package/dist/CodeBody.js +4 -10
- package/dist/CodeExample.d.ts +1 -1
- package/dist/CodeExample.js +3 -2
- package/dist/ColourSchemeToggle.d.ts +21 -5
- package/dist/ColourSchemeToggle.js +15 -9
- package/dist/ColourSwatch.d.ts +15 -0
- package/dist/ColourSwatch.js +14 -0
- package/dist/Combobox.d.ts +42 -0
- package/dist/Combobox.js +43 -0
- package/dist/ConfirmDialog.d.ts +40 -0
- package/dist/ConfirmDialog.js +36 -0
- package/dist/Container.d.ts +3 -3
- package/dist/Container.js +1 -1
- package/dist/CopyButton.d.ts +8 -2
- package/dist/CopyButton.js +38 -28
- package/dist/CopyLine.d.ts +4 -2
- package/dist/CopyLine.js +4 -4
- package/dist/DateCalendar.d.ts +2 -0
- package/dist/DateCalendar.js +11 -9
- package/dist/DateField.d.ts +52 -21
- package/dist/DateField.js +73 -37
- package/dist/DateFieldCalendar.d.ts +12 -8
- package/dist/DateFieldCalendar.js +37 -18
- package/dist/DateRangePicker.d.ts +23 -3
- package/dist/DateRangePicker.js +10 -8
- package/dist/DateTimeField.d.ts +31 -0
- package/dist/DateTimeField.js +19 -0
- package/dist/Dialog.d.ts +42 -6
- package/dist/Dialog.js +50 -12
- package/dist/Disclosure.js +9 -1
- package/dist/DocsLayout.d.ts +13 -5
- package/dist/DocsLayout.js +11 -9
- package/dist/Drawer.d.ts +22 -7
- package/dist/Drawer.js +89 -8
- package/dist/EmbedFrame.d.ts +36 -0
- package/dist/EmbedFrame.js +18 -0
- package/dist/Field.d.ts +41 -4
- package/dist/Field.js +61 -25
- package/dist/FieldDialog.d.ts +8 -3
- package/dist/FieldDialog.js +19 -9
- package/dist/Fieldset.d.ts +3 -3
- package/dist/Fieldset.js +7 -9
- package/dist/FileDrop.js +2 -1
- package/dist/FlowDiagram.d.ts +92 -0
- package/dist/FlowDiagram.js +100 -0
- package/dist/FormRow.d.ts +6 -4
- package/dist/FormRow.js +11 -9
- package/dist/Hero.d.ts +30 -7
- package/dist/Hero.js +23 -9
- package/dist/Icon.d.ts +1 -1
- package/dist/Icon.js +1 -1
- package/dist/IconButton.js +1 -1
- package/dist/Image.d.ts +33 -9
- package/dist/Image.js +61 -16
- package/dist/Input.d.ts +1 -1
- package/dist/Input.js +4 -4
- package/dist/InputShell.d.ts +7 -0
- package/dist/InputShell.js +18 -3
- package/dist/KeyValueList.d.ts +2 -2
- package/dist/Lightbox.js +5 -3
- package/dist/ListRow.d.ts +4 -5
- package/dist/ListRow.js +36 -26
- package/dist/Mark.d.ts +10 -0
- package/dist/Mark.js +9 -0
- package/dist/Markdown.d.ts +18 -4
- package/dist/Markdown.js +176 -37
- package/dist/MediaTile.d.ts +9 -3
- package/dist/MediaTile.js +8 -4
- package/dist/Menu.d.ts +19 -8
- package/dist/Menu.js +13 -11
- package/dist/MetaList.d.ts +4 -3
- package/dist/MetaList.js +12 -4
- package/dist/Morph.d.ts +15 -1
- package/dist/Morph.js +70 -22
- package/dist/NavigationProgress.d.ts +2 -2
- package/dist/NavigationProgress.js +7 -5
- package/dist/NumberField.d.ts +66 -0
- package/dist/NumberField.js +68 -0
- package/dist/OutlineRegion.d.ts +41 -10
- package/dist/OutlineRegion.js +31 -6
- package/dist/PageFade.d.ts +9 -5
- package/dist/PageFade.js +39 -8
- package/dist/PageLayouts.d.ts +15 -5
- package/dist/PageLayouts.js +3 -3
- package/dist/Pill.d.ts +9 -4
- package/dist/Pill.js +15 -6
- package/dist/Popover.d.ts +31 -0
- package/dist/Popover.js +43 -0
- package/dist/Price.d.ts +21 -0
- package/dist/Price.js +34 -0
- package/dist/ProductTile.d.ts +36 -0
- package/dist/ProductTile.js +31 -0
- package/dist/ProgressBar.js +4 -2
- package/dist/PromoBanner.d.ts +25 -0
- package/dist/PromoBanner.js +16 -0
- package/dist/RadioGroup.d.ts +18 -8
- package/dist/RadioGroup.js +42 -18
- package/dist/ScrollStrip.d.ts +1 -1
- package/dist/ScrollStrip.js +1 -1
- package/dist/SearchInput.d.ts +17 -2
- package/dist/SearchInput.js +72 -13
- package/dist/SegmentedField.d.ts +15 -0
- package/dist/SegmentedField.js +15 -0
- package/dist/Select.js +5 -4
- package/dist/Show.d.ts +1 -1
- package/dist/Show.js +1 -1
- package/dist/SideColumn.d.ts +42 -15
- package/dist/SideColumn.js +45 -19
- package/dist/SiteFooter.d.ts +3 -3
- package/dist/SiteFooter.js +4 -3
- package/dist/SiteSearch.d.ts +57 -27
- package/dist/SiteSearch.js +13 -93
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +58 -0
- package/dist/SortableList.d.ts +19 -35
- package/dist/SortableList.js +36 -88
- package/dist/Stack.d.ts +4 -4
- package/dist/StackedBar.d.ts +13 -4
- package/dist/StackedBar.js +12 -7
- package/dist/StateMachine.d.ts +65 -0
- package/dist/StateMachine.js +113 -0
- package/dist/StatusPages.d.ts +28 -10
- package/dist/StatusPages.js +10 -10
- package/dist/Stepper.d.ts +21 -0
- package/dist/Stepper.js +33 -0
- package/dist/Steps.js +4 -3
- package/dist/Switch.d.ts +3 -3
- package/dist/Switch.js +18 -14
- package/dist/Table.d.ts +32 -9
- package/dist/Table.js +50 -20
- package/dist/TableCells.d.ts +24 -21
- package/dist/TableCells.js +68 -27
- package/dist/TableEditCell.d.ts +1 -1
- package/dist/TableOfContents.d.ts +34 -0
- package/dist/TableOfContents.js +23 -0
- package/dist/Tabs.d.ts +31 -16
- package/dist/Tabs.js +97 -22
- package/dist/TextLink.d.ts +18 -5
- package/dist/TextLink.js +19 -6
- package/dist/Textarea.d.ts +12 -1
- package/dist/Textarea.js +15 -2
- package/dist/ToastRegion.d.ts +17 -9
- package/dist/ToastRegion.js +70 -13
- package/dist/Tooltip.d.ts +10 -2
- package/dist/Tooltip.js +32 -11
- package/dist/Video.d.ts +19 -4
- package/dist/Video.js +15 -5
- package/dist/cardContext.d.ts +7 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardControl.d.ts +15 -0
- package/dist/cardControl.js +32 -0
- package/dist/cardForm.d.ts +39 -0
- package/dist/cardForm.js +81 -0
- package/dist/cardWait.js +2 -1
- package/dist/colourScheme.d.ts +12 -2
- package/dist/colourScheme.js +32 -6
- package/dist/control.d.ts +30 -8
- package/dist/control.js +74 -7
- package/dist/copyScript.d.ts +7 -8
- package/dist/copyScript.js +8 -9
- package/dist/cx.d.ts +22 -3
- package/dist/cx.js +22 -3
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +15 -1
- package/dist/density.js +27 -8
- package/dist/emptySlot.d.ts +1 -0
- package/dist/fieldAnnounce.d.ts +11 -0
- package/dist/fieldAnnounce.js +36 -0
- package/dist/fieldControl.d.ts +7 -2
- package/dist/fieldControl.js +6 -2
- package/dist/fieldWait.d.ts +3 -3
- package/dist/fieldWait.js +3 -4
- package/dist/flowLayout.d.ts +68 -0
- package/dist/flowLayout.js +105 -0
- package/dist/fromXState.d.ts +73 -0
- package/dist/fromXState.js +110 -0
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +37 -11
- package/dist/index.js +24 -2
- package/dist/isoDate.d.ts +8 -1
- package/dist/isoDate.js +20 -1
- package/dist/labelWords.d.ts +16 -7
- package/dist/labelWords.js +14 -12
- package/dist/listRowProps.d.ts +17 -15
- package/dist/modal.d.ts +5 -0
- package/dist/modal.js +21 -1
- package/dist/navFold.js +6 -3
- package/dist/optionCard.d.ts +18 -0
- package/dist/optionCard.js +16 -0
- package/dist/scrollBody.d.ts +16 -0
- package/dist/scrollBody.js +15 -0
- package/dist/scrollEdges.d.ts +7 -0
- package/dist/scrollEdges.js +39 -5
- package/dist/scrollStop.d.ts +6 -2
- package/dist/scrollStop.js +24 -8
- package/dist/shownDate.d.ts +28 -10
- package/dist/shownDate.js +41 -22
- package/dist/siteSearchBody.d.ts +34 -0
- package/dist/siteSearchBody.js +117 -0
- package/dist/size.d.ts +7 -1
- package/dist/sortableDrop.d.ts +44 -0
- package/dist/sortableDrop.js +78 -0
- package/dist/sortableSlide.d.ts +9 -0
- package/dist/sortableSlide.js +70 -0
- package/dist/sortableTitle.d.ts +10 -0
- package/dist/sortableTitle.js +48 -0
- package/dist/stateMachineDots.d.ts +45 -0
- package/dist/stateMachineDots.js +162 -0
- package/dist/stickyColumn.d.ts +2 -2
- package/dist/stickyColumn.js +2 -2
- package/dist/switcher.d.ts +10 -5
- package/dist/switcher.js +7 -5
- package/dist/tableColumns.d.ts +17 -0
- package/dist/tableColumns.js +30 -2
- package/dist/tableEmpty.js +5 -5
- package/dist/tableRow.d.ts +26 -2
- package/dist/tableRow.js +23 -1
- package/dist/tableSort.d.ts +10 -5
- package/dist/tableSort.js +15 -4
- package/dist/target.d.ts +12 -0
- package/dist/target.js +12 -0
- package/dist/textBox.js +1 -1
- package/dist/truncated.d.ts +31 -0
- package/dist/truncated.js +51 -0
- package/dist/typography.d.ts +19 -11
- package/dist/typography.js +11 -13
- package/dist/useFlowLayout.d.ts +27 -0
- package/dist/useFlowLayout.js +119 -0
- package/package.json +3 -2
package/dist/Tabs.js
CHANGED
|
@@ -1,46 +1,121 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { hasReason } from "./blocked.js";
|
|
4
|
+
import { cx, focusRing, forcedFill } from "./cx.js";
|
|
3
5
|
import { controlText, useTypeStep } from "./density.js";
|
|
6
|
+
import { useScrollEdges } from "./scrollEdges.js";
|
|
4
7
|
import { Switcher } from "./switcher.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
+
// Every underline tab is `font-medium`, so choosing one does not widen it and shift the row. The
|
|
9
|
+
// focus ring is drawn inside the tab, since the row scrolls and would clip one drawn outside.
|
|
10
|
+
const BASE = "border-b-2 px-1 py-2 font-medium transition focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
|
|
11
|
+
// In forced colours a transparent border is painted in the text colour, so every tab would look
|
|
12
|
+
// underlined: the others take the page's Canvas, and the current one the system's Highlight. The
|
|
13
|
+
// rule under the row takes Canvas too, or it shows in the gaps between the tabs.
|
|
14
|
+
const ON = "border-violet-600 text-violet-700 forced-colors:border-[color:Highlight]!";
|
|
15
|
+
const OFF = "border-transparent text-slate-600 forced-colors:border-[color:Canvas]!";
|
|
8
16
|
const OFF_LIVE = "hover:text-violet-700";
|
|
9
|
-
//
|
|
10
|
-
|
|
17
|
+
// The rule under the row; the tab list inside it sits over the rule by a pixel, so the current
|
|
18
|
+
// tab's underline covers it.
|
|
19
|
+
const UNDERLINE_RULE = "border-b border-slate-200 forced-colors:border-[color:Canvas]!";
|
|
20
|
+
// One line that never wraps: a row wider than its box scrolls sideways, with no scrollbar, and
|
|
21
|
+
// fades out on the side that has more (a mask, so it follows any theme; it flips right to left).
|
|
22
|
+
// While the keyboard's focus is in the row the fade is off, so a focused tab at an edge stays whole.
|
|
23
|
+
const UNDERLINE_ROW = "-mb-px flex gap-x-4 overflow-x-auto whitespace-nowrap text-sm [scrollbar-width:none] *:shrink-0 [--fade-dir:to_right] rtl:[--fade-dir:to_left] data-more-start:[--fade-start:1.5rem] data-more-end:[--fade-end:1.5rem] data-more:[mask-image:linear-gradient(var(--fade-dir),transparent,#000_var(--fade-start,0px),#000_calc(100%_-_var(--fade-end,0px)),transparent)] data-more:has-focus-visible:[mask-image:none]";
|
|
24
|
+
// A transparent border, so a pill is as tall as a `Button` of the same size; the current pill's
|
|
25
|
+
// border shows, so it is told apart by its outline as well as its fill.
|
|
26
|
+
const PILL = `rounded-lg border transition ${focusRing}`;
|
|
11
27
|
/** A pill's padding, by `size`; its text is a control's (`controlText`), so it lines up with a `Button`. */
|
|
12
28
|
const PILL_SIZE = {
|
|
13
29
|
sm: "px-2.5 py-1",
|
|
14
30
|
md: "px-3 py-2",
|
|
15
31
|
lg: "px-4 py-2.5",
|
|
16
32
|
};
|
|
17
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The classes of one pill tab at the type `step` in force. Every pill is `font-medium`, so the
|
|
35
|
+
* current one is no wider than it was; it has a fill and an outline. A `disabled` one drops the
|
|
36
|
+
* hover fill.
|
|
37
|
+
*/
|
|
18
38
|
export function pillTabClass(active, disabled = false, size = "md", step) {
|
|
19
|
-
return cx(PILL, PILL_SIZE[size], controlText(size, step, false),
|
|
39
|
+
return cx(PILL, PILL_SIZE[size], controlText(size, step, false), "font-medium", active
|
|
40
|
+
? cx("border-slate-300 bg-slate-100 text-slate-900",
|
|
41
|
+
// Forced colours paint every pill's fill the page's Canvas and its border the text
|
|
42
|
+
// colour, so the current one is the system's Highlight, as a selected option is there. It
|
|
43
|
+
// names only system colours, so it opts out of the backplate drawn behind text there.
|
|
44
|
+
forcedFill, "forced-colors:border-[color:Highlight]! forced-colors:text-[color:HighlightText]! forced-color-adjust-none")
|
|
45
|
+
: "border-transparent text-slate-600", !active && !disabled && "hover:bg-slate-100");
|
|
20
46
|
}
|
|
21
47
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `size`. `items` are `{ value, label }` buttons (`value` and `onChange` are the caller's state;
|
|
26
|
-
* the arrow keys, Home and End move between tabs) or links (`href`, an in-app one through
|
|
27
|
-
* `LinkProvider`; `selected` on an item, or `value`, marks the current one, which gets
|
|
28
|
-
* `aria-current`). An item may carry a `count`, and a button one `disabledReason` (it stays
|
|
29
|
-
* reachable by the arrows and its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label` names the tab list. The panel is
|
|
30
|
-
* the caller's: give it `role="tabpanel"`, and a tab `controls` to point at it.
|
|
48
|
+
* One tab's panel. Hidden while its tab is not current; where the browser has it, hidden
|
|
49
|
+
* `until-found`, so find in page reaches the text and `beforematch` switches to the tab. That is
|
|
50
|
+
* applied after hydration (React renders `hidden` as a boolean), and not for a disabled tab.
|
|
31
51
|
*/
|
|
32
|
-
|
|
33
|
-
const
|
|
52
|
+
function TabPanel({ id, tabId, active, findable, onFound, children, }) {
|
|
53
|
+
const panel = useRef(null);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const el = panel.current;
|
|
56
|
+
if (!el || active || !findable || !("onbeforematch" in el))
|
|
57
|
+
return undefined;
|
|
58
|
+
el.setAttribute("hidden", "until-found");
|
|
59
|
+
el.addEventListener("beforematch", onFound);
|
|
60
|
+
return () => {
|
|
61
|
+
el.removeEventListener("beforematch", onFound);
|
|
62
|
+
// A panel that stays hidden but is no longer findable (its tab was disabled) is plainly
|
|
63
|
+
// hidden again; one that became current has had `hidden` removed by React already.
|
|
64
|
+
if (el.getAttribute("hidden") === "until-found")
|
|
65
|
+
el.setAttribute("hidden", "");
|
|
66
|
+
};
|
|
67
|
+
}, [active, findable, onFound]);
|
|
68
|
+
return (_jsx("div", { ref: panel, id: id, role: "tabpanel", "aria-labelledby": tabId, tabIndex: 0, hidden: !active, className: "min-w-0 flex-1 rounded-lg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600", children: children }));
|
|
69
|
+
}
|
|
70
|
+
const hasPanels = (items) => items.some((item) => item.href === undefined && item.panel !== undefined);
|
|
71
|
+
/** The tab list on its own: the underline row in its rule, or the pill rail. */
|
|
72
|
+
function TabList({ size, stacked, ids, ...props }) {
|
|
34
73
|
const step = useTypeStep();
|
|
35
|
-
|
|
74
|
+
const [row, setRow] = useState(null);
|
|
75
|
+
useScrollEdges(stacked ? null : row, "x");
|
|
76
|
+
const list = (_jsx(Switcher, { ...props, parts: {
|
|
36
77
|
group: "tablist",
|
|
37
78
|
item: "tab",
|
|
38
79
|
vertical: stacked,
|
|
39
80
|
stacked,
|
|
40
81
|
root: stacked ? "flex flex-col gap-1" : UNDERLINE_ROW,
|
|
82
|
+
onRoot: setRow,
|
|
83
|
+
ids,
|
|
41
84
|
option: (active, disabled) => stacked
|
|
42
85
|
? pillTabClass(active, disabled, size, step)
|
|
43
86
|
: cx(BASE, active ? ON : OFF, !active && !disabled && OFF_LIVE),
|
|
44
87
|
} }));
|
|
88
|
+
return stacked ? list : _jsx("div", { className: UNDERLINE_RULE, children: list });
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Tabs for switching a view in place or between pages. Across (the default) they are underline
|
|
92
|
+
* tabs: one line over a bottom rule, the current tab underlined in the accent, scrolling sideways
|
|
93
|
+
* with a fade when the row is too wide. `orientation="vertical"` is the pill rail instead, the
|
|
94
|
+
* current tab filled and outlined, for a `SidebarLayout` aside, and takes a `size`. `items` are
|
|
95
|
+
* `{ value, label, panel }` buttons (`value` and `onChange` are the caller's state; the arrow
|
|
96
|
+
* keys, Home and End move between tabs) or links (`href`, an in-app one through `LinkProvider`;
|
|
97
|
+
* `selected` on an item, or `value`, marks the current one, which gets `aria-current`). A button's
|
|
98
|
+
* `panel` is rendered as its `tabpanel`, wired to the tab and hidden while another is current. An
|
|
99
|
+
* item may carry a `count`, and a button one `disabledReason` (it stays reachable by the arrows and
|
|
100
|
+
* its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label`
|
|
101
|
+
* names the tab list.
|
|
102
|
+
*/
|
|
103
|
+
export function Tabs({ size = "md", orientation = "horizontal", ...props }) {
|
|
104
|
+
const stacked = orientation === "vertical";
|
|
105
|
+
const base = useId();
|
|
106
|
+
const items = props.items;
|
|
107
|
+
const panels = hasPanels(items) ? items : undefined;
|
|
108
|
+
const ids = (index) => panels?.[index]?.panel === undefined
|
|
109
|
+
? undefined
|
|
110
|
+
: { tab: `${base}-tab-${index}`, panel: `${base}-panel-${index}` };
|
|
111
|
+
const list = _jsx(TabList, { ...props, size: size, stacked: stacked, ids: ids });
|
|
112
|
+
if (!panels || props.onChange === undefined)
|
|
113
|
+
return list;
|
|
114
|
+
const { value, onChange, disabled } = props;
|
|
115
|
+
return (_jsxs("div", { className: stacked ? "flex items-start gap-6" : "flex flex-col gap-4", children: [list, panels.map((item, index) => {
|
|
116
|
+
const own = ids(index);
|
|
117
|
+
if (!own)
|
|
118
|
+
return null;
|
|
119
|
+
return (_jsx(TabPanel, { id: own.panel, tabId: own.tab, active: item.value === value, findable: !(disabled || item.disabled || hasReason(item.disabledReason)), onFound: () => onChange(item.value), children: item.panel }, item.value));
|
|
120
|
+
})] }));
|
|
45
121
|
}
|
|
46
|
-
const UNDERLINE_ROW = "flex flex-wrap gap-x-5 border-b border-slate-200 text-sm";
|
package/dist/TextLink.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentPropsWithoutRef, ReactElement } from "react";
|
|
2
|
+
import { type IconName } from "./icons.js";
|
|
2
3
|
import type { Unstyled } from "./props.js";
|
|
3
4
|
import type { Size } from "./size.js";
|
|
4
5
|
import { type TextTone } from "./typography.js";
|
|
@@ -11,6 +12,13 @@ export declare const linkClass: string;
|
|
|
11
12
|
* above it leaves this one alone.
|
|
12
13
|
*/
|
|
13
14
|
export declare const linkStretchClass = "link-stretch after:absolute after:inset-0";
|
|
15
|
+
/**
|
|
16
|
+
* A TextLink's colour: a text tone, as on the inline roles, or `quiet`, the primary ink at rest and
|
|
17
|
+
* the accent on hover, for a link in a row or list of links (a footer row, a table of contents),
|
|
18
|
+
* never inside a sentence, where with no colour or underline at rest it reads as plain text. This
|
|
19
|
+
* extends `TextTone` outward with `quiet`, a look only a link has.
|
|
20
|
+
*/
|
|
21
|
+
export type TextLinkTone = TextTone | "quiet";
|
|
14
22
|
/** A TextLink's pinned type size, on the `Size` scale; left out, it takes the size of the text around it. */
|
|
15
23
|
export type TextLinkSize = Size;
|
|
16
24
|
type TextLinkProps = {
|
|
@@ -21,9 +29,13 @@ type TextLinkProps = {
|
|
|
21
29
|
size?: TextLinkSize | undefined;
|
|
22
30
|
/**
|
|
23
31
|
* A meaning's colour, as on the inline roles: `warn` for a warning link, `danger`, `positive`,
|
|
24
|
-
* `info` or `muted
|
|
32
|
+
* `info` or `muted`; or `quiet`, the primary ink at rest and the accent on hover, for a row or list
|
|
33
|
+
* of links and never inside a sentence. Left out, the
|
|
34
|
+
* link is the accent colour.
|
|
25
35
|
*/
|
|
26
|
-
tone?:
|
|
36
|
+
tone?: TextLinkTone | undefined;
|
|
37
|
+
/** An icon after the words (`chevron-right`, say), at one size on the baseline; it is decorative and hidden from assistive tech. */
|
|
38
|
+
icon?: IconName | undefined;
|
|
27
39
|
/** The monospace face, for a path, an id or a command. */
|
|
28
40
|
mono?: boolean | undefined;
|
|
29
41
|
/** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
|
|
@@ -44,8 +56,9 @@ type TextLinkProps = {
|
|
|
44
56
|
/**
|
|
45
57
|
* An inline text link in the accent colour. Every anchor prop goes on the `<a>`; an in-app `href`
|
|
46
58
|
* is drawn by the app's router link through `LinkProvider`.
|
|
47
|
-
* `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour
|
|
48
|
-
* monospace face.
|
|
59
|
+
* `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour (or `quiet`,
|
|
60
|
+
* ink that turns the accent on hover) and `mono` sets the monospace face. `icon` puts one of the
|
|
61
|
+
* library's icons after the words, hidden from assistive tech: the words name the link.
|
|
49
62
|
*/
|
|
50
|
-
export declare function TextLink({ size, tone, mono, external, stretch, underline, href, children, ...rest }: TextLinkProps): ReactElement;
|
|
63
|
+
export declare function TextLink({ size, tone, mono, external, stretch, underline, href, icon, children, ...rest }: TextLinkProps): ReactElement;
|
|
51
64
|
export {};
|
package/dist/TextLink.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { cx, focusRing } from "./cx.js";
|
|
3
|
+
import { iconGlyph } from "./icons.js";
|
|
2
4
|
import { renderLink } from "./link.js";
|
|
3
5
|
import { TEXT_TONE } from "./typography.js";
|
|
4
6
|
const LINK = "rounded font-medium underline-offset-2 transition-colors";
|
|
@@ -14,8 +16,18 @@ const toneClass = (tone) => cx(LINK, TEXT_TONE[tone], "hover:underline", focusRi
|
|
|
14
16
|
* above it leaves this one alone.
|
|
15
17
|
*/
|
|
16
18
|
export const linkStretchClass = "link-stretch after:absolute after:inset-0";
|
|
17
|
-
// The
|
|
18
|
-
const
|
|
19
|
+
// The ink at rest, the accent on hover; focus draws the accent ring, as on every link.
|
|
20
|
+
const QUIET = cx(LINK, "text-slate-900 hover:text-violet-700", focusRing);
|
|
21
|
+
// The tone's colour, the quiet ink, or the accent with its hover shade.
|
|
22
|
+
function colourClass(tone) {
|
|
23
|
+
if (tone === "quiet")
|
|
24
|
+
return QUIET;
|
|
25
|
+
if (tone === undefined || tone === "neutral")
|
|
26
|
+
return linkClass;
|
|
27
|
+
return toneClass(tone);
|
|
28
|
+
}
|
|
29
|
+
// The trailing icon: one size, a touch under the text's, sitting on the baseline.
|
|
30
|
+
const ICON = "ms-1 inline-block size-[0.875em] align-[-0.125em] [&>svg]:size-full";
|
|
19
31
|
const SIZE = {
|
|
20
32
|
sm: "text-xs/4",
|
|
21
33
|
md: "text-sm/5",
|
|
@@ -24,15 +36,16 @@ const SIZE = {
|
|
|
24
36
|
/**
|
|
25
37
|
* An inline text link in the accent colour. Every anchor prop goes on the `<a>`; an in-app `href`
|
|
26
38
|
* is drawn by the app's router link through `LinkProvider`.
|
|
27
|
-
* `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour
|
|
28
|
-
* monospace face.
|
|
39
|
+
* `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour (or `quiet`,
|
|
40
|
+
* ink that turns the accent on hover) and `mono` sets the monospace face. `icon` puts one of the
|
|
41
|
+
* library's icons after the words, hidden from assistive tech: the words name the link.
|
|
29
42
|
*/
|
|
30
|
-
export function TextLink({ size, tone, mono = false, external = false, stretch = false, underline = false, href, children, ...rest }) {
|
|
43
|
+
export function TextLink({ size, tone, mono = false, external = false, stretch = false, underline = false, href, icon, children, ...rest }) {
|
|
31
44
|
return renderLink({
|
|
32
45
|
...rest,
|
|
33
46
|
href,
|
|
34
47
|
external,
|
|
35
48
|
className: cx(colourClass(tone), size && SIZE[size], mono && "font-mono", stretch && linkStretchClass, underline && "underline"),
|
|
36
|
-
children,
|
|
49
|
+
children: icon === undefined ? (children) : (_jsxs(_Fragment, { children: [children, _jsx("span", { "aria-hidden": "true", className: ICON, children: iconGlyph(icon) })] })),
|
|
37
50
|
});
|
|
38
51
|
}
|
package/dist/Textarea.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ComponentPropsWithoutRef, ReactElement, Ref } from "react";
|
|
2
|
-
import { type ControlProps } from "./control.js";
|
|
2
|
+
import { type ControlProps, type ControlSize, type ControlWidth } from "./control.js";
|
|
3
3
|
import type { Unstyled } from "./props.js";
|
|
4
|
+
import type { ResponsiveSize } from "./size.js";
|
|
4
5
|
export type TextareaProps = ControlProps & {
|
|
5
6
|
/** The monospace face, for pasted CSV or statement text, where the columns must line up. Off by default. */
|
|
6
7
|
mono?: boolean | undefined;
|
|
@@ -9,3 +10,13 @@ export type TextareaProps = ControlProps & {
|
|
|
9
10
|
} & Unstyled<Omit<ComponentPropsWithoutRef<"textarea">, "width">>;
|
|
10
11
|
/** A multi-line text input, styled like `Input`. `rows` defaults to 3. Takes `size`, `width` and `mono` too. The `ref` reaches the `<textarea>`, for focus control. */
|
|
11
12
|
export declare function Textarea({ size, width, mono, ...rest }: TextareaProps): ReactElement;
|
|
13
|
+
/**
|
|
14
|
+
* `Textarea`, plus `grow` for the library's own boxes (`ChatComposer`): a `md` box that grows from 2
|
|
15
|
+
* rows to 8 with its text. Not exported from `index.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function TextareaControl({ size, width, mono, grow, ...rest }: Omit<TextareaProps, "size" | "width" | "mono"> & {
|
|
18
|
+
size: ControlSize | ResponsiveSize;
|
|
19
|
+
width: ControlWidth;
|
|
20
|
+
mono: boolean;
|
|
21
|
+
grow?: boolean;
|
|
22
|
+
}): ReactElement;
|
package/dist/Textarea.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { controlPad, controlClass, } from "./control.js";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
import { useTypeStep } from "./density.js";
|
|
5
5
|
import { useFieldControl } from "./fieldControl.js";
|
|
6
|
+
/**
|
|
7
|
+
* A box that grows with its text from 2 rows to 8, then scrolls: `field-sizing: content` where the
|
|
8
|
+
* browser has it (newer than the Baseline floor, so feature-detected), else a fixed 2 rows. For the
|
|
9
|
+
* `md` size, whose padding (`py-2`) and border the heights add.
|
|
10
|
+
*/
|
|
11
|
+
const GROW = "supports-[field-sizing:content]:[field-sizing:content] supports-[field-sizing:content]:min-h-[calc(2lh+1rem+2px)] max-h-[calc(8lh+1rem+2px)]";
|
|
6
12
|
/** A multi-line text input, styled like `Input`. `rows` defaults to 3. Takes `size`, `width` and `mono` too. The `ref` reaches the `<textarea>`, for focus control. */
|
|
7
13
|
export function Textarea({ size = "md", width = "full", mono = false, ...rest }) {
|
|
14
|
+
return _jsx(TextareaControl, { ...rest, size: size, width: width, mono: mono });
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `Textarea`, plus `grow` for the library's own boxes (`ChatComposer`): a `md` box that grows from 2
|
|
18
|
+
* rows to 8 with its text. Not exported from `index.ts`.
|
|
19
|
+
*/
|
|
20
|
+
export function TextareaControl({ size, width, mono, grow = false, ...rest }) {
|
|
8
21
|
const step = useTypeStep();
|
|
9
22
|
const field = useFieldControl(rest);
|
|
10
|
-
return (_jsx("textarea", { rows: 3, ...rest, ...field, className: cx(controlClass(size, width, step),
|
|
23
|
+
return (_jsx("textarea", { rows: grow ? 2 : 3, ...rest, ...field, className: cx(controlClass(size, width, step), controlPad(size), mono && "font-mono", grow && GROW) }));
|
|
11
24
|
}
|
package/dist/ToastRegion.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import type { Passthrough } from "./props.js";
|
|
3
3
|
import type { Tone } from "./tone.js";
|
|
4
4
|
/** One notice in a `ToastRegion`. The caller holds the list; the region draws it. */
|
|
@@ -8,7 +8,7 @@ export type Toast = {
|
|
|
8
8
|
/** The bold line: the whole message for a short one ("Saved"). */
|
|
9
9
|
title: string;
|
|
10
10
|
/** A line of detail under the title. */
|
|
11
|
-
|
|
11
|
+
description?: ReactNode;
|
|
12
12
|
/**
|
|
13
13
|
* What the notice means, with `Callout`'s surfaces. A `warn` or `danger` toast never hides itself.
|
|
14
14
|
* @default neutral
|
|
@@ -19,17 +19,20 @@ export type Toast = {
|
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* The page's toasts: short notices fixed to the bottom of the viewport, from a list the app holds.
|
|
22
|
-
* Mount it once, at the root beside `AppShell`; add a toast to `
|
|
22
|
+
* Mount it once, at the root beside `AppShell`; add a toast to `items` to show it, and drop it in
|
|
23
23
|
* `onDismiss` to remove it. A `neutral`, `info` or `positive` toast with no `actions` leaves on its
|
|
24
|
-
* own after
|
|
24
|
+
* own after eight seconds (paused while the pointer is over it or focus is in it); a `warn` or
|
|
25
25
|
* `danger` toast, or one with `actions`, stays until dismissed. The region is a named landmark with
|
|
26
|
-
* a polite `role="status"
|
|
27
|
-
*
|
|
26
|
+
* a polite `role="status"` kept in the page while empty, which reads each new toast's text once,
|
|
27
|
+
* followed by "Actions available" when it has actions; its buttons are not read out. A `danger`
|
|
28
|
+
* toast is read through a `role="alert"` beside it instead, so it interrupts. Dismissing the
|
|
29
|
+
* toast that holds focus moves focus to the next toast, or back where it was. A toast raised while a
|
|
30
|
+
* `Dialog`, `Drawer` or `Lightbox` is open is held back (those already shown stay), shown and read once the modal has closed.
|
|
28
31
|
*/
|
|
29
|
-
export declare function ToastRegion({
|
|
32
|
+
export declare function ToastRegion({ items, onDismiss, label, dismissLabel, actionsLabel, ...rest }: {
|
|
30
33
|
/** What is shown, oldest first. `[]` shows nothing and keeps the live region in the page. */
|
|
31
|
-
|
|
32
|
-
/** Called by a toast's close button and when a self-hiding toast's time is up: drop it from `
|
|
34
|
+
items: readonly Toast[];
|
|
35
|
+
/** Called by a toast's close button and when a self-hiding toast's time is up: drop it from `items`. */
|
|
33
36
|
onDismiss: (id: string) => void;
|
|
34
37
|
/**
|
|
35
38
|
* The region's accessible name.
|
|
@@ -41,4 +44,9 @@ export declare function ToastRegion({ toasts, onDismiss, label, dismissLabel, ..
|
|
|
41
44
|
* @default Dismiss
|
|
42
45
|
*/
|
|
43
46
|
dismissLabel?: string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Read after a toast that has `actions`, so a screen reader user knows to go and find them.
|
|
49
|
+
* @default Actions available
|
|
50
|
+
*/
|
|
51
|
+
actionsLabel?: string | undefined;
|
|
44
52
|
} & Passthrough): ReactElement;
|
package/dist/ToastRegion.js
CHANGED
|
@@ -1,37 +1,94 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState, } from "react";
|
|
2
3
|
import { TONE_SURFACE, TONE_TEXT } from "./Callout.js";
|
|
3
4
|
import { cx } from "./cx.js";
|
|
4
5
|
import { IconButton } from "./IconButton.js";
|
|
6
|
+
import { useModalOpen } from "./modal.js";
|
|
5
7
|
// The hide is CSS, not a timer. A toast that may leave on its own carries `data-toast-hide`: it is
|
|
6
|
-
// shown for
|
|
7
|
-
// caller drops it from the list
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
const css = `[data-toast-hide]{animation:hc-toast-hide .2s ease-in
|
|
8
|
+
// shown for eight seconds, then fades for 200ms, and the animation's end calls `onDismiss`, so the
|
|
9
|
+
// caller drops it from the list. Hovering the region or focusing anything in it pauses the run.
|
|
10
|
+
// Under reduced motion the same run holds a discrete `visibility` keyframe instead of the fade, so
|
|
11
|
+
// the toast still leaves at the same moment.
|
|
12
|
+
const css = `[data-toast-hide]{animation:hc-toast-hide .2s ease-in 8s forwards}[data-hc-toasts]:hover [data-toast-hide],[data-hc-toasts]:focus-within [data-toast-hide]{animation-play-state:paused}@keyframes hc-toast-hide{to{opacity:0}}@media (prefers-reduced-motion:reduce){[data-toast-hide]{animation-name:hc-toast-cut}}@keyframes hc-toast-cut{from,to{visibility:visible}}`;
|
|
11
13
|
/** Only a plain confirmation leaves on its own: no action to reach, nothing that must be read. */
|
|
12
14
|
function hides(toast) {
|
|
13
15
|
const tone = toast.tone ?? "neutral";
|
|
14
16
|
return toast.actions == null && (tone === "neutral" || tone === "info" || tone === "positive");
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Puts the toast's words in the live region once, when it first shows, and takes them out when it
|
|
20
|
+
* goes: the title, the description's text, and `actionsLabel` when it has actions. The buttons themselves
|
|
21
|
+
* are never read out as part of the notice.
|
|
22
|
+
*/
|
|
23
|
+
function useAnnounce(live, title, actionsLabel) {
|
|
24
|
+
const body = useRef(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const line = document.createElement("p");
|
|
27
|
+
line.textContent = [title, body.current?.textContent, actionsLabel].filter(Boolean).join(". ");
|
|
28
|
+
live.current?.append(line);
|
|
29
|
+
return () => line.remove();
|
|
30
|
+
}, [live, title, actionsLabel]);
|
|
31
|
+
return body;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Where focus goes when the toast holding it is dismissed: the next toast's dismiss button, else the
|
|
35
|
+
* one before, else back where it was before it came into the region.
|
|
36
|
+
*/
|
|
37
|
+
function focusAfter(toast, back) {
|
|
38
|
+
if (!toast.contains(document.activeElement))
|
|
39
|
+
return;
|
|
40
|
+
const sibling = toast.nextElementSibling ?? toast.previousElementSibling;
|
|
41
|
+
const next = sibling?.querySelector("[data-toast-dismiss]");
|
|
42
|
+
if (next)
|
|
43
|
+
return next.focus();
|
|
44
|
+
if (back.current?.isConnected)
|
|
45
|
+
back.current.focus();
|
|
46
|
+
back.current = null;
|
|
47
|
+
}
|
|
48
|
+
function ToastItem({ toast, dismissLabel, actionsLabel, live, alert, back, onDismiss, }) {
|
|
17
49
|
const tone = toast.tone ?? "neutral";
|
|
18
50
|
const hide = hides(toast);
|
|
51
|
+
const body = useAnnounce(tone === "danger" ? alert : live, toast.title, toast.actions == null ? null : actionsLabel);
|
|
19
52
|
return (_jsxs("div", { "data-toast": "", "data-toast-hide": hide ? "" : undefined, onAnimationEnd: (event) => {
|
|
20
53
|
// A child's animation (a busy Button's spinner) bubbles here too: only the toast's own
|
|
21
54
|
// animation, which is the hide, counts.
|
|
22
55
|
if (hide && event.target === event.currentTarget)
|
|
23
56
|
onDismiss(toast.id);
|
|
24
|
-
}, className: cx("pointer-events-auto flex items-start gap-3 rounded-xl border p-3 pl-4 text-sm shadow-lg", TONE_SURFACE[tone], TONE_TEXT[tone]), children: [_jsxs("div", { className: "min-w-0 flex-1 py-0.5", children: [_jsx("p", { className: "font-semibold", children: toast.title }), toast.
|
|
57
|
+
}, className: cx("pointer-events-auto flex items-start gap-3 rounded-xl border p-3 pl-4 text-sm shadow-lg", TONE_SURFACE[tone], TONE_TEXT[tone]), children: [_jsxs("div", { className: "min-w-0 flex-1 py-0.5", children: [_jsx("p", { className: "font-semibold", children: toast.title }), toast.description != null && (_jsx("div", { ref: body, className: "mt-1", children: toast.description }))] }), toast.actions != null && (_jsx("div", { className: "flex shrink-0 items-center gap-2", children: toast.actions })), _jsx(IconButton, { size: "sm", variant: "ghost", icon: "close", label: dismissLabel, "data-toast-dismiss": "", onClick: (event) => {
|
|
58
|
+
const box = event.currentTarget.closest("[data-toast]");
|
|
59
|
+
if (box)
|
|
60
|
+
focusAfter(box, back);
|
|
61
|
+
onDismiss(toast.id);
|
|
62
|
+
} })] }));
|
|
25
63
|
}
|
|
26
64
|
/**
|
|
27
65
|
* The page's toasts: short notices fixed to the bottom of the viewport, from a list the app holds.
|
|
28
|
-
* Mount it once, at the root beside `AppShell`; add a toast to `
|
|
66
|
+
* Mount it once, at the root beside `AppShell`; add a toast to `items` to show it, and drop it in
|
|
29
67
|
* `onDismiss` to remove it. A `neutral`, `info` or `positive` toast with no `actions` leaves on its
|
|
30
|
-
* own after
|
|
68
|
+
* own after eight seconds (paused while the pointer is over it or focus is in it); a `warn` or
|
|
31
69
|
* `danger` toast, or one with `actions`, stays until dismissed. The region is a named landmark with
|
|
32
|
-
* a polite `role="status"
|
|
33
|
-
*
|
|
70
|
+
* a polite `role="status"` kept in the page while empty, which reads each new toast's text once,
|
|
71
|
+
* followed by "Actions available" when it has actions; its buttons are not read out. A `danger`
|
|
72
|
+
* toast is read through a `role="alert"` beside it instead, so it interrupts. Dismissing the
|
|
73
|
+
* toast that holds focus moves focus to the next toast, or back where it was. A toast raised while a
|
|
74
|
+
* `Dialog`, `Drawer` or `Lightbox` is open is held back (those already shown stay), shown and read once the modal has closed.
|
|
34
75
|
*/
|
|
35
|
-
export function ToastRegion({
|
|
36
|
-
|
|
76
|
+
export function ToastRegion({ items, onDismiss, label = "Notifications", dismissLabel = "Dismiss", actionsLabel = "Actions available", ...rest }) {
|
|
77
|
+
const live = useRef(null);
|
|
78
|
+
const alert = useRef(null);
|
|
79
|
+
/** What had focus before it came into the region, to hand it back when the last toast goes. */
|
|
80
|
+
const back = useRef(null);
|
|
81
|
+
const held = useModalOpen();
|
|
82
|
+
// The toasts on screen when a modal opened stay; only newer ones are held back. The ids shown
|
|
83
|
+
// are kept from the last render with no modal open, adjusted during render rather than in an effect.
|
|
84
|
+
const [kept, setKept] = useState([]);
|
|
85
|
+
const ids = items.map((toast) => toast.id);
|
|
86
|
+
if (!held && ids.join("\n") !== kept.join("\n"))
|
|
87
|
+
setKept(ids);
|
|
88
|
+
const visible = held ? items.filter((toast) => kept.includes(toast.id)) : items;
|
|
89
|
+
return (_jsxs("section", { "aria-label": label, ...rest, "data-hc-toasts": "", onFocus: (event) => {
|
|
90
|
+
const from = event.relatedTarget;
|
|
91
|
+
if (from instanceof HTMLElement && !event.currentTarget.contains(from))
|
|
92
|
+
back.current = from;
|
|
93
|
+
}, className: "pointer-events-none fixed inset-x-0 bottom-0 z-50 flex justify-center px-4 pb-[max(1rem,env(safe-area-inset-bottom))]", children: [_jsx("style", { children: css }), _jsx("div", { ref: live, role: "status", "aria-live": "polite", "aria-atomic": "false", className: "sr-only" }), _jsx("div", { ref: alert, role: "alert", "aria-atomic": "false", className: "sr-only" }), _jsx("div", { className: "flex w-full max-w-sm flex-col gap-2", children: visible.map((toast) => (_jsx(ToastItem, { toast: toast, dismissLabel: dismissLabel, actionsLabel: actionsLabel, live: live, alert: alert, back: back, onDismiss: onDismiss }, toast.id))) })] }));
|
|
37
94
|
}
|
package/dist/Tooltip.d.ts
CHANGED
|
@@ -23,16 +23,24 @@ type Options = {
|
|
|
23
23
|
describes: boolean;
|
|
24
24
|
/** A touch tap on the trigger shows the tooltip, and the next tap anywhere hides it. */
|
|
25
25
|
tap?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The keyboard's focus, for a trigger that cannot hear it: a run inside a grid row, where the row
|
|
28
|
+
* takes the focus. While `true` the tooltip shows as for a focus on the trigger; the caller sets
|
|
29
|
+
* it back to `false` on blur and on Escape.
|
|
30
|
+
*/
|
|
31
|
+
focused?: boolean | undefined;
|
|
26
32
|
};
|
|
27
33
|
/**
|
|
28
34
|
* Wires one internal tooltip to a trigger. Spread `props` on the trigger after the caller's own
|
|
29
35
|
* props: it holds the same keys, merged (`aria-describedby` and the handlers keep the caller's), and
|
|
30
36
|
* render `tooltip` right after the trigger. With no `text`, `props` is `own` unchanged and
|
|
31
|
-
* `tooltip` is null.
|
|
37
|
+
* `tooltip` is null. `enhanced` is false where the tooltip falls back to the native `title` (no
|
|
38
|
+
* anchor positioning, and the server markup), which a hover shows but focus never does. Internal: not exported from the package.
|
|
32
39
|
*/
|
|
33
|
-
export declare function useTooltip<E extends Element>(text: string | undefined, { describes, tap }: Options, own: TriggerOwn<E>): {
|
|
40
|
+
export declare function useTooltip<E extends Element>(text: string | undefined, { describes, tap, focused }: Options, own: TriggerOwn<E>): {
|
|
34
41
|
props: TriggerProps<E>;
|
|
35
42
|
tooltip: ReactNode;
|
|
43
|
+
enhanced: boolean;
|
|
36
44
|
};
|
|
37
45
|
/**
|
|
38
46
|
* `useTooltip` as a part, for a component that picks its element in a branch: `children` draws the
|
package/dist/Tooltip.js
CHANGED
|
@@ -39,10 +39,19 @@ function useLayer(layer, open) {
|
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
if (!layer)
|
|
41
41
|
return;
|
|
42
|
-
if (open)
|
|
43
|
-
layer.showPopover();
|
|
44
|
-
else
|
|
42
|
+
if (!open) {
|
|
45
43
|
layer.hidePopover();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// A popover that closes puts the focus back on its trigger while it is still hiding, and the
|
|
47
|
+
// browser refuses to show another one then: the tip stays shut, and the next focus shows it.
|
|
48
|
+
try {
|
|
49
|
+
layer.showPopover();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!(error instanceof DOMException && error.name === "InvalidStateError"))
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
46
55
|
}, [layer, open]);
|
|
47
56
|
}
|
|
48
57
|
/** While a tap holds the tooltip open, the next tap anywhere but the trigger closes it. */
|
|
@@ -78,6 +87,12 @@ function useEscape(on, close) {
|
|
|
78
87
|
return () => document.removeEventListener("keydown", escape, true);
|
|
79
88
|
}, [on, close]);
|
|
80
89
|
}
|
|
90
|
+
/** Why the tooltip shows: its own reason, else a focus the trigger cannot hear (the caller hides it again on Escape). */
|
|
91
|
+
function shownVia(via, focused) {
|
|
92
|
+
if (via !== null)
|
|
93
|
+
return via;
|
|
94
|
+
return focused ? "focus" : null;
|
|
95
|
+
}
|
|
81
96
|
/** The pointer left the trigger or the tooltip: close a hover tip, unless it moved onto the other. */
|
|
82
97
|
function leave(tip, related, from) {
|
|
83
98
|
const other = from === "trigger" ? tip.layer : tip.trigger;
|
|
@@ -137,9 +152,10 @@ function handlers(own, tip) {
|
|
|
137
152
|
* Wires one internal tooltip to a trigger. Spread `props` on the trigger after the caller's own
|
|
138
153
|
* props: it holds the same keys, merged (`aria-describedby` and the handlers keep the caller's), and
|
|
139
154
|
* render `tooltip` right after the trigger. With no `text`, `props` is `own` unchanged and
|
|
140
|
-
* `tooltip` is null.
|
|
155
|
+
* `tooltip` is null. `enhanced` is false where the tooltip falls back to the native `title` (no
|
|
156
|
+
* anchor positioning, and the server markup), which a hover shows but focus never does. Internal: not exported from the package.
|
|
141
157
|
*/
|
|
142
|
-
export function useTooltip(text, { describes, tap = false }, own) {
|
|
158
|
+
export function useTooltip(text, { describes, tap = false, focused }, own) {
|
|
143
159
|
const id = useId();
|
|
144
160
|
// False in the server markup and while the client hydrates, so both render the native `title`.
|
|
145
161
|
const enhanced = useSyncExternalStore(never, anchorPositioning, () => false);
|
|
@@ -148,13 +164,18 @@ export function useTooltip(text, { describes, tap = false }, own) {
|
|
|
148
164
|
const [layer, setLayer] = useState(null);
|
|
149
165
|
const [pressed, setPressed] = useState(false);
|
|
150
166
|
const close = useCallback(() => setVia(null), []);
|
|
151
|
-
|
|
167
|
+
const shown = shownVia(via, focused);
|
|
168
|
+
useLayer(layer, shown !== null);
|
|
152
169
|
useTapAway(via === "tap", trigger, close);
|
|
153
170
|
useEscape(via !== null, close);
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
// A tip whose text went empty while open closes, so it does not come back open with new text.
|
|
172
|
+
if (!text) {
|
|
173
|
+
if (via !== null)
|
|
174
|
+
setVia(null);
|
|
175
|
+
return { props: own, tooltip: null, enhanced };
|
|
176
|
+
}
|
|
156
177
|
if (!enhanced)
|
|
157
|
-
return { props: { ...own, title: text }, tooltip: null };
|
|
178
|
+
return { props: { ...own, title: text }, tooltip: null, enhanced };
|
|
158
179
|
const tip = { via, setVia, trigger, setTrigger, layer, pressed, setPressed, tap };
|
|
159
180
|
const anchor = `--hc-tip${id.replaceAll(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
160
181
|
const tipId = `${id}-tip`;
|
|
@@ -168,8 +189,8 @@ export function useTooltip(text, { describes, tap = false }, own) {
|
|
|
168
189
|
"aria-describedby": describedBy || undefined,
|
|
169
190
|
style: { anchorName: anchor },
|
|
170
191
|
};
|
|
171
|
-
const tooltip = (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("span", { ref: setLayer, id: tipId, role: "tooltip", popover: "manual", "data-hc-tooltip": "", "data-via":
|
|
172
|
-
return { props, tooltip };
|
|
192
|
+
const tooltip = (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("span", { ref: setLayer, id: tipId, role: "tooltip", popover: "manual", "data-hc-tooltip": "", "data-via": shown ?? undefined, "aria-hidden": describes ? undefined : true, style: { positionAnchor: anchor }, onPointerLeave: (event) => leave(tip, event.relatedTarget, "tooltip"), children: _jsx("span", { className: CHIP, children: text }) })] }));
|
|
193
|
+
return { props, tooltip, enhanced };
|
|
173
194
|
}
|
|
174
195
|
/**
|
|
175
196
|
* `useTooltip` as a part, for a component that picks its element in a branch: `children` draws the
|
package/dist/Video.d.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import type { ReactElement, VideoHTMLAttributes } from "react";
|
|
2
|
+
import { type ImageAspect } from "./Image.js";
|
|
2
3
|
import type { Unstyled } from "./props.js";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* `loading="lazy"` on a media element: the browser holds back even the metadata of one far below
|
|
6
|
+
* the fold. React passes the attribute through, but its types know it only on `<img>` and
|
|
7
|
+
* `<iframe>`, so it is spread from here; a browser without it ignores it and loads as before.
|
|
7
8
|
*/
|
|
8
|
-
export declare
|
|
9
|
+
export declare const LAZY_MEDIA: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* A `<video>` with controls, full width and rounded, in a fixed shape: `aspect` reserves its space
|
|
12
|
+
* before it loads, so the page does not jump, and the video fits inside it whole. It loads metadata
|
|
13
|
+
* only, and lazily where the browser can, so the page does not pull the file until it is played.
|
|
14
|
+
* `src` is the app's own video; `captions` is a WebVTT file, offered as the default track.
|
|
15
|
+
* `children` is the fallback for a browser that cannot play it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function Video({ src, captions, aspect, children, ...rest }: {
|
|
9
18
|
/** The video file, the app's own. */
|
|
10
19
|
src: string;
|
|
11
20
|
/** A WebVTT file, offered as the default captions track. */
|
|
12
21
|
captions?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The shape it reserves, as `Image`'s `aspect`: `16:9`, `16:10`, `4:3`, `3:2`, `square`, or the
|
|
24
|
+
* portrait `3:4` and `9:16`. A video of another shape fits inside it, letterboxed.
|
|
25
|
+
* @default 16:9
|
|
26
|
+
*/
|
|
27
|
+
aspect?: Exclude<ImageAspect, "natural"> | undefined;
|
|
13
28
|
} & Unstyled<Omit<VideoHTMLAttributes<HTMLVideoElement>, "src" | "controls">>): ReactElement;
|