@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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
## ConfirmDialog
|
|
2
|
+
|
|
3
|
+
Group: Feedback
|
|
4
|
+
|
|
5
|
+
When to use: An action that destroys something or cannot be undone: delete, discard, revoke, sign out everywhere.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- Dialog (dialog.md): A form, or a question with more than two answers.
|
|
9
|
+
- Toast (toast.md): The action can be undone: do it, and offer Undo in a toast.
|
|
10
|
+
|
|
11
|
+
### The one right way
|
|
12
|
+
A question that names the action, one line of consequence, and Cancel beside the action: it opens on Cancel, so a stray Enter cancels.
|
|
13
|
+
```tsx
|
|
14
|
+
import { useState } from "react";
|
|
15
|
+
import { Button, ConfirmDialog } from "@slashsuite/ui-react";
|
|
16
|
+
|
|
17
|
+
function Example() {
|
|
18
|
+
const [open, setOpen] = useState(false);
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<Button variant="outline" onClick={() => setOpen(true)}>
|
|
22
|
+
Delete build
|
|
23
|
+
</Button>
|
|
24
|
+
{open && (
|
|
25
|
+
<ConfirmDialog
|
|
26
|
+
title="Delete build?"
|
|
27
|
+
description="This removes the build and every snapshot in it."
|
|
28
|
+
confirm="Delete"
|
|
29
|
+
busyLabel="Deleting…"
|
|
30
|
+
onConfirm={() => Promise.resolve()}
|
|
31
|
+
onClose={() => setOpen(false)}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
</>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Do
|
|
40
|
+
- Render it only while it is open: `{open && <ConfirmDialog … onClose={() => setOpen(false)} />}`.
|
|
41
|
+
- `title` is the question and names the action ("Delete build?"), `description` is the consequence in one sentence, and `confirm` is the action as a verb ("Delete"), never "OK" or "Yes".
|
|
42
|
+
- `tone` is `danger` (the default) for an action that destroys or cannot be undone, and `neutral` for one that can be reversed, such as Archive.
|
|
43
|
+
- `onConfirm` runs the action. Return its promise: the button is busy (`busyLabel`) until it settles, resolving closes the dialog, and a rejection shows its message above the buttons and keeps the dialog open for a retry.
|
|
44
|
+
- Set `cancel` and `closeLabel` to the reader's language when the page is not in English.
|
|
45
|
+
|
|
46
|
+
### Don't
|
|
47
|
+
- Do not ask before an action that can be undone: do it, and offer Undo in a `Toast`.
|
|
48
|
+
- Do not build one from a `Dialog` with only the action in its footer: a confirmation always has Cancel.
|
|
49
|
+
|
|
50
|
+
A hand-built `Dialog` with no Cancel and no consequence: the only way on is the one button that destroys the build, and nothing says what it destroys.
|
|
51
|
+
```tsx
|
|
52
|
+
import { useState } from "react";
|
|
53
|
+
import { Button, Dialog } from "@slashsuite/ui-react";
|
|
54
|
+
|
|
55
|
+
function Example() {
|
|
56
|
+
const [open, setOpen] = useState(false);
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<Button variant="outline" onClick={() => setOpen(true)}>
|
|
60
|
+
Delete build
|
|
61
|
+
</Button>
|
|
62
|
+
{open && (
|
|
63
|
+
<Dialog
|
|
64
|
+
title="Are you sure?"
|
|
65
|
+
onClose={() => setOpen(false)}
|
|
66
|
+
footer={
|
|
67
|
+
<Button tone="danger" onClick={() => setOpen(false)}>
|
|
68
|
+
Delete
|
|
69
|
+
</Button>
|
|
70
|
+
}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Accessibility
|
|
79
|
+
- It is an `alertdialog` on the browser's own `<dialog>`: the page behind goes inert, focus stays inside and Esc closes it.
|
|
80
|
+
- It is named by its `title` and described by its `description`, so a screen reader reads the question and the consequence as it opens.
|
|
81
|
+
- It opens on Cancel, so Enter or Space pressed by habit cancels rather than destroys.
|
|
82
|
+
- Esc, the backdrop and the close button all cancel, as Cancel does; only the confirm button runs the action.
|
|
83
|
+
- While the action runs, the confirm button is busy (`aria-busy`); a rejection is announced as an alert inside the dialog.
|
|
84
|
+
|
|
85
|
+
### Props
|
|
86
|
+
### ConfirmDialog
|
|
87
|
+
A `Dialog` that asks before an action: the question as its title, the consequence under it, and Cancel beside the one action. It is an `alertdialog` and opens on Cancel, so a stray Enter cancels. Render it only while it is open.
|
|
88
|
+
- busyLabel: string. What the confirm button says while `onConfirm` runs, such as "Deleting…".
|
|
89
|
+
- cancel: string (default Cancel). The cancel button's text, for an app in another language.
|
|
90
|
+
- closeLabel: string (default Close). The name of the close button in the top corner, for an app in another language.
|
|
91
|
+
- confirm: string (required). The confirm button's text, the action as a verb: "Delete".
|
|
92
|
+
- description: ReactNode (required). The consequence, in one sentence: "This removes the build and every snapshot in it." It describes the dialog.
|
|
93
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
94
|
+
- onClose: () => void (required). Called when the dialog closes: Cancel, Esc, the backdrop, the close button, or a confirm that went through.
|
|
95
|
+
- onConfirm: () => void | Promise<unknown> (required). Runs the action. A returned promise keeps the confirm button busy until it settles: resolving
|
|
96
|
+
closes the dialog, and a rejection shows its message in the dialog and keeps it open.
|
|
97
|
+
- title: string (required). The question, naming the action: "Delete build?". It is the dialog's accessible name.
|
|
98
|
+
- tone: "neutral" | "danger" (default danger). `danger` for an action that destroys or cannot be undone, which draws the confirm button red.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
## Container
|
|
2
|
+
|
|
3
|
+
Group: Layout
|
|
4
|
+
|
|
5
|
+
When to use: Content outside an `AppShell`, such as a band in a `bleed` shell, that must start at the same x as the page.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
One `Container` is the content edge: everything inside it starts at the same x.
|
|
9
|
+
```tsx
|
|
10
|
+
import { Card, Container, Text } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<Container as="section" aria-label="Billing">
|
|
13
|
+
<Card title="Plan">
|
|
14
|
+
<Text>Team, billed monthly.</Text>
|
|
15
|
+
</Card>
|
|
16
|
+
</Container>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Do
|
|
20
|
+
- `Container` is the only place the page width (`max-w-6xl`) and side padding are defined; a header, a page and a footer inside one start at the same x.
|
|
21
|
+
- `AppShell` already wraps its header, main and footer in one. Use `Container` only for a part of a `bleed` shell that spans the page, so its content still keeps the edge.
|
|
22
|
+
- `as` picks the element: `div` (default), `main`, `header`, `footer`, `section` or `nav`. A `section` or `nav` needs an `aria-label`.
|
|
23
|
+
- Space inside it with a `Stack`; a `Container` has no vertical padding or gap of its own.
|
|
24
|
+
- `ref` reaches the rendered element, for a parent that measures or scrolls it.
|
|
25
|
+
|
|
26
|
+
### Don't
|
|
27
|
+
- Never nest a `Container` in a `Container`: the padding doubles.
|
|
28
|
+
|
|
29
|
+
A `Container` inside a `Container` pads the content twice, so it no longer lines up with the page. `AppShell` already wraps its main in one.
|
|
30
|
+
```tsx
|
|
31
|
+
import { Card, Container, Text } from "@slashsuite/ui-react";
|
|
32
|
+
|
|
33
|
+
<Container as="section" aria-label="Billing">
|
|
34
|
+
<Container>
|
|
35
|
+
<Card title="Plan">
|
|
36
|
+
<Text>Team, billed monthly.</Text>
|
|
37
|
+
</Card>
|
|
38
|
+
</Container>
|
|
39
|
+
</Container>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Accessibility
|
|
43
|
+
- A `Container` adds no role: a `div` is not a landmark. `as` picks `main`, `header`, `footer`, `section` or `nav` when the part should be one.
|
|
44
|
+
- `aria-*` and `data-*` go on the rendered element.
|
|
45
|
+
|
|
46
|
+
### Props
|
|
47
|
+
### Container
|
|
48
|
+
The one content edge: every page's width and side padding. This file is the only place they are defined, so a header, a page and a footer inside a Container start at the same x.
|
|
49
|
+
- as: "nav" | "header" | "footer" | "main" | "div" | "section" (default div). The element: `div`, `main`, `header`, `footer`, `section` or `nav`.
|
|
50
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
51
|
+
- ref: Ref<HTMLElement>. Reaches the rendered element, for a parent that measures or scrolls it.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
## CopyButton
|
|
2
|
+
|
|
3
|
+
Group: Actions
|
|
4
|
+
|
|
5
|
+
When to use: A value the page already shows that a reader will paste elsewhere.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- CopyLine (copy-line.md): The text to copy is one line, such as a command.
|
|
9
|
+
- Code (code.md): The text to copy is a block of code: `CodeBlock copy`, or `CodeExample copy` in docs.
|
|
10
|
+
|
|
11
|
+
### The one right way
|
|
12
|
+
`CopyButton` writes `text` to the clipboard and swaps its label to `copiedLabel`.
|
|
13
|
+
```tsx
|
|
14
|
+
import { CopyButton } from "@slashsuite/ui-react";
|
|
15
|
+
|
|
16
|
+
<CopyButton text="hc_live_9f2c41" label="Copy token" copiedLabel="Token copied" />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Do
|
|
20
|
+
- `text` is what is copied; `copiedLabel` shows in place of the label for two seconds once it is on the clipboard, and `failedLabel` ("Failed") when the browser refuses the copy or has no clipboard.
|
|
21
|
+
- Name what is copied in `label` and `copiedLabel` (`"Copy token"`, `"Token copied"`) when the page has more than one.
|
|
22
|
+
- A command or token in its own box is a `CopyLine`, which carries this button.
|
|
23
|
+
- Place a `CopyButton` yourself only when neither a `CopyLine` nor `copy` on a `CodeBlock` or `CodeExample` fits.
|
|
24
|
+
- On a page rendered to static HTML and never hydrated, inline `copyScript` once, as `colourSchemeScript` is: every `CopyButton`, `CopyLine`, and `CodeBlock` or `CodeExample` with `copy` then works. A hydrated button copies for itself and the script stays out of its way.
|
|
25
|
+
|
|
26
|
+
### Don't
|
|
27
|
+
- Do not write the clipboard call by hand in a `Button`.
|
|
28
|
+
|
|
29
|
+
A hand-rolled copy Button gives no feedback and does not survive a refused clipboard.
|
|
30
|
+
```tsx
|
|
31
|
+
import { Button } from "@slashsuite/ui-react";
|
|
32
|
+
|
|
33
|
+
<Button
|
|
34
|
+
variant="ghost"
|
|
35
|
+
size="sm"
|
|
36
|
+
onClick={() => {
|
|
37
|
+
void navigator.clipboard.writeText("hc_live_9f2c41");
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
Copy token
|
|
41
|
+
</Button>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Accessibility
|
|
45
|
+
- A native `<button>` with `type="button"` and a focus ring from the component.
|
|
46
|
+
- The accessible name is always `label`. A copy shows `copiedLabel` (or `failedLabel`) for two seconds and a polite status region beside the button announces it, again on every press; the region empties when the label goes back.
|
|
47
|
+
- The button is at least 24px square, the WCAG minimum target.
|
|
48
|
+
- No `<style>` element: the two seconds are a Web Animation, so the label works under a strict, nonce-based CSP.
|
|
49
|
+
|
|
50
|
+
### Props
|
|
51
|
+
### CopyButton
|
|
52
|
+
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.
|
|
53
|
+
- copiedLabel: string (default Copied). The text shown for two seconds once the copy has gone through, and announced.
|
|
54
|
+
- failedLabel: string (default Failed). The text shown for two seconds when the browser refuses the copy or has no clipboard, and
|
|
55
|
+
announced. Keep it about as long as `copiedLabel`, since the button is as wide as the longest.
|
|
56
|
+
- label: string (default Copy). The button's text, and its accessible name.
|
|
57
|
+
- text: string (required). What goes on the clipboard.
|
|
58
|
+
|
|
59
|
+
### Functions
|
|
60
|
+
- copyScript: `copyScript: string`. A string of JavaScript to inline once on a page rendered to static HTML: one click listener on `document` that makes every copy button work without hydration.
|
|
61
|
+
```tsx
|
|
62
|
+
<script is:inline set:html={copyScript} />
|
|
63
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
## CopyLine
|
|
2
|
+
|
|
3
|
+
Group: Actions
|
|
4
|
+
|
|
5
|
+
When to use: A command or token a reader pastes elsewhere.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- CopyButton (copy-button.md): Neither a line nor a code block fits, so the button is placed by hand.
|
|
9
|
+
- Code (code.md): The text is a block of several lines: `CodeBlock copy`.
|
|
10
|
+
|
|
11
|
+
### The one right way
|
|
12
|
+
One command or token to paste: `CopyLine` is the box and the copy button together.
|
|
13
|
+
```tsx
|
|
14
|
+
import { CopyLine } from "@slashsuite/ui-react";
|
|
15
|
+
|
|
16
|
+
<CopyLine text="bun add @slashsuite/ui-react" label="install command" />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Do
|
|
20
|
+
- Give the whole line as `text`; the box shows it and the button copies it.
|
|
21
|
+
- Say what the line is in `label` (`"install command"`, `"API token"`): the button is named "Copy install command", so two lines on one page are told apart. It still reads "Copy".
|
|
22
|
+
- Several lines are a `CodeBlock`; `CopyLine` is one line.
|
|
23
|
+
- A long token wraps inside the box.
|
|
24
|
+
- `disabled` disables the button, for a line shown before the page is interactive.
|
|
25
|
+
|
|
26
|
+
### Don't
|
|
27
|
+
Inline code beside a loose `CopyButton` is two parts that drift apart; the text can differ from what is copied.
|
|
28
|
+
```tsx
|
|
29
|
+
import { Cluster, Code, CopyButton } from "@slashsuite/ui-react";
|
|
30
|
+
|
|
31
|
+
<Cluster>
|
|
32
|
+
<Code>bun add @slashsuite/ui-react</Code>
|
|
33
|
+
<CopyButton text="bun add @slashsuite/ui-react" />
|
|
34
|
+
</Cluster>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`CopyLine` is one line of text: a newline in it collapses into a space and the box runs on.
|
|
38
|
+
```tsx
|
|
39
|
+
import { CopyLine } from "@slashsuite/ui-react";
|
|
40
|
+
|
|
41
|
+
<CopyLine text={"bun install\nbun run build"} label="commands" />
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Accessibility
|
|
46
|
+
- The text is a `<code>` element, so a reader can select it by hand as well.
|
|
47
|
+
- The button is a `CopyButton`: a native button named "Copy" and `label`, whose status region announces "Copied" (or "Failed") after each press.
|
|
48
|
+
|
|
49
|
+
### Props
|
|
50
|
+
### CopyLine
|
|
51
|
+
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`.
|
|
52
|
+
- disabled: boolean. Disables the copy button, e.g. until hydration.
|
|
53
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
54
|
+
- label: string (required). What the line is, in a few lower-case words ("install command", "API token"): the copy button's accessible name is "Copy " and this.
|
|
55
|
+
- text: string (required). The line shown, and what the button copies.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
## DateField
|
|
2
|
+
|
|
3
|
+
Group: Forms
|
|
4
|
+
|
|
5
|
+
When to use: Any date a person enters; leave `calendar` off for a date the person knows by heart.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
```tsx
|
|
9
|
+
import { DateField } from "@slashsuite/ui-react";
|
|
10
|
+
|
|
11
|
+
<DateField calendar label="Date of birth" hint="As on your ID document." />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Do
|
|
15
|
+
- A date is a `DateField`, never an `Input`. It follows the browser's locale: 11/29/2026 in en-US, 29/11/2026 in en-GB. `locale` (a BCP 47 tag) sets another for the order, the month names and the messages; `name` posts `YYYY-MM-DD` whatever the locale. The calendar's weeks start on Monday.
|
|
16
|
+
- `calendar` adds a calendar button, and `defaultOpen` opens it on mount; without `calendar` the field is typed only, for a date the person knows by heart (a birthday).
|
|
17
|
+
- It draws its own label: give it `label` and `hint`, and do not wrap it in a `Field`.
|
|
18
|
+
- A message from outside, a server's say, is `error`: it marks the field invalid and replaces the hint. An impossible date, such as 31/02/1990, shows its own message.
|
|
19
|
+
- The value is a `CalendarDate` (`value`, `defaultValue`, `onChange`, `minValue`, `maxValue`). `fromISODate` reads a stored `YYYY-MM-DD` and `toISODate` writes one.
|
|
20
|
+
- `name` posts the date as `YYYY-MM-DD` in a form, or an empty string.
|
|
21
|
+
- `size` is `sm`, `md` (default) or `lg`, the same heights as `Input`. `disabled` and `required` work as on an `Input`; say why it is disabled in its `hint`.
|
|
22
|
+
- With `calendar`, `monthLabel` and `yearLabel` name the month and year dropdowns and `clearLabel` the Clear button, for an app in another language.
|
|
23
|
+
|
|
24
|
+
### Don't
|
|
25
|
+
A text input takes any characters, so 17/5/90, 1990-05-17 and "May" all arrive, and nothing says which is meant.
|
|
26
|
+
```tsx
|
|
27
|
+
import { Input } from "@slashsuite/ui-react";
|
|
28
|
+
|
|
29
|
+
<Input aria-label="Date of birth" placeholder="DD/MM/YYYY" />
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A hint where the error belongs: the field is never marked invalid and the reader is not told what is wrong. A rejected date takes `error` with the reason.
|
|
34
|
+
```tsx
|
|
35
|
+
import { DateField } from "@slashsuite/ui-react";
|
|
36
|
+
|
|
37
|
+
<DateField calendar label="Paid on" hint="The day the money moved." />
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A stored date written by hand from its parts drops the leading zeros (2026-10-6). `toISODate` writes the one `YYYY-MM-DD` form.
|
|
41
|
+
```tsx
|
|
42
|
+
import { Caption, DateField, fromISODate, Stack } from "@slashsuite/ui-react";
|
|
43
|
+
import { useState } from "react";
|
|
44
|
+
|
|
45
|
+
function Example() {
|
|
46
|
+
const [paid, setPaid] = useState(fromISODate("2026-10-06"));
|
|
47
|
+
return (
|
|
48
|
+
<Stack gap="xs">
|
|
49
|
+
<DateField calendar label="Paid on" value={paid} onChange={setPaid} />
|
|
50
|
+
<Caption>
|
|
51
|
+
Stored as {paid ? `${paid.year}-${paid.month}-${paid.day}` : "nothing yet"}.
|
|
52
|
+
</Caption>
|
|
53
|
+
</Stack>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A calendar for a date the person knows by heart makes them page back decades. A birthday is typed: leave `calendar` out.
|
|
59
|
+
```tsx
|
|
60
|
+
import { DateField } from "@slashsuite/ui-react";
|
|
61
|
+
|
|
62
|
+
<DateField calendar label="Date of birth" hint="As on your ID document." />
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Accessibility
|
|
66
|
+
- The label names a `role="group"`; each of day, month and year is its own editable segment (`role="spinbutton"`), so a person can type digits or use the arrow keys.
|
|
67
|
+
- The `hint` is the field's `aria-describedby`; the `error` and the built-in messages replace it, and an `error` is `role="alert"`.
|
|
68
|
+
- With `calendar`, the calendar button is labelled "Calendar" and opens a popover dialog, with a month and a year select (named by `monthLabel` and `yearLabel`), arrow-key movement across days and a Clear button.
|
|
69
|
+
- Inside a `Dialog` or `Drawer` the calendar opens inside it, so it still takes focus.
|
|
70
|
+
- The focus ring comes from the component.
|
|
71
|
+
|
|
72
|
+
### Props
|
|
73
|
+
### DateField
|
|
74
|
+
A segmented date input, in the order of its `locale` (by default the browser's): DD / MM / YYYY in en-GB. Values are `CalendarDate`s; `name` posts it as `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is drawn and the field is a bone of its height.
|
|
75
|
+
- calendar: boolean. Adds a calendar button that opens a month view in a popover; the field is a date picker.
|
|
76
|
+
- clearLabel: string (default Clear). The calendar's footer button that empties the field, for an app in another language. Only a `calendar` field takes `clearLabel`.
|
|
77
|
+
- defaultOpen: boolean. Open the calendar on mount. Only a `calendar` field takes `defaultOpen`.
|
|
78
|
+
- defaultValue: CalendarDate | null. The date it starts with, uncontrolled.
|
|
79
|
+
- disabled: boolean. Disables the field: no typing, no calendar.
|
|
80
|
+
- error: ReactNode. Marks the field invalid and shows this in red under the hint, announced politely, in place of
|
|
81
|
+
the built-in message (an impossible date, or one outside min/max). Like `Field`'s `error`.
|
|
82
|
+
- hint: ReactNode. A muted line under the field that says more; it stays while an error shows under it.
|
|
83
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
84
|
+
- label: ReactNode. The field's visible label, above it. Without one, name the field with `aria-label`.
|
|
85
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
86
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
87
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
88
|
+
- locale: string. The locale the field writes its date in, a BCP 47 tag: `en-GB` is DD/MM/YYYY, `en-US`
|
|
89
|
+
MM/DD/YYYY, `en-ZA` YYYY/MM/DD. It sets the order of the segments, the month names, the
|
|
90
|
+
calendar's first weekday and the dates in its messages. Without it the field follows the app's
|
|
91
|
+
own `I18nProvider`, or else the browser's language.
|
|
92
|
+
- maxValue: DateValue | null. The latest date allowed: a later one marks the field invalid with its own message.
|
|
93
|
+
- minValue: DateValue | null. The earliest date allowed: an earlier one marks the field invalid with its own message.
|
|
94
|
+
- monthLabel: string (default Month). The month dropdown's name, for an app in another language. Only a `calendar` field takes `monthLabel`.
|
|
95
|
+
- name: string. Posts the date in a form as `YYYY-MM-DD` under this key, or an empty string, whatever the `locale`.
|
|
96
|
+
- onChange: ((value: CalendarDate | null) => void). Called with the new date, or `null` when the field is cleared or the date is incomplete.
|
|
97
|
+
- required: boolean. Marks a date required: the field is `aria-required`, and an empty one is invalid.
|
|
98
|
+
- size: Size | ResponsiveSize (default md). The field's height and text, on the same scale as an `Input`: `sm` is `text-sm`, `md` `text-base`,
|
|
99
|
+
`lg` `text-lg`, one step down under an `AppShell density="compact"`, and never under 16px on touch.
|
|
100
|
+
`{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS, as an `Input`'s does.
|
|
101
|
+
- value: CalendarDate | null. The date shown, controlled, with `onChange`; `null` is an empty field.
|
|
102
|
+
- yearLabel: string (default Year). The year dropdown's name, for an app in another language. Only a `calendar` field takes `yearLabel`.
|
|
103
|
+
|
|
104
|
+
### Functions
|
|
105
|
+
- fromISODate: `fromISODate(iso: string | null | undefined): CalendarDate | null`. Reads a stored `"YYYY-MM-DD"` into the `CalendarDate` a picker takes; `null` for an empty, malformed or impossible string.
|
|
106
|
+
- toISODate: `toISODate(date: CalendarDate | null | undefined): string`. Writes a `CalendarDate` as `"YYYY-MM-DD"`, or `""` for none, so it drops into a form field or storage.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
## DateRangePicker
|
|
2
|
+
|
|
3
|
+
Group: Forms
|
|
4
|
+
|
|
5
|
+
When to use: A from and to date: a report period, a timeline filter.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
A from and to date is one `DateRangePicker`, with the app's presets built from its own today.
|
|
9
|
+
```tsx
|
|
10
|
+
import {
|
|
11
|
+
Caption,
|
|
12
|
+
DateRangePicker,
|
|
13
|
+
DateRange,
|
|
14
|
+
fromISODate,
|
|
15
|
+
Stack,
|
|
16
|
+
toISODate,
|
|
17
|
+
} from "@slashsuite/ui-react";
|
|
18
|
+
import { useState } from "react";
|
|
19
|
+
|
|
20
|
+
function Example() {
|
|
21
|
+
const today = fromISODate("2026-10-31");
|
|
22
|
+
const presets = today
|
|
23
|
+
? [7, 30, 90].map((days) => ({
|
|
24
|
+
label: `Last ${days} days`,
|
|
25
|
+
value: { start: today.subtract({ days: days - 1 }), end: today },
|
|
26
|
+
}))
|
|
27
|
+
: [];
|
|
28
|
+
const [period, setPeriod] = useState<DateRange | null>(
|
|
29
|
+
today ? { start: today.set({ day: 1 }), end: today } : null,
|
|
30
|
+
);
|
|
31
|
+
return (
|
|
32
|
+
<Stack gap="xs">
|
|
33
|
+
<DateRangePicker
|
|
34
|
+
label="Report period"
|
|
35
|
+
startName="from"
|
|
36
|
+
endName="to"
|
|
37
|
+
value={period}
|
|
38
|
+
onChange={setPeriod}
|
|
39
|
+
presets={presets}
|
|
40
|
+
/>
|
|
41
|
+
<Caption>
|
|
42
|
+
{period ? `From ${toISODate(period.start)} to ${toISODate(period.end)}.` : "No period yet."}
|
|
43
|
+
</Caption>
|
|
44
|
+
</Stack>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Do
|
|
50
|
+
- A from and to date is one `DateRangePicker`, never two `DateField`s. A single date is a `DateField`.
|
|
51
|
+
- The value is `{ start, end }` of `CalendarDate`s, or `null`. It is reported only when both sides are complete, real dates within `minValue` and `maxValue` and the start is on or before the end; anything else reports `null` and the field says why. `startName` and `endName` post each side as `YYYY-MM-DD` in a form, or an empty string while there is no range.
|
|
52
|
+
- Presets come from the app: build "Last 7 days", "Last 30 days" and "Last 90 days" from the app's own today (`today(getLocalTimeZone())` from `@internationalized/date`) and pass them as `presets`. The picker has none of its own and never reads the clock. A preset sets the range and closes the calendar.
|
|
53
|
+
- It draws its own label: give it `label` and `hint`, and do not wrap it in a `Field`. `error`, `size`, `disabled`, `required`, `locale`, `monthLabel` and `yearLabel` work as on `DateField`.
|
|
54
|
+
|
|
55
|
+
### Don't
|
|
56
|
+
Two `DateField`s do not know about each other: nothing stops an end before the start, and there is no one press for "Last 30 days".
|
|
57
|
+
```tsx
|
|
58
|
+
import { Cluster, DateField, fromISODate } from "@slashsuite/ui-react";
|
|
59
|
+
|
|
60
|
+
<Cluster gap="sm">
|
|
61
|
+
<DateField calendar label="From" defaultValue={fromISODate("2026-10-02")} />
|
|
62
|
+
<DateField calendar label="To" defaultValue={fromISODate("2026-10-31")} />
|
|
63
|
+
</Cluster>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Accessibility
|
|
67
|
+
- Each side is a `role="group"` named "Start date" and "End date" (`startLabel` and `endLabel` rename them, and `toLabel` the "to" between them; `clearLabel` the calendar's Clear), of day, month and year segments in the order of the locale (`role="spinbutton"`) that take digits or the arrow keys.
|
|
68
|
+
- The calendar button is labelled "Calendar" and opens a popover dialog: the arrow keys move across days, Enter on a day starts the range and Enter on a second ends it, and Escape closes it without a change.
|
|
69
|
+
- An impossible day, such as 31/02/2026, keeps what was typed and says which side and why: "End date: February 2026 has 28 days."
|
|
70
|
+
- Inside a `Dialog` or `Drawer` the calendar opens inside it, so it still takes focus. The focus ring comes from the component.
|
|
71
|
+
|
|
72
|
+
### Props
|
|
73
|
+
### DateRangePicker
|
|
74
|
+
A from and to date in one field, each side in the locale's order, and a calendar button that opens one Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges above the month. The range is reported only when both sides are complete, real dates within min/max and the start is on or before the end; otherwise `null`.
|
|
75
|
+
- clearLabel: string (default Clear). The calendar's footer button that empties the range.
|
|
76
|
+
- defaultOpen: boolean. Open the calendar on mount.
|
|
77
|
+
- defaultValue: { start: CalendarDate; end: CalendarDate } | null. The range shown first when the picker holds its own value.
|
|
78
|
+
- disabled: boolean. Disables the field: no typing, no calendar.
|
|
79
|
+
- endLabel: string (default End date). The name of the end date's segments, for a screen reader.
|
|
80
|
+
- endName: string. Posts the end as `YYYY-MM-DD` in a form, or `""` while there is no range.
|
|
81
|
+
- error: ReactNode. Marks the field invalid and shows this in red under the hint, announced politely, in place of
|
|
82
|
+
the built-in message (an impossible date, or one outside min/max). Like `Field`'s `error`.
|
|
83
|
+
- hint: ReactNode. A muted line under the field that says more; it stays while an error shows under it.
|
|
84
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
85
|
+
- label: ReactNode. The field's visible label, above it. Without one, name the field with `aria-label`.
|
|
86
|
+
- locale: string. The locale the field writes its date in, a BCP 47 tag: `en-GB` is DD/MM/YYYY, `en-US`
|
|
87
|
+
MM/DD/YYYY, `en-ZA` YYYY/MM/DD. It sets the order of the segments, the month names, the
|
|
88
|
+
calendar's first weekday and the dates in its messages. Without it the field follows the app's
|
|
89
|
+
own `I18nProvider`, or else the browser's language.
|
|
90
|
+
- maxValue: DateValue | null. The latest date allowed: a later one marks the field invalid with its own message.
|
|
91
|
+
- minValue: DateValue | null. The earliest date allowed: an earlier one marks the field invalid with its own message.
|
|
92
|
+
- monthLabel: string (default Month). The month dropdown's name, for an app in another language.
|
|
93
|
+
- onChange: ((range: { start: CalendarDate; end: CalendarDate } | null) => void). Called with the range once both sides make one, and with `null` when they stop making one.
|
|
94
|
+
- presets: readonly DateRangePreset[]. Ready-made ranges, a row of buttons above the month. The app builds them from its own today;
|
|
95
|
+
the picker has none of its own and never reads the clock.
|
|
96
|
+
- required: boolean. Marks a date required: the field is `aria-required`, and an empty one is invalid.
|
|
97
|
+
- size: Size | ResponsiveSize (default md). The field's height and text, on the same scale as an `Input`: `sm` is `text-sm`, `md` `text-base`,
|
|
98
|
+
`lg` `text-lg`, one step down under an `AppShell density="compact"`, and never under 16px on touch.
|
|
99
|
+
`{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS, as an `Input`'s does.
|
|
100
|
+
- startLabel: string (default Start date). The name of the start date's segments, for a screen reader.
|
|
101
|
+
- startName: string. Posts the start as `YYYY-MM-DD` in a form, or `""` while there is no range.
|
|
102
|
+
- toLabel: string (default to). The word between the two dates.
|
|
103
|
+
- value: { start: CalendarDate; end: CalendarDate } | null. The range, or `null` for none. Reported only when both days are complete, real and in order.
|
|
104
|
+
- yearLabel: string (default Year). The year dropdown's name, for an app in another language.
|
|
105
|
+
|
|
106
|
+
### Types
|
|
107
|
+
- DateRange: `{ start: CalendarDate; end: CalendarDate }`. A from and to date: `start` on or before `end`.
|
|
108
|
+
- DateRangePreset: `{ label: string; value: DateRange }`. A ready-made range the app builds from its own today, such as "Last 7 days".
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
## DateTimeField
|
|
2
|
+
|
|
3
|
+
Group: Forms
|
|
4
|
+
|
|
5
|
+
When to use: A moment a person enters: a booking, a meeting's start, a deadline with its hour.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
A date with its time is one `DateTimeField`: one label, one value, posted as `YYYY-MM-DDTHH:mm`.
|
|
9
|
+
```tsx
|
|
10
|
+
import { DateTimeField, fromISODateTime } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<DateTimeField
|
|
13
|
+
label="Starts at"
|
|
14
|
+
hint="Your local time."
|
|
15
|
+
name="startsAt"
|
|
16
|
+
defaultValue={fromISODateTime("2026-11-29T14:05")}
|
|
17
|
+
/>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Do
|
|
21
|
+
- A date with its time is one `DateTimeField`, never a `DateField` beside an `Input`. A date alone is a `DateField`.
|
|
22
|
+
- The clock follows the locale: 24-hour in en-GB, AM/PM in en-US. `locale` sets another, as on `DateField`.
|
|
23
|
+
- The value is a `CalendarDateTime`. `name` posts `YYYY-MM-DDTHH:mm` on the 24-hour clock, or an empty string; `fromISODateTime` reads that string and `toISODateTime` writes one.
|
|
24
|
+
- It has no calendar. `label`, `hint`, `error`, `minValue`, `maxValue`, `required`, `disabled`, `size` and `loading` work as on `DateField`.
|
|
25
|
+
|
|
26
|
+
### Don't
|
|
27
|
+
A date field beside a text input: the time takes any characters, and the two halves are checked and posted apart.
|
|
28
|
+
```tsx
|
|
29
|
+
import { DateField, Input, Stack } from "@slashsuite/ui-react";
|
|
30
|
+
|
|
31
|
+
<Stack gap="sm">
|
|
32
|
+
<DateField label="Starts on" />
|
|
33
|
+
<Input aria-label="Starts at" placeholder="14:05" />
|
|
34
|
+
</Stack>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Accessibility
|
|
38
|
+
- The label names a `role="group"` of day, month, year, hour and minute segments (and AM/PM where the locale has it), each a `role="spinbutton"` that takes digits or the arrow keys.
|
|
39
|
+
- A required field partly filled blocks the form and says "Enter the whole date and time."
|
|
40
|
+
- The focus ring comes from the component.
|
|
41
|
+
|
|
42
|
+
### Props
|
|
43
|
+
### DateTimeField
|
|
44
|
+
A segmented date and time input, to the minute: the date in the order of its `locale` (by default the browser's), then hours and minutes on the clock the locale uses, 24-hour in en-GB and with AM/PM in en-US. Values are `CalendarDateTime`s; `name` posts it as `YYYY-MM-DDTHH:mm`. It has no calendar. While `loading` the label is drawn and the field is a bone of its height.
|
|
45
|
+
- defaultValue: CalendarDateTime | null. The date and time shown first when the field holds its own value.
|
|
46
|
+
- disabled: boolean. Disables the field: no typing, no calendar.
|
|
47
|
+
- error: ReactNode. Marks the field invalid and shows this in red under the hint, announced politely, in place of
|
|
48
|
+
the built-in message (an impossible date, or one outside min/max). Like `Field`'s `error`.
|
|
49
|
+
- hint: ReactNode. A muted line under the field that says more; it stays while an error shows under it.
|
|
50
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
51
|
+
- label: ReactNode. The field's visible label, above it. Without one, name the field with `aria-label`.
|
|
52
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
53
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
54
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
55
|
+
- locale: string. The locale the field writes its date in, a BCP 47 tag: `en-GB` is DD/MM/YYYY, `en-US`
|
|
56
|
+
MM/DD/YYYY, `en-ZA` YYYY/MM/DD. It sets the order of the segments, the month names, the
|
|
57
|
+
calendar's first weekday and the dates in its messages. Without it the field follows the app's
|
|
58
|
+
own `I18nProvider`, or else the browser's language.
|
|
59
|
+
- maxValue: DateValue | null. The latest date and time the field takes; later ones are invalid.
|
|
60
|
+
- minValue: DateValue | null. The earliest date and time the field takes; earlier ones are invalid.
|
|
61
|
+
- name: string. Posts the date and time in a form as `YYYY-MM-DDTHH:mm` (24-hour) under this key, or an empty
|
|
62
|
+
string, whatever the `locale`.
|
|
63
|
+
- onChange: ((value: CalendarDateTime | null) => void). Called with the date and time once every segment is filled, the day exists and it is within
|
|
64
|
+
`minValue`/`maxValue`, and with `null` when it stops being one.
|
|
65
|
+
- required: boolean. Marks a date required: the field is `aria-required`, and an empty one is invalid.
|
|
66
|
+
- size: Size | ResponsiveSize (default md). The field's height and text, on the same scale as an `Input`: `sm` is `text-sm`, `md` `text-base`,
|
|
67
|
+
`lg` `text-lg`, one step down under an `AppShell density="compact"`, and never under 16px on touch.
|
|
68
|
+
`{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS, as an `Input`'s does.
|
|
69
|
+
- value: CalendarDateTime | null. The date and time shown, controlled, with `onChange`; `null` is an empty field.
|
|
70
|
+
|
|
71
|
+
### Functions
|
|
72
|
+
- fromISODateTime: `fromISODateTime(iso: string | null | undefined): CalendarDateTime | null`. Reads a stored `"YYYY-MM-DDTHH:mm"` into a `CalendarDateTime`; `null` for an empty, malformed or impossible string.
|
|
73
|
+
- toISODateTime: `toISODateTime(value: CalendarDateTime | null | undefined): string`. Writes a `CalendarDateTime` as `"YYYY-MM-DDTHH:mm"`, or `""` for none.
|