@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,49 @@
|
|
|
1
|
+
## ChatThread
|
|
2
|
+
|
|
3
|
+
Group: Content
|
|
4
|
+
|
|
5
|
+
When to use: Holding the messages and tool calls of a chat, an agent log or a message thread.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
Nothing to show yet is the thread's `empty`, which goes away with the first message.
|
|
9
|
+
```tsx
|
|
10
|
+
import { ChatThread, EmptyState } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<ChatThread label="New chat" empty={<EmptyState title="No messages yet" level={3} />} />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Do
|
|
16
|
+
- Name it with `label`. Its children are `ChatMessage`s and anything else that belongs in the conversation (a tool call is a bordered `Disclosure` whose `summary` names the tool and carries a `Pill` for how it went), in order, oldest first.
|
|
17
|
+
- It starts at the bottom and stays there as content grows, a streamed reply included. When the reader scrolls up it leaves them where they are; scrolling back to the bottom (within 32px) follows again. You write no scrolling of your own.
|
|
18
|
+
- `height` caps it: `sm`, `md` (default) or `lg`. `fill` takes the height of a parent that sets one, for a whole-page chat.
|
|
19
|
+
- `empty` is what it draws with no children, an `EmptyState`, at its full size.
|
|
20
|
+
- Set `announce` when a message is finished ("Helper replied"), not on each token.
|
|
21
|
+
- An approval is a `Callout` with `Button`s in its `actions`, placed in the thread, not a component of its own. So is a notice beside a message.
|
|
22
|
+
- It knows nothing about where messages come from: no fetch, no AI SDK. Map your own messages to its children.
|
|
23
|
+
|
|
24
|
+
### Don't
|
|
25
|
+
A made-up message is not an empty state: a screen reader reads it as something somebody said.
|
|
26
|
+
```tsx
|
|
27
|
+
import { ChatMessage, ChatThread } from "@slashsuite/ui-react";
|
|
28
|
+
|
|
29
|
+
<ChatThread label="New chat">
|
|
30
|
+
<ChatMessage role="assistant" author="Helper">
|
|
31
|
+
No messages yet
|
|
32
|
+
</ChatMessage>
|
|
33
|
+
</ChatThread>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Accessibility
|
|
37
|
+
- The box is `role="region"` named by `label`, with `tabIndex={0}`, so a keyboard can reach it and scroll it with the arrow keys. Use a different `label` for each thread on a page.
|
|
38
|
+
- It is deliberately not `role="log"` and has no `aria-live`: a live region round streamed text reads every token aloud. `announce` goes in a visually hidden `aria-live="polite"` element beside the box.
|
|
39
|
+
- Following the bottom is instant, never a smooth scroll.
|
|
40
|
+
|
|
41
|
+
### Props
|
|
42
|
+
### ChatThread
|
|
43
|
+
The scrolling box of a chat: its children are the messages, tool cards and anything else, a gap apart. It follows the newest content unless the reader has scrolled up. It is a named region and a tab stop, so a keyboard can scroll it. It is deliberately not a live region, which would read every streamed token aloud: set `announce` when a message is finished.
|
|
44
|
+
- announce: string. Text a screen reader reads out politely when it changes. Set it when a message is finished, not on each token.
|
|
45
|
+
- empty: ReactNode. Drawn instead when there are no children: an `EmptyState`.
|
|
46
|
+
- height: "sm" | "md" | "lg" | "fill" (default md). The tallest it gets before it scrolls: `sm` 20rem, `md` 28rem, `lg` 40rem. `fill` takes the
|
|
47
|
+
height of a parent that sets one.
|
|
48
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
49
|
+
- label: string (required). Names the region.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
## Checkbox
|
|
2
|
+
|
|
3
|
+
Group: Forms
|
|
4
|
+
|
|
5
|
+
When to use: An on/off option the person ticks: a setting, a filter, a row to select.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
A yes or no is a `Checkbox` with its `label`: the whole label is the click target.
|
|
9
|
+
```tsx
|
|
10
|
+
import { Checkbox } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<Checkbox label="Email me when a shop I follow posts" defaultChecked />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Do
|
|
16
|
+
- Give a `Checkbox` a `label`; the whole label is the click target.
|
|
17
|
+
- In a table cell leave the `label` out, use `size="sm"` and name the box with `aria-label`. `size="lg"` matches a large `Input`.
|
|
18
|
+
- A `hint` is a muted line under the label for an option that needs a sentence, and an `error` goes under it in red. The box always sits on the label's first line.
|
|
19
|
+
- A setting that takes effect the moment it is flipped, usually by saving it, is a `Switch`. A `Checkbox` is ticked and then submitted with the form.
|
|
20
|
+
- Choosing one of several is a `RadioGroup`, a `Select` or a `SegmentedControl`, not a row of checkboxes.
|
|
21
|
+
- Several checkboxes for one question go in a `Fieldset`.
|
|
22
|
+
- `variant="card"` is an option card, the label its title and the `hint` its description, for a few options that each need a sentence; give every box in the `Fieldset` the same variant.
|
|
23
|
+
- Say why the box cannot change with `disabledReason`.
|
|
24
|
+
|
|
25
|
+
### Don't
|
|
26
|
+
- Do not wrap a `Checkbox` in a `Field`; it is its own label.
|
|
27
|
+
|
|
28
|
+
A checkbox with the words beside it, not in it, names nothing: clicking the words does nothing.
|
|
29
|
+
```tsx
|
|
30
|
+
import { Checkbox, Cluster, Text } from "@slashsuite/ui-react";
|
|
31
|
+
|
|
32
|
+
<Cluster gap="sm">
|
|
33
|
+
<Checkbox />
|
|
34
|
+
<Text>Email me when a shop I follow posts</Text>
|
|
35
|
+
</Cluster>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Words beside a box in a table cell crowd the row and repeat the row's own name. Leave the `label` out and name the box with `aria-label`.
|
|
39
|
+
```tsx
|
|
40
|
+
import { Checkbox } from "@slashsuite/ui-react";
|
|
41
|
+
|
|
42
|
+
<Checkbox label="Select row" />
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A bare `disabled` box drops out of the tab order and never says why.
|
|
47
|
+
```tsx
|
|
48
|
+
import { Checkbox } from "@slashsuite/ui-react";
|
|
49
|
+
|
|
50
|
+
<Checkbox label="Email the team" disabled />
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Accessibility
|
|
55
|
+
- A native `<input type="checkbox">` inside a `<label>`, so clicking the text toggles it and the label is its name.
|
|
56
|
+
- A bare box has no name of its own: `aria-label` is required.
|
|
57
|
+
- A `hint` and an `error` are the box's `aria-describedby`, added to any you pass; an `error` is announced politely, not as an alert, and marks the box `aria-invalid`. `indeterminate` draws a dash for a group partly ticked and is read out as "mixed".
|
|
58
|
+
- `disabledReason` sets `aria-disabled` and keeps the box in the tab order; a click and Space do nothing, and the reason shows as a tooltip on hover, keyboard focus and a tap, read out as its description (the native `title` without CSS anchor positioning).
|
|
59
|
+
- The focus ring comes from the component.
|
|
60
|
+
|
|
61
|
+
### Props
|
|
62
|
+
### Checkbox
|
|
63
|
+
A checkbox with its label. It is a real `<input type="checkbox">`, drawn by the library (an empty outlined box, then a filled accent one with a check mark) so it reads the same in every theme and browser. Every prop but the label goes on the input, and `ref` reaches it. `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted line under the label that says more, like a `Field`'s; `error` adds a red line under it, with an alert icon, and makes the box `aria-invalid` and red-edged. The note is the box's `aria-describedby`. `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone. `indeterminate` draws a dash for a select-all box over a partly chosen list. `variant="card"` draws it as an option card: a bordered box with the label as its title and the hint under it. Under a finger the hit area grows to 44px. While `loading` the label is drawn and the box is a bone of its size.
|
|
64
|
+
- disabledReason: string. Why the box cannot be changed: it dims and is blocked (`aria-disabled`; a click and Space
|
|
65
|
+
change nothing) while it stays in the tab order, and the reason is its tooltip on hover,
|
|
66
|
+
keyboard focus and a tap, read out as its description.
|
|
67
|
+
- error: ReactNode. A red line under the hint, with an alert icon, announced politely; makes the box `aria-invalid`.
|
|
68
|
+
- hint: ReactNode. A muted line under the label that says more. It is the box's `aria-describedby`.
|
|
69
|
+
- indeterminate: boolean (default false). Mixed: some of what the box stands for is chosen and some is not, as a select-all box over a
|
|
70
|
+
partly chosen list. It draws a dash and is read as "mixed"; a click checks it. The caller owns
|
|
71
|
+
it: work it out from the list on every render.
|
|
72
|
+
- label: ReactNode. The text beside the box. Leave it out for a bare box (a table cell) and name it with `aria-label`.
|
|
73
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
74
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
75
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
76
|
+
- onChange: ((checked: boolean) => void). Called with the new checked state when the person ticks or clears the box.
|
|
77
|
+
- ref: Ref<HTMLInputElement>. The `<input>`, for focus control.
|
|
78
|
+
- size: "sm" | "md" | "lg" (default md). The label's text size and the box with it.
|
|
79
|
+
- variant: "card" | "plain" (default plain). `plain` is the box and its words. `card` puts them in a bordered box the width of its parent,
|
|
80
|
+
the label a title and the `hint` its description: for a few options that each need a line of
|
|
81
|
+
explaining. The whole card is the click target, and a ticked one takes an accent edge.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
## Cluster
|
|
2
|
+
|
|
3
|
+
Group: Layout
|
|
4
|
+
|
|
5
|
+
When to use: Items in a line that are not buttons: a label beside a value, an input beside its actions, a row of pills.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
The one item that should take the room left goes in `ClusterGrow`: the input fills the row and the buttons keep their size.
|
|
9
|
+
```tsx
|
|
10
|
+
import { Button, Cluster, ClusterGrow, Input } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<Cluster>
|
|
13
|
+
<ClusterGrow>
|
|
14
|
+
<Input aria-label="Search" placeholder="Search invoices" />
|
|
15
|
+
</ClusterGrow>
|
|
16
|
+
<Button>Search</Button>
|
|
17
|
+
</Cluster>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Do
|
|
21
|
+
- `gap` is `xs`, `sm` (default) or `md`, the first steps of the `Stack` scale: the items of a row sit closer than the blocks of a column. The `Size` type lists every default that is not `md`.
|
|
22
|
+
- `align` is the cross axis: `center` (default), `baseline` for mixed text sizes, `start` or `end`. `justify` is the main axis: `start` (default), `center`, `between` for the two ends, `end`.
|
|
23
|
+
- The items flow onto more lines when the row runs out of room; `wrap={false}` keeps them on one line.
|
|
24
|
+
- Wrap the one item that should fill the row in `ClusterGrow`; it can shrink to nothing, so a long value truncates and the others stay.
|
|
25
|
+
- An empty `ClusterGrow` is a spacer: what follows it goes to the end.
|
|
26
|
+
- A row of buttons is a `ButtonGroup`, which wraps on a phone and can pin an item to the end. Use `Cluster` for every other row.
|
|
27
|
+
- `justify="between"` is for two items; with more, the middle one floats, so use a spacer.
|
|
28
|
+
- `as="ul"` or `as="ol"` makes a wrapping row of like things (tags, chips) a list, and `as="nav"` a row of links (a footer's) in a `<nav>` named by its required `aria-label`. Pass the items themselves: the Cluster puts each in its own `<li>`, and a `ClusterGrow` does not belong in a list.
|
|
29
|
+
|
|
30
|
+
### Don't
|
|
31
|
+
Without `ClusterGrow` the input keeps a fixed width and the rest of the row sits empty. Wrap the input in `ClusterGrow` instead.
|
|
32
|
+
```tsx
|
|
33
|
+
import { Button, Cluster, Input } from "@slashsuite/ui-react";
|
|
34
|
+
|
|
35
|
+
<Cluster>
|
|
36
|
+
<Input aria-label="Search" placeholder="Search invoices" width="sm" />
|
|
37
|
+
<Button>Search</Button>
|
|
38
|
+
</Cluster>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`Cluster` is for every other row; a row of buttons in it does not wrap and has no end slot.
|
|
42
|
+
```tsx
|
|
43
|
+
import { Button, Cluster } from "@slashsuite/ui-react";
|
|
44
|
+
|
|
45
|
+
<Cluster>
|
|
46
|
+
<Button>Send</Button>
|
|
47
|
+
<Button variant="outline">Download</Button>
|
|
48
|
+
<Button variant="outline">Back</Button>
|
|
49
|
+
</Cluster>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`justify="between"` spreads three items evenly, so the middle one floats away from the group it belongs to.
|
|
53
|
+
```tsx
|
|
54
|
+
import { Button, Cluster, Text } from "@slashsuite/ui-react";
|
|
55
|
+
|
|
56
|
+
<Cluster justify="between">
|
|
57
|
+
<Text strong>Invoice 1042</Text>
|
|
58
|
+
<Button size="sm" variant="outline">
|
|
59
|
+
Edit
|
|
60
|
+
</Button>
|
|
61
|
+
<Button size="sm" variant="outline" tone="danger">
|
|
62
|
+
Remove
|
|
63
|
+
</Button>
|
|
64
|
+
</Cluster>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The same pills in a plain Cluster are three loose items: no list, no count.
|
|
68
|
+
```tsx
|
|
69
|
+
import { Cluster, Pill } from "@slashsuite/ui-react";
|
|
70
|
+
|
|
71
|
+
<Cluster>
|
|
72
|
+
<Pill>Vintage</Pill>
|
|
73
|
+
<Pill>Books</Pill>
|
|
74
|
+
<Pill>Vinyl</Pill>
|
|
75
|
+
</Cluster>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Accessibility
|
|
79
|
+
- A `Cluster` is a `div` (or a `span` with `as="span"`) and adds no role; the reading and tab order is the source order of its children.
|
|
80
|
+
- A `ul` or `ol` Cluster is a list a screen reader counts; give it an `aria-label` when more than one list is on the page.
|
|
81
|
+
- A `nav` Cluster is a navigation landmark named by its `aria-label`, holding a list of its links.
|
|
82
|
+
- `ClusterGrow` is a `div` too: put the labelled control inside it, with its own `aria-label` or `Field`.
|
|
83
|
+
|
|
84
|
+
### Props
|
|
85
|
+
### Cluster
|
|
86
|
+
A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the main one (`start` default, `between` to push the first and last items to the two ends, `end`). The items flow onto further lines when the row runs out of room; `wrap={false}` keeps them on one line. Put one `ClusterGrow` around the item that takes the room left over, an input beside its buttons, say. An empty `ClusterGrow` is a spacer that pushes what follows it to the end. `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers (tags, chips), as in `CardGrid`: the Cluster wraps each child in its own `<li>`, so the caller writes the items (`Pill`s) and never an `<li>`. `as="nav"` is a row of links (a footer's or a section's): a `<nav>` named by its required `aria-label`, holding a list with each link in its own `<li>`.
|
|
87
|
+
- align: "center" | "baseline" | "end" | "start" (default center). The cross axis: `center`, `baseline` (for mixed text sizes), `start` or `end`.
|
|
88
|
+
- as: "nav" | "div" | "ol" | "span" | "ul" (default div). The element: `div`, `span` for a row inside a `<p>` or other phrasing content, `ul` or `ol`
|
|
89
|
+
for a list (no markers; the Cluster wraps each child in an `<li>`), or `nav` for a row of
|
|
90
|
+
links (a `<nav>` named by `aria-label`, around such a list).
|
|
91
|
+
|
|
92
|
+
In a `span` the items must be phrasing content, so no `ClusterGrow`.
|
|
93
|
+
- gap: "sm" | "md" | "xs" (default sm). The space between items: the first steps of the gap scale. Its default is one of those the
|
|
94
|
+
`Size` type lists as not `md`.
|
|
95
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
96
|
+
- justify: "center" | "end" | "start" | "between" (default start). The main axis: `start`, `center`, `between` (the first and last items at the two ends) or `end`.
|
|
97
|
+
- wrap: boolean (default true). Let the items flow onto further lines when the row runs out of room. `false` keeps them on one line.
|
|
98
|
+
|
|
99
|
+
### ClusterGrow
|
|
100
|
+
The one child of a `Cluster` (or of a `Stack` with `rowFrom`) that grows to the room left in the row. By default it can shrink to nothing (`min-w-0`), so the items beside it stay on the line and a long value truncates instead of pushing them out. With `minWidth` it instead keeps that width (`sm` 12rem, `md` 17rem) and, in a `Cluster` with `wrap`, drops onto the next line when the room left is narrower, rather than being squashed. Empty, it is a spacer.
|
|
101
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
102
|
+
- minWidth: "sm" | "md". The narrowest it gets: `sm` 12rem or `md` 17rem. In a `Cluster` with `wrap` it wraps under the other items below this width. Left out, it shrinks to nothing.
|
|
103
|
+
|
|
104
|
+
### Types
|
|
105
|
+
- ClusterAlign: `"end" | "start" | "center" | "baseline"`. Where a `Cluster`'s items sit across the row: `center`, `baseline` for mixed text sizes, `start` or `end`.
|
|
106
|
+
- ClusterGap: `"sm" | "md" | "xs"`. The first three steps of `Stack`'s scale: `xs` between items in a line, `sm` inside a group, `md` between blocks.
|
|
107
|
+
- ClusterGrowMinWidth: `"sm" | "md"`. The narrowest a `ClusterGrow` gets before the row wraps: `sm` or `md`.
|
|
108
|
+
- ClusterJustify: `"end" | "start" | "center" | "between"`. Where a `Cluster`'s items sit along the row: `start`, `center`, `end`, or `between` to spread them to both ends.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
## CodeExample
|
|
2
|
+
|
|
3
|
+
Group: Text
|
|
4
|
+
|
|
5
|
+
When to use: Documentation that shows a part and its source together.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
`CodeExample` frames a rendered part with the code that makes it, in one box.
|
|
9
|
+
```tsx
|
|
10
|
+
import { Button, CodeExample } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<CodeExample code={'<Button variant="primary">Save</Button>'}>
|
|
13
|
+
<Button variant="primary">Save</Button>
|
|
14
|
+
</CodeExample>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Do
|
|
18
|
+
- Put the rendered part in `children` and its source in `code`, a string with the newlines kept.
|
|
19
|
+
- `caption` is one note on the example, the last band of the frame.
|
|
20
|
+
- Side by side in a grid, each frame is its own height, so do not pad the previews to match.
|
|
21
|
+
- A wide preview or a long line of code scrolls inside the frame under a themed scrollbar; it does not widen the page.
|
|
22
|
+
- `copy` adds a button beside the code that copies the code, not the preview. It needs client JS; on a page rendered to static HTML, inline `copyScript` once (see CopyButton).
|
|
23
|
+
- Inside a `Prose` the preview stays on the app scale, so the part looks as it does on an app screen; the caption is outside it.
|
|
24
|
+
- Only for documentation. A command to copy is a `CopyLine`, and code alone is a `CodeBlock`.
|
|
25
|
+
|
|
26
|
+
### Don't
|
|
27
|
+
A loose preview with a `CodeBlock` under it is two unrelated things: no shared frame, and they drift apart.
|
|
28
|
+
```tsx
|
|
29
|
+
import { Button, CodeBlock, Stack } from "@slashsuite/ui-react";
|
|
30
|
+
|
|
31
|
+
<Stack gap="sm">
|
|
32
|
+
<Button variant="primary">Save</Button>
|
|
33
|
+
<CodeBlock>{'<Button variant="primary">Save</Button>'}</CodeBlock>
|
|
34
|
+
</Stack>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Accessibility
|
|
38
|
+
- A `<figure>` holds the preview and the code in `<pre><code>`; `caption` is its `<figcaption>`.
|
|
39
|
+
- `aria-*` and `data-*` go on the figure.
|
|
40
|
+
|
|
41
|
+
### Props
|
|
42
|
+
### CodeExample
|
|
43
|
+
One framed example: the rendered `children` on top and the `code` that makes them attached underneath, in a single bordered box with one divider between. With `copy`, a copy button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to a shared minimum so two frames side by side start alike. A wide preview or a long line of code scrolls inside the frame, under a themed scrollbar, instead of widening the page or wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component does anywhere else; the caption is outside it.
|
|
44
|
+
- caption: ReactNode. One note on the example, under the code.
|
|
45
|
+
- code: string (required). The source shown under the preview, newlines kept.
|
|
46
|
+
- copy: boolean (default false). A copy button beside the code. On a page rendered to static HTML without hydration, inline
|
|
47
|
+
`copyScript` and it works there too.
|
|
48
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
## Code
|
|
2
|
+
|
|
3
|
+
Group: Text
|
|
4
|
+
|
|
5
|
+
When to use: A command, name or path inside a sentence is `Code`; several lines of code are a `CodeBlock`.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- CopyButton (copy-button.md): Neither a `CopyLine` nor `copy` on a `CodeBlock` or `CodeExample` fits.
|
|
9
|
+
- CopyLine (copy-line.md): The text to copy is one line, such as an install command.
|
|
10
|
+
|
|
11
|
+
### The one right way
|
|
12
|
+
`Code` is one short run of code inside a sentence: a command, a name, a path.
|
|
13
|
+
```tsx
|
|
14
|
+
import { Code, Text } from "@slashsuite/ui-react";
|
|
15
|
+
|
|
16
|
+
<Text>
|
|
17
|
+
Run <Code>bun install</Code> once, then <Code>bunx nx run-many -t test</Code> to check it.
|
|
18
|
+
</Text>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Do
|
|
22
|
+
- Use `Code` for one short run inside a sentence. It takes the text colour and size around it, and keeps no line breaks. A long value (a hash, a path) takes `lines={1}`, cut with an ellipsis and showing its whole text in a tooltip while it is cut, or `breakWords`, which breaks it at the edge of its box.
|
|
23
|
+
- Use `CodeBlock` for several lines. Give the text as `children`, or as `lines` with one entry per line.
|
|
24
|
+
- `label` names the language or file (`bash`, `css`) in a caption above the code; `language` says what to colour, from `tsx`, `ts`, `js`, `json`, `bash`, `console`, `css`, `html` and `yaml`.
|
|
25
|
+
- A shell session is `console`: a line starting with `$ ` is a command, coloured as bash, and every other line is output. With `copy`, only the commands are copied, without the `$ `.
|
|
26
|
+
- A line a reader copies is a `CopyLine`, not a one-line `CodeBlock`. A rendered part shown with its code is a `CodeExample`.
|
|
27
|
+
- Without a `language` the code is one colour (`text`), which suits an error or a log.
|
|
28
|
+
- A long line wraps, so a command is never cut off and still copies as one line. `overflow="scroll"` keeps lines whole and scrolls them sideways under a scrollbar in the theme's colour, for code whose layout matters.
|
|
29
|
+
- `copy` adds a copy button beside the code. It needs client JS; on a page rendered to static HTML, inline `copyScript` once (see CopyButton).
|
|
30
|
+
|
|
31
|
+
### Don't
|
|
32
|
+
`Code` is inline, so its line breaks collapse into one run. Several lines are a `CodeBlock`.
|
|
33
|
+
```tsx
|
|
34
|
+
import { Code, Text } from "@slashsuite/ui-react";
|
|
35
|
+
|
|
36
|
+
<Text>
|
|
37
|
+
<Code>{"bun install\nbun run build\nbun run test"}</Code>
|
|
38
|
+
</Text>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
One short line a reader copies is a `CopyLine`, the smaller box. A one-line `CodeBlock` is for a command that needs a `label` or colour.
|
|
42
|
+
```tsx
|
|
43
|
+
import { CodeBlock } from "@slashsuite/ui-react";
|
|
44
|
+
|
|
45
|
+
<CodeBlock language="bash">bun add @slashsuite/ui-react</CodeBlock>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Accessibility
|
|
49
|
+
- `Code` renders a `<code>`. `CodeBlock` renders a `<figure>` with the code in `<pre><code>`, so the line breaks are kept.
|
|
50
|
+
- `label` is the `<figcaption>`, which names the figure.
|
|
51
|
+
- `CodeBlock` takes `aria-*` and `data-*` on its figure.
|
|
52
|
+
|
|
53
|
+
### Props
|
|
54
|
+
### Code
|
|
55
|
+
Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a touch smaller, for the mono face). `lines={1}` keeps a long value (a hash, a path) on one line, cut with an ellipsis, and shows its whole text in a tooltip while it is cut; `breakWords` instead breaks a long unbroken value at the edge of its box, as `Text` does.
|
|
56
|
+
- breakWords: boolean (default false). Breaks a long unbroken value (a URL, a hash) at the edge of its box.
|
|
57
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
58
|
+
- lines: 1. `1` keeps it on one line, cut with an ellipsis; while it is cut, its whole text shows in a tooltip.
|
|
59
|
+
|
|
60
|
+
### CodeBlock
|
|
61
|
+
A block of code: mono, in a bordered inset box. No client JS unless `copy` adds a copy button beside the code, which copies it exactly as given. `language` colours it: `tsx`, `ts`, `js`, `json`, `bash`, `console`, `css`, `html` or `yaml`. `console` is a shell session: a line starting with `$ ` is a command (coloured as bash, its `$ ` dimmed and not selectable) and any other line is output; with `copy` only the commands are copied, without the `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole and scrolls them sideways under a themed scrollbar, for code whose layout matters. With `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the smaller box.
|
|
62
|
+
- copy: boolean (default false). A copy button beside the code, which copies it exactly as given (a `console` block copies only
|
|
63
|
+
its commands). On a page rendered to static HTML without hydration, inline `copyScript` and it works there too.
|
|
64
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
65
|
+
- label: string. A caption above the code naming its language or file (`bash`, `theme.css`).
|
|
66
|
+
- language: "text" | "html" | "tsx" | "ts" | "js" | "json" | "bash" | "console" | "css" | "yaml" (default text). What the code is written in; `text` (the default) colours nothing.
|
|
67
|
+
- lines: string[]. The code as one array entry per line, in place of `children`.
|
|
68
|
+
- overflow: "wrap" | "scroll" (default wrap). What a line longer than the box does: `wrap` onto the next line (the default, nothing is cut
|
|
69
|
+
off), or `scroll` sideways inside the box.
|
|
70
|
+
|
|
71
|
+
### Types
|
|
72
|
+
- CodeLanguage: `"text" | "tsx" | "ts" | "js" | "json" | "bash" | "console" | "css" | "html" | "yaml"`. The languages a `CodeBlock` colours; `text` is plain, and `console` marks the commands of a terminal session.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
## ColourSchemeToggle
|
|
2
|
+
|
|
3
|
+
Group: Actions
|
|
4
|
+
|
|
5
|
+
When to use: A site that offers both schemes: one toggle in the header or controls.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
One `ColourSchemeToggle` in the page header: it switches `<html>`, remembers the choice and shows the scheme you would switch to.
|
|
9
|
+
```tsx
|
|
10
|
+
import { ColourSchemeToggle } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<ColourSchemeToggle />
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Do
|
|
17
|
+
- Use one `ColourSchemeToggle` per site. It switches `<html>` between light and dark and remembers the choice in `localStorage`.
|
|
18
|
+
- It follows the system until a click picks the other scheme; a click back to the system's scheme forgets the choice, so the page follows the system again. It also takes a choice made in another tab, and the system switching while nothing is stored.
|
|
19
|
+
- `size` is `sm`, `md` (default) or `lg`, the same squares as `IconButton`.
|
|
20
|
+
- Put `colourSchemeScript` inline in `<head>`, so the stored or system scheme is on `<html>` before first paint and neither scheme flashes the other. It knows only the `dark` class.
|
|
21
|
+
- A light theme with a class of its own passes `schemes`, as in `schemes={{ light: "my-light", dark: "dark" }}`; render the same class on `<html>` on the server with `schemeClass`, and leave the head script out.
|
|
22
|
+
- An app that knows the scheme on the server (from a cookie) passes it as `defaultValue`, sets `store={false}` and persists from `onChange`, clearing the cookie when its `followsSystem` is true. It then leaves the head script out.
|
|
23
|
+
|
|
24
|
+
### Don't
|
|
25
|
+
- Do not build a switch from your own buttons; the functions below are what the toggle itself calls.
|
|
26
|
+
|
|
27
|
+
Two hand-rolled buttons forget the choice, and nothing shows which scheme is on.
|
|
28
|
+
```tsx
|
|
29
|
+
import { applyColourScheme, Button, ButtonGroup } from "@slashsuite/ui-react";
|
|
30
|
+
|
|
31
|
+
<ButtonGroup label="Colour scheme">
|
|
32
|
+
<Button variant="outline" size="sm" onClick={() => applyColourScheme("light")}>
|
|
33
|
+
Light
|
|
34
|
+
</Button>
|
|
35
|
+
<Button variant="outline" size="sm" onClick={() => applyColourScheme("dark")}>
|
|
36
|
+
Dark
|
|
37
|
+
</Button>
|
|
38
|
+
</ButtonGroup>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Without `schemes` the toggle only adds and removes `dark`, so the light theme's own class is never put back.
|
|
42
|
+
```tsx
|
|
43
|
+
import { ColourSchemeToggle } from "@slashsuite/ui-react";
|
|
44
|
+
|
|
45
|
+
<ColourSchemeToggle />
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Accessibility
|
|
50
|
+
- It is a button named `Switch to dark theme` or `Switch to light theme` (`darkLabel` and `lightLabel`, for an app in another language), so the name says the action, and the icon is `aria-hidden`. The name follows the class on `<html>` through CSS before hydration, with no script; only the tooltip waits for the client.
|
|
51
|
+
- The icon shown is the scheme you would switch to: the moon on a light page, the sun on a dark one. It follows the class on `<html>` through CSS, so it is right on the first frame.
|
|
52
|
+
- `applyColourScheme` also sets `color-scheme` on `<html>`, so native controls and scrollbars follow.
|
|
53
|
+
|
|
54
|
+
### Props
|
|
55
|
+
### ColourSchemeToggle
|
|
56
|
+
A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to. 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. 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. An app whose light scheme has a class of its own passes `schemes` (`{ light: "my-light", dark: "dark" }`); the toggle swaps those classes, and `schemeClass` gives the same one for the server to render on `<html>`. An app that knows the scheme on the server (from a cookie) passes it as `defaultValue`, so the server markup, the hydrating client and the `<html>` class agree; persist a change from `onChange`. The icon and the button's accessible name follow the class on `<html>` through CSS (the name is two visually hidden "Switch to …" spans, one hidden by `display:none`), so even without `defaultValue` a dark page shows the sun and is named `lightLabel` ("Switch to light theme") from the first frame, with no script. Only the tooltip catches up once the client has hydrated. `store={false}` skips `localStorage`, for an app that keeps the choice in a server cookie and writes it from `onChange`. Every other button prop (`id`, `data-*`, `aria-*`) goes on the button.
|
|
57
|
+
- darkLabel: string (default Switch to dark theme). The button's accessible name and tooltip on a light page, where it switches to dark.
|
|
58
|
+
- defaultValue: (ColourScheme & (string | number | readonly string[])) (default light). The scheme the server rendered. What the server and the hydrating client show; the real state follows right after.
|
|
59
|
+
- lightLabel: string (default Switch to light theme). The button's accessible name and tooltip on a dark page, where it switches to light.
|
|
60
|
+
- onChange: (scheme: ColourScheme, followsSystem: boolean) => void. Called with the new scheme after a click, for an app that persists the choice itself (a cookie).
|
|
61
|
+
`followsSystem` is true when the new scheme is the system's: forget the choice (clear the cookie)
|
|
62
|
+
rather than store it, so the page follows the system again.
|
|
63
|
+
- schemes: ColourSchemeClasses (default { light: "", dark: "dark" }). The class each scheme puts on `<html>`.
|
|
64
|
+
- size: "sm" | "md" | "lg" (default md). The button's height, as an `IconButton`'s.
|
|
65
|
+
- store: boolean (default true). Remember the choice in `localStorage`. `false` leaves persisting to `onChange`.
|
|
66
|
+
|
|
67
|
+
### Types
|
|
68
|
+
- ColourScheme: `"light" | "dark"`. The two colour schemes a site switches between: `light` and `dark`.
|
|
69
|
+
- ColourSchemeClasses: `{ light: string; dark: string }`. The class each scheme puts on `<html>`: none for light and `dark` for dark, unless the app's theme says otherwise (a light theme with a scope class of its own).
|
|
70
|
+
|
|
71
|
+
### Functions
|
|
72
|
+
- applyColourScheme: `applyColourScheme(scheme: ColourScheme, root?: HTMLElement, schemes?: ColourSchemeClasses): void`. Puts a scheme on `<html>`: its class, the other scheme's class taken off, and `color-scheme`.
|
|
73
|
+
```tsx
|
|
74
|
+
button.addEventListener("click", () => {
|
|
75
|
+
const next = readColourScheme() === "dark" ? "light" : "dark";
|
|
76
|
+
applyColourScheme(next);
|
|
77
|
+
storeColourScheme(next);
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
- schemeClass: `schemeClass(scheme: ColourScheme, schemes?: ColourSchemeClasses): string`. The class a scheme puts on `<html>`, for the server to render so the first paint is right; empty for the default light scheme.
|
|
81
|
+
```tsx
|
|
82
|
+
<html className={schemeClass(scheme, { light: "my-light", dark: "dark" })}>
|
|
83
|
+
```
|
|
84
|
+
- colourSchemeScript: `colourSchemeScript: string`. A string of JavaScript to inline in `<head>` before first paint: applies the stored scheme, else the system one, then follows another tab's choice and the system switching while nothing is stored.
|
|
85
|
+
```tsx
|
|
86
|
+
<head>
|
|
87
|
+
<script dangerouslySetInnerHTML={{ __html: colourSchemeScript }} />
|
|
88
|
+
</head>
|
|
89
|
+
```
|
|
90
|
+
- readColourScheme: `readColourScheme(fallback?: ColourScheme): ColourScheme`. The stored choice, else the system preference, with a fallback (default light) when neither is available, as on the server.
|
|
91
|
+
```tsx
|
|
92
|
+
const scheme = readColourScheme(); // the stored choice, else the system's, else light
|
|
93
|
+
```
|
|
94
|
+
- storeColourScheme: `storeColourScheme(scheme: ColourScheme | "system"): void`. Remembers a scheme in `localStorage` for the next visit, or with `system` forgets it so the page follows the system again; a storage error is swallowed.
|
|
95
|
+
```tsx
|
|
96
|
+
storeColourScheme(next); // read back on the next visit
|
|
97
|
+
storeColourScheme("system"); // follow the system again
|
|
98
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
## ColourSwatch
|
|
2
|
+
|
|
3
|
+
Group: Content
|
|
4
|
+
|
|
5
|
+
When to use: Showing a colour as data: one read off a page, a screenshot, a brand or a theme.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- Image (image.md): What is shown is a picture, not one colour.
|
|
9
|
+
|
|
10
|
+
### The one right way
|
|
11
|
+
Each colour as a swatch with its name and its hex value in text, so it reads without seeing the square.
|
|
12
|
+
```tsx
|
|
13
|
+
import { ColourSwatch, Stack } from "@slashsuite/ui-react";
|
|
14
|
+
|
|
15
|
+
<Stack gap="sm">
|
|
16
|
+
<ColourSwatch value="#1e293b" label="Background" />
|
|
17
|
+
<ColourSwatch value="#38bdf8" label="Accent" />
|
|
18
|
+
</Stack>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Do
|
|
22
|
+
- `value` is the colour as `#rrggbb`. Anything else draws an empty swatch and leaves the value out, so a bad value never paints the page.
|
|
23
|
+
- `label` says what the colour is, as "Background" or "Accent". The hex value follows it in mono, lower case.
|
|
24
|
+
- A list of colours is a `Stack` of swatches, or swatches in the cells of a `Table`.
|
|
25
|
+
|
|
26
|
+
### Don't
|
|
27
|
+
A painted square alone says nothing to a screen reader, nor to anyone who cannot tell the colours apart.
|
|
28
|
+
```tsx
|
|
29
|
+
<span style={{ display: "inline-block", width: 16, height: 16, backgroundColor: "#1e293b" }} />
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Accessibility
|
|
33
|
+
- The square is decorative and hidden from a screen reader; the label and the hex value say the colour in text.
|
|
34
|
+
- A hairline edges the square, so a colour close to the page's own still shows.
|
|
35
|
+
|
|
36
|
+
### Props
|
|
37
|
+
### ColourSwatch
|
|
38
|
+
A small square in a measured colour, with its `label` and its hex `value` beside it in mono: a colour read off a page, a screenshot or a theme. The colour is the data on show, not a look, so it is painted from `value`; anything but a `#rrggbb` value draws an empty swatch and no value. A hairline edges the square, so a colour close to the page still shows. The square is decorative: the label and the value say the colour.
|
|
39
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
40
|
+
- label: string (required). What the colour is, as "Background" or "Accent", shown before the value.
|
|
41
|
+
- value: string (required). The colour, as `#rrggbb`. Anything else draws an empty swatch and leaves the value out.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
## Combobox
|
|
2
|
+
|
|
3
|
+
Group: Forms
|
|
4
|
+
|
|
5
|
+
When to use: One choice from more items than a `Select` reads well: a country, a time zone, a teammate.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
A choice from a long list is a `Combobox`: typing a few letters finds it.
|
|
9
|
+
```tsx
|
|
10
|
+
import { Combobox } from "@slashsuite/ui-react";
|
|
11
|
+
|
|
12
|
+
<Combobox
|
|
13
|
+
label="Time zone"
|
|
14
|
+
defaultValue="Europe/Amsterdam"
|
|
15
|
+
width="md"
|
|
16
|
+
items={[
|
|
17
|
+
"Africa/Johannesburg",
|
|
18
|
+
"America/New_York",
|
|
19
|
+
"Asia/Singapore",
|
|
20
|
+
"Asia/Tokyo",
|
|
21
|
+
"Australia/Sydney",
|
|
22
|
+
"Europe/Amsterdam",
|
|
23
|
+
"Europe/London",
|
|
24
|
+
"Pacific/Auckland",
|
|
25
|
+
].map((zone) => ({ value: zone, label: zone.replace("_", " ") }))}
|
|
26
|
+
/>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Do
|
|
30
|
+
- Give it a `label`; it draws its own label, `hint` and `error`, so it is never put in a `Field`.
|
|
31
|
+
- `items` are a `Select`'s: `{ value, label, disabled? }`. Typing filters them by label; the chevron opens the whole list.
|
|
32
|
+
- Keep it with `defaultValue`, or control it with `value` and `onChange(value)`; `name` posts the chosen `value`.
|
|
33
|
+
- Say what an empty filter means in another language with `emptyLabel`.
|
|
34
|
+
- `size` and `width` are the same choices as on `Input`. Up to a dozen choices is a `Select`, and up to five a `RadioGroup`.
|
|
35
|
+
|
|
36
|
+
### Don't
|
|
37
|
+
- Do not make the person scroll a long `Select` for their entry.
|
|
38
|
+
|
|
39
|
+
A `Select` of a long list makes the person scroll through every entry for theirs.
|
|
40
|
+
```tsx
|
|
41
|
+
import { Select } from "@slashsuite/ui-react";
|
|
42
|
+
|
|
43
|
+
<Select
|
|
44
|
+
aria-label="Time zone"
|
|
45
|
+
defaultValue="Europe/Amsterdam"
|
|
46
|
+
items={[
|
|
47
|
+
"Africa/Johannesburg",
|
|
48
|
+
"America/New_York",
|
|
49
|
+
"Asia/Singapore",
|
|
50
|
+
"Asia/Tokyo",
|
|
51
|
+
"Australia/Sydney",
|
|
52
|
+
"Europe/Amsterdam",
|
|
53
|
+
"Europe/London",
|
|
54
|
+
"Pacific/Auckland",
|
|
55
|
+
].map((zone) => ({ value: zone, label: zone.replace("_", " ") }))}
|
|
56
|
+
/>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Accessibility
|
|
60
|
+
- React Aria's combobox: the input is a `combobox` with the label as its name, and the list a `listbox` it controls.
|
|
61
|
+
- Arrow keys move through the list, Enter picks, Escape closes it; the chevron button is out of the tab order.
|
|
62
|
+
- A `hint` and an `error` are the field's description; an `error` marks it `aria-invalid` and is announced politely.
|
|
63
|
+
- Inside a modal `Dialog` the list draws in the dialog, so it stays reachable.
|
|
64
|
+
|
|
65
|
+
### Props
|
|
66
|
+
### Combobox
|
|
67
|
+
A text field that filters a list of choices as the person types, for a choice from more items than a `Select` reads well (a country, a time zone, a teammate): React Aria's `ComboBox`. Typing narrows the list by label; arrow keys move through it, Enter picks, Escape closes it. The chevron opens the whole list. Its value is the chosen item's `value`, posted under `name`. `label`, `hint`, `error`, `required` and `disabled` are a `DateField`'s; `size` and `width` an `Input`'s. Inside a modal `Dialog` the list draws in the dialog. While `loading` the label is drawn and the field is a bone of its height.
|
|
68
|
+
- defaultValue: string | null. The item's `value` it starts with, uncontrolled.
|
|
69
|
+
- disabled: boolean. Disables the field and its button.
|
|
70
|
+
- emptyLabel: string (default No matches). The line the list shows when nothing matches what was typed, for an app in another language.
|
|
71
|
+
- error: ReactNode. Marks the field invalid and shows this in red under the hint, announced politely.
|
|
72
|
+
- hint: ReactNode. A muted line under the field that says more; it stays while an error shows under it.
|
|
73
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
74
|
+
- items: readonly SelectItem[] (required). The choices, in order; typing filters them by label.
|
|
75
|
+
- label: ReactNode. The field's visible label, above it. Without one, name the field with `aria-label`.
|
|
76
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
77
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
78
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
79
|
+
- name: string. Posts the chosen item's `value` in a form under this key.
|
|
80
|
+
- onChange: ((value: string | null) => void). Called with the chosen item's `value`, or `null` when the choice is cleared.
|
|
81
|
+
- required: boolean. Marks a choice required: the field is `aria-required`, and an empty one is invalid.
|
|
82
|
+
- size: Size | ResponsiveSize (default md). `sm` is compact, `text-sm` with less padding, for dense forms and table rows; `md` is `text-base`;
|
|
83
|
+
`lg` is `text-lg` with more padding, for a hero form. Under an `AppShell density="compact"` each
|
|
84
|
+
is one type step down, and on a touch screen a field is never under 16px.
|
|
85
|
+
`{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS, as a `Button`'s
|
|
86
|
+
does: give the field and the buttons in its row the same value, so the row stays aligned.
|
|
87
|
+
- value: string | null. The chosen item's `value`, controlled, with `onChange`. `null` is nothing chosen.
|
|
88
|
+
- width: "sm" | "md" | "lg" | "auto" | "xs" | "fill" | "full". `full` (default) fills the parent; `fill` grows to fill the room left in a row beside other items (it can shrink to nothing, so buttons stay on the line); `xs`, `sm`, `md`, `lg` are fixed; `auto` adds no width class, so the control is as wide as the browser makes it.
|