@slashsuite/ui-react 0.12.0 → 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 +101 -44
- package/agent-docs/components/app-shell.md +139 -0
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/avatar-stack.md +64 -0
- package/agent-docs/components/avatar.md +76 -0
- package/agent-docs/components/badge.md +62 -0
- package/agent-docs/components/body-text.md +169 -0
- package/agent-docs/components/bottom-sheet.md +105 -0
- package/agent-docs/components/breadcrumbs.md +66 -0
- package/agent-docs/components/bullet-list.md +54 -0
- package/agent-docs/components/button.md +135 -0
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +87 -0
- package/agent-docs/components/card-grid.md +116 -0
- package/agent-docs/components/card.md +128 -0
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/centered-layout.md +90 -0
- package/agent-docs/components/chat-composer.md +49 -0
- package/agent-docs/components/chat-message.md +61 -0
- package/agent-docs/components/chat-thread.md +49 -0
- package/agent-docs/components/checkbox.md +81 -0
- package/agent-docs/components/cluster.md +108 -0
- package/agent-docs/components/code-example.md +48 -0
- package/agent-docs/components/code.md +72 -0
- package/agent-docs/components/colour-scheme-toggle.md +98 -0
- 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 +51 -0
- package/agent-docs/components/copy-button.md +63 -0
- package/agent-docs/components/copy-line.md +55 -0
- package/agent-docs/components/date-field.md +106 -0
- package/agent-docs/components/date-range-picker.md +108 -0
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/detail-layout.md +147 -0
- package/agent-docs/components/dialog.md +132 -0
- package/agent-docs/components/disclosure.md +70 -0
- package/agent-docs/components/divider.md +62 -0
- package/agent-docs/components/docs-layout.md +164 -0
- package/agent-docs/components/drawer.md +137 -0
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +70 -0
- package/agent-docs/components/field-dialog.md +98 -0
- package/agent-docs/components/field.md +71 -0
- package/agent-docs/components/fieldset.md +82 -0
- package/agent-docs/components/file-drop.md +52 -0
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +144 -0
- package/agent-docs/components/form-row.md +93 -0
- package/agent-docs/components/full-bleed-layout.md +114 -0
- package/agent-docs/components/headings.md +107 -0
- package/agent-docs/components/hero.md +68 -0
- package/agent-docs/components/icon-button.md +90 -0
- package/agent-docs/components/icon.md +59 -0
- package/agent-docs/components/image.md +74 -0
- package/agent-docs/components/input.md +84 -0
- package/agent-docs/components/kbd.md +38 -0
- package/agent-docs/components/key-value-list.md +84 -0
- package/agent-docs/components/lightbox.md +97 -0
- package/agent-docs/components/list-layout.md +152 -0
- package/agent-docs/components/list-row.md +119 -0
- package/agent-docs/components/loading.md +69 -0
- package/agent-docs/components/markdown.md +51 -0
- package/agent-docs/components/media-tile.md +101 -0
- package/agent-docs/components/menu.md +110 -0
- package/agent-docs/components/meta-list.md +69 -0
- package/agent-docs/components/morph.md +134 -0
- package/agent-docs/components/navigation-progress.md +56 -0
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +74 -0
- package/agent-docs/components/page-fade.md +117 -0
- package/agent-docs/components/page-header.md +93 -0
- package/agent-docs/components/pagination.md +64 -0
- package/agent-docs/components/pill.md +105 -0
- 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/progress-bar.md +66 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +87 -0
- package/agent-docs/components/prose.md +41 -0
- package/agent-docs/components/radio-group.md +77 -0
- package/agent-docs/components/scroll-strip.md +48 -0
- package/agent-docs/components/segmented-control.md +135 -0
- package/agent-docs/components/select.md +70 -0
- package/agent-docs/components/show.md +120 -0
- package/agent-docs/components/side-column.md +74 -0
- package/agent-docs/components/sidebar-layout.md +134 -0
- package/agent-docs/components/site-footer.md +63 -0
- package/agent-docs/components/site-search.md +79 -0
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +112 -0
- package/agent-docs/components/split-bar.md +54 -0
- package/agent-docs/components/stack.md +197 -0
- package/agent-docs/components/stacked-bar.md +91 -0
- package/agent-docs/components/stat-tile.md +69 -0
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +112 -0
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/steps.md +74 -0
- package/agent-docs/components/sticky-bar.md +51 -0
- package/agent-docs/components/switch.md +79 -0
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +384 -0
- package/agent-docs/components/tabs.md +178 -0
- package/agent-docs/components/text-link.md +110 -0
- package/agent-docs/components/textarea.md +53 -0
- package/agent-docs/components/timeline.md +79 -0
- package/agent-docs/components/toast.md +91 -0
- package/agent-docs/components/trend-chart.md +61 -0
- package/agent-docs/components/video.md +49 -0
- package/agent-docs/llms.txt +174 -0
- 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 +7 -3
- package/skills/uislash/SKILL.md +20 -0
|
@@ -3,7 +3,9 @@ import { type ColourScheme, type ColourSchemeClasses } from "./colourScheme.js";
|
|
|
3
3
|
import type { Unstyled } from "./props.js";
|
|
4
4
|
import type { Size } from "./size.js";
|
|
5
5
|
/**
|
|
6
|
-
* A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to.
|
|
6
|
+
* A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to.
|
|
7
|
+
* A click that lands on the system's own scheme forgets the stored choice, so the page follows the system again; a click away from it stores the choice.
|
|
8
|
+
* With `store` on, the page also follows a choice made in another tab and, while nothing is stored, the system switching. Pair it with `colourSchemeScript` in `<head>`, unless you pass `schemes` or `defaultValue`: the script knows only the `dark` class and the stored choice, so an app that sets the scheme itself leaves it out.
|
|
7
9
|
*
|
|
8
10
|
* An app whose light scheme has a class of its own passes `schemes` (`{ light: "my-light", dark: "dark" }`);
|
|
9
11
|
* the toggle swaps those classes, and `schemeClass` gives the same one for the server to render on `<html>`.
|
|
@@ -11,19 +13,23 @@ import type { Size } from "./size.js";
|
|
|
11
13
|
* markup, the hydrating client and the `<html>` class agree; persist a change from `onChange`.
|
|
12
14
|
* The icon and the button's accessible name follow the class on `<html>` through CSS (the name is
|
|
13
15
|
* two visually hidden "Switch to …" spans, one hidden by `display:none`), so even without `defaultValue`
|
|
14
|
-
* a dark page shows the sun and is named "Switch to light theme" from the first frame, with no
|
|
16
|
+
* a dark page shows the sun and is named `lightLabel` ("Switch to light theme") from the first frame, with no
|
|
15
17
|
* script. Only the tooltip catches up once the client has hydrated.
|
|
16
18
|
* `store={false}` skips `localStorage`, for an app that keeps the choice in a server cookie and
|
|
17
19
|
* writes it from `onChange`. Every other button prop (`id`, `data-*`, `aria-*`) goes on the button.
|
|
18
20
|
*/
|
|
19
|
-
export declare function ColourSchemeToggle({ onChange, schemes, defaultValue, store, size, ...rest }: {
|
|
21
|
+
export declare function ColourSchemeToggle({ onChange, schemes, defaultValue, store, size, darkLabel, lightLabel, ...rest }: {
|
|
20
22
|
/**
|
|
21
23
|
* The button's height, as an `IconButton`'s.
|
|
22
24
|
* @default md
|
|
23
25
|
*/
|
|
24
26
|
size?: Size | undefined;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Called with the new scheme after a click, for an app that persists the choice itself (a cookie).
|
|
29
|
+
* `followsSystem` is true when the new scheme is the system's: forget the choice (clear the cookie)
|
|
30
|
+
* rather than store it, so the page follows the system again.
|
|
31
|
+
*/
|
|
32
|
+
onChange?: (scheme: ColourScheme, followsSystem: boolean) => void;
|
|
27
33
|
/** The class each scheme puts on `<html>`. */
|
|
28
34
|
schemes?: ColourSchemeClasses | undefined;
|
|
29
35
|
/**
|
|
@@ -33,4 +39,14 @@ export declare function ColourSchemeToggle({ onChange, schemes, defaultValue, st
|
|
|
33
39
|
defaultValue?: ColourScheme | undefined;
|
|
34
40
|
/** Remember the choice in `localStorage`. `false` leaves persisting to `onChange`. */
|
|
35
41
|
store?: boolean | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The button's accessible name and tooltip on a light page, where it switches to dark.
|
|
44
|
+
* @default Switch to dark theme
|
|
45
|
+
*/
|
|
46
|
+
darkLabel?: string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The button's accessible name and tooltip on a dark page, where it switches to light.
|
|
49
|
+
* @default Switch to light theme
|
|
50
|
+
*/
|
|
51
|
+
lightLabel?: string | undefined;
|
|
36
52
|
} & Unstyled<Omit<ComponentPropsWithoutRef<"button">, "onChange" | "onClick" | "children" | "aria-label" | "title">>): ReactElement;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
import { appliedColourScheme, applyColourScheme, storeColourScheme, } from "./colourScheme.js";
|
|
2
|
+
import { useEffect, useSyncExternalStore, } from "react";
|
|
3
|
+
import { appliedColourScheme, applyColourScheme, followColourScheme, storeColourScheme, systemColourScheme, } from "./colourScheme.js";
|
|
4
4
|
import { look } from "./IconButton.js";
|
|
5
5
|
import { Tipped } from "./Tooltip.js";
|
|
6
6
|
const sun = (_jsxs("svg", { "data-scheme-icon": "sun", viewBox: "0 0 24 24", className: "h-4 w-4", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" })] }));
|
|
@@ -38,7 +38,9 @@ function subscribe(onChange) {
|
|
|
38
38
|
// cannot choose, so it is rendered only once the client knows the scheme.
|
|
39
39
|
const never = () => () => { };
|
|
40
40
|
/**
|
|
41
|
-
* A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to.
|
|
41
|
+
* A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to.
|
|
42
|
+
* A click that lands on the system's own scheme forgets the stored choice, so the page follows the system again; a click away from it stores the choice.
|
|
43
|
+
* With `store` on, the page also follows a choice made in another tab and, while nothing is stored, the system switching. Pair it with `colourSchemeScript` in `<head>`, unless you pass `schemes` or `defaultValue`: the script knows only the `dark` class and the stored choice, so an app that sets the scheme itself leaves it out.
|
|
42
44
|
*
|
|
43
45
|
* An app whose light scheme has a class of its own passes `schemes` (`{ light: "my-light", dark: "dark" }`);
|
|
44
46
|
* the toggle swaps those classes, and `schemeClass` gives the same one for the server to render on `<html>`.
|
|
@@ -46,19 +48,23 @@ const never = () => () => { };
|
|
|
46
48
|
* markup, the hydrating client and the `<html>` class agree; persist a change from `onChange`.
|
|
47
49
|
* The icon and the button's accessible name follow the class on `<html>` through CSS (the name is
|
|
48
50
|
* two visually hidden "Switch to …" spans, one hidden by `display:none`), so even without `defaultValue`
|
|
49
|
-
* a dark page shows the sun and is named "Switch to light theme" from the first frame, with no
|
|
51
|
+
* a dark page shows the sun and is named `lightLabel` ("Switch to light theme") from the first frame, with no
|
|
50
52
|
* script. Only the tooltip catches up once the client has hydrated.
|
|
51
53
|
* `store={false}` skips `localStorage`, for an app that keeps the choice in a server cookie and
|
|
52
54
|
* writes it from `onChange`. Every other button prop (`id`, `data-*`, `aria-*`) goes on the button.
|
|
53
55
|
*/
|
|
54
|
-
export function ColourSchemeToggle({ onChange, schemes = { light: "", dark: "dark" }, defaultValue, store = true, size = "md", ...rest }) {
|
|
56
|
+
export function ColourSchemeToggle({ onChange, schemes = { light: "", dark: "dark" }, defaultValue, store = true, size = "md", darkLabel = "Switch to dark theme", lightLabel = "Switch to light theme", ...rest }) {
|
|
55
57
|
const scheme = useSyncExternalStore(subscribe, () => appliedColourScheme(document.documentElement, schemes), () => defaultValue ?? "light");
|
|
56
58
|
const hydrated = useSyncExternalStore(never, () => true, () => false);
|
|
59
|
+
const { light, dark } = schemes;
|
|
60
|
+
useEffect(() => (store ? followColourScheme(document.documentElement, { light, dark }) : undefined), [store, light, dark]);
|
|
57
61
|
const next = scheme === "dark" ? "light" : "dark";
|
|
58
|
-
|
|
62
|
+
const nextLabel = next === "dark" ? darkLabel : lightLabel;
|
|
63
|
+
return (_jsx(Tipped, { text: hydrated ? nextLabel : undefined, describes: false, own: rest, children: (tip) => (_jsxs("button", { type: "button", ...rest, ...tip, className: look({ size }), onClick: () => {
|
|
64
|
+
const followsSystem = next === systemColourScheme();
|
|
59
65
|
applyColourScheme(next, document.documentElement, schemes);
|
|
60
66
|
if (store)
|
|
61
|
-
storeColourScheme(next);
|
|
62
|
-
onChange?.(next);
|
|
63
|
-
}, children: [_jsx("style", { children: schemeRules(schemes) }), sun, moon, _jsx("span", { className: "sr-only", "data-scheme-name": "dark", children:
|
|
67
|
+
storeColourScheme(followsSystem ? "system" : next);
|
|
68
|
+
onChange?.(next, followsSystem);
|
|
69
|
+
}, children: [_jsx("style", { children: schemeRules(schemes) }), sun, moon, _jsx("span", { className: "sr-only", "data-scheme-name": "dark", children: darkLabel }), _jsx("span", { className: "sr-only", "data-scheme-name": "light", children: lightLabel })] })) }));
|
|
64
70
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/**
|
|
4
|
+
* A small square in a measured colour, with its `label` and its hex `value` beside it in mono: a
|
|
5
|
+
* colour read off a page, a screenshot or a theme. The colour is the data on show, not a look, so
|
|
6
|
+
* it is painted from `value`; anything but a `#rrggbb` value draws an empty swatch and no value.
|
|
7
|
+
* A hairline edges the square, so a colour close to the page still shows. The square is
|
|
8
|
+
* decorative: the label and the value say the colour.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ColourSwatch({ value, label, ...rest }: {
|
|
11
|
+
/** The colour, as `#rrggbb`. Anything else draws an empty swatch and leaves the value out. */
|
|
12
|
+
value: string;
|
|
13
|
+
/** What the colour is, as "Background" or "Accent", shown before the value. */
|
|
14
|
+
label: string;
|
|
15
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** A colour as six hex digits after a `#`, and nothing else: no name, no function, no CSS. */
|
|
3
|
+
const HEX = /^#[0-9a-f]{6}$/i;
|
|
4
|
+
/**
|
|
5
|
+
* A small square in a measured colour, with its `label` and its hex `value` beside it in mono: a
|
|
6
|
+
* colour read off a page, a screenshot or a theme. The colour is the data on show, not a look, so
|
|
7
|
+
* it is painted from `value`; anything but a `#rrggbb` value draws an empty swatch and no value.
|
|
8
|
+
* A hairline edges the square, so a colour close to the page still shows. The square is
|
|
9
|
+
* decorative: the label and the value say the colour.
|
|
10
|
+
*/
|
|
11
|
+
export function ColourSwatch({ value, label, ...rest }) {
|
|
12
|
+
const valid = HEX.test(value);
|
|
13
|
+
return (_jsxs("span", { ...rest, className: "inline-flex min-w-0 items-center gap-2 font-mono text-sm", children: [_jsx("span", { "aria-hidden": "true", className: "size-4 shrink-0 rounded-sm border border-slate-300 bg-slate-100", style: valid ? { backgroundColor: value } : undefined }), _jsx("span", { className: "truncate text-slate-900", children: label }), valid && _jsx("span", { className: "text-slate-600", children: value.toLowerCase() })] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { type ControlProps } from "./control.js";
|
|
3
|
+
import { type Passthrough } from "./props.js";
|
|
4
|
+
import type { SelectItem } from "./Select.js";
|
|
5
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
6
|
+
export type ComboboxProps = {
|
|
7
|
+
/** The field's visible label, above it. Without one, name the field with `aria-label`. */
|
|
8
|
+
label?: ReactNode;
|
|
9
|
+
/** A muted line under the field that says more; it stays while an error shows under it. */
|
|
10
|
+
hint?: ReactNode;
|
|
11
|
+
/** Marks the field invalid and shows this in red under the hint, announced politely. */
|
|
12
|
+
error?: ReactNode;
|
|
13
|
+
/** The choices, in order; typing filters them by label. */
|
|
14
|
+
items: readonly SelectItem[];
|
|
15
|
+
/** The chosen item's `value`, controlled, with `onChange`. `null` is nothing chosen. */
|
|
16
|
+
value?: string | null | undefined;
|
|
17
|
+
/** The item's `value` it starts with, uncontrolled. */
|
|
18
|
+
defaultValue?: string | null | undefined;
|
|
19
|
+
/** Called with the chosen item's `value`, or `null` when the choice is cleared. */
|
|
20
|
+
onChange?: ((value: string | null) => void) | undefined;
|
|
21
|
+
/** Posts the chosen item's `value` in a form under this key. */
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
/** Disables the field and its button. */
|
|
24
|
+
disabled?: boolean | undefined;
|
|
25
|
+
/** Marks a choice required: the field is `aria-required`, and an empty one is invalid. */
|
|
26
|
+
required?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The line the list shows when nothing matches what was typed, for an app in another language.
|
|
29
|
+
* @default No matches
|
|
30
|
+
*/
|
|
31
|
+
emptyLabel?: string | undefined;
|
|
32
|
+
} & ControlProps & LoadingProps & Passthrough;
|
|
33
|
+
/**
|
|
34
|
+
* A text field that filters a list of choices as the person types, for a choice from more items
|
|
35
|
+
* than a `Select` reads well (a country, a time zone, a teammate): React Aria's `ComboBox`. Typing
|
|
36
|
+
* narrows the list by label; arrow keys move through it, Enter picks, Escape closes it. The chevron
|
|
37
|
+
* opens the whole list. Its value is the chosen item's `value`, posted under `name`. `label`, `hint`,
|
|
38
|
+
* `error`, `required` and `disabled` are a `DateField`'s; `size` and `width` an `Input`'s. Inside a
|
|
39
|
+
* modal `Dialog` the list draws in the dialog. While `loading` the label is drawn and the field is a
|
|
40
|
+
* bone of its height.
|
|
41
|
+
*/
|
|
42
|
+
export declare function Combobox({ loading, loadingLabel, ...field }: ComboboxProps): ReactElement;
|
package/dist/Combobox.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, ComboBox as AriaComboBox, FieldError, Group, Input, ListBox, ListBoxItem, Popover, Text, } from "react-aria-components";
|
|
3
|
+
import { CONTROL_WIDTH, controlHeight } from "./control.js";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { fieldFlags, FieldLabel, frameClass, iconButtonLook, useLabelClass } from "./DateField.js";
|
|
6
|
+
import { pickerButton, useDialogContainer } from "./DateFieldCalendar.js";
|
|
7
|
+
import { controlText, useFieldType, useTypeStep } from "./density.js";
|
|
8
|
+
import { ErrorLine } from "./Field.js";
|
|
9
|
+
import { WaitingField } from "./fieldWait.js";
|
|
10
|
+
import { iconGlyph } from "./icons.js";
|
|
11
|
+
import { definedProps } from "./props.js";
|
|
12
|
+
import { useLoading } from "./skeleton.js";
|
|
13
|
+
/** An option's look, from React Aria's state: hovered or keyed, chosen, blocked. */
|
|
14
|
+
function optionClass(state) {
|
|
15
|
+
return cx("rounded-md px-2 py-1.5 outline-none", state.isFocused && "bg-slate-100", state.isSelected && "font-medium", state.isDisabled ? "cursor-not-allowed text-slate-400" : "cursor-pointer", !state.isDisabled && (state.isSelected ? "text-violet-700" : "text-slate-900"));
|
|
16
|
+
}
|
|
17
|
+
/** The hint and, under it, the error line: the given `error`, or React Aria's own message. */
|
|
18
|
+
function ComboNotes({ hint, error }) {
|
|
19
|
+
const { note } = useFieldType();
|
|
20
|
+
return (_jsxs(_Fragment, { children: [hint ? (_jsx(Text, { slot: "description", className: cx("text-slate-500", note), children: hint })) : null, _jsx(FieldError, { className: "block", children: (validation) => _jsx(ErrorLine, { error: error || validation.validationErrors.join(" ") }) })] }));
|
|
21
|
+
}
|
|
22
|
+
/** A combobox drawn: the label, the input with its chevron, the notes and the list in a popover. */
|
|
23
|
+
function ShownCombobox({ label, hint, error, disabled, required, items, value, defaultValue, onChange, name, emptyLabel = "No matches", size = "md", width = "full", ...rest }) {
|
|
24
|
+
const step = useTypeStep();
|
|
25
|
+
const { container, findDialog } = useDialogContainer();
|
|
26
|
+
return (_jsxs(AriaComboBox, { ...fieldFlags(disabled, required), ...(error ? { isInvalid: true } : {}), ...(value === undefined ? {} : { selectedKey: value }), ...(defaultValue === undefined ? {} : { defaultSelectedKey: defaultValue }), ...(name ? { name, formValue: "key" } : {}), onSelectionChange: (key) => onChange?.(key === null ? null : String(key)), defaultItems: items, menuTrigger: "focus", allowsEmptyCollection: true, ref: findDialog, className: cx("flex flex-col gap-1.5", CONTROL_WIDTH[width]), children: [_jsx(FieldLabel, { label: label, required: required }), _jsxs(Group, { className: (state) => cx(frameClass(state), controlHeight(size), "pr-1"), children: [_jsx(Input, { ...definedProps(rest), className: cx("h-full min-w-0 flex-1 rounded-lg bg-white px-3 text-slate-900 outline-none", controlText(size, step, true)) }), _jsx(Button, { className: cx(iconButtonLook, pickerButton(size), "cursor-pointer"), children: iconGlyph("chevron-down") })] }), _jsx(ComboNotes, { hint: hint, error: error }), _jsx(Popover, { ...(container ? { UNSTABLE_portalContainer: container } : {}), placement: "bottom start", className: "w-(--trigger-width) rounded-xl border border-slate-200 bg-white p-1 shadow-lg", children: _jsx(ListBox, { className: cx("max-h-72 overflow-auto outline-none", controlText(size, step, true)), renderEmptyState: () => _jsx("p", { className: "px-2 py-1.5 text-slate-500", children: emptyLabel }), children: (item) => (_jsx(ListBoxItem, { id: item.value, textValue: item.label, isDisabled: item.disabled ?? false, className: optionClass, children: item.label })) }) })] }));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A text field that filters a list of choices as the person types, for a choice from more items
|
|
30
|
+
* than a `Select` reads well (a country, a time zone, a teammate): React Aria's `ComboBox`. Typing
|
|
31
|
+
* narrows the list by label; arrow keys move through it, Enter picks, Escape closes it. The chevron
|
|
32
|
+
* opens the whole list. Its value is the chosen item's `value`, posted under `name`. `label`, `hint`,
|
|
33
|
+
* `error`, `required` and `disabled` are a `DateField`'s; `size` and `width` an `Input`'s. Inside a
|
|
34
|
+
* modal `Dialog` the list draws in the dialog. While `loading` the label is drawn and the field is a
|
|
35
|
+
* bone of its height.
|
|
36
|
+
*/
|
|
37
|
+
export function Combobox({ loading, loadingLabel, ...field }) {
|
|
38
|
+
const labelClass = useLabelClass();
|
|
39
|
+
if (useLoading(loading).loading) {
|
|
40
|
+
return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
|
|
41
|
+
}
|
|
42
|
+
return _jsx(ShownCombobox, { ...field });
|
|
43
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
export type ConfirmDialogProps = {
|
|
4
|
+
/** The question, naming the action: "Delete build?". It is the dialog's accessible name. */
|
|
5
|
+
title: string;
|
|
6
|
+
/** The consequence, in one sentence: "This removes the build and every snapshot in it." It describes the dialog. */
|
|
7
|
+
description: ReactNode;
|
|
8
|
+
/** The confirm button's text, the action as a verb: "Delete". */
|
|
9
|
+
confirm: string;
|
|
10
|
+
/**
|
|
11
|
+
* `danger` for an action that destroys or cannot be undone, which draws the confirm button red.
|
|
12
|
+
* @default danger
|
|
13
|
+
*/
|
|
14
|
+
tone?: "danger" | "neutral";
|
|
15
|
+
/** What the confirm button says while `onConfirm` runs, such as "Deleting…". */
|
|
16
|
+
busyLabel?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The cancel button's text, for an app in another language.
|
|
19
|
+
* @default Cancel
|
|
20
|
+
*/
|
|
21
|
+
cancel?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Runs the action. A returned promise keeps the confirm button busy until it settles: resolving
|
|
24
|
+
* closes the dialog, and a rejection shows its message in the dialog and keeps it open.
|
|
25
|
+
*/
|
|
26
|
+
onConfirm: () => void | Promise<unknown>;
|
|
27
|
+
/** Called when the dialog closes: Cancel, Esc, the backdrop, the close button, or a confirm that went through. */
|
|
28
|
+
onClose: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* The name of the close button in the top corner, for an app in another language.
|
|
31
|
+
* @default Close
|
|
32
|
+
*/
|
|
33
|
+
closeLabel?: string | undefined;
|
|
34
|
+
} & Passthrough;
|
|
35
|
+
/**
|
|
36
|
+
* A `Dialog` that asks before an action: the question as its title, the consequence under it, and
|
|
37
|
+
* Cancel beside the one action. It is an `alertdialog` and opens on Cancel, so a stray Enter cancels.
|
|
38
|
+
* Render it only while it is open.
|
|
39
|
+
*/
|
|
40
|
+
export declare function ConfirmDialog({ title, description, confirm, tone, busyLabel, cancel, onConfirm, onClose, closeLabel, ...rest }: ConfirmDialogProps): ReactElement;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useState } from "react";
|
|
3
|
+
import { Button } from "./Button.js";
|
|
4
|
+
import { DialogFrame } from "./Dialog.js";
|
|
5
|
+
/** The `<dialog>` a button is in, closed so it animates out before `onClose` unmounts it. */
|
|
6
|
+
const closeFrom = (event) => event.currentTarget.closest("dialog")?.close();
|
|
7
|
+
/** The confirm's in-flight state and its error; `run` is the confirm button's click handler. */
|
|
8
|
+
function useConfirm(onConfirm) {
|
|
9
|
+
const [busy, setBusy] = useState(false);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const run = (event) => {
|
|
12
|
+
if (busy)
|
|
13
|
+
return;
|
|
14
|
+
// Kept before the await: the event's target is gone by the time it settles.
|
|
15
|
+
const dialog = event.currentTarget.closest("dialog");
|
|
16
|
+
setError(null);
|
|
17
|
+
setBusy(true);
|
|
18
|
+
void Promise.resolve()
|
|
19
|
+
.then(() => onConfirm())
|
|
20
|
+
.then(() => dialog?.close(), (e) => {
|
|
21
|
+
setBusy(false);
|
|
22
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return { busy, error, run };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A `Dialog` that asks before an action: the question as its title, the consequence under it, and
|
|
29
|
+
* Cancel beside the one action. It is an `alertdialog` and opens on Cancel, so a stray Enter cancels.
|
|
30
|
+
* Render it only while it is open.
|
|
31
|
+
*/
|
|
32
|
+
export function ConfirmDialog({ title, description, confirm, tone = "danger", busyLabel, cancel = "Cancel", onConfirm, onClose, closeLabel, ...rest }) {
|
|
33
|
+
const descriptionId = useId();
|
|
34
|
+
const { busy, error, run } = useConfirm(onConfirm);
|
|
35
|
+
return (_jsx(DialogFrame, { ...rest, role: "alertdialog", "aria-describedby": [rest["aria-describedby"], descriptionId].filter(Boolean).join(" "), title: title, description: _jsx("span", { id: descriptionId, children: description }), width: "sm", error: error, onClose: onClose, closeLabel: closeLabel, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", autoFocus: true, onClick: closeFrom, children: cancel }), _jsx(Button, { tone: tone, busy: busy && (busyLabel || true), onClick: run, children: confirm })] }) }));
|
|
36
|
+
}
|
package/dist/Container.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
1
|
+
import { type ReactElement, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
3
|
/**
|
|
4
4
|
* The one content edge: every page's width and side padding. This file is the only place they are
|
|
5
5
|
* defined, so a header, a page and a footer inside a Container start at the same x.
|
|
@@ -14,7 +14,7 @@ type ContainerProps = {
|
|
|
14
14
|
/** Reaches the rendered element, for a parent that measures or scrolls it. */
|
|
15
15
|
ref?: Ref<HTMLElement> | undefined;
|
|
16
16
|
children?: ReactNode;
|
|
17
|
-
} &
|
|
17
|
+
} & Passthrough;
|
|
18
18
|
/** Container with the extra classes its own parts need (AppShell's padding): internal, not exported. */
|
|
19
19
|
export declare function ContainerFrame({ as: Tag, className, ref, children, ...rest }: ContainerProps & {
|
|
20
20
|
className?: string;
|
package/dist/Container.js
CHANGED
package/dist/CopyButton.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ComponentPropsWithoutRef, type ReactElement } from "react";
|
|
2
2
|
import type { Unstyled } from "./props.js";
|
|
3
|
-
/** Writes `text` to the clipboard and shows `copiedLabel` for two seconds, then `label` again. Defaults to `type="button"
|
|
4
|
-
export declare function CopyButton({ text, label, copiedLabel, onClick, ...rest }: {
|
|
3
|
+
/** Writes `text` to the clipboard and shows `copiedLabel` for two seconds, then `label` again; a refused or missing clipboard shows `failedLabel` instead. Defaults to `type="button"` and is at least 24px square. Its accessible name stays `label`; a polite status region beside it announces `copiedLabel` or `failedLabel` on each press and empties again when the label goes back. Every other button prop, `disabled` included, goes on the `<button>`. Nothing is styled by a `<style>` element, so it works under a strict CSP. On a page rendered to static HTML without hydration, inline `copyScript` and the button works there too. */
|
|
4
|
+
export declare function CopyButton({ text, label, copiedLabel, failedLabel, onClick, ...rest }: {
|
|
5
5
|
/** What goes on the clipboard. */
|
|
6
6
|
text: string;
|
|
7
7
|
/**
|
|
@@ -14,4 +14,10 @@ export declare function CopyButton({ text, label, copiedLabel, onClick, ...rest
|
|
|
14
14
|
* @default Copied
|
|
15
15
|
*/
|
|
16
16
|
copiedLabel?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The text shown for two seconds when the browser refuses the copy or has no clipboard, and
|
|
19
|
+
* announced. Keep it about as long as `copiedLabel`, since the button is as wide as the longest.
|
|
20
|
+
* @default Failed
|
|
21
|
+
*/
|
|
22
|
+
failedLabel?: string;
|
|
17
23
|
} & Unstyled<Omit<ComponentPropsWithoutRef<"button">, "children">>): ReactElement;
|
package/dist/CopyButton.js
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import {} from "react";
|
|
3
3
|
import { focusRing } from "./cx.js";
|
|
4
|
-
const BASE = `shrink-0 rounded px-1.5 py-0.5 font-sans text-xs text-slate-400 hover:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 ${focusRing}`;
|
|
5
|
-
/**
|
|
4
|
+
const BASE = `min-h-6 min-w-6 shrink-0 cursor-pointer rounded px-1.5 py-0.5 font-sans text-xs text-slate-400 hover:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 ${focusRing}`;
|
|
5
|
+
/** The labels share one grid cell, centred, so the button is as wide as the longest and never resizes. */
|
|
6
6
|
const CELL = "col-start-1 row-start-1";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
/** How long the copied or failed label shows, in milliseconds. */
|
|
8
|
+
const SHOWN = 2000;
|
|
9
|
+
/** The clipboard, which an insecure page or an old browser does not have, whatever the DOM types say. */
|
|
10
|
+
const clipboardOf = (from) => from.clipboard;
|
|
11
|
+
/**
|
|
12
|
+
* Shows the `done` or `failed` label for two seconds and puts it in the status region beside the
|
|
13
|
+
* button, then empties the region. No timer and no stylesheet: two Web Animations hold `visibility`
|
|
14
|
+
* for the run (a stylesheet's `<style>` element is blocked by a nonce-based CSP; an animation is
|
|
15
|
+
* not), and the run's own end clears the region. A second copy cancels the run in progress and starts
|
|
16
|
+
* again. `copyScript` does the same on a page that is never hydrated.
|
|
17
|
+
*/
|
|
18
|
+
function flash(button, outcome) {
|
|
19
|
+
const shown = button.querySelector(`[data-copy-${outcome}]`);
|
|
20
|
+
const idle = button.querySelector("[data-copy-idle]");
|
|
21
|
+
const status = button.nextElementSibling;
|
|
22
|
+
const region = status?.matches("[data-copy-status]") ? status : null;
|
|
23
|
+
// A new text node each time, so a second copy is announced too.
|
|
24
|
+
region?.replaceChildren(shown?.textContent ?? "");
|
|
25
|
+
if (!shown?.animate || !idle)
|
|
26
|
+
return;
|
|
27
|
+
for (const run of button.getAnimations({ subtree: true }))
|
|
28
|
+
run.cancel();
|
|
29
|
+
idle.animate({ visibility: ["hidden", "hidden"] }, SHOWN);
|
|
30
|
+
const run = shown.animate({ visibility: ["visible", "visible"] }, SHOWN);
|
|
31
|
+
run.onfinish = () => region?.replaceChildren();
|
|
32
|
+
}
|
|
33
|
+
/** Writes `text` to the clipboard and shows `copiedLabel` for two seconds, then `label` again; a refused or missing clipboard shows `failedLabel` instead. Defaults to `type="button"` and is at least 24px square. Its accessible name stays `label`; a polite status region beside it announces `copiedLabel` or `failedLabel` on each press and empties again when the label goes back. Every other button prop, `disabled` included, goes on the `<button>`. Nothing is styled by a `<style>` element, so it works under a strict CSP. On a page rendered to static HTML without hydration, inline `copyScript` and the button works there too. */
|
|
34
|
+
export function CopyButton({ text, label = "Copy", copiedLabel = "Copied", failedLabel = "Failed", onClick, ...rest }) {
|
|
35
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "aria-label": label, ...rest, "data-copy-text": text, className: BASE, onClick: (event) => {
|
|
23
36
|
onClick?.(event);
|
|
24
37
|
// `copyScript` hears this same click on `document`. Whichever of the two runs first copies
|
|
25
38
|
// and flags the event, so the other skips it.
|
|
@@ -27,13 +40,10 @@ export function CopyButton({ text, label = "Copy", copiedLabel = "Copied", onCli
|
|
|
27
40
|
if (native.copyHandled)
|
|
28
41
|
return;
|
|
29
42
|
native.copyHandled = true;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
status.current?.replaceChildren(copiedLabel);
|
|
37
|
-
}, () => { });
|
|
38
|
-
}, children: _jsxs("span", { className: "grid justify-items-center", onAnimationEnd: () => setCopied(false), children: [_jsx("span", { "data-copy-idle": "", className: CELL, children: label }), _jsx("span", { "data-copy-done": "", "aria-hidden": "true", className: `invisible ${CELL}`, children: copiedLabel })] }, copies) }), _jsx("span", { ref: status, role: "status", "data-copy-status": "", className: "sr-only", suppressHydrationWarning: true, children: "" })] }));
|
|
43
|
+
const target = event.currentTarget;
|
|
44
|
+
const clipboard = clipboardOf(navigator);
|
|
45
|
+
if (!clipboard)
|
|
46
|
+
return flash(target, "failed");
|
|
47
|
+
clipboard.writeText(text).then(() => flash(target, "done"), () => flash(target, "failed"));
|
|
48
|
+
}, children: _jsxs("span", { className: "grid justify-items-center", children: [_jsx("span", { "data-copy-idle": "", className: CELL, children: label }), _jsx("span", { "data-copy-done": "", "aria-hidden": "true", className: `invisible ${CELL}`, children: copiedLabel }), _jsx("span", { "data-copy-failed": "", "aria-hidden": "true", className: `invisible ${CELL}`, children: failedLabel })] }) }), _jsx("span", { role: "status", "data-copy-status": "", className: "sr-only", suppressHydrationWarning: true, children: "" })] }));
|
|
39
49
|
}
|
package/dist/CopyLine.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
import type { Passthrough } from "./props.js";
|
|
3
|
-
/** One line of mono text in a box, with a `CopyButton`: a command or a token to paste elsewhere. `disabled` disables the button, e.g. until hydration. An `id`, `data-*` and `aria-*` go on the root `<div>`, so `data-testid` lands there; the `<code>` holds only `text`. */
|
|
4
|
-
export declare function CopyLine({ text, disabled, ...rest }: {
|
|
3
|
+
/** One line of mono text in a box, with a `CopyButton`: a command or a token to paste elsewhere. `label` says what the line is, and the button is named "Copy <label>" (it still reads "Copy"), so several lines on a page can be told apart. `disabled` disables the button, e.g. until hydration. An `id`, `data-*` and `aria-*` go on the root `<div>`, so `data-testid` lands there; the `<code>` holds only `text`. */
|
|
4
|
+
export declare function CopyLine({ text, label, disabled, ...rest }: {
|
|
5
5
|
/** The line shown, and what the button copies. */
|
|
6
6
|
text: string;
|
|
7
|
+
/** What the line is, in a few lower-case words ("install command", "API token"): the copy button's accessible name is "Copy " and this. */
|
|
8
|
+
label: string;
|
|
7
9
|
/** Disables the copy button, e.g. until hydration. */
|
|
8
10
|
disabled?: boolean;
|
|
9
11
|
} & Passthrough): ReactElement;
|
package/dist/CopyLine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CopyButton } from "./CopyButton.js";
|
|
3
|
-
const BOX = "flex items-center justify-between gap-3 rounded-lg border border-slate-200 bg-white px-2.5 py-2 font-mono text-[
|
|
4
|
-
/** One line of mono text in a box, with a `CopyButton`: a command or a token to paste elsewhere. `disabled` disables the button, e.g. until hydration. An `id`, `data-*` and `aria-*` go on the root `<div>`, so `data-testid` lands there; the `<code>` holds only `text`. */
|
|
5
|
-
export function CopyLine({ text, disabled, ...rest }) {
|
|
6
|
-
return (_jsxs("div", { ...rest, className: BOX, children: [_jsx("code", { className: "min-w-0 break-words", children: text }), _jsx(CopyButton, { text: text, disabled: disabled })] }));
|
|
3
|
+
const BOX = "flex items-center justify-between gap-3 rounded-lg border border-slate-200 bg-white px-2.5 py-2 font-mono text-[0.78125rem] leading-normal text-slate-900";
|
|
4
|
+
/** One line of mono text in a box, with a `CopyButton`: a command or a token to paste elsewhere. `label` says what the line is, and the button is named "Copy <label>" (it still reads "Copy"), so several lines on a page can be told apart. `disabled` disables the button, e.g. until hydration. An `id`, `data-*` and `aria-*` go on the root `<div>`, so `data-testid` lands there; the `<code>` holds only `text`. */
|
|
5
|
+
export function CopyLine({ text, label, disabled, ...rest }) {
|
|
6
|
+
return (_jsxs("div", { ...rest, className: BOX, children: [_jsx("code", { className: "min-w-0 break-words", children: text }), _jsx(CopyButton, { text: text, disabled: disabled, "aria-label": `Copy ${label}` })] }));
|
|
7
7
|
}
|
package/dist/DateCalendar.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare const calendarIcon: import("react").JSX.Element;
|
|
|
9
9
|
export type CalendarLabels = {
|
|
10
10
|
monthLabel: string;
|
|
11
11
|
yearLabel: string;
|
|
12
|
+
/** The footer button that empties the picker. With none, `Clear`. */
|
|
13
|
+
clearLabel?: string | undefined;
|
|
12
14
|
};
|
|
13
15
|
/** The date picker's popover: header, a Monday-first month grid and a Clear footer. */
|
|
14
16
|
export declare function CalendarPopover({ container, labels, }: {
|
package/dist/DateCalendar.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { getLocalTimeZone, today } from "@internationalized/date";
|
|
3
3
|
import { useContext } from "react";
|
|
4
|
-
import { Button, Calendar, CalendarCell, CalendarGrid, CalendarGridBody, CalendarGridHeader, CalendarHeaderCell, CalendarStateContext, DatePickerStateContext, DateRangePickerStateContext, Dialog, Popover, RangeCalendar, RangeCalendarStateContext, } from "react-aria-components";
|
|
4
|
+
import { Button, Calendar, CalendarCell, CalendarGrid, CalendarGridBody, CalendarGridHeader, CalendarHeaderCell, CalendarStateContext, DatePickerStateContext, DateRangePickerStateContext, Dialog, Popover, RangeCalendar, RangeCalendarStateContext, useLocale, } from "react-aria-components";
|
|
5
5
|
import { cx, focusRing } from "./cx.js";
|
|
6
6
|
import { Button as PresetButton } from "./Button.js";
|
|
7
|
-
import {
|
|
7
|
+
import { iconButtonClass } from "./DateField.js";
|
|
8
|
+
import { monthNames } from "./dateLocale.js";
|
|
8
9
|
import { Icon } from "./Icon.js";
|
|
9
10
|
export const calendarIcon = (_jsx(Icon, { children: _jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", children: [_jsx("rect", { x: "3", y: "4.5", width: "14", height: "12.5", rx: "2" }), _jsx("path", { d: "M3 8.5h14M7 2.5v4M13 2.5v4" })] }) }));
|
|
10
11
|
const chevron = (d) => (_jsx(Icon, { children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: d }) }) }));
|
|
@@ -13,6 +14,7 @@ function CalendarHeader({ monthLabel, yearLabel }) {
|
|
|
13
14
|
const single = useContext(CalendarStateContext);
|
|
14
15
|
const range = useContext(RangeCalendarStateContext);
|
|
15
16
|
const state = single ?? range;
|
|
17
|
+
const months = monthNames(useLocale().locale);
|
|
16
18
|
if (!state)
|
|
17
19
|
return null;
|
|
18
20
|
const focused = state.focusedDate;
|
|
@@ -20,17 +22,17 @@ function CalendarHeader({ monthLabel, yearLabel }) {
|
|
|
20
22
|
const first = Math.min(state.minValue?.year ?? now - 100, focused.year);
|
|
21
23
|
const last = Math.max(state.maxValue?.year ?? now + 10, focused.year);
|
|
22
24
|
const years = Array.from({ length: last - first + 1 }, (_, i) => first + i);
|
|
23
|
-
return (_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Button, { slot: "previous", className: iconButtonClass, children: chevron("M12.5 15l-5-5 5-5") }), _jsx("select", { "aria-label": monthLabel, className: cx(selectClass, "flex-1"), value: focused.month, disabled: state.isDisabled, onChange: (event) => state.setFocusedDate(focused.set({ month: Number(event.target.value) })), children:
|
|
25
|
+
return (_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Button, { slot: "previous", className: iconButtonClass, children: chevron("M12.5 15l-5-5 5-5") }), _jsx("select", { "aria-label": monthLabel, className: cx(selectClass, "flex-1"), value: focused.month, disabled: state.isDisabled, onChange: (event) => state.setFocusedDate(focused.set({ month: Number(event.target.value) })), children: months.map((name, i) => (_jsx("option", { value: i + 1, children: name }, name))) }), _jsx("select", { "aria-label": yearLabel, className: selectClass, value: focused.year, disabled: state.isDisabled, onChange: (event) => state.setFocusedDate(focused.set({ year: Number(event.target.value) })), children: years.map((year) => (_jsx("option", { value: year, children: year }, year))) }), _jsx(Button, { slot: "next", className: iconButtonClass, children: chevron("M7.5 5l5 5-5 5") })] }));
|
|
24
26
|
}
|
|
25
27
|
/** Clears the picker's value, a date or a range, and closes the popover. */
|
|
26
|
-
function ClearButton() {
|
|
28
|
+
function ClearButton({ label }) {
|
|
27
29
|
const single = useContext(DatePickerStateContext);
|
|
28
30
|
const range = useContext(DateRangePickerStateContext);
|
|
29
31
|
const picker = single ?? range;
|
|
30
32
|
return (_jsx("button", { type: "button", className: `rounded-md px-2 py-1 text-sm font-medium text-violet-600 transition hover:bg-violet-50 ${focusRing}`, onClick: () => {
|
|
31
33
|
picker?.setValue(null);
|
|
32
34
|
picker?.close();
|
|
33
|
-
}, children:
|
|
35
|
+
}, children: label }));
|
|
34
36
|
}
|
|
35
37
|
const cellClass = ({ isSelected, isOutsideMonth, isDisabled, isUnavailable, isInvalid, }) => {
|
|
36
38
|
let tone = "cursor-pointer text-slate-700 hover:bg-slate-100";
|
|
@@ -68,12 +70,12 @@ function MonthGrid({ cellClass: dayClass, }) {
|
|
|
68
70
|
* modal makes everything outside it inert and paints above the body, so the popover renders inside
|
|
69
71
|
* it (which also keeps the theme's scope class).
|
|
70
72
|
*/
|
|
71
|
-
function PickerPopover({ container, children, }) {
|
|
72
|
-
return (_jsx(Popover, { ...(container ? { UNSTABLE_portalContainer: container } : {}), placement: "bottom start", className: "rounded-xl border border-slate-200 bg-white p-3 text-slate-900 shadow-lg", children: _jsxs(Dialog, { className: "flex flex-col gap-3 outline-none", children: [children, _jsx("div", { className: "flex justify-end border-t border-slate-200 pt-2", children: _jsx(ClearButton, {}) })] }) }));
|
|
73
|
+
function PickerPopover({ container, clearLabel = "Clear", children, }) {
|
|
74
|
+
return (_jsx(Popover, { ...(container ? { UNSTABLE_portalContainer: container } : {}), placement: "bottom start", className: "rounded-xl border border-slate-200 bg-white p-3 text-slate-900 shadow-lg", children: _jsxs(Dialog, { className: "flex flex-col gap-3 outline-none", children: [children, _jsx("div", { className: "flex justify-end border-t border-slate-200 pt-2", children: _jsx(ClearButton, { label: clearLabel }) })] }) }));
|
|
73
75
|
}
|
|
74
76
|
/** The date picker's popover: header, a Monday-first month grid and a Clear footer. */
|
|
75
77
|
export function CalendarPopover({ container, labels, }) {
|
|
76
|
-
return (_jsx(PickerPopover, { container: container, children: _jsxs(Calendar, { firstDayOfWeek: "mon", className: "flex flex-col gap-3", children: [_jsx(CalendarHeader, { ...labels }), _jsx(MonthGrid, { cellClass: cellClass })] }) }));
|
|
78
|
+
return (_jsx(PickerPopover, { container: container, clearLabel: labels.clearLabel, children: _jsxs(Calendar, { firstDayOfWeek: "mon", className: "flex flex-col gap-3", children: [_jsx(CalendarHeader, { ...labels }), _jsx(MonthGrid, { cellClass: cellClass })] }) }));
|
|
77
79
|
}
|
|
78
80
|
/** A preset's button: sets the range, which reports it, and closes the popover. */
|
|
79
81
|
function PresetRow({ presets }) {
|
|
@@ -85,5 +87,5 @@ function PresetRow({ presets }) {
|
|
|
85
87
|
}
|
|
86
88
|
/** The range picker's popover: the presets, if any, the header, one Monday-first month and Clear. */
|
|
87
89
|
export function RangeCalendarPopover({ container, presets, labels, }) {
|
|
88
|
-
return (_jsxs(PickerPopover, { container: container, children: [presets && presets.length > 0 ? _jsx(PresetRow, { presets: presets }) : null, _jsxs(RangeCalendar, { firstDayOfWeek: "mon", className: "flex flex-col gap-3", children: [_jsx(CalendarHeader, { ...labels }), _jsx(MonthGrid, { cellClass: rangeCellClass })] })] }));
|
|
90
|
+
return (_jsxs(PickerPopover, { container: container, clearLabel: labels.clearLabel, children: [presets && presets.length > 0 ? _jsx(PresetRow, { presets: presets }) : null, _jsxs(RangeCalendar, { firstDayOfWeek: "mon", className: "flex flex-col gap-3", children: [_jsx(CalendarHeader, { ...labels }), _jsx(MonthGrid, { cellClass: rangeCellClass })] })] }));
|
|
89
91
|
}
|