@slashsuite/ui-react 0.12.0 → 0.12.1
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/README.md +12 -0
- package/agent-docs/components/app-shell.md +136 -0
- package/agent-docs/components/avatar-stack.md +64 -0
- package/agent-docs/components/avatar.md +76 -0
- package/agent-docs/components/badge.md +61 -0
- package/agent-docs/components/body-text.md +158 -0
- package/agent-docs/components/bottom-sheet.md +95 -0
- package/agent-docs/components/breadcrumbs.md +62 -0
- package/agent-docs/components/bullet-list.md +54 -0
- package/agent-docs/components/button.md +135 -0
- package/agent-docs/components/callout.md +86 -0
- package/agent-docs/components/card-grid.md +108 -0
- package/agent-docs/components/card.md +113 -0
- package/agent-docs/components/centered-layout.md +90 -0
- package/agent-docs/components/chat-composer.md +48 -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 +75 -0
- package/agent-docs/components/cluster.md +106 -0
- package/agent-docs/components/code-example.md +48 -0
- package/agent-docs/components/code.md +70 -0
- package/agent-docs/components/colour-scheme-toggle.md +92 -0
- package/agent-docs/components/container.md +50 -0
- package/agent-docs/components/copy-button.md +61 -0
- package/agent-docs/components/copy-line.md +54 -0
- package/agent-docs/components/date-field.md +103 -0
- package/agent-docs/components/date-range-picker.md +101 -0
- package/agent-docs/components/detail-layout.md +147 -0
- package/agent-docs/components/dialog.md +178 -0
- package/agent-docs/components/disclosure.md +66 -0
- package/agent-docs/components/divider.md +62 -0
- package/agent-docs/components/docs-layout.md +160 -0
- package/agent-docs/components/drawer.md +128 -0
- package/agent-docs/components/empty-state.md +67 -0
- package/agent-docs/components/field-dialog.md +97 -0
- package/agent-docs/components/field.md +68 -0
- package/agent-docs/components/fieldset.md +82 -0
- package/agent-docs/components/file-drop.md +52 -0
- package/agent-docs/components/form-layout.md +141 -0
- package/agent-docs/components/form-row.md +93 -0
- package/agent-docs/components/full-bleed-layout.md +116 -0
- package/agent-docs/components/headings.md +101 -0
- package/agent-docs/components/hero.md +59 -0
- package/agent-docs/components/icon-button.md +92 -0
- package/agent-docs/components/icon.md +66 -0
- package/agent-docs/components/image.md +64 -0
- package/agent-docs/components/input.md +83 -0
- package/agent-docs/components/kbd.md +38 -0
- package/agent-docs/components/key-value-list.md +81 -0
- package/agent-docs/components/lightbox.md +97 -0
- package/agent-docs/components/list-layout.md +154 -0
- package/agent-docs/components/list-row.md +116 -0
- package/agent-docs/components/loading.md +69 -0
- package/agent-docs/components/markdown.md +51 -0
- package/agent-docs/components/media-tile.md +97 -0
- package/agent-docs/components/menu.md +103 -0
- package/agent-docs/components/meta-list.md +69 -0
- package/agent-docs/components/morph.md +128 -0
- package/agent-docs/components/navigation-progress.md +56 -0
- package/agent-docs/components/outline-region.md +63 -0
- package/agent-docs/components/page-fade.md +116 -0
- package/agent-docs/components/page-header.md +93 -0
- package/agent-docs/components/pagination.md +64 -0
- package/agent-docs/components/pill.md +104 -0
- package/agent-docs/components/progress-bar.md +66 -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 +74 -0
- package/agent-docs/components/scroll-strip.md +48 -0
- package/agent-docs/components/segmented-control.md +133 -0
- package/agent-docs/components/select.md +65 -0
- package/agent-docs/components/show.md +120 -0
- package/agent-docs/components/side-column.md +70 -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 +67 -0
- package/agent-docs/components/sortable-list.md +107 -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 +88 -0
- package/agent-docs/components/stat-tile.md +69 -0
- package/agent-docs/components/status-pages.md +105 -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.md +373 -0
- package/agent-docs/components/tabs.md +180 -0
- package/agent-docs/components/text-link.md +105 -0
- package/agent-docs/components/textarea.md +51 -0
- package/agent-docs/components/timeline.md +79 -0
- package/agent-docs/components/toast.md +86 -0
- package/agent-docs/components/trend-chart.md +61 -0
- package/agent-docs/components/video.md +44 -0
- package/agent-docs/llms.txt +155 -0
- package/package.json +6 -3
- package/skills/uislash/SKILL.md +20 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
## Switch
|
|
2
|
+
|
|
3
|
+
Group: Forms
|
|
4
|
+
|
|
5
|
+
When to use: A setting that acts the moment it is flipped, usually by saving it to a server: a flag per environment, notifications on or off.
|
|
6
|
+
|
|
7
|
+
### The one right way
|
|
8
|
+
A Switch takes a `label`: the whole label is the click target, and it names the switch.
|
|
9
|
+
```tsx
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { Switch } from "@slashsuite/ui-react";
|
|
12
|
+
|
|
13
|
+
function Example() {
|
|
14
|
+
const [checked, setChecked] = useState(true);
|
|
15
|
+
return <Switch label="Live in staging" checked={checked} onChange={setChecked} />;
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Do
|
|
20
|
+
- Control it: you own `checked`, and `onChange` gets the next value. There is no uncontrolled mode.
|
|
21
|
+
- Give a `Switch` a `label`; the whole label is the click target. In a table cell leave the `label` out, use `size="sm"` and name it with `aria-label`: one of the two is required.
|
|
22
|
+
- Keep `checked` as it was while the change saves and pass `busy`: a click or a key does nothing, and it keeps its colour and its focus. Flip `checked` when the save lands.
|
|
23
|
+
- A `hint` is a muted line under the label for a setting that needs a sentence, and an `error` replaces it in red; the switch sits on the label's first line.
|
|
24
|
+
- `size` is `sm`, `md` (default) or `lg`, the same scale as a `Checkbox`.
|
|
25
|
+
- Say why it cannot flip with `disabledReason`.
|
|
26
|
+
- A value sent with a form, ticked and then submitted, is a `Checkbox`. One of several is a `RadioGroup`, a `Select` or a `SegmentedControl`.
|
|
27
|
+
|
|
28
|
+
### Don't
|
|
29
|
+
- Do not wrap a `Switch` in a `Field`; it is its own label.
|
|
30
|
+
|
|
31
|
+
Words beside the switch, not in it, name nothing: clicking the words does nothing.
|
|
32
|
+
```tsx
|
|
33
|
+
import { useState } from "react";
|
|
34
|
+
import { Cluster, Switch, Text } from "@slashsuite/ui-react";
|
|
35
|
+
|
|
36
|
+
function Example() {
|
|
37
|
+
const [checked, setChecked] = useState(true);
|
|
38
|
+
return (
|
|
39
|
+
<Cluster gap="sm">
|
|
40
|
+
<Switch aria-label="Live in staging" checked={checked} onChange={setChecked} />
|
|
41
|
+
<Text>Live in staging</Text>
|
|
42
|
+
</Cluster>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A bare `disabled` switch drops out of the tab order and never says why.
|
|
48
|
+
```tsx
|
|
49
|
+
import { Switch } from "@slashsuite/ui-react";
|
|
50
|
+
|
|
51
|
+
<Switch label="Live in production" checked={false} onChange={() => undefined} disabled />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Accessibility
|
|
55
|
+
- A native `<button type="button" role="switch">` with `aria-checked`, inside a `<label>`, so clicking the text flips it and the label is its name. Space and Enter flip it.
|
|
56
|
+
- A bare switch has no name of its own: `aria-label` is required.
|
|
57
|
+
- `busy` sets `aria-busy` and `aria-disabled` and keeps focus on the switch; `disabled` is the native one and takes it out of the tab order.
|
|
58
|
+
- `disabledReason` sets `aria-disabled` and keeps the switch in the tab order; a click, Space and Enter 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
|
+
- A `hint` or an `error` is the switch's `aria-describedby`, added to any you pass; an `error` is `role="alert"` and marks the switch `aria-invalid`.
|
|
60
|
+
- The thumb's slide stops under `prefers-reduced-motion`. The focus ring comes from the component.
|
|
61
|
+
|
|
62
|
+
### Props
|
|
63
|
+
### Switch
|
|
64
|
+
An on/off switch for a setting that takes effect at once, usually by saving it to a server: a native `<button role="switch" aria-checked>`. The caller owns `checked` and flips it in `onChange`, or gives `defaultChecked` and the switch keeps its own state. A value sent with a form is a `Checkbox`, not a Switch. Give it a `label` (the whole label is the click target), or in a table cell leave the label out and name it with `aria-label`. `hint` is a muted line under the label; `error` replaces it with a red line (`role="alert"`) and makes the switch `aria-invalid`. The note is the switch's `aria-describedby`. `size` is `sm`, `md` (the default) or `lg`. `busy` is for the save in flight: clicks and keys do nothing, and the switch keeps its colour and its focus. `disabledReason` blocks it, focusable, with the reason as its tooltip. `disabled` is the native one, washed out. While `loading` the label is drawn and the track is a bone of its size.
|
|
65
|
+
- busy: boolean. The change is being saved: `aria-busy`, and a click or a key does nothing. It keeps its colour
|
|
66
|
+
and its focus, which a native `disabled` would lose when the save starts.
|
|
67
|
+
- checked: boolean. Whether it is on, when the caller owns it (with `onChange`).
|
|
68
|
+
- defaultChecked: boolean. Whether it starts on, when the switch keeps its own state.
|
|
69
|
+
- disabledReason: string. Why the switch cannot be flipped: it washes out and is blocked (`aria-disabled`; a click,
|
|
70
|
+
Enter and Space do nothing) while it keeps its focus, and the reason is its tooltip on hover,
|
|
71
|
+
keyboard focus and a tap, read out as its description.
|
|
72
|
+
- error: ReactNode. Replaces the hint with a red line (`role="alert"`) and makes the switch `aria-invalid`.
|
|
73
|
+
- hint: ReactNode. A muted line under the label that says more. It is the switch's `aria-describedby`.
|
|
74
|
+
- label: NonNullable<ReactNode>. The text beside the switch; the whole label is a click target.
|
|
75
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
76
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
77
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
78
|
+
- onChange: ((checked: boolean) => void). Called with the next value when the person flips it. Not called while `busy`.
|
|
79
|
+
- size: "sm" | "md" | "lg" (default md). The label's text size and the switch with it.
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
## Table
|
|
2
|
+
|
|
3
|
+
Group: Data
|
|
4
|
+
|
|
5
|
+
When to use: Records that share columns, where a person compares values down a column.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- KeyValueList (key-value-list.md): One record's fields, each label beside its value.
|
|
9
|
+
- ListRow (list-row.md): Each record is a thing to open, with a line or two of detail.
|
|
10
|
+
- MetaList (meta-list.md): A few short facts inline, on one line under a title.
|
|
11
|
+
|
|
12
|
+
### The one right way
|
|
13
|
+
A table is a head and a body: names in strong cells, amounts in `numeric` cells so the figures line up.
|
|
14
|
+
```tsx
|
|
15
|
+
import {
|
|
16
|
+
Table,
|
|
17
|
+
TableBody,
|
|
18
|
+
TableCell,
|
|
19
|
+
TableHead,
|
|
20
|
+
TableHeaderCell,
|
|
21
|
+
TableRow,
|
|
22
|
+
} from "@slashsuite/ui-react";
|
|
23
|
+
|
|
24
|
+
<Table label="Quotes">
|
|
25
|
+
<TableHead>
|
|
26
|
+
<TableRow>
|
|
27
|
+
<TableHeaderCell>Client</TableHeaderCell>
|
|
28
|
+
<TableHeaderCell numeric>Premium</TableHeaderCell>
|
|
29
|
+
</TableRow>
|
|
30
|
+
</TableHead>
|
|
31
|
+
<TableBody>
|
|
32
|
+
<TableRow>
|
|
33
|
+
<TableCell tone="strong">Naledi Dlamini</TableCell>
|
|
34
|
+
<TableCell numeric>R 1 249.00</TableCell>
|
|
35
|
+
</TableRow>
|
|
36
|
+
<TableRow>
|
|
37
|
+
<TableCell tone="strong">Pieter van Wyk</TableCell>
|
|
38
|
+
<TableCell numeric>R 880.50</TableCell>
|
|
39
|
+
</TableRow>
|
|
40
|
+
</TableBody>
|
|
41
|
+
</Table>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Do
|
|
45
|
+
- Compose a `Table` from `TableHead`, `TableBody` and, for totals, `TableFoot`. A `TableHead` holds one `TableRow` of `TableHeaderCell`s; give the `Table` a `label` that names it.
|
|
46
|
+
- A column of amounts says so once, with `numeric` on its `TableHeaderCell`: the title and every cell under it are end aligned and the figures line up. A code or a type is `mono`.
|
|
47
|
+
- A cell's `tone` is `neutral` (the default), `strong` for the name of the row, `muted` for the secondary column, or a Callout tone for an amount that carries a meaning; pair the tone with a sign or a word. `secondary` is a muted second line under a cell.
|
|
48
|
+
- The total of the whole table is a `TableFoot` row. A subtotal among the body's rows is a `TableRow` with `emphasis`, the same look; a bold subtotal is not a `tone`. Neither row takes a `tone`.
|
|
49
|
+
- Mark a row's status with `tone` (a stripe and a soft fill, or `muted` to fade the row) or with `stripe` (the stripe alone, in the `muted`, `info`, `positive`, `warn` or `danger` tone, which keeps the row's hover). Give one of them, never both, and name the status in a cell as well (a `Pill`), or draw a `Legend` for the colours.
|
|
50
|
+
- A table with no rows takes `TableBody empty={<EmptyState title="No quotes yet." />}`: one muted line in a cell that spans every column the head declares, with the head still drawn. Write `TableHead` and its cells inline, so the table can count them.
|
|
51
|
+
- Group rows with a `TableGroupRow`: it spans every column the head declares, and `trailing` is a count or a subtotal at the far end. A full-width note or panel is a `TableCell span="full"`; `align="center"` centres it. `indent` (1 to 3) sets a start-aligned cell in, for the lines under a parent row.
|
|
52
|
+
- A column with nothing to say in its head (its actions) takes a `TableHeaderCell` with `label="Actions"`. Inside a `Card` a table is plain: no card of its own, only the row dividers.
|
|
53
|
+
|
|
54
|
+
### Don't
|
|
55
|
+
Amounts in plain start-aligned cells do not line up, so the eye cannot compare them.
|
|
56
|
+
```tsx
|
|
57
|
+
import {
|
|
58
|
+
Table,
|
|
59
|
+
TableBody,
|
|
60
|
+
TableCell,
|
|
61
|
+
TableHead,
|
|
62
|
+
TableHeaderCell,
|
|
63
|
+
TableRow,
|
|
64
|
+
} from "@slashsuite/ui-react";
|
|
65
|
+
|
|
66
|
+
<Table label="Quotes">
|
|
67
|
+
<TableHead>
|
|
68
|
+
<TableRow>
|
|
69
|
+
<TableHeaderCell>Client</TableHeaderCell>
|
|
70
|
+
<TableHeaderCell>Premium</TableHeaderCell>
|
|
71
|
+
</TableRow>
|
|
72
|
+
</TableHead>
|
|
73
|
+
<TableBody>
|
|
74
|
+
<TableRow>
|
|
75
|
+
<TableCell>Naledi Dlamini</TableCell>
|
|
76
|
+
<TableCell>R 1 249.00</TableCell>
|
|
77
|
+
</TableRow>
|
|
78
|
+
<TableRow>
|
|
79
|
+
<TableCell>Pieter van Wyk</TableCell>
|
|
80
|
+
<TableCell>R 880.50</TableCell>
|
|
81
|
+
</TableRow>
|
|
82
|
+
</TableBody>
|
|
83
|
+
</Table>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A total faked as one more body row, in a strong cell, reads like a line item and is not a `<tfoot>`.
|
|
87
|
+
```tsx
|
|
88
|
+
import {
|
|
89
|
+
Table,
|
|
90
|
+
TableBody,
|
|
91
|
+
TableCell,
|
|
92
|
+
TableHead,
|
|
93
|
+
TableHeaderCell,
|
|
94
|
+
TableRow,
|
|
95
|
+
} from "@slashsuite/ui-react";
|
|
96
|
+
|
|
97
|
+
<Table label="Budget">
|
|
98
|
+
<TableHead>
|
|
99
|
+
<TableRow>
|
|
100
|
+
<TableHeaderCell>Line</TableHeaderCell>
|
|
101
|
+
<TableHeaderCell numeric>Spent</TableHeaderCell>
|
|
102
|
+
</TableRow>
|
|
103
|
+
</TableHead>
|
|
104
|
+
<TableBody>
|
|
105
|
+
<TableRow>
|
|
106
|
+
<TableCell>Groceries</TableCell>
|
|
107
|
+
<TableCell numeric>R 4 120.00</TableCell>
|
|
108
|
+
</TableRow>
|
|
109
|
+
<TableRow>
|
|
110
|
+
<TableCell>Eating out</TableCell>
|
|
111
|
+
<TableCell numeric>R 2 980.00</TableCell>
|
|
112
|
+
</TableRow>
|
|
113
|
+
<TableRow>
|
|
114
|
+
<TableCell tone="strong">Total</TableCell>
|
|
115
|
+
<TableCell numeric tone="strong">
|
|
116
|
+
R 7 100.00
|
|
117
|
+
</TableCell>
|
|
118
|
+
</TableRow>
|
|
119
|
+
</TableBody>
|
|
120
|
+
</Table>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
A toned row whose cells never say what the tone means: colour alone tells nobody who cannot see it.
|
|
124
|
+
```tsx
|
|
125
|
+
import {
|
|
126
|
+
Table,
|
|
127
|
+
TableBody,
|
|
128
|
+
TableCell,
|
|
129
|
+
TableHead,
|
|
130
|
+
TableHeaderCell,
|
|
131
|
+
TableRow,
|
|
132
|
+
} from "@slashsuite/ui-react";
|
|
133
|
+
|
|
134
|
+
<Table label="Debit orders">
|
|
135
|
+
<TableHead>
|
|
136
|
+
<TableRow>
|
|
137
|
+
<TableHeaderCell>Debit order</TableHeaderCell>
|
|
138
|
+
<TableHeaderCell numeric>Amount</TableHeaderCell>
|
|
139
|
+
</TableRow>
|
|
140
|
+
</TableHead>
|
|
141
|
+
<TableBody>
|
|
142
|
+
<TableRow>
|
|
143
|
+
<TableCell tone="strong">Insurance</TableCell>
|
|
144
|
+
<TableCell numeric>R 1 850.00</TableCell>
|
|
145
|
+
</TableRow>
|
|
146
|
+
<TableRow tone="danger">
|
|
147
|
+
<TableCell tone="strong">Gym</TableCell>
|
|
148
|
+
<TableCell numeric>R 349.00</TableCell>
|
|
149
|
+
</TableRow>
|
|
150
|
+
</TableBody>
|
|
151
|
+
</Table>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
An empty header cell leaves the column with no name, so a screen reader hears a column of unlabelled buttons.
|
|
155
|
+
```tsx
|
|
156
|
+
import {
|
|
157
|
+
Button,
|
|
158
|
+
Table,
|
|
159
|
+
TableBody,
|
|
160
|
+
TableCell,
|
|
161
|
+
TableHead,
|
|
162
|
+
TableHeaderCell,
|
|
163
|
+
TableRow,
|
|
164
|
+
} from "@slashsuite/ui-react";
|
|
165
|
+
|
|
166
|
+
<Table label="Clients">
|
|
167
|
+
<TableHead>
|
|
168
|
+
<TableRow>
|
|
169
|
+
<TableHeaderCell>Client</TableHeaderCell>
|
|
170
|
+
<TableHeaderCell align="end" />
|
|
171
|
+
</TableRow>
|
|
172
|
+
</TableHead>
|
|
173
|
+
<TableBody>
|
|
174
|
+
<TableRow>
|
|
175
|
+
<TableCell tone="strong">Naledi Dlamini</TableCell>
|
|
176
|
+
<TableCell align="end">
|
|
177
|
+
<Button variant="outline" size="sm">
|
|
178
|
+
Open
|
|
179
|
+
</Button>
|
|
180
|
+
</TableCell>
|
|
181
|
+
</TableRow>
|
|
182
|
+
</TableBody>
|
|
183
|
+
</Table>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
A button put in a header cell by hand says nothing about the order to a screen reader, and looks unlike every other sortable column.
|
|
187
|
+
```tsx
|
|
188
|
+
import {
|
|
189
|
+
Button,
|
|
190
|
+
Table,
|
|
191
|
+
TableBody,
|
|
192
|
+
TableCell,
|
|
193
|
+
TableHead,
|
|
194
|
+
TableHeaderCell,
|
|
195
|
+
TableRow,
|
|
196
|
+
} from "@slashsuite/ui-react";
|
|
197
|
+
|
|
198
|
+
<Table label="Quotes">
|
|
199
|
+
<TableHead>
|
|
200
|
+
<TableRow>
|
|
201
|
+
<TableHeaderCell>Quote</TableHeaderCell>
|
|
202
|
+
<TableHeaderCell numeric>
|
|
203
|
+
<Button variant="ghost" size="sm">
|
|
204
|
+
Total
|
|
205
|
+
</Button>
|
|
206
|
+
</TableHeaderCell>
|
|
207
|
+
</TableRow>
|
|
208
|
+
</TableHead>
|
|
209
|
+
<TableBody>
|
|
210
|
+
<TableRow>
|
|
211
|
+
<TableCell>Q-1043</TableCell>
|
|
212
|
+
<TableCell>R 18400</TableCell>
|
|
213
|
+
</TableRow>
|
|
214
|
+
</TableBody>
|
|
215
|
+
</Table>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
A cell with a column count written by hand breaks the day a column is added, and is a second empty look.
|
|
219
|
+
```tsx
|
|
220
|
+
import {
|
|
221
|
+
Table,
|
|
222
|
+
TableBody,
|
|
223
|
+
TableCell,
|
|
224
|
+
TableHead,
|
|
225
|
+
TableHeaderCell,
|
|
226
|
+
TableRow,
|
|
227
|
+
} from "@slashsuite/ui-react";
|
|
228
|
+
|
|
229
|
+
<Table label="Quotes">
|
|
230
|
+
<TableHead>
|
|
231
|
+
<TableRow>
|
|
232
|
+
<TableHeaderCell>Quote</TableHeaderCell>
|
|
233
|
+
<TableHeaderCell>Customer</TableHeaderCell>
|
|
234
|
+
<TableHeaderCell numeric>Total</TableHeaderCell>
|
|
235
|
+
</TableRow>
|
|
236
|
+
</TableHead>
|
|
237
|
+
<TableBody>
|
|
238
|
+
<TableRow>
|
|
239
|
+
<TableCell colSpan={5} align="center" tone="muted">
|
|
240
|
+
No quotes yet.
|
|
241
|
+
</TableCell>
|
|
242
|
+
</TableRow>
|
|
243
|
+
</TableBody>
|
|
244
|
+
</Table>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Accessibility
|
|
248
|
+
- A Table renders a native `<table>`; its `label` is the accessible name, a visually hidden caption.
|
|
249
|
+
- A `TableHeaderCell` is a `<th scope="col">`; a `TableGroupRow` is a `<th scope="rowgroup">`.
|
|
250
|
+
- A `TableHeaderCell` `label` is hidden text inside the header cell, so an actions column still has a name for a screen reader.
|
|
251
|
+
- Colour alone never carries a row's or a cell's status; name it in text.
|
|
252
|
+
- A `truncate` cell puts its full text in a `title`.
|
|
253
|
+
- A stretched `TextLink` is a real link and the only tab stop in its row; the row's whole area is its click target.
|
|
254
|
+
- A `TableEditCell` or `InlineEdit` is a native `<button>` named by its value and its `label`. Opening moves the focus to the editor, a group named by `label`; Esc and `close` move it back to the value.
|
|
255
|
+
- On a narrow screen the card scrolls sideways instead of squeezing its columns.
|
|
256
|
+
- A sorted column's header has `aria-sort` (`ascending` or `descending`); a sortable column it is not sorted by has none, and its title is a native button named by the title.
|
|
257
|
+
- A `selected` row has `aria-current`, not `aria-selected`, which a plain table row does not support.
|
|
258
|
+
- A `TableExpandCell` is a native button named by its `label` and `count` ("Details, 3"), with `aria-expanded` and the `aria-controls` you give it.
|
|
259
|
+
|
|
260
|
+
### Props
|
|
261
|
+
### Table
|
|
262
|
+
A list of records in a rounded, bordered card that scrolls sideways on a narrow screen. Compose it from `TableHead`, `TableBody`, `TableFoot`, `TableRow`, `TableHeaderCell` and `TableCell`. `label` names the table for assistive tech and is not drawn. Inside a `Card` it is plain: no card of its own (border, fill and shadow), no tinted head strip and no row hover, only the row dividers. A column of figures says so once, with `numeric` on its `TableHeaderCell`: its cells then take end alignment and tabular figures. `size` is the row padding, and the controls in the rows follow it (`sm` by default). Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a body with no rows draws five rows of bones, one per column, and an empty cell draws a bone; the table keeps its role and its name.
|
|
263
|
+
- label: string (required). Names the table for assistive tech; it is not drawn.
|
|
264
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
265
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
266
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
267
|
+
- size: "sm" | "md" | "lg" (default sm). The row padding; the buttons and fields in the rows take the same size.
|
|
268
|
+
|
|
269
|
+
### TableHead
|
|
270
|
+
The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card. Holds one `TableRow` of `TableHeaderCell`s.
|
|
271
|
+
|
|
272
|
+
### TableBody
|
|
273
|
+
The `<tbody>`: the rows, each with a line above it and, unless the table is in a card, a fill on hover. With no rows it draws `empty` (an `EmptyState`, one muted line here) in one cell that spans every column the head declares; the head stays drawn, so the reader sees what the table holds. In a loading `Table` a body with no rows draws five rows of bones instead, never `empty`.
|
|
274
|
+
- empty: ReactNode. Shown in one full-width cell when there are no rows: an `EmptyState`.
|
|
275
|
+
|
|
276
|
+
### TableFoot
|
|
277
|
+
The `<tfoot>`: totals and subtotals. Its cells are strong by default and each row has a firmer line above it, alone and in a card alike. Put it after `TableBody`; a row of it takes no `tone`.
|
|
278
|
+
|
|
279
|
+
### TableRow
|
|
280
|
+
A `<tr>`, `relative`: the anchor a `TextLink stretch` (with `href`) stretches to. Any other link, button or control in the row (a `TextLink`, a `Button`, a `Checkbox`) sits above that link and is clickable on its own, with no class from the caller. Use it in the head and the body. In the body it also draws the line above the row and, unless the table is in a card, the hover fill. `selected` marks the current row (the one open beside the table, the one being edited): the `ListRow` selected fill and `aria-current`, the row whose detail is open, not a multi-select; it wins over `tone` and `stripe`. `tone` marks the row's status (see `RowTone`): a stripe on the leading edge and a soft fill, or `muted` to fade it. A toned row keeps its fill on hover (the status stays readable), so a linked row's link, not a hover fill, says it is clickable. `stripe` is the stripe alone, in the `TextTone` colours (the first five names of a `StackedBar` segment's `VizTone`), with no fill: the row keeps its hover and its own look. Give `tone` or `stripe`, not both. Body rows only; colour alone does not say it, so name the status in a cell too (a `Pill`). A bold subtotal is not a tone: a total of the whole table is a `TableFoot` row, and a subtotal among the body's rows is `emphasis`, the same look.
|
|
281
|
+
- emphasis: boolean (default false). A subtotal in the body: the look of a `TableFoot` row, with strong cells, a firmer line
|
|
282
|
+
above and no hover. Give only one of `tone`, `stripe` and `emphasis`.
|
|
283
|
+
|
|
284
|
+
A sign row or a subtotal needs no other part.
|
|
285
|
+
- selected: boolean (default false). The row in view (its detail open beside the table): the selected fill and `aria-current`. Body
|
|
286
|
+
rows only.
|
|
287
|
+
|
|
288
|
+
As on a `ListRow`, it is not a multi-select, and a selected row takes no `tone`.
|
|
289
|
+
- stripe: "info" | "positive" | "warn" | "danger" | "muted" | "accent". A stripe on the leading edge in this tone, with no fill. Give only one of `tone`, `stripe` and `emphasis`.
|
|
290
|
+
- tone: "neutral" | "info" | "positive" | "warn" | "danger" | "muted". The row's status: a stripe on the leading edge plus the tone's soft fill, or `muted` to fade the row. Give only one of `tone`, `stripe` and `emphasis`.
|
|
291
|
+
|
|
292
|
+
### TableHeaderCell
|
|
293
|
+
A column title, `<th scope="col">`. `numeric` declares a column of figures, once: the title and every cell under it take end alignment and tabular figures. A column with nothing to show in its head (a row's actions) takes `label` instead of `children`: the name a screen reader hears ("Actions"), visually hidden so the head keeps its column. `sort` and `onSort` make the column sortable: the title becomes a button that asks for the next direction, and the column says where it stands with `aria-sort`. The app sorts its rows; the table never does.
|
|
294
|
+
- align: "center" | "end" | "start" (default numeric ? "end" : "start"). The title's horizontal alignment; `end` over a column of buttons, `center` over a centred column.
|
|
295
|
+
- label: string. The column's name for a screen reader, visually hidden, for a column with no visible title (a row's actions).
|
|
296
|
+
- numeric: boolean (default false). A column of figures: this title and the cells under it are end aligned, the cells in tabular figures.
|
|
297
|
+
- onSort: ((next: "ascending" | "descending") => void). Called with the next direction on a click: `none` goes to `ascending`, then each click flips it.
|
|
298
|
+
- sort: "none" | "ascending" | "descending". Where this column stands: `ascending`, `descending`, or `none` when the table is sorted by
|
|
299
|
+
another column. The app sorts its rows and passes it back; one sorted column at a time.
|
|
300
|
+
|
|
301
|
+
With `onSort` the title becomes a button that asks for the next direction. The table never
|
|
302
|
+
sorts, filters or pages.
|
|
303
|
+
|
|
304
|
+
### TableCell
|
|
305
|
+
A `<td>`. `tone` is the text weight and colour (see `CellTone`; in a `TableFoot` it defaults to `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is numeric already), `mono` a small mono face. `secondary` is a second, muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver), a cell that holds a control or a link takes that content's width, and a `numeric` or `mono` cell (a figure, a code, a type) never breaks. `truncate` caps a long value's width, cuts it with an ellipsis on one line and puts the full text in a `title`; the content is then plain text (strings and numbers), since that is what the title shows. `colSpan` passes through: a cell that spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row. While `loading` an empty cell draws one bone, the width of a short value.
|
|
306
|
+
- align: "center" | "end" | "start" (default end for a numeric cell, else start). The cell's horizontal alignment; `center` for a full-width note.
|
|
307
|
+
- colSpan: number. How many columns the cell spans; `span="full"` spans them all without a count.
|
|
308
|
+
- indent: 2 | 3 | 1. Sets the cell in by this many levels (1 to 3), for a line under a parent row. Start-aligned cells only.
|
|
309
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
310
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
311
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
312
|
+
- mono: boolean (default false). A small monospace face for a code or a type, and the cell never wraps.
|
|
313
|
+
- numeric: boolean (default the column's, from a `numeric` head cell). A figure: end aligned, tabular figures, and the cell never wraps.
|
|
314
|
+
- secondary: ReactNode. A second, muted line under the content.
|
|
315
|
+
- span: "full". `full` spans every column the head declares: a panel under a row, an open row's detail.
|
|
316
|
+
- tone: "strong" | "neutral" | "info" | "positive" | "warn" | "danger" | "muted". The text weight and colour (see `CellTone`). In a `TableFoot` it defaults to `strong`.
|
|
317
|
+
- truncate: boolean (default false). Caps the width and cuts a long value with an ellipsis on one line, the full text in a `title`.
|
|
318
|
+
Plain text content only.
|
|
319
|
+
|
|
320
|
+
Without it, a prose cell wraps down to a floor so it never becomes a sliver, a cell that holds
|
|
321
|
+
a control or a link (a `Pill`, a `Switch`, a `Button`, a `TextLink`) takes its content's width,
|
|
322
|
+
and a `numeric` or `mono` cell never breaks.
|
|
323
|
+
|
|
324
|
+
### TableEditCell
|
|
325
|
+
A `TableCell` whose value opens an editor in place: a cell that holds one `InlineEdit` and nothing else. It shows `children` as a button with a dotted underline; a click, Enter or Space swaps it for `renderEditor(close)` and moves the focus into the editor. The editor calls `close` when it has saved, and Esc closes it: both put the focus back on the value. A press outside it or Tab out of it closes it too and leaves the focus where it went, so the editor saves its value on its own change or submit, never on a close. Put the control in the cell itself, not in a popover of its own, which counts as outside. Takes `TableCell`'s `align`, `tone`, `numeric`, `mono`, `indent`, `secondary` and `span`. For an edit trigger in a cell that holds other content too, put an `InlineEdit` in a `TableCell`.
|
|
326
|
+
- align: "center" | "end" | "start" (default end for a numeric cell, else start). The cell's horizontal alignment; `center` for a full-width note.
|
|
327
|
+
- children: ReactNode (required). The value, shown while closed.
|
|
328
|
+
- colSpan: number. How many columns the cell spans; `span="full"` spans them all without a count.
|
|
329
|
+
- indent: 2 | 3 | 1. Sets the cell in by this many levels (1 to 3), for a line under a parent row. Start-aligned cells only.
|
|
330
|
+
- label: string (required). What the button does, for a screen reader, heard after the value: "Edit category". It also names the editor.
|
|
331
|
+
- loading: boolean. The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
332
|
+
Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
333
|
+
- loadingLabel: string (default Loading). What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
334
|
+
- mono: boolean. A small monospace face for a code or a type, and the cell never wraps.
|
|
335
|
+
- numeric: boolean (default the column's, from a `numeric` head cell). A figure: end aligned, tabular figures, and the cell never wraps.
|
|
336
|
+
- renderEditor: (close: () => void) => ReactNode (required). The control that edits the value, drawn while open. `close` shuts it and returns the focus to
|
|
337
|
+
the value.
|
|
338
|
+
|
|
339
|
+
Call `close` once the control has saved: a press outside the cell, Tab out of it and Esc all
|
|
340
|
+
close it without a save, so save on the control's own change or submit. The control sits in the
|
|
341
|
+
cell, not in a popover of its own.
|
|
342
|
+
- secondary: ReactNode. A second, muted line under the content.
|
|
343
|
+
- span: "full". `full` spans every column the head declares: a panel under a row, an open row's detail.
|
|
344
|
+
- tone: "strong" | "neutral" | "info" | "positive" | "warn" | "danger" | "muted". The text weight and colour (see `CellTone`). In a `TableFoot` it defaults to `strong`.
|
|
345
|
+
|
|
346
|
+
### InlineEdit
|
|
347
|
+
A value that opens an editor in place, as a part inside a `TableCell` that holds more than the value (an edit trigger in a column cell with other content, say). It shows `children` as a button with a dotted underline; a click, Enter or Space swaps it for `renderEditor(close)` and moves the focus into the editor. The part keeps its own open state. The editor calls `close` when it has saved, and Esc closes it: both put the focus back on the value. A press outside it or Tab out of it closes it too and leaves the focus where it went, so the editor saves its value on its own change or submit, never on a close. Put the control in the part itself, not in a popover of its own, which counts as outside. It takes the alignment of the cell around it. It is a block that bleeds half a rem into the padding of the cell it sits in, so it belongs inside a `TableCell`; a cell that holds only the value is a `TableEditCell`. `data-*` and `aria-*` go on the button, and on the editor's group while open.
|
|
348
|
+
- children: ReactNode (required). The value, shown while closed.
|
|
349
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
350
|
+
- label: string (required). What the button does, for a screen reader, heard after the value: "Edit category". It also names the editor.
|
|
351
|
+
- renderEditor: (close: () => void) => ReactNode (required). The control that edits the value, drawn while open. `close` shuts it and returns the focus to the value.
|
|
352
|
+
|
|
353
|
+
### TableGroupRow
|
|
354
|
+
A full-width group header in the body: a tinted row with a `label` that spans every column the head declares (or `colSpan` columns), and optional `trailing` content at the far end (a count, a subtotal, a small button). The group's rows follow it. For a panel of other content across the whole row, use a `TableCell span="full"` instead.
|
|
355
|
+
- colSpan: number (default every column the `TableHead` declares). How many columns the header spans.
|
|
356
|
+
- label: ReactNode (required). The group's name, at the start of the row.
|
|
357
|
+
- trailing: ReactNode. Content at the far end of the row: a count, a subtotal, a small button.
|
|
358
|
+
|
|
359
|
+
### TableExpandCell
|
|
360
|
+
The cell that opens and closes the row it sits in: a small ghost button with a chevron that turns down when `expanded`, named by `label` (visually hidden) and, with a `count`, the count chip after it, so it reads "Details, 3". The app holds `expanded` and renders what opens under the row: a `TableRow` with one `TableCell span="full"`, or indented child rows. Give its column a head of `<TableHeaderCell label="Details" />`. `aria-controls` names what it opens; other props go on the `<td>`.
|
|
361
|
+
- count: number. A count chip after the chevron: how many lines open under the row.
|
|
362
|
+
- expanded: boolean (required). Whether the row is open.
|
|
363
|
+
|
|
364
|
+
Hold it yourself and render what opens under the row: a `TableRow` with one `TableCell
|
|
365
|
+
span="full"`, or indented child rows. Head the column `<TableHeaderCell label="Details" />`.
|
|
366
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
367
|
+
- label: string (required). The button's name, visually hidden: "Details".
|
|
368
|
+
- onClick: MouseEventHandler<HTMLButtonElement> (required). Opens or closes the row: the app flips `expanded`.
|
|
369
|
+
|
|
370
|
+
### Types
|
|
371
|
+
- CellTone: `Tone | "muted" | "strong"`. The text of a cell: its weight and colour. `neutral` (the default), `strong` and `muted` are the plain ones; the rest are the shared tones, for an amount that carries a meaning (a gain, an overspend). Colour alone does not say it, so a signed figure or a word says it too.
|
|
372
|
+
- RowTone: `"neutral" | "info" | "positive" | "warn" | "danger" | "muted"`. The status of a row: the Callout's tones, plus `muted`. A toned row gets a stripe on its leading edge and the tone's soft fill; `muted` fades the row instead, for one that matters less. The stripe takes the tone's text colour, which every theme already remaps, so no new palette entry.
|
|
373
|
+
- TableSort: `"ascending" | "descending" | "none"`. Where a sortable column stands: ARIA's own words. `none` is a column the table is not sorted by.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
## Tabs
|
|
2
|
+
|
|
3
|
+
Group: Navigation
|
|
4
|
+
|
|
5
|
+
When to use: Tabs switch a panel on the same page. A row of links to other pages is `Tabs` with link items.
|
|
6
|
+
|
|
7
|
+
### Use instead
|
|
8
|
+
- SegmentedControl (segmented-control.md): One value is picked from two to five, and no panel switches under the row.
|
|
9
|
+
- Fieldset (fieldset.md): Toggles that can be on together narrow a list: pressed `Button`s in a `Fieldset`, one per facet.
|
|
10
|
+
|
|
11
|
+
### The one right way
|
|
12
|
+
`Tabs` switches a view in place; the panel it controls sits right under the row.
|
|
13
|
+
```tsx
|
|
14
|
+
import { useState } from "react";
|
|
15
|
+
import { Tabs, Stack, Text } from "@slashsuite/ui-react";
|
|
16
|
+
|
|
17
|
+
function Example() {
|
|
18
|
+
const [value, setValue] = useState("overview");
|
|
19
|
+
return (
|
|
20
|
+
<Stack>
|
|
21
|
+
<Tabs
|
|
22
|
+
label="Project views"
|
|
23
|
+
value={value}
|
|
24
|
+
onChange={setValue}
|
|
25
|
+
items={[
|
|
26
|
+
{ value: "overview", label: "Overview", controls: "panel" },
|
|
27
|
+
{ value: "activity", label: "Activity", controls: "panel" },
|
|
28
|
+
{ value: "settings", label: "Settings", controls: "panel" },
|
|
29
|
+
]}
|
|
30
|
+
/>
|
|
31
|
+
<Text id="panel" role="tabpanel">
|
|
32
|
+
Showing {value}.
|
|
33
|
+
</Text>
|
|
34
|
+
</Stack>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Do
|
|
40
|
+
- `Tabs` switches a view in place; the caller owns `value` and `onChange`, and the panel sits right under the row.
|
|
41
|
+
- Going to another page is link items (`href`, and `selected` on the current one): links, so the URL, the back button and a new tab all work.
|
|
42
|
+
- A `count` sits muted after the label and is read as part of the tab's name.
|
|
43
|
+
- Across, tabs are always underline, under a `PageHeader` too. `orientation="vertical"` is the pill rail, the current tab filled, for a `SidebarLayout` aside, and only the rail takes `size`.
|
|
44
|
+
- `size` (`sm`, `md` the default, `lg`) sets the vertical rail on the control scale, so it lines up with a `Button` of the same size; the underline row has one size.
|
|
45
|
+
- A tab that cannot be chosen yet takes a `disabledReason` that says why.
|
|
46
|
+
- Pill links with `orientation="vertical"` are the rail of a `SidebarLayout`: one link per line.
|
|
47
|
+
|
|
48
|
+
### Don't
|
|
49
|
+
A `SegmentedControl` that swaps the panel under it picks a value, not a view: no tab list, no panel tied to it. Switching the panel is `Tabs`.
|
|
50
|
+
```tsx
|
|
51
|
+
import { useState } from "react";
|
|
52
|
+
import { SegmentedControl, Stack, Text } from "@slashsuite/ui-react";
|
|
53
|
+
|
|
54
|
+
function Example() {
|
|
55
|
+
const [value, setValue] = useState("overview");
|
|
56
|
+
return (
|
|
57
|
+
<Stack>
|
|
58
|
+
<SegmentedControl
|
|
59
|
+
label="Project views"
|
|
60
|
+
value={value}
|
|
61
|
+
onChange={setValue}
|
|
62
|
+
items={[
|
|
63
|
+
{ value: "overview", label: "Overview" },
|
|
64
|
+
{ value: "activity", label: "Activity" },
|
|
65
|
+
{ value: "settings", label: "Settings" },
|
|
66
|
+
]}
|
|
67
|
+
/>
|
|
68
|
+
<Text>Showing {value}.</Text>
|
|
69
|
+
</Stack>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A `Tabs` row that only navigates leaves the URL, the back button and a new tab behind.
|
|
75
|
+
```tsx
|
|
76
|
+
import { useState } from "react";
|
|
77
|
+
import { Tabs } from "@slashsuite/ui-react";
|
|
78
|
+
|
|
79
|
+
function Example() {
|
|
80
|
+
const [value, setValue] = useState("quotes");
|
|
81
|
+
return (
|
|
82
|
+
<Tabs
|
|
83
|
+
label="Sections"
|
|
84
|
+
value={value}
|
|
85
|
+
onChange={(next) => {
|
|
86
|
+
setValue(next);
|
|
87
|
+
location.assign(`#${next}`);
|
|
88
|
+
}}
|
|
89
|
+
items={[
|
|
90
|
+
{ value: "quotes", label: "Quotes" },
|
|
91
|
+
{ value: "invoices", label: "Invoices" },
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A count typed into the label is plain text: it does not mute, and it cannot be styled the same.
|
|
99
|
+
```tsx
|
|
100
|
+
import { useState } from "react";
|
|
101
|
+
import { Tabs } from "@slashsuite/ui-react";
|
|
102
|
+
|
|
103
|
+
function Example() {
|
|
104
|
+
const [value, setValue] = useState("shots");
|
|
105
|
+
return (
|
|
106
|
+
<Tabs
|
|
107
|
+
label="Assets"
|
|
108
|
+
value={value}
|
|
109
|
+
onChange={setValue}
|
|
110
|
+
items={[
|
|
111
|
+
{ value: "shots", label: "Shots (12)" },
|
|
112
|
+
{ value: "clips", label: "Clips (3)" },
|
|
113
|
+
]}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A bare `disabled` tab is skipped by the arrows and never says why.
|
|
120
|
+
```tsx
|
|
121
|
+
import { useState } from "react";
|
|
122
|
+
import { Tabs } from "@slashsuite/ui-react";
|
|
123
|
+
|
|
124
|
+
function Example() {
|
|
125
|
+
const [value, setValue] = useState("overview");
|
|
126
|
+
return (
|
|
127
|
+
<Tabs
|
|
128
|
+
label="Project views"
|
|
129
|
+
items={[
|
|
130
|
+
{ value: "overview", label: "Overview" },
|
|
131
|
+
{ value: "builds", label: "Builds" },
|
|
132
|
+
{ value: "billing", label: "Billing", disabled: true },
|
|
133
|
+
]}
|
|
134
|
+
value={value}
|
|
135
|
+
onChange={setValue}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
A stack of ghost link `Button`s is not a nav landmark, and nothing marks the current page.
|
|
142
|
+
```tsx
|
|
143
|
+
import { Button, Stack } from "@slashsuite/ui-react";
|
|
144
|
+
|
|
145
|
+
<Stack gap="xs">
|
|
146
|
+
<Button href="#overview" variant="ghost">
|
|
147
|
+
Overview
|
|
148
|
+
</Button>
|
|
149
|
+
<Button href="#button" variant="ghost">
|
|
150
|
+
Button
|
|
151
|
+
</Button>
|
|
152
|
+
<Button href="#card" variant="ghost">
|
|
153
|
+
Card
|
|
154
|
+
</Button>
|
|
155
|
+
</Stack>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Accessibility
|
|
159
|
+
- The row is a tab list named by `label`; the arrow keys, Home and End move between the tabs, and a `disabled` tab is skipped.
|
|
160
|
+
- A tab with `disabledReason` is `aria-disabled`: the arrow keys reach it and choose 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).
|
|
161
|
+
- Give the panel `role="tabpanel"` and a tab `controls` that points at its `id`.
|
|
162
|
+
- A tab is a `button` with `role="tab"` and `aria-selected`; only the current tab is in the tab order, and the arrow keys move and choose.
|
|
163
|
+
- Link items form a `<nav>` named by `label`; the current link gets `aria-current="page"`.
|
|
164
|
+
|
|
165
|
+
### Props
|
|
166
|
+
### Tabs
|
|
167
|
+
Tabs for switching a view in place or between pages. Across (the default) they are underline tabs: a row over a bottom rule, the current tab underlined in the accent. `orientation="vertical"` is the pill rail instead, the current tab filled, for a `SidebarLayout` aside, and takes a `size`. `items` are `{ value, label }` buttons (`value` and `onChange` are the caller's state; the arrow keys, Home and End move between tabs) or links (`href`, an in-app one through `LinkProvider`; `selected` on an item, or `value`, marks the current one, which gets `aria-current`). An item may carry a `count`, and a button one `disabledReason` (it stays reachable by the arrows and its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label` names the tab list. The panel is the caller's: give it `role="tabpanel"`, and a tab `controls` to point at it.
|
|
168
|
+
- disabled: boolean. Every option is disabled, e.g. until the page has hydrated.
|
|
169
|
+
- id: string. The root element's `id`: an anchor, or the target of a `for` or an `aria-describedby`.
|
|
170
|
+
- items: Tab[] (required). The options in order: `{ value, label }` buttons, or links (`href`), the current link marked by its `selected` or by a `value` equal to the group's. Either may carry a `count`; a button may be `disabled`.
|
|
171
|
+
- label: string (required). The accessible name of the group.
|
|
172
|
+
- onChange: ((value: string) => void). Called with the option's `value` when one is chosen, by click or arrow key.
|
|
173
|
+
- orientation: "horizontal" | "vertical" (default horizontal). `horizontal` is a row of underline tabs over a bottom rule; `vertical` is the pill rail, a
|
|
174
|
+
column at the rail's width for a `SidebarLayout` aside, where the up and down arrows move
|
|
175
|
+
between button tabs.
|
|
176
|
+
- size: "sm" | "md" | "lg" (default md). The pills' height and text, on the scale of a `Button`. Only the vertical rail takes a `size`.
|
|
177
|
+
- value: string. The `value` of the current option; for links, an alternative to `selected` on the item.
|
|
178
|
+
|
|
179
|
+
### Types
|
|
180
|
+
- Tab: `{ label: ReactNode; count?: number; title?: string; value: string; disabled?: boolean; disabledReason?: string; controls?: string } | { label: ReactNode; count?: number; title?: string; value?: string; selected?: boolean; external?: boolean; href: string }`. One tab of a Tabs row: a button with a `value`, or a link with an `href`; never both kinds in one row.
|