@tempoxyz/ds 0.3.14 → 0.3.15
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/dist/docs/AGENTS.md +73 -10
- package/dist/docs/{marketing/introduction/getting-started.md → marketing.md} +28 -20
- package/dist/docs/product/components/actions.md +2058 -0
- package/dist/docs/product/components/blockchain.md +3825 -0
- package/dist/docs/product/components/data-display.md +5901 -0
- package/dist/docs/product/components/feedback-and-status.md +4008 -0
- package/dist/docs/product/components/forms-and-inputs.md +10543 -0
- package/dist/docs/product/components/layout.md +3339 -0
- package/dist/docs/product/components/navigation.md +2914 -0
- package/dist/docs/product/components/overlays.md +4917 -0
- package/dist/docs/product/components.md +125 -125
- package/dist/docs/product/foundations.md +4596 -0
- package/dist/docs/product/patterns.md +10129 -0
- package/package.json +1 -1
- package/dist/docs/index.md +0 -145
- package/dist/docs/product/components/accordion.md +0 -489
- package/dist/docs/product/components/address-card.md +0 -147
- package/dist/docs/product/components/agent-logo.md +0 -194
- package/dist/docs/product/components/alert-dialog.md +0 -631
- package/dist/docs/product/components/alert.md +0 -448
- package/dist/docs/product/components/amount-input.md +0 -305
- package/dist/docs/product/components/amount.md +0 -794
- package/dist/docs/product/components/app-shell.md +0 -559
- package/dist/docs/product/components/asset-chip.md +0 -294
- package/dist/docs/product/components/autocomplete.md +0 -620
- package/dist/docs/product/components/avatar.md +0 -321
- package/dist/docs/product/components/badge.md +0 -339
- package/dist/docs/product/components/badged-logo.md +0 -116
- package/dist/docs/product/components/banner.md +0 -379
- package/dist/docs/product/components/bar-chart.md +0 -208
- package/dist/docs/product/components/breadcrumbs.md +0 -380
- package/dist/docs/product/components/button-group.md +0 -286
- package/dist/docs/product/components/button.md +0 -650
- package/dist/docs/product/components/calendar.md +0 -375
- package/dist/docs/product/components/callout.md +0 -96
- package/dist/docs/product/components/checkbox-group.md +0 -521
- package/dist/docs/product/components/checkbox.md +0 -467
- package/dist/docs/product/components/choice-group.md +0 -516
- package/dist/docs/product/components/choicebox.md +0 -641
- package/dist/docs/product/components/code.md +0 -100
- package/dist/docs/product/components/combobox.md +0 -939
- package/dist/docs/product/components/container.md +0 -257
- package/dist/docs/product/components/copy-button.md +0 -642
- package/dist/docs/product/components/date-picker.md +0 -514
- package/dist/docs/product/components/dialog.md +0 -1332
- package/dist/docs/product/components/drawer.md +0 -966
- package/dist/docs/product/components/empty.md +0 -340
- package/dist/docs/product/components/field.md +0 -570
- package/dist/docs/product/components/fieldset.md +0 -398
- package/dist/docs/product/components/frame.md +0 -434
- package/dist/docs/product/components/gauge.md +0 -299
- package/dist/docs/product/components/get-started-visual.md +0 -117
- package/dist/docs/product/components/grid.md +0 -288
- package/dist/docs/product/components/hero-visual.md +0 -155
- package/dist/docs/product/components/hex.md +0 -487
- package/dist/docs/product/components/icon-tile.md +0 -292
- package/dist/docs/product/components/identicon.md +0 -371
- package/dist/docs/product/components/inline.md +0 -233
- package/dist/docs/product/components/inset.md +0 -225
- package/dist/docs/product/components/kbd.md +0 -423
- package/dist/docs/product/components/list-group.md +0 -981
- package/dist/docs/product/components/loading-dots.md +0 -237
- package/dist/docs/product/components/menu.md +0 -934
- package/dist/docs/product/components/native-select.md +0 -204
- package/dist/docs/product/components/network-logo.md +0 -248
- package/dist/docs/product/components/number-field.md +0 -543
- package/dist/docs/product/components/otp-field.md +0 -616
- package/dist/docs/product/components/pagination.md +0 -516
- package/dist/docs/product/components/popover.md +0 -544
- package/dist/docs/product/components/progress.md +0 -388
- package/dist/docs/product/components/qr.md +0 -314
- package/dist/docs/product/components/radio-group.md +0 -528
- package/dist/docs/product/components/secret-value.md +0 -406
- package/dist/docs/product/components/select.md +0 -751
- package/dist/docs/product/components/separator.md +0 -379
- package/dist/docs/product/components/sidebar-menu.md +0 -922
- package/dist/docs/product/components/skeleton.md +0 -517
- package/dist/docs/product/components/slider.md +0 -539
- package/dist/docs/product/components/snippet.md +0 -424
- package/dist/docs/product/components/spinner.md +0 -216
- package/dist/docs/product/components/split-bar.md +0 -139
- package/dist/docs/product/components/split-button.md +0 -464
- package/dist/docs/product/components/stack.md +0 -299
- package/dist/docs/product/components/status-chip.md +0 -226
- package/dist/docs/product/components/status-indicator.md +0 -119
- package/dist/docs/product/components/status-row.md +0 -174
- package/dist/docs/product/components/stepper.md +0 -451
- package/dist/docs/product/components/success-hero.md +0 -157
- package/dist/docs/product/components/surface.md +0 -639
- package/dist/docs/product/components/switch.md +0 -472
- package/dist/docs/product/components/table.md +0 -968
- package/dist/docs/product/components/tabs.md +0 -627
- package/dist/docs/product/components/tempo-logo.md +0 -185
- package/dist/docs/product/components/text-input.md +0 -624
- package/dist/docs/product/components/textarea.md +0 -352
- package/dist/docs/product/components/toast.md +0 -535
- package/dist/docs/product/components/token-logo.md +0 -371
- package/dist/docs/product/components/token.md +0 -247
- package/dist/docs/product/components/tooltip.md +0 -490
- package/dist/docs/product/components/verification-code.md +0 -116
- package/dist/docs/product/components/visual.md +0 -249
- package/dist/docs/product/foundations/accessibility.md +0 -377
- package/dist/docs/product/foundations/agents.md +0 -159
- package/dist/docs/product/foundations/color.md +0 -522
- package/dist/docs/product/foundations/content/tone.md +0 -194
- package/dist/docs/product/foundations/content/voice.md +0 -194
- package/dist/docs/product/foundations/content/writing-style.md +0 -406
- package/dist/docs/product/foundations/iconography.md +0 -282
- package/dist/docs/product/foundations/intent.md +0 -360
- package/dist/docs/product/foundations/layout.md +0 -508
- package/dist/docs/product/foundations/linter.md +0 -523
- package/dist/docs/product/foundations/motion.md +0 -151
- package/dist/docs/product/foundations/radius-and-padding.md +0 -86
- package/dist/docs/product/foundations/typography.md +0 -331
- package/dist/docs/product/introduction/faq.md +0 -133
- package/dist/docs/product/introduction/getting-started.md +0 -377
- package/dist/docs/product/patterns/blockchain-values.md +0 -709
- package/dist/docs/product/patterns/dashboards.md +0 -638
- package/dist/docs/product/patterns/destructive-actions.md +0 -626
- package/dist/docs/product/patterns/empty-states.md +0 -612
- package/dist/docs/product/patterns/errors-and-validation.md +0 -808
- package/dist/docs/product/patterns/feedback-and-status.md +0 -518
- package/dist/docs/product/patterns/forms.md +0 -679
- package/dist/docs/product/patterns/loading.md +0 -630
- package/dist/docs/product/patterns/navigation.md +0 -397
- package/dist/docs/product/patterns/payments.md +0 -765
- package/dist/docs/product/patterns/responsive-layout.md +0 -997
- package/dist/docs/product/patterns/tables-and-lists.md +0 -1170
- package/dist/docs/product/products/tempo-console.md +0 -671
- package/dist/docs/product/products/tempo-performance.md +0 -435
- package/dist/docs/product/products/tempo-wallet.md +0 -438
|
@@ -0,0 +1,2058 @@
|
|
|
1
|
+
# Actions
|
|
2
|
+
|
|
3
|
+
Each component section states its guidance first, then its Examples and Use Cases. Read a section up to its Examples heading before you use the component, then read the examples it needs.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
Controls that start an action or copy a value.
|
|
8
|
+
|
|
9
|
+
- [Button](#button): Triggers an action, such as submitting a form or sending a payment.
|
|
10
|
+
- [ButtonGroup](#buttongroup): Lays out the actions at the foot of a dialog or focused flow.
|
|
11
|
+
- [CopyButton](#copybutton): Copies a value to the clipboard and confirms the copy.
|
|
12
|
+
- [SplitButton](#splitbutton): Pairs a primary action with a menu of alternatives.
|
|
13
|
+
|
|
14
|
+
## Button
|
|
15
|
+
|
|
16
|
+
Triggers an action, such as submitting a form or sending a payment.
|
|
17
|
+
|
|
18
|
+
[View source and API](https://github.com/tempoxyz/ds/blob/main/src/web/components/Button.tsx)
|
|
19
|
+
|
|
20
|
+
Figma: [Button](https://www.figma.com/design/yE96kcymnNR88PJp6G1sPs?node-id=1186-3148), [Icon Button](https://www.figma.com/design/yE96kcymnNR88PJp6G1sPs?node-id=1186-3395), [Text Button](https://www.figma.com/design/yE96kcymnNR88PJp6G1sPs?node-id=5601-90)
|
|
21
|
+
|
|
22
|
+
### Overview
|
|
23
|
+
|
|
24
|
+
A native `<button>` for actions. `Button.Link` renders the same styles for navigation.
|
|
25
|
+
|
|
26
|
+
### Anatomy
|
|
27
|
+
|
|
28
|
+
Import the component and assemble its parts.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { Button } from '@tempoxyz/ds'
|
|
32
|
+
|
|
33
|
+
<Button />
|
|
34
|
+
<Button.Link />
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Guidelines
|
|
38
|
+
|
|
39
|
+
#### When to Use
|
|
40
|
+
|
|
41
|
+
* Start an action in the current view, such as Send payment, Save changes, or Open settings.
|
|
42
|
+
* Submit a form. Set `type="submit"` on the form's main button.
|
|
43
|
+
* Use `Button.Link` when navigation needs a button's weight, such as Create account in an empty state.
|
|
44
|
+
|
|
45
|
+
#### When Not to Use
|
|
46
|
+
|
|
47
|
+
* Use a text link for navigation inside sentences, lists, and tables.
|
|
48
|
+
* Use [CopyButton](#copybutton) to copy a value, and [SplitButton](#splitbutton) for a main action with related alternatives.
|
|
49
|
+
* Use [Tabs](navigation.md#tabs) or [ChoiceGroup](forms-and-inputs.md#choicegroup) to switch views, and [Switch](forms-and-inputs.md#switch) to turn a setting on or off.
|
|
50
|
+
* If a section has more than three secondary actions, put them in a [Menu](overlays.md#menu) behind an icon button.
|
|
51
|
+
|
|
52
|
+
#### Choose a Variant by Emphasis
|
|
53
|
+
|
|
54
|
+
* **Main Action (primary):** The main action of a view, dialog, or section, such as Send payment. Use one per section.
|
|
55
|
+
* **Supporting Actions (secondary):** Supporting actions beside a primary action, or actions of equal weight.
|
|
56
|
+
* **Low-Emphasis Actions (tertiary):** Dense areas, such as toolbars, table rows, and inline Cancel actions.
|
|
57
|
+
|
|
58
|
+
A destructive action takes the variant of its place in the flow, and its label names the outcome, such as Revoke key. Confirm it with an [AlertDialog](overlays.md#alertdialog), whose confirming button takes `danger`. See [Destructive Actions](../patterns.md#destructive-actions) and [Payments](../patterns.md#payments).
|
|
59
|
+
|
|
60
|
+
#### Use One Primary Action
|
|
61
|
+
|
|
62
|
+
Give other actions `secondary` or `tertiary`, even if they matter. [Forms](../patterns.md#submitting) sets the order of the actions.
|
|
63
|
+
|
|
64
|
+
**Do:** Pair one `primary` action with `secondary` alternatives.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
/**
|
|
68
|
+
* Do example for "Use One Primary Action" on the Button page.
|
|
69
|
+
* Pair one `primary` action with `secondary` alternatives.
|
|
70
|
+
* @module
|
|
71
|
+
*/
|
|
72
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
73
|
+
|
|
74
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
75
|
+
export function Demo() {
|
|
76
|
+
return (
|
|
77
|
+
<div {...styles.row()}>
|
|
78
|
+
<Button variant="secondary">Cancel</Button>
|
|
79
|
+
<Button>Send payment</Button>
|
|
80
|
+
</div>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
namespace styles {
|
|
85
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Don't:** Give several actions in one section the `primary` variant.
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
/**
|
|
93
|
+
* Don't example for "Use One Primary Action" on the Button page.
|
|
94
|
+
* Don't give several actions in one section the `primary` variant.
|
|
95
|
+
* @module
|
|
96
|
+
*/
|
|
97
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
98
|
+
|
|
99
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
100
|
+
export function Demo() {
|
|
101
|
+
return (
|
|
102
|
+
<div {...styles.row()}>
|
|
103
|
+
<Button>Send</Button>
|
|
104
|
+
<Button>Deposit</Button>
|
|
105
|
+
<Button>Swap</Button>
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
namespace styles {
|
|
111
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Match Size to Context
|
|
116
|
+
|
|
117
|
+
* **Row Actions (xsmall):** A pill for an action inside a row or field, such as Copy or Edit. Never the main action.
|
|
118
|
+
* **Dense Layouts (small):** Tables, toolbars, cards, and icon buttons inside fields and rows, such as Export in a toolbar.
|
|
119
|
+
* **Default (medium):** Forms, page actions, and actions inside a dialog body, such as Copy address.
|
|
120
|
+
* **Dialog Footers (large):** Every action in a dialog footer, and the final step of a focused flow, such as Confirm send.
|
|
121
|
+
|
|
122
|
+
Lay out the actions in a dialog footer with a [ButtonGroup](#buttongroup).
|
|
123
|
+
|
|
124
|
+
#### Show Progress With Loading
|
|
125
|
+
|
|
126
|
+
**Do:** Set `loading` on the button that started the action.
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
/**
|
|
130
|
+
* Do example for "Show Progress With Loading" on the Button page.
|
|
131
|
+
* Set `loading` on the button that started the action.
|
|
132
|
+
* @module
|
|
133
|
+
*/
|
|
134
|
+
import { Button } from '@tempoxyz/ds'
|
|
135
|
+
|
|
136
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
137
|
+
export function Demo() {
|
|
138
|
+
return <Button loading>Send payment</Button>
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Don't:** Disable the button and place a separate [Spinner](feedback-and-status.md#spinner) beside it.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
/**
|
|
146
|
+
* Don't example for "Show Progress With Loading" on the Button page.
|
|
147
|
+
* Don't disable the button and place a separate Spinner beside it.
|
|
148
|
+
* @module
|
|
149
|
+
*/
|
|
150
|
+
import { Button, Spinner, style } from '@tempoxyz/ds'
|
|
151
|
+
|
|
152
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
153
|
+
export function Demo() {
|
|
154
|
+
return (
|
|
155
|
+
<div {...styles.row()}>
|
|
156
|
+
<Button disabled>Send payment</Button>
|
|
157
|
+
<Spinner aria-label="Loading" />
|
|
158
|
+
</div>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
namespace styles {
|
|
163
|
+
export const row = style({ alignItems: 'center', display: 'flex', gap: '12' })
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Avoid Disabled Buttons
|
|
168
|
+
|
|
169
|
+
Keep a button enabled when you can, and show validation errors after a press. If a button must stay disabled:
|
|
170
|
+
|
|
171
|
+
* Explain why in nearby text.
|
|
172
|
+
* Set `focusableWhenDisabled` so keyboard users can reach it.
|
|
173
|
+
* Don't rely on a [Tooltip](overlays.md#tooltip). Many readers can't open it on a disabled button.
|
|
174
|
+
|
|
175
|
+
**Do:** Explain in nearby text why the button is unavailable.
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
/**
|
|
179
|
+
* Do example for "Avoid Disabled Buttons" on the Button page.
|
|
180
|
+
* Explain in nearby text why the button is unavailable.
|
|
181
|
+
* @module
|
|
182
|
+
*/
|
|
183
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
184
|
+
|
|
185
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
186
|
+
export function Demo() {
|
|
187
|
+
return (
|
|
188
|
+
<div {...styles.stack()}>
|
|
189
|
+
<Button disabled focusableWhenDisabled>
|
|
190
|
+
Send payment
|
|
191
|
+
</Button>
|
|
192
|
+
<p {...styles.hint()}>Add a recipient address to send.</p>
|
|
193
|
+
</div>
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
namespace styles {
|
|
198
|
+
export const hint = style({
|
|
199
|
+
color: 'content.secondary',
|
|
200
|
+
margin: '0 !custom',
|
|
201
|
+
typography: 'body.b3',
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
export const stack = style({
|
|
205
|
+
alignItems: 'flex-start',
|
|
206
|
+
display: 'flex',
|
|
207
|
+
flexDirection: 'column',
|
|
208
|
+
rowGap: '8',
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Don't:** Disable a button without saying what is missing.
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
/**
|
|
217
|
+
* Don't example for "Avoid Disabled Buttons" on the Button page.
|
|
218
|
+
* Don't disable a button without saying what is missing.
|
|
219
|
+
* @module
|
|
220
|
+
*/
|
|
221
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
222
|
+
|
|
223
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
224
|
+
export function Demo() {
|
|
225
|
+
return (
|
|
226
|
+
<div {...styles.stack()}>
|
|
227
|
+
<Button disabled>Send payment</Button>
|
|
228
|
+
</div>
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
namespace styles {
|
|
233
|
+
export const stack = style({
|
|
234
|
+
alignItems: 'flex-start',
|
|
235
|
+
display: 'flex',
|
|
236
|
+
flexDirection: 'column',
|
|
237
|
+
rowGap: '8',
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### Use Icons to Reinforce the Label
|
|
243
|
+
|
|
244
|
+
Place an icon before the label if it aids recognition, such as a plus for Add. An icon-only button (`shape="icon"`) needs a [Tooltip](overlays.md#tooltip) with its `aria-label` text. Use it only for familiar actions, such as Close or Copy.
|
|
245
|
+
|
|
246
|
+
**Do:** Add an icon only where it aids recognition.
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
/**
|
|
250
|
+
* Do example for "Use Icons to Reinforce the Label" on the Button page.
|
|
251
|
+
* Add an icon only where it aids recognition.
|
|
252
|
+
* @module
|
|
253
|
+
*/
|
|
254
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
255
|
+
import { Plus } from '@tempoxyz/ds/icons'
|
|
256
|
+
|
|
257
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
258
|
+
export function Demo() {
|
|
259
|
+
return (
|
|
260
|
+
<div {...styles.row()}>
|
|
261
|
+
<Button size="small" variant="secondary">
|
|
262
|
+
Export
|
|
263
|
+
</Button>
|
|
264
|
+
<Button size="small" variant="secondary">
|
|
265
|
+
Rotate key
|
|
266
|
+
</Button>
|
|
267
|
+
<Button size="small">
|
|
268
|
+
<Plus />
|
|
269
|
+
Add key
|
|
270
|
+
</Button>
|
|
271
|
+
</div>
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
namespace styles {
|
|
276
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '8' })
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Don't:** Add icons to every button in a group.
|
|
281
|
+
|
|
282
|
+
```tsx
|
|
283
|
+
/**
|
|
284
|
+
* Don't example for "Use Icons to Reinforce the Label" on the Button page.
|
|
285
|
+
* Don't add icons to every button in a group.
|
|
286
|
+
* @module
|
|
287
|
+
*/
|
|
288
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
289
|
+
import { Export, Plus, Refresh } from '@tempoxyz/ds/icons'
|
|
290
|
+
|
|
291
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
292
|
+
export function Demo() {
|
|
293
|
+
return (
|
|
294
|
+
<div {...styles.row()}>
|
|
295
|
+
<Button size="small" variant="secondary">
|
|
296
|
+
<Export />
|
|
297
|
+
Export
|
|
298
|
+
</Button>
|
|
299
|
+
<Button size="small" variant="secondary">
|
|
300
|
+
<Refresh />
|
|
301
|
+
Rotate key
|
|
302
|
+
</Button>
|
|
303
|
+
<Button size="small">
|
|
304
|
+
<Plus />
|
|
305
|
+
Add key
|
|
306
|
+
</Button>
|
|
307
|
+
</div>
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
namespace styles {
|
|
312
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '8' })
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Content
|
|
317
|
+
|
|
318
|
+
#### Start With a Verb
|
|
319
|
+
|
|
320
|
+
Name the action and its object, such as Send payment or Create key.
|
|
321
|
+
|
|
322
|
+
**Do:** Repeat the action on each button, such as Revoke key and Keep key.
|
|
323
|
+
|
|
324
|
+
```tsx
|
|
325
|
+
/**
|
|
326
|
+
* Do example for "Start With a Verb" on the Button page.
|
|
327
|
+
* Repeat the action on each button, such as Revoke key and Keep key.
|
|
328
|
+
* @module
|
|
329
|
+
*/
|
|
330
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
331
|
+
|
|
332
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
333
|
+
export function Demo() {
|
|
334
|
+
return (
|
|
335
|
+
<div {...styles.row()}>
|
|
336
|
+
<Button variant="secondary">Keep key</Button>
|
|
337
|
+
<Button>Revoke key</Button>
|
|
338
|
+
</div>
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
namespace styles {
|
|
343
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Don't:** Use generic labels such as Yes, No, OK, or Submit.
|
|
348
|
+
|
|
349
|
+
```tsx
|
|
350
|
+
/**
|
|
351
|
+
* Don't example for "Start With a Verb" on the Button page.
|
|
352
|
+
* Don't use generic labels such as Yes, No, OK, or Submit.
|
|
353
|
+
* @module
|
|
354
|
+
*/
|
|
355
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
356
|
+
|
|
357
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
358
|
+
export function Demo() {
|
|
359
|
+
return (
|
|
360
|
+
<div {...styles.row()}>
|
|
361
|
+
<Button variant="secondary">No</Button>
|
|
362
|
+
<Button>Yes</Button>
|
|
363
|
+
</div>
|
|
364
|
+
)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
namespace styles {
|
|
368
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
#### Describe the Outcome, Not the Control
|
|
373
|
+
|
|
374
|
+
Write Continue to review, not Click here. Screen readers list buttons out of context, so each label must make sense alone.
|
|
375
|
+
|
|
376
|
+
### Accessibility
|
|
377
|
+
|
|
378
|
+
`Button` renders a native `<button type="button">`, and `Button.Link` a native `<a>`. Both follow the [WAI-ARIA button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/). See [Accessibility](../foundations.md#accessibility) for the baseline.
|
|
379
|
+
|
|
380
|
+
#### Semantics
|
|
381
|
+
|
|
382
|
+
* **Button (button):** Enter and Space activate it. Name an icon-only button with `aria-label`.
|
|
383
|
+
* **Button.Link (link):** Announced as a link and listed among the page's links. A modifier click opens a new tab.
|
|
384
|
+
* **Disabled:** Removes the button from the tab order, so keyboards skip it. Explain the reason in nearby text.
|
|
385
|
+
* **Focusable When Disabled (aria-disabled):** Keeps a disabled button in the tab order. It ignores every key except Tab.
|
|
386
|
+
* **Loading (aria-busy):** Disables the button and labels its spinner "Loading" for screen readers.
|
|
387
|
+
* **Icons (aria-hidden):** Hidden from assistive technology, so the button's text or label names it.
|
|
388
|
+
|
|
389
|
+
#### Keyboard
|
|
390
|
+
|
|
391
|
+
* **Move to the Button (Tab):** Focuses the button, skipping disabled ones.
|
|
392
|
+
* **Activate the Button (Enter or Space):** Activates the button.
|
|
393
|
+
* **Follow a Link (Enter):** Follows a `Button.Link`.
|
|
394
|
+
|
|
395
|
+
#### Your Responsibilities
|
|
396
|
+
|
|
397
|
+
* **Name Icon-Only Buttons (aria-label):** An icon-only button has no visible text. Name the action, such as "Copy address", not "Copy icon".
|
|
398
|
+
* **Announce Loading Results:** Loading announces only the busy state. Announce the outcome with a [Toast](feedback-and-status.md#toast) or an [Alert](feedback-and-status.md#alert).
|
|
399
|
+
* **Use Links for Navigation (Button.Link):** Use it for navigation, not a button with a click handler that changes the page.
|
|
400
|
+
|
|
401
|
+
### Related
|
|
402
|
+
|
|
403
|
+
[ButtonGroup](#buttongroup)
|
|
404
|
+
|
|
405
|
+
Use for the actions at the foot of a dialog.
|
|
406
|
+
|
|
407
|
+
[SplitButton](#splitbutton)
|
|
408
|
+
|
|
409
|
+
Use for a main action with alternatives.
|
|
410
|
+
|
|
411
|
+
[CopyButton](#copybutton)
|
|
412
|
+
|
|
413
|
+
Use for copying a value.
|
|
414
|
+
|
|
415
|
+
[AlertDialog](overlays.md#alertdialog)
|
|
416
|
+
|
|
417
|
+
Use for confirming an action.
|
|
418
|
+
|
|
419
|
+
[Forms](../patterns.md#forms)
|
|
420
|
+
|
|
421
|
+
Covers placing submit and cancel actions.
|
|
422
|
+
|
|
423
|
+
[Destructive Actions](../patterns.md#destructive-actions)
|
|
424
|
+
|
|
425
|
+
Covers deleting and revoking.
|
|
426
|
+
|
|
427
|
+
### Examples
|
|
428
|
+
|
|
429
|
+
#### Basic
|
|
430
|
+
|
|
431
|
+
```tsx
|
|
432
|
+
import { Button } from '@tempoxyz/ds'
|
|
433
|
+
|
|
434
|
+
export function Demo() {
|
|
435
|
+
return <Button>Continue</Button>
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Basic.tsx)
|
|
440
|
+
|
|
441
|
+
#### Variant
|
|
442
|
+
|
|
443
|
+
Set `variant` to `primary` (default), `secondary`, `tertiary`, `danger`, or `text`. A `tertiary` button has no fill until hover.
|
|
444
|
+
|
|
445
|
+
```tsx
|
|
446
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
447
|
+
|
|
448
|
+
export function Demo() {
|
|
449
|
+
return (
|
|
450
|
+
<div {...styles.row()}>
|
|
451
|
+
{(['primary', 'secondary', 'tertiary', 'danger'] as const).map((variant) => (
|
|
452
|
+
<Button key={variant} variant={variant}>
|
|
453
|
+
Continue
|
|
454
|
+
</Button>
|
|
455
|
+
))}
|
|
456
|
+
</div>
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
namespace styles {
|
|
461
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Variant.tsx)
|
|
466
|
+
|
|
467
|
+
#### Text
|
|
468
|
+
|
|
469
|
+
Set `variant="text"` for a low-emphasis action in running content, such as See more. It renders the secondary label and a trailing 12px icon without a fill or padding, and ignores `size`.
|
|
470
|
+
|
|
471
|
+
```tsx
|
|
472
|
+
import { Button } from '@tempoxyz/ds'
|
|
473
|
+
import { ChevronRight } from '@tempoxyz/ds/icons'
|
|
474
|
+
|
|
475
|
+
export function Demo() {
|
|
476
|
+
return (
|
|
477
|
+
<Button variant="text">
|
|
478
|
+
See more
|
|
479
|
+
<ChevronRight />
|
|
480
|
+
</Button>
|
|
481
|
+
)
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Text.tsx)
|
|
486
|
+
|
|
487
|
+
#### Inverse
|
|
488
|
+
|
|
489
|
+
Set `appearance="inverse"` on an inverse surface, such as a dark banner on a light page. The surface turns light in dark mode, and the button colors flip with it.
|
|
490
|
+
|
|
491
|
+
```tsx
|
|
492
|
+
/** Demonstrates the inverse appearance of each Button variant on an inverse surface. @module */
|
|
493
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
494
|
+
|
|
495
|
+
export function Demo() {
|
|
496
|
+
return (
|
|
497
|
+
<div {...styles.surface()}>
|
|
498
|
+
{(['primary', 'secondary', 'tertiary'] as const).map((variant) => (
|
|
499
|
+
<Button appearance="inverse" key={variant} variant={variant}>
|
|
500
|
+
Continue
|
|
501
|
+
</Button>
|
|
502
|
+
))}
|
|
503
|
+
</div>
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
namespace styles {
|
|
508
|
+
export const surface = style({
|
|
509
|
+
alignItems: 'center',
|
|
510
|
+
backgroundColor: 'inverse.background.primary',
|
|
511
|
+
borderRadius: 'sm',
|
|
512
|
+
display: 'flex',
|
|
513
|
+
flexWrap: 'wrap',
|
|
514
|
+
gap: '12',
|
|
515
|
+
padding: '16',
|
|
516
|
+
})
|
|
517
|
+
}
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Inverse.tsx)
|
|
521
|
+
|
|
522
|
+
#### Overlay
|
|
523
|
+
|
|
524
|
+
Set `appearance="overlay"` over an image or video. The `secondary` fill is a translucent gray, and the `secondary` and `tertiary` labels stay white in both color schemes.
|
|
525
|
+
|
|
526
|
+
```tsx
|
|
527
|
+
/** Demonstrates the overlay appearance of each Button variant over an image. @module */
|
|
528
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
529
|
+
|
|
530
|
+
export function Demo() {
|
|
531
|
+
return (
|
|
532
|
+
<div {...styles.image()}>
|
|
533
|
+
{(['primary', 'secondary', 'tertiary'] as const).map((variant) => (
|
|
534
|
+
<Button appearance="overlay" key={variant} variant={variant}>
|
|
535
|
+
Continue
|
|
536
|
+
</Button>
|
|
537
|
+
))}
|
|
538
|
+
</div>
|
|
539
|
+
)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
namespace styles {
|
|
543
|
+
// A mid-tone gradient stands in for a photo, so the labels stay legible in both color schemes.
|
|
544
|
+
export const image = style({
|
|
545
|
+
alignItems: 'center',
|
|
546
|
+
backgroundImage: 'linear-gradient(135deg, #6b7f99, #a3866a) !custom',
|
|
547
|
+
borderRadius: 'sm',
|
|
548
|
+
display: 'flex',
|
|
549
|
+
flexWrap: 'wrap',
|
|
550
|
+
gap: '12',
|
|
551
|
+
padding: '16',
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Overlay.tsx)
|
|
557
|
+
|
|
558
|
+
#### Size
|
|
559
|
+
|
|
560
|
+
Set `size` to `xsmall`, `small`, `medium` (default), or `large`. Heights step from 24px to 48px. `large` and `medium` take the `sm` corner radius, `small` takes `xs`, and `xsmall` renders a pill.
|
|
561
|
+
|
|
562
|
+
```tsx
|
|
563
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
564
|
+
|
|
565
|
+
export function Demo() {
|
|
566
|
+
return (
|
|
567
|
+
<div {...styles.row()}>
|
|
568
|
+
{(['xsmall', 'small', 'medium', 'large'] as const).map((size) => (
|
|
569
|
+
<Button key={size} size={size}>
|
|
570
|
+
Continue
|
|
571
|
+
</Button>
|
|
572
|
+
))}
|
|
573
|
+
</div>
|
|
574
|
+
)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
namespace styles {
|
|
578
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Size.tsx)
|
|
583
|
+
|
|
584
|
+
#### Shape
|
|
585
|
+
|
|
586
|
+
Set `shape="icon"` for a round button that holds only an icon. The icon renders at 16px, and at 20px on a large button. Give the button an `aria-label`.
|
|
587
|
+
|
|
588
|
+
```tsx
|
|
589
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
590
|
+
import { Plus as Add } from '@tempoxyz/ds/icons'
|
|
591
|
+
|
|
592
|
+
export function Demo() {
|
|
593
|
+
return (
|
|
594
|
+
<div {...styles.row()}>
|
|
595
|
+
<Button>
|
|
596
|
+
<Add />
|
|
597
|
+
Add funds
|
|
598
|
+
</Button>
|
|
599
|
+
{(['primary', 'secondary', 'tertiary'] as const).map((variant) => (
|
|
600
|
+
<Button aria-label="Add" key={variant} shape="icon" variant={variant}>
|
|
601
|
+
<Add />
|
|
602
|
+
</Button>
|
|
603
|
+
))}
|
|
604
|
+
</div>
|
|
605
|
+
)
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
namespace styles {
|
|
609
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
610
|
+
}
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Shape.tsx)
|
|
614
|
+
|
|
615
|
+
#### Loading
|
|
616
|
+
|
|
617
|
+
Set `loading` to disable the button and mark it busy. The label stays visible, with a spinner centered in the leading space before it. An icon-only button shows only the centered spinner.
|
|
618
|
+
|
|
619
|
+
```tsx
|
|
620
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
621
|
+
|
|
622
|
+
export function Demo() {
|
|
623
|
+
return (
|
|
624
|
+
<div {...styles.row()}>
|
|
625
|
+
{(['primary', 'secondary', 'tertiary'] as const).map((variant) => (
|
|
626
|
+
<Button key={variant} loading variant={variant}>
|
|
627
|
+
Loading
|
|
628
|
+
</Button>
|
|
629
|
+
))}
|
|
630
|
+
</div>
|
|
631
|
+
)
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
namespace styles {
|
|
635
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
636
|
+
}
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Loading.tsx)
|
|
640
|
+
|
|
641
|
+
#### Disabled
|
|
642
|
+
|
|
643
|
+
```tsx
|
|
644
|
+
import { Button, style } from '@tempoxyz/ds'
|
|
645
|
+
|
|
646
|
+
export function Demo() {
|
|
647
|
+
return (
|
|
648
|
+
<div {...styles.row()}>
|
|
649
|
+
{(['primary', 'secondary', 'tertiary'] as const).map((variant) => (
|
|
650
|
+
<Button disabled key={variant} variant={variant}>
|
|
651
|
+
Disabled
|
|
652
|
+
</Button>
|
|
653
|
+
))}
|
|
654
|
+
</div>
|
|
655
|
+
)
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
namespace styles {
|
|
659
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Button/Disabled.tsx)
|
|
664
|
+
|
|
665
|
+
## ButtonGroup
|
|
666
|
+
|
|
667
|
+
Lays out the actions at the foot of a dialog or focused flow.
|
|
668
|
+
|
|
669
|
+
[View source and API](https://github.com/tempoxyz/ds/blob/main/src/web/components/ButtonGroup.tsx)
|
|
670
|
+
|
|
671
|
+
Figma: [Button Group](https://www.figma.com/design/yE96kcymnNR88PJp6G1sPs?node-id=1269-1089)
|
|
672
|
+
|
|
673
|
+
### Overview
|
|
674
|
+
|
|
675
|
+
A button group places [Buttons](#button) side by side at equal widths, or stacks them at full width.
|
|
676
|
+
|
|
677
|
+
### Anatomy
|
|
678
|
+
|
|
679
|
+
Import the component and assemble its parts.
|
|
680
|
+
|
|
681
|
+
```tsx
|
|
682
|
+
import { Button, ButtonGroup } from '@tempoxyz/ds'
|
|
683
|
+
|
|
684
|
+
<ButtonGroup>
|
|
685
|
+
<Button />
|
|
686
|
+
</ButtonGroup>
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
### Guidelines
|
|
690
|
+
|
|
691
|
+
#### When to Use
|
|
692
|
+
|
|
693
|
+
* Close a dialog with two actions of equal weight, such as Cancel and Confirm.
|
|
694
|
+
* Stack a main action above a dismiss action in an intro or announcement, such as Get started and Not now.
|
|
695
|
+
|
|
696
|
+
#### When Not to Use
|
|
697
|
+
|
|
698
|
+
* Use a [SplitButton](#splitbutton) for a main action with related alternatives.
|
|
699
|
+
* Use an [Inline](layout.md#inline) row for actions at their natural width, such as a toolbar.
|
|
700
|
+
* Use a [Menu](overlays.md#menu) for more than three actions.
|
|
701
|
+
|
|
702
|
+
#### Put the Primary Action Last
|
|
703
|
+
|
|
704
|
+
Place the `primary` action on the right of a pair. Keep the source order the same as the visual order, so focus reaches the main action last.
|
|
705
|
+
|
|
706
|
+
**Do:** Put the `secondary` action first and the `primary` action last.
|
|
707
|
+
|
|
708
|
+
```tsx
|
|
709
|
+
/**
|
|
710
|
+
* Do example for "Put the Primary Action Last" on the ButtonGroup page.
|
|
711
|
+
* Put the `secondary` action first and the `primary` action last.
|
|
712
|
+
* @module
|
|
713
|
+
*/
|
|
714
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
715
|
+
|
|
716
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
717
|
+
export function Demo() {
|
|
718
|
+
return (
|
|
719
|
+
<ButtonGroup {...styles.group()}>
|
|
720
|
+
<Button size="large" variant="secondary">
|
|
721
|
+
Cancel
|
|
722
|
+
</Button>
|
|
723
|
+
<Button size="large">Confirm</Button>
|
|
724
|
+
</ButtonGroup>
|
|
725
|
+
)
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
namespace styles {
|
|
729
|
+
export const group = style({ maxWidth: '320', width: '100% !custom' })
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Don't:** Put the `primary` action on the left of a pair.
|
|
734
|
+
|
|
735
|
+
```tsx
|
|
736
|
+
/**
|
|
737
|
+
* Don't example for "Put the Primary Action Last" on the ButtonGroup page.
|
|
738
|
+
* Don't put the `primary` action on the left of a pair.
|
|
739
|
+
* @module
|
|
740
|
+
*/
|
|
741
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
742
|
+
|
|
743
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
744
|
+
export function Demo() {
|
|
745
|
+
return (
|
|
746
|
+
<ButtonGroup {...styles.group()}>
|
|
747
|
+
<Button size="large">Confirm</Button>
|
|
748
|
+
<Button size="large" variant="secondary">
|
|
749
|
+
Cancel
|
|
750
|
+
</Button>
|
|
751
|
+
</ButtonGroup>
|
|
752
|
+
)
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
namespace styles {
|
|
756
|
+
export const group = style({ maxWidth: '320', width: '100% !custom' })
|
|
757
|
+
}
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
#### Keep Every Button the Same Size
|
|
761
|
+
|
|
762
|
+
Give every button in a dialog footer the `large` size. In a stack, the `tertiary` dismiss action keeps that size.
|
|
763
|
+
|
|
764
|
+
**Do:** Give the dismiss action the same `large` size as the `primary` action.
|
|
765
|
+
|
|
766
|
+
```tsx
|
|
767
|
+
/**
|
|
768
|
+
* Do example for "Keep Every Button the Same Size" on the ButtonGroup page.
|
|
769
|
+
* Give the dismiss action the same `large` size as the `primary` action.
|
|
770
|
+
* @module
|
|
771
|
+
*/
|
|
772
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
773
|
+
|
|
774
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
775
|
+
export function Demo() {
|
|
776
|
+
return (
|
|
777
|
+
<ButtonGroup orientation="vertical" {...styles.group()}>
|
|
778
|
+
<Button size="large">Get started</Button>
|
|
779
|
+
<Button size="large" variant="tertiary">
|
|
780
|
+
Not now
|
|
781
|
+
</Button>
|
|
782
|
+
</ButtonGroup>
|
|
783
|
+
)
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
namespace styles {
|
|
787
|
+
export const group = style({ maxWidth: '320', width: '100% !custom' })
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
**Don't:** Shrink the dismiss action below the `primary` action.
|
|
792
|
+
|
|
793
|
+
```tsx
|
|
794
|
+
/**
|
|
795
|
+
* Don't example for "Keep Every Button the Same Size" on the ButtonGroup page.
|
|
796
|
+
* Don't shrink the dismiss action below the `primary` action.
|
|
797
|
+
* @module
|
|
798
|
+
*/
|
|
799
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
800
|
+
|
|
801
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
802
|
+
export function Demo() {
|
|
803
|
+
return (
|
|
804
|
+
<ButtonGroup orientation="vertical" {...styles.group()}>
|
|
805
|
+
<Button size="large">Get started</Button>
|
|
806
|
+
<Button size="small" variant="tertiary">
|
|
807
|
+
Not now
|
|
808
|
+
</Button>
|
|
809
|
+
</ButtonGroup>
|
|
810
|
+
)
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
namespace styles {
|
|
814
|
+
export const group = style({ maxWidth: '320', width: '100% !custom' })
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
### Content
|
|
819
|
+
|
|
820
|
+
#### Name the Destructive Action
|
|
821
|
+
|
|
822
|
+
If the action destroys data or removes access, name what it does on the `primary` button, such as Revoke all.
|
|
823
|
+
|
|
824
|
+
**Do:** Name both outcomes, such as Keep keys and Revoke all.
|
|
825
|
+
|
|
826
|
+
```tsx
|
|
827
|
+
/**
|
|
828
|
+
* Do example for "Name the Destructive Action" on the ButtonGroup page.
|
|
829
|
+
* Name both outcomes, such as Keep keys and Revoke all.
|
|
830
|
+
* @module
|
|
831
|
+
*/
|
|
832
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
833
|
+
|
|
834
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
835
|
+
export function Demo() {
|
|
836
|
+
return (
|
|
837
|
+
<ButtonGroup {...styles.group()}>
|
|
838
|
+
<Button size="large" variant="secondary">
|
|
839
|
+
Keep keys
|
|
840
|
+
</Button>
|
|
841
|
+
<Button size="large">Revoke all</Button>
|
|
842
|
+
</ButtonGroup>
|
|
843
|
+
)
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
namespace styles {
|
|
847
|
+
export const group = style({ maxWidth: '320', width: '100% !custom' })
|
|
848
|
+
}
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
**Don't:** Label a destructive action OK.
|
|
852
|
+
|
|
853
|
+
```tsx
|
|
854
|
+
/**
|
|
855
|
+
* Don't example for "Name the Destructive Action" on the ButtonGroup page.
|
|
856
|
+
* Don't label a destructive action OK.
|
|
857
|
+
* @module
|
|
858
|
+
*/
|
|
859
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
860
|
+
|
|
861
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
862
|
+
export function Demo() {
|
|
863
|
+
return (
|
|
864
|
+
<ButtonGroup {...styles.group()}>
|
|
865
|
+
<Button size="large" variant="secondary">
|
|
866
|
+
Cancel
|
|
867
|
+
</Button>
|
|
868
|
+
<Button size="large">OK</Button>
|
|
869
|
+
</ButtonGroup>
|
|
870
|
+
)
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
namespace styles {
|
|
874
|
+
export const group = style({ maxWidth: '320', width: '100% !custom' })
|
|
875
|
+
}
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
### Accessibility
|
|
879
|
+
|
|
880
|
+
`ButtonGroup` renders a `div` with `role="group"` around native buttons. See [Accessibility](../foundations.md#accessibility) for the baseline.
|
|
881
|
+
|
|
882
|
+
* **Group (group):** Groups the actions. Name it with `aria-label` when the dialog title does not.
|
|
883
|
+
* **Focus Order (Tab):** Follows the source order, which matches the visual order in both orientations.
|
|
884
|
+
* **Target Size (48px):** Large buttons stretch to the full width, which leaves a wide target on touch screens.
|
|
885
|
+
|
|
886
|
+
### Related
|
|
887
|
+
|
|
888
|
+
[Button](#button)
|
|
889
|
+
|
|
890
|
+
Use for each action in the group.
|
|
891
|
+
|
|
892
|
+
[Dialog](overlays.md#dialog)
|
|
893
|
+
|
|
894
|
+
Use for the focused task that the group closes.
|
|
895
|
+
|
|
896
|
+
[AlertDialog](overlays.md#alertdialog)
|
|
897
|
+
|
|
898
|
+
Use for confirming a destructive action.
|
|
899
|
+
|
|
900
|
+
### Examples
|
|
901
|
+
|
|
902
|
+
#### Basic
|
|
903
|
+
|
|
904
|
+
```tsx
|
|
905
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
906
|
+
|
|
907
|
+
export const fill = true
|
|
908
|
+
export function Demo() {
|
|
909
|
+
return (
|
|
910
|
+
<ButtonGroup {...styles.group()}>
|
|
911
|
+
<Button size="large" variant="secondary">
|
|
912
|
+
Cancel
|
|
913
|
+
</Button>
|
|
914
|
+
<Button size="large">Confirm</Button>
|
|
915
|
+
</ButtonGroup>
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
namespace styles {
|
|
920
|
+
export const group = style({ maxWidth: '360', width: '100% !custom' })
|
|
921
|
+
}
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/ButtonGroup/Basic.tsx)
|
|
925
|
+
|
|
926
|
+
#### Orientation
|
|
927
|
+
|
|
928
|
+
Set `orientation` to `horizontal` (default) or `vertical`. Both place the buttons 8px apart.
|
|
929
|
+
|
|
930
|
+
```tsx
|
|
931
|
+
import { Button, ButtonGroup, style } from '@tempoxyz/ds'
|
|
932
|
+
|
|
933
|
+
export const fill = true
|
|
934
|
+
export function Demo() {
|
|
935
|
+
return (
|
|
936
|
+
<ButtonGroup orientation="vertical" {...styles.group()}>
|
|
937
|
+
<Button size="large">Get started</Button>
|
|
938
|
+
<Button size="large" variant="tertiary">
|
|
939
|
+
Not now
|
|
940
|
+
</Button>
|
|
941
|
+
</ButtonGroup>
|
|
942
|
+
)
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
namespace styles {
|
|
946
|
+
export const group = style({ maxWidth: '360', width: '100% !custom' })
|
|
947
|
+
}
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/ButtonGroup/Orientation.tsx)
|
|
951
|
+
|
|
952
|
+
## CopyButton
|
|
953
|
+
|
|
954
|
+
Copies a value to the clipboard and confirms the copy.
|
|
955
|
+
|
|
956
|
+
[View source and API](https://github.com/tempoxyz/ds/blob/main/src/web/components/CopyButton.tsx)
|
|
957
|
+
|
|
958
|
+
### Overview
|
|
959
|
+
|
|
960
|
+
A copy button is an icon-only button that writes a value to the clipboard and confirms the copy for two seconds.
|
|
961
|
+
|
|
962
|
+
### Anatomy
|
|
963
|
+
|
|
964
|
+
Import the component and assemble its parts.
|
|
965
|
+
|
|
966
|
+
```tsx
|
|
967
|
+
import { CopyButton } from '@tempoxyz/ds'
|
|
968
|
+
|
|
969
|
+
<CopyButton />
|
|
970
|
+
```
|
|
971
|
+
|
|
972
|
+
### Guidelines
|
|
973
|
+
|
|
974
|
+
#### When to Use
|
|
975
|
+
|
|
976
|
+
* Copy a value you'd otherwise select by hand, such as a webhook ID or an invite link.
|
|
977
|
+
* Add copying beside a value in your own layout, such as a table cell.
|
|
978
|
+
|
|
979
|
+
#### When Not to Use
|
|
980
|
+
|
|
981
|
+
* Use [Hex](blockchain.md#hex) with `copy` for addresses and transaction hashes. It truncates the middle and adds this button.
|
|
982
|
+
* Use [Snippet](data-display.md#snippet) for a command or code value.
|
|
983
|
+
* Use [SecretValue](blockchain.md#secretvalue) for API keys and other secrets that stay hidden until revealed.
|
|
984
|
+
* Use a [Button](#button) for other actions, such as Share or Download.
|
|
985
|
+
|
|
986
|
+
#### Place It Right After the Value
|
|
987
|
+
|
|
988
|
+
Put the button on the same line, immediately after the value. Give each value its own button.
|
|
989
|
+
|
|
990
|
+
**Do:** Place a copy button directly after each value.
|
|
991
|
+
|
|
992
|
+
```tsx
|
|
993
|
+
/**
|
|
994
|
+
* Do example for "Place It Right After the Value" on the CopyButton page.
|
|
995
|
+
* Place a copy button directly after each value.
|
|
996
|
+
* @module
|
|
997
|
+
*/
|
|
998
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
999
|
+
|
|
1000
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1001
|
+
export function Demo() {
|
|
1002
|
+
return (
|
|
1003
|
+
<div {...styles.rows()}>
|
|
1004
|
+
<div {...styles.row()}>
|
|
1005
|
+
<span {...styles.label()}>Webhook ID</span>
|
|
1006
|
+
<span {...styles.value()}>
|
|
1007
|
+
wh_51c8e20d
|
|
1008
|
+
<CopyButton aria-label="Copy webhook ID" value="wh_51c8e20d" />
|
|
1009
|
+
</span>
|
|
1010
|
+
</div>
|
|
1011
|
+
<div {...styles.row()}>
|
|
1012
|
+
<span {...styles.label()}>Key ID</span>
|
|
1013
|
+
<span {...styles.value()}>
|
|
1014
|
+
key_9f2c41a7
|
|
1015
|
+
<CopyButton aria-label="Copy key ID" value="key_9f2c41a7" />
|
|
1016
|
+
</span>
|
|
1017
|
+
</div>
|
|
1018
|
+
</div>
|
|
1019
|
+
)
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
namespace styles {
|
|
1023
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b2' })
|
|
1024
|
+
|
|
1025
|
+
export const row = style({
|
|
1026
|
+
alignItems: 'center',
|
|
1027
|
+
display: 'flex',
|
|
1028
|
+
justifyContent: 'space-between',
|
|
1029
|
+
minHeight: '32',
|
|
1030
|
+
})
|
|
1031
|
+
|
|
1032
|
+
export const rows = style({
|
|
1033
|
+
display: 'flex',
|
|
1034
|
+
flexDirection: 'column',
|
|
1035
|
+
rowGap: '8',
|
|
1036
|
+
width: '16rem !custom',
|
|
1037
|
+
})
|
|
1038
|
+
|
|
1039
|
+
export const value = style({
|
|
1040
|
+
alignItems: 'center',
|
|
1041
|
+
color: 'content.primary',
|
|
1042
|
+
columnGap: '4',
|
|
1043
|
+
display: 'flex',
|
|
1044
|
+
typography: 'mono.m1',
|
|
1045
|
+
})
|
|
1046
|
+
}
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
**Don't:** Place one copy button away from the values, where its target is unclear.
|
|
1050
|
+
|
|
1051
|
+
```tsx
|
|
1052
|
+
/**
|
|
1053
|
+
* Don't example for "Place It Right After the Value" on the CopyButton page.
|
|
1054
|
+
* Don't place one copy button away from the values, where its target is unclear.
|
|
1055
|
+
* @module
|
|
1056
|
+
*/
|
|
1057
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1058
|
+
|
|
1059
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1060
|
+
export function Demo() {
|
|
1061
|
+
return (
|
|
1062
|
+
<div {...styles.rows()}>
|
|
1063
|
+
<div {...styles.header()}>
|
|
1064
|
+
<span {...styles.title()}>Webhook</span>
|
|
1065
|
+
<CopyButton aria-label="Copy" value="wh_51c8e20d" />
|
|
1066
|
+
</div>
|
|
1067
|
+
<div {...styles.row()}>
|
|
1068
|
+
<span {...styles.label()}>Webhook ID</span>
|
|
1069
|
+
<span {...styles.value()}>wh_51c8e20d</span>
|
|
1070
|
+
</div>
|
|
1071
|
+
<div {...styles.row()}>
|
|
1072
|
+
<span {...styles.label()}>Key ID</span>
|
|
1073
|
+
<span {...styles.value()}>key_9f2c41a7</span>
|
|
1074
|
+
</div>
|
|
1075
|
+
</div>
|
|
1076
|
+
)
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
namespace styles {
|
|
1080
|
+
export const header = style({
|
|
1081
|
+
alignItems: 'center',
|
|
1082
|
+
display: 'flex',
|
|
1083
|
+
justifyContent: 'space-between',
|
|
1084
|
+
marginBottom: '4',
|
|
1085
|
+
})
|
|
1086
|
+
|
|
1087
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b2' })
|
|
1088
|
+
|
|
1089
|
+
export const row = style({
|
|
1090
|
+
alignItems: 'center',
|
|
1091
|
+
display: 'flex',
|
|
1092
|
+
justifyContent: 'space-between',
|
|
1093
|
+
minHeight: '32',
|
|
1094
|
+
})
|
|
1095
|
+
|
|
1096
|
+
export const rows = style({
|
|
1097
|
+
display: 'flex',
|
|
1098
|
+
flexDirection: 'column',
|
|
1099
|
+
rowGap: '8',
|
|
1100
|
+
width: '16rem !custom',
|
|
1101
|
+
})
|
|
1102
|
+
|
|
1103
|
+
export const title = style({ color: 'content.primary', typography: 'body.b1Strong' })
|
|
1104
|
+
|
|
1105
|
+
export const value = style({ color: 'content.primary', typography: 'mono.m1' })
|
|
1106
|
+
}
|
|
1107
|
+
```
|
|
1108
|
+
|
|
1109
|
+
#### Copy the Full Value
|
|
1110
|
+
|
|
1111
|
+
Pass the complete value to `value`, even when the screen shows a shortened form.
|
|
1112
|
+
|
|
1113
|
+
**Do:** Copy the complete value behind a shortened display.
|
|
1114
|
+
|
|
1115
|
+
```tsx
|
|
1116
|
+
/**
|
|
1117
|
+
* Do example for "Copy the Full Value" on the CopyButton page.
|
|
1118
|
+
* Copy the complete value behind a shortened display.
|
|
1119
|
+
* @module
|
|
1120
|
+
*/
|
|
1121
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1122
|
+
|
|
1123
|
+
const url = 'https://hooks.tempo.xyz/v1/payments/wh_51c8e20d'
|
|
1124
|
+
|
|
1125
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1126
|
+
export function Demo() {
|
|
1127
|
+
return (
|
|
1128
|
+
<div {...styles.stack()}>
|
|
1129
|
+
<span {...styles.value()}>
|
|
1130
|
+
hooks.tempo.xyz/…/wh_51c8e20d
|
|
1131
|
+
<CopyButton aria-label="Copy webhook URL" copied value={url} />
|
|
1132
|
+
</span>
|
|
1133
|
+
<div {...styles.clipboard()}>
|
|
1134
|
+
<span {...styles.label()}>Clipboard</span>
|
|
1135
|
+
<span {...styles.copied()}>{url}</span>
|
|
1136
|
+
</div>
|
|
1137
|
+
</div>
|
|
1138
|
+
)
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
namespace styles {
|
|
1142
|
+
export const clipboard = style({
|
|
1143
|
+
backgroundColor: 'container.regular',
|
|
1144
|
+
borderRadius: '2xs',
|
|
1145
|
+
display: 'flex',
|
|
1146
|
+
flexDirection: 'column',
|
|
1147
|
+
paddingBlock: '8',
|
|
1148
|
+
paddingInline: '12',
|
|
1149
|
+
rowGap: '2px !custom',
|
|
1150
|
+
})
|
|
1151
|
+
|
|
1152
|
+
export const copied = style({ color: 'content.primary', typography: 'mono.m1' })
|
|
1153
|
+
|
|
1154
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b3' })
|
|
1155
|
+
|
|
1156
|
+
export const stack = style({
|
|
1157
|
+
display: 'flex',
|
|
1158
|
+
flexDirection: 'column',
|
|
1159
|
+
rowGap: '8',
|
|
1160
|
+
width: '17rem !custom',
|
|
1161
|
+
})
|
|
1162
|
+
|
|
1163
|
+
export const value = style({
|
|
1164
|
+
alignItems: 'center',
|
|
1165
|
+
color: 'content.primary',
|
|
1166
|
+
columnGap: '4',
|
|
1167
|
+
display: 'flex',
|
|
1168
|
+
typography: 'mono.m1',
|
|
1169
|
+
})
|
|
1170
|
+
}
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
**Don't:** Copy the shortened text that the screen shows.
|
|
1174
|
+
|
|
1175
|
+
```tsx
|
|
1176
|
+
/**
|
|
1177
|
+
* Don't example for "Copy the Full Value" on the CopyButton page.
|
|
1178
|
+
* Don't copy the shortened text that the screen shows.
|
|
1179
|
+
* @module
|
|
1180
|
+
*/
|
|
1181
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1182
|
+
|
|
1183
|
+
const display = 'hooks.tempo.xyz/…/wh_51c8e20d'
|
|
1184
|
+
|
|
1185
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1186
|
+
export function Demo() {
|
|
1187
|
+
return (
|
|
1188
|
+
<div {...styles.stack()}>
|
|
1189
|
+
<span {...styles.value()}>
|
|
1190
|
+
{display}
|
|
1191
|
+
<CopyButton aria-label="Copy webhook URL" copied value={display} />
|
|
1192
|
+
</span>
|
|
1193
|
+
<div {...styles.clipboard()}>
|
|
1194
|
+
<span {...styles.label()}>Clipboard</span>
|
|
1195
|
+
<span {...styles.copied()}>{display}</span>
|
|
1196
|
+
</div>
|
|
1197
|
+
</div>
|
|
1198
|
+
)
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
namespace styles {
|
|
1202
|
+
export const clipboard = style({
|
|
1203
|
+
backgroundColor: 'container.regular',
|
|
1204
|
+
borderRadius: '2xs',
|
|
1205
|
+
display: 'flex',
|
|
1206
|
+
flexDirection: 'column',
|
|
1207
|
+
paddingBlock: '8',
|
|
1208
|
+
paddingInline: '12',
|
|
1209
|
+
rowGap: '2px !custom',
|
|
1210
|
+
})
|
|
1211
|
+
|
|
1212
|
+
export const copied = style({ color: 'content.primary', typography: 'mono.m1' })
|
|
1213
|
+
|
|
1214
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b3' })
|
|
1215
|
+
|
|
1216
|
+
export const stack = style({
|
|
1217
|
+
display: 'flex',
|
|
1218
|
+
flexDirection: 'column',
|
|
1219
|
+
rowGap: '8',
|
|
1220
|
+
width: '17rem !custom',
|
|
1221
|
+
})
|
|
1222
|
+
|
|
1223
|
+
export const value = style({
|
|
1224
|
+
alignItems: 'center',
|
|
1225
|
+
color: 'content.primary',
|
|
1226
|
+
columnGap: '4',
|
|
1227
|
+
display: 'flex',
|
|
1228
|
+
typography: 'mono.m1',
|
|
1229
|
+
})
|
|
1230
|
+
}
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
#### Keep the Built-In Confirmation
|
|
1234
|
+
|
|
1235
|
+
After a copy, the icon turns into a check for two seconds and screen readers announce Copied. If the clipboard refuses the write, the button shows no confirmation and doesn't call `onCopy`, so keep the value selectable as text.
|
|
1236
|
+
|
|
1237
|
+
**Do:** Let the check icon confirm the copy.
|
|
1238
|
+
|
|
1239
|
+
```tsx
|
|
1240
|
+
/**
|
|
1241
|
+
* Do example for "Keep the Built-In Confirmation" on the CopyButton page.
|
|
1242
|
+
* Let the check icon confirm the copy.
|
|
1243
|
+
* @module
|
|
1244
|
+
*/
|
|
1245
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1246
|
+
|
|
1247
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1248
|
+
export function Demo() {
|
|
1249
|
+
return (
|
|
1250
|
+
<div {...styles.stack()}>
|
|
1251
|
+
<div {...styles.row()}>
|
|
1252
|
+
<span {...styles.label()}>Webhook ID</span>
|
|
1253
|
+
<span {...styles.value()}>
|
|
1254
|
+
wh_51c8e20d
|
|
1255
|
+
<CopyButton aria-label="Copy webhook ID" copied value="wh_51c8e20d" />
|
|
1256
|
+
</span>
|
|
1257
|
+
</div>
|
|
1258
|
+
</div>
|
|
1259
|
+
)
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
namespace styles {
|
|
1263
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b2' })
|
|
1264
|
+
|
|
1265
|
+
export const row = style({
|
|
1266
|
+
alignItems: 'center',
|
|
1267
|
+
display: 'flex',
|
|
1268
|
+
justifyContent: 'space-between',
|
|
1269
|
+
minHeight: '32',
|
|
1270
|
+
})
|
|
1271
|
+
|
|
1272
|
+
export const stack = style({
|
|
1273
|
+
display: 'flex',
|
|
1274
|
+
flexDirection: 'column',
|
|
1275
|
+
rowGap: '16',
|
|
1276
|
+
width: '16rem !custom',
|
|
1277
|
+
})
|
|
1278
|
+
|
|
1279
|
+
export const value = style({
|
|
1280
|
+
alignItems: 'center',
|
|
1281
|
+
color: 'content.primary',
|
|
1282
|
+
columnGap: '4',
|
|
1283
|
+
display: 'flex',
|
|
1284
|
+
typography: 'mono.m1',
|
|
1285
|
+
})
|
|
1286
|
+
}
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
**Don't:** Add a [Toast](feedback-and-status.md#toast) or text such as Copied to clipboard.
|
|
1290
|
+
|
|
1291
|
+
```tsx
|
|
1292
|
+
/**
|
|
1293
|
+
* Don't example for "Keep the Built-In Confirmation" on the CopyButton page.
|
|
1294
|
+
* Don't add a Toast or text such as Copied to clipboard.
|
|
1295
|
+
* @module
|
|
1296
|
+
*/
|
|
1297
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1298
|
+
import { CheckCircle } from '@tempoxyz/ds/icons'
|
|
1299
|
+
|
|
1300
|
+
// Toasts render in a portal, so this preview draws one in place with the toast's styles.
|
|
1301
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1302
|
+
export function Demo() {
|
|
1303
|
+
return (
|
|
1304
|
+
<div {...styles.stack()}>
|
|
1305
|
+
<div {...styles.row()}>
|
|
1306
|
+
<span {...styles.label()}>Webhook ID</span>
|
|
1307
|
+
<span {...styles.value()}>
|
|
1308
|
+
wh_51c8e20d
|
|
1309
|
+
<CopyButton aria-label="Copy webhook ID" copied value="wh_51c8e20d" />
|
|
1310
|
+
</span>
|
|
1311
|
+
</div>
|
|
1312
|
+
<div {...styles.toast()}>
|
|
1313
|
+
<CheckCircle {...styles.icon()} />
|
|
1314
|
+
<span {...styles.title()}>Copied to clipboard</span>
|
|
1315
|
+
</div>
|
|
1316
|
+
</div>
|
|
1317
|
+
)
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
namespace styles {
|
|
1321
|
+
export const icon = style({ color: 'content.positive', flexShrink: '0 !custom', fontSize: '20' })
|
|
1322
|
+
|
|
1323
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b2' })
|
|
1324
|
+
|
|
1325
|
+
export const row = style({
|
|
1326
|
+
alignItems: 'center',
|
|
1327
|
+
display: 'flex',
|
|
1328
|
+
justifyContent: 'space-between',
|
|
1329
|
+
minHeight: '32',
|
|
1330
|
+
})
|
|
1331
|
+
|
|
1332
|
+
export const stack = style({
|
|
1333
|
+
display: 'flex',
|
|
1334
|
+
flexDirection: 'column',
|
|
1335
|
+
rowGap: '16',
|
|
1336
|
+
width: '16rem !custom',
|
|
1337
|
+
})
|
|
1338
|
+
|
|
1339
|
+
export const title = style({ color: 'content.primary', typography: 'body.b2Strong' })
|
|
1340
|
+
|
|
1341
|
+
export const toast = style({
|
|
1342
|
+
alignItems: 'center',
|
|
1343
|
+
backgroundColor: 'background.elevated',
|
|
1344
|
+
borderRadius: 'sm',
|
|
1345
|
+
boxShadow: 'regular',
|
|
1346
|
+
boxSizing: 'border-box',
|
|
1347
|
+
columnGap: '12',
|
|
1348
|
+
display: 'flex',
|
|
1349
|
+
paddingBlock: '16',
|
|
1350
|
+
paddingInline: '20',
|
|
1351
|
+
})
|
|
1352
|
+
|
|
1353
|
+
export const value = style({
|
|
1354
|
+
alignItems: 'center',
|
|
1355
|
+
color: 'content.primary',
|
|
1356
|
+
columnGap: '4',
|
|
1357
|
+
display: 'flex',
|
|
1358
|
+
typography: 'mono.m1',
|
|
1359
|
+
})
|
|
1360
|
+
}
|
|
1361
|
+
```
|
|
1362
|
+
|
|
1363
|
+
#### Choose a Variant by Context
|
|
1364
|
+
|
|
1365
|
+
* **Text (default):** Inline values in rows, tables, and cards.
|
|
1366
|
+
* **Secondary (secondary):** A standalone value you mainly copy, such as an invite link.
|
|
1367
|
+
|
|
1368
|
+
Keep `small` beside body text. Use `medium` or `large` in touch layouts, or beside a large value or a control of that size.
|
|
1369
|
+
|
|
1370
|
+
#### Let a Clickable Row Copy
|
|
1371
|
+
|
|
1372
|
+
If a whole row copies on press, handle the copy in the row and pass `copied` to the button. The button shows the confirmation without a second copy. [Snippet](data-display.md#snippet) and [SecretValue](blockchain.md#secretvalue) work this way.
|
|
1373
|
+
|
|
1374
|
+
**Do:** Pass `copied` so the button confirms the row's copy.
|
|
1375
|
+
|
|
1376
|
+
```tsx
|
|
1377
|
+
/**
|
|
1378
|
+
* Do example for "Let a Clickable Row Copy" on the CopyButton page.
|
|
1379
|
+
* Pass `copied` so the button confirms the row's copy.
|
|
1380
|
+
* @module
|
|
1381
|
+
*/
|
|
1382
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1383
|
+
|
|
1384
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1385
|
+
export function Demo() {
|
|
1386
|
+
return (
|
|
1387
|
+
<div {...styles.row()}>
|
|
1388
|
+
<span {...styles.label()}>Invite link</span>
|
|
1389
|
+
<span {...styles.value()}>
|
|
1390
|
+
tempo.xyz/invite/7kq2
|
|
1391
|
+
<CopyButton aria-label="Copy invite link" copied value="https://tempo.xyz/invite/7kq2" />
|
|
1392
|
+
</span>
|
|
1393
|
+
</div>
|
|
1394
|
+
)
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
namespace styles {
|
|
1398
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b2' })
|
|
1399
|
+
|
|
1400
|
+
// The pressed row draws its hover background, since the preview is inert.
|
|
1401
|
+
export const row = style({
|
|
1402
|
+
alignItems: 'center',
|
|
1403
|
+
backgroundColor: 'container.regular',
|
|
1404
|
+
borderRadius: 'xs',
|
|
1405
|
+
boxSizing: 'border-box',
|
|
1406
|
+
display: 'flex',
|
|
1407
|
+
justifyContent: 'space-between',
|
|
1408
|
+
minHeight: '40',
|
|
1409
|
+
paddingInline: '12',
|
|
1410
|
+
width: '17rem !custom',
|
|
1411
|
+
})
|
|
1412
|
+
|
|
1413
|
+
export const value = style({
|
|
1414
|
+
alignItems: 'center',
|
|
1415
|
+
color: 'content.primary',
|
|
1416
|
+
columnGap: '4',
|
|
1417
|
+
display: 'flex',
|
|
1418
|
+
typography: 'mono.m1',
|
|
1419
|
+
})
|
|
1420
|
+
}
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
**Don't:** Leave the button unconfirmed after the row copies.
|
|
1424
|
+
|
|
1425
|
+
```tsx
|
|
1426
|
+
/**
|
|
1427
|
+
* Don't example for "Let a Clickable Row Copy" on the CopyButton page.
|
|
1428
|
+
* Don't leave the button unconfirmed after the row copies.
|
|
1429
|
+
* @module
|
|
1430
|
+
*/
|
|
1431
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1432
|
+
|
|
1433
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1434
|
+
export function Demo() {
|
|
1435
|
+
return (
|
|
1436
|
+
<div {...styles.row()}>
|
|
1437
|
+
<span {...styles.label()}>Invite link</span>
|
|
1438
|
+
<span {...styles.value()}>
|
|
1439
|
+
tempo.xyz/invite/7kq2
|
|
1440
|
+
<CopyButton aria-label="Copy invite link" value="https://tempo.xyz/invite/7kq2" />
|
|
1441
|
+
</span>
|
|
1442
|
+
</div>
|
|
1443
|
+
)
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
namespace styles {
|
|
1447
|
+
export const label = style({ color: 'content.secondary', typography: 'body.b2' })
|
|
1448
|
+
|
|
1449
|
+
// The pressed row draws its hover background, since the preview is inert.
|
|
1450
|
+
export const row = style({
|
|
1451
|
+
alignItems: 'center',
|
|
1452
|
+
backgroundColor: 'container.regular',
|
|
1453
|
+
borderRadius: 'xs',
|
|
1454
|
+
boxSizing: 'border-box',
|
|
1455
|
+
display: 'flex',
|
|
1456
|
+
justifyContent: 'space-between',
|
|
1457
|
+
minHeight: '40',
|
|
1458
|
+
paddingInline: '12',
|
|
1459
|
+
width: '17rem !custom',
|
|
1460
|
+
})
|
|
1461
|
+
|
|
1462
|
+
export const value = style({
|
|
1463
|
+
alignItems: 'center',
|
|
1464
|
+
color: 'content.primary',
|
|
1465
|
+
columnGap: '4',
|
|
1466
|
+
display: 'flex',
|
|
1467
|
+
typography: 'mono.m1',
|
|
1468
|
+
})
|
|
1469
|
+
}
|
|
1470
|
+
```
|
|
1471
|
+
|
|
1472
|
+
### Accessibility
|
|
1473
|
+
|
|
1474
|
+
A copy button renders an icon-only [Button](#button) with a visually hidden status message. It follows the [WAI-ARIA Authoring Practices button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/).
|
|
1475
|
+
|
|
1476
|
+
#### Semantics
|
|
1477
|
+
|
|
1478
|
+
* **Button (button):** A native button. Enter and Space copy, and it joins the tab order.
|
|
1479
|
+
* **Name (aria-label):** Defaults to "Copy" and the value. Shows on hover, not on focus or touch.
|
|
1480
|
+
* **Copied State (2s):** After a copy, the name changes to "Copied", then returns.
|
|
1481
|
+
* **Status Region (status):** A polite live region holds the confirmation text.
|
|
1482
|
+
* **Disabled (disabled):** Removes the button from the tab order unless you set `focusableWhenDisabled`.
|
|
1483
|
+
* **Clipboard Fallback (execCommand):** Copies where the Clipboard API is unavailable, such as insecure contexts and some iframes.
|
|
1484
|
+
|
|
1485
|
+
#### Keyboard
|
|
1486
|
+
|
|
1487
|
+
* **Move Focus to the Button (Tab):** Moves focus to the button.
|
|
1488
|
+
* **Copy the Value (Enter or Space):** Copies the value.
|
|
1489
|
+
|
|
1490
|
+
#### Your Responsibilities
|
|
1491
|
+
|
|
1492
|
+
* **Name What It Copies (aria-label):** Name the value, such as "Copy address". A raw address reads poorly.
|
|
1493
|
+
* **Announce Parent Failures (copied):** If a parent copies on its own click, announce failures from that parent.
|
|
1494
|
+
|
|
1495
|
+
### Related
|
|
1496
|
+
|
|
1497
|
+
[Hex](blockchain.md#hex)
|
|
1498
|
+
|
|
1499
|
+
Use for addresses and hashes with copying built in.
|
|
1500
|
+
|
|
1501
|
+
[Snippet](data-display.md#snippet)
|
|
1502
|
+
|
|
1503
|
+
Use for commands and code.
|
|
1504
|
+
|
|
1505
|
+
[SecretValue](blockchain.md#secretvalue)
|
|
1506
|
+
|
|
1507
|
+
Use for API keys and secrets.
|
|
1508
|
+
|
|
1509
|
+
[Button](#button)
|
|
1510
|
+
|
|
1511
|
+
Use for other icon-only actions.
|
|
1512
|
+
|
|
1513
|
+
[Blockchain Values](../patterns.md#blockchain-values)
|
|
1514
|
+
|
|
1515
|
+
Covers showing addresses, hashes, and amounts.
|
|
1516
|
+
|
|
1517
|
+
### Examples
|
|
1518
|
+
|
|
1519
|
+
#### Basic
|
|
1520
|
+
|
|
1521
|
+
```tsx
|
|
1522
|
+
import { CopyButton } from '@tempoxyz/ds'
|
|
1523
|
+
|
|
1524
|
+
export function Demo() {
|
|
1525
|
+
return <CopyButton value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" />
|
|
1526
|
+
}
|
|
1527
|
+
```
|
|
1528
|
+
|
|
1529
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/CopyButton/Basic.tsx)
|
|
1530
|
+
|
|
1531
|
+
#### Size
|
|
1532
|
+
|
|
1533
|
+
Set `size` to `small` (default), `medium`, or `large`.
|
|
1534
|
+
|
|
1535
|
+
```tsx
|
|
1536
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1537
|
+
|
|
1538
|
+
const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
|
|
1539
|
+
|
|
1540
|
+
export function Demo() {
|
|
1541
|
+
return (
|
|
1542
|
+
<div {...styles.row()}>
|
|
1543
|
+
{(['small', 'medium', 'large'] as const).map((size) => (
|
|
1544
|
+
<CopyButton key={size} size={size} value={address} />
|
|
1545
|
+
))}
|
|
1546
|
+
</div>
|
|
1547
|
+
)
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
namespace styles {
|
|
1551
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
1552
|
+
}
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/CopyButton/Size.tsx)
|
|
1556
|
+
|
|
1557
|
+
#### Variant
|
|
1558
|
+
|
|
1559
|
+
Set `variant` to any [Button](#button) variant, such as `tertiary` (default) or `secondary`.
|
|
1560
|
+
|
|
1561
|
+
```tsx
|
|
1562
|
+
import { CopyButton, style } from '@tempoxyz/ds'
|
|
1563
|
+
|
|
1564
|
+
const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
|
|
1565
|
+
|
|
1566
|
+
export function Demo() {
|
|
1567
|
+
return (
|
|
1568
|
+
<div {...styles.row()}>
|
|
1569
|
+
<CopyButton value={address} />
|
|
1570
|
+
<CopyButton value={address} variant="secondary" />
|
|
1571
|
+
<CopyButton size="medium" value={address} variant="secondary" />
|
|
1572
|
+
</div>
|
|
1573
|
+
)
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
namespace styles {
|
|
1577
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
1578
|
+
}
|
|
1579
|
+
```
|
|
1580
|
+
|
|
1581
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/CopyButton/Variant.tsx)
|
|
1582
|
+
|
|
1583
|
+
#### Disabled
|
|
1584
|
+
|
|
1585
|
+
```tsx
|
|
1586
|
+
import { CopyButton } from '@tempoxyz/ds'
|
|
1587
|
+
|
|
1588
|
+
export function Demo() {
|
|
1589
|
+
return <CopyButton disabled value="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" />
|
|
1590
|
+
}
|
|
1591
|
+
```
|
|
1592
|
+
|
|
1593
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/CopyButton/Disabled.tsx)
|
|
1594
|
+
|
|
1595
|
+
## SplitButton
|
|
1596
|
+
|
|
1597
|
+
Pairs a primary action with a menu of alternatives.
|
|
1598
|
+
|
|
1599
|
+
[View source and API](https://github.com/tempoxyz/ds/blob/main/src/web/components/SplitButton.tsx)
|
|
1600
|
+
|
|
1601
|
+
### Overview
|
|
1602
|
+
|
|
1603
|
+
A split button places the most common action beside a trigger that opens a menu of alternatives.
|
|
1604
|
+
|
|
1605
|
+
### Anatomy
|
|
1606
|
+
|
|
1607
|
+
Import the component and assemble its parts.
|
|
1608
|
+
|
|
1609
|
+
```tsx
|
|
1610
|
+
import { Menu, SplitButton } from '@tempoxyz/ds'
|
|
1611
|
+
|
|
1612
|
+
<SplitButton.Root>
|
|
1613
|
+
<SplitButton.Action />
|
|
1614
|
+
<Menu.Root>
|
|
1615
|
+
<SplitButton.Trigger />
|
|
1616
|
+
<Menu.Popup />
|
|
1617
|
+
</Menu.Root>
|
|
1618
|
+
</SplitButton.Root>
|
|
1619
|
+
```
|
|
1620
|
+
|
|
1621
|
+
### Guidelines
|
|
1622
|
+
|
|
1623
|
+
#### When to Use
|
|
1624
|
+
|
|
1625
|
+
* Offer a main action with a few variations, such as Export CSV with Export JSON and Schedule export.
|
|
1626
|
+
* Keep the common choice one press away, such as Create key with Create test key.
|
|
1627
|
+
|
|
1628
|
+
#### When Not to Use
|
|
1629
|
+
|
|
1630
|
+
* Use a [Button](#button) with a [Menu](overlays.md#menu) when no option is the clear default.
|
|
1631
|
+
* Use two [Buttons](#button) when both actions matter equally.
|
|
1632
|
+
* Use [Select](forms-and-inputs.md#select) or [ChoiceGroup](forms-and-inputs.md#choicegroup) to choose a value or mode, not to run an action.
|
|
1633
|
+
* Use a separate [Button](#button) for destructive actions, confirmed with an [AlertDialog](overlays.md#alertdialog).
|
|
1634
|
+
|
|
1635
|
+
#### Make the Action the Common Choice
|
|
1636
|
+
|
|
1637
|
+
`SplitButton.Action` runs without opening the menu, so give it the option most people pick. If people often open the menu first, move the popular option into the action, or use a [Menu](overlays.md#menu) button.
|
|
1638
|
+
|
|
1639
|
+
**Do:** Put the option most people pick on the action.
|
|
1640
|
+
|
|
1641
|
+
```tsx
|
|
1642
|
+
/**
|
|
1643
|
+
* Do example for "Make the Action the Common Choice" on the SplitButton page.
|
|
1644
|
+
* Put the option most people pick on the action.
|
|
1645
|
+
* @module
|
|
1646
|
+
*/
|
|
1647
|
+
import { Menu, SplitButton, style } from '@tempoxyz/ds'
|
|
1648
|
+
|
|
1649
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1650
|
+
export function Demo() {
|
|
1651
|
+
return (
|
|
1652
|
+
<div {...styles.stack()}>
|
|
1653
|
+
<SplitButton.Root aria-label="Keys">
|
|
1654
|
+
<SplitButton.Action>Create key</SplitButton.Action>
|
|
1655
|
+
<Menu.Root>
|
|
1656
|
+
<SplitButton.Trigger aria-label="More key options" />
|
|
1657
|
+
</Menu.Root>
|
|
1658
|
+
</SplitButton.Root>
|
|
1659
|
+
<div {...styles.popup()}>
|
|
1660
|
+
<div {...styles.item()}>Create test key</div>
|
|
1661
|
+
<div {...styles.item()}>Import key</div>
|
|
1662
|
+
</div>
|
|
1663
|
+
</div>
|
|
1664
|
+
)
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
namespace styles {
|
|
1668
|
+
export const item = style({
|
|
1669
|
+
alignItems: 'center',
|
|
1670
|
+
borderRadius: 'xs',
|
|
1671
|
+
color: 'content.primary',
|
|
1672
|
+
display: 'flex',
|
|
1673
|
+
minHeight: '40',
|
|
1674
|
+
paddingInline: '12',
|
|
1675
|
+
typography: 'body.b2Strong',
|
|
1676
|
+
})
|
|
1677
|
+
|
|
1678
|
+
export const popup = style({
|
|
1679
|
+
backgroundColor: 'background.elevated',
|
|
1680
|
+
borderRadius: 'sm',
|
|
1681
|
+
boxShadow: 'regular',
|
|
1682
|
+
boxSizing: 'border-box',
|
|
1683
|
+
minWidth: '14rem !custom',
|
|
1684
|
+
padding: '12',
|
|
1685
|
+
})
|
|
1686
|
+
|
|
1687
|
+
export const stack = style({
|
|
1688
|
+
alignItems: 'flex-end',
|
|
1689
|
+
display: 'flex',
|
|
1690
|
+
flexDirection: 'column',
|
|
1691
|
+
rowGap: '4',
|
|
1692
|
+
})
|
|
1693
|
+
}
|
|
1694
|
+
```
|
|
1695
|
+
|
|
1696
|
+
**Don't:** Put a rare option on the action and the common one in the menu.
|
|
1697
|
+
|
|
1698
|
+
```tsx
|
|
1699
|
+
/**
|
|
1700
|
+
* Don't example for "Make the Action the Common Choice" on the SplitButton page.
|
|
1701
|
+
* Don't put a rare option on the action and the common one in the menu.
|
|
1702
|
+
* @module
|
|
1703
|
+
*/
|
|
1704
|
+
import { Menu, SplitButton, style } from '@tempoxyz/ds'
|
|
1705
|
+
|
|
1706
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1707
|
+
export function Demo() {
|
|
1708
|
+
return (
|
|
1709
|
+
<div {...styles.stack()}>
|
|
1710
|
+
<SplitButton.Root aria-label="Keys">
|
|
1711
|
+
<SplitButton.Action>Import key</SplitButton.Action>
|
|
1712
|
+
<Menu.Root>
|
|
1713
|
+
<SplitButton.Trigger aria-label="More key options" />
|
|
1714
|
+
</Menu.Root>
|
|
1715
|
+
</SplitButton.Root>
|
|
1716
|
+
<div {...styles.popup()}>
|
|
1717
|
+
<div {...styles.item()}>Create key</div>
|
|
1718
|
+
<div {...styles.item()}>Create test key</div>
|
|
1719
|
+
</div>
|
|
1720
|
+
</div>
|
|
1721
|
+
)
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
namespace styles {
|
|
1725
|
+
export const item = style({
|
|
1726
|
+
alignItems: 'center',
|
|
1727
|
+
borderRadius: 'xs',
|
|
1728
|
+
color: 'content.primary',
|
|
1729
|
+
display: 'flex',
|
|
1730
|
+
minHeight: '40',
|
|
1731
|
+
paddingInline: '12',
|
|
1732
|
+
typography: 'body.b2Strong',
|
|
1733
|
+
})
|
|
1734
|
+
|
|
1735
|
+
export const popup = style({
|
|
1736
|
+
backgroundColor: 'background.elevated',
|
|
1737
|
+
borderRadius: 'sm',
|
|
1738
|
+
boxShadow: 'regular',
|
|
1739
|
+
boxSizing: 'border-box',
|
|
1740
|
+
minWidth: '14rem !custom',
|
|
1741
|
+
padding: '12',
|
|
1742
|
+
})
|
|
1743
|
+
|
|
1744
|
+
export const stack = style({
|
|
1745
|
+
alignItems: 'flex-end',
|
|
1746
|
+
display: 'flex',
|
|
1747
|
+
flexDirection: 'column',
|
|
1748
|
+
rowGap: '4',
|
|
1749
|
+
})
|
|
1750
|
+
}
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
#### Keep Alternatives Related
|
|
1754
|
+
|
|
1755
|
+
Make every menu item a variation of the action, such as a different format or timing, and use two to five of them. Put unrelated commands, or a longer list, in a [Menu](overlays.md#menu).
|
|
1756
|
+
|
|
1757
|
+
**Do:** Fill the menu with variations of the main action.
|
|
1758
|
+
|
|
1759
|
+
```tsx
|
|
1760
|
+
/**
|
|
1761
|
+
* Do example for "Keep Alternatives Related" on the SplitButton page.
|
|
1762
|
+
* Fill the menu with variations of the main action.
|
|
1763
|
+
* @module
|
|
1764
|
+
*/
|
|
1765
|
+
import { Menu, SplitButton, style } from '@tempoxyz/ds'
|
|
1766
|
+
|
|
1767
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1768
|
+
export function Demo() {
|
|
1769
|
+
return (
|
|
1770
|
+
<div {...styles.stack()}>
|
|
1771
|
+
<SplitButton.Root aria-label="Export" variant="secondary">
|
|
1772
|
+
<SplitButton.Action>Export CSV</SplitButton.Action>
|
|
1773
|
+
<Menu.Root>
|
|
1774
|
+
<SplitButton.Trigger aria-label="More export options" />
|
|
1775
|
+
</Menu.Root>
|
|
1776
|
+
</SplitButton.Root>
|
|
1777
|
+
<div {...styles.popup()}>
|
|
1778
|
+
<div {...styles.item()}>Export JSON</div>
|
|
1779
|
+
<div {...styles.item()}>Schedule export</div>
|
|
1780
|
+
</div>
|
|
1781
|
+
</div>
|
|
1782
|
+
)
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
namespace styles {
|
|
1786
|
+
export const item = style({
|
|
1787
|
+
alignItems: 'center',
|
|
1788
|
+
borderRadius: 'xs',
|
|
1789
|
+
color: 'content.primary',
|
|
1790
|
+
display: 'flex',
|
|
1791
|
+
minHeight: '40',
|
|
1792
|
+
paddingInline: '12',
|
|
1793
|
+
typography: 'body.b2Strong',
|
|
1794
|
+
})
|
|
1795
|
+
|
|
1796
|
+
export const popup = style({
|
|
1797
|
+
backgroundColor: 'background.elevated',
|
|
1798
|
+
borderRadius: 'sm',
|
|
1799
|
+
boxShadow: 'regular',
|
|
1800
|
+
boxSizing: 'border-box',
|
|
1801
|
+
minWidth: '14rem !custom',
|
|
1802
|
+
padding: '12',
|
|
1803
|
+
})
|
|
1804
|
+
|
|
1805
|
+
export const stack = style({
|
|
1806
|
+
alignItems: 'flex-end',
|
|
1807
|
+
display: 'flex',
|
|
1808
|
+
flexDirection: 'column',
|
|
1809
|
+
rowGap: '4',
|
|
1810
|
+
})
|
|
1811
|
+
}
|
|
1812
|
+
```
|
|
1813
|
+
|
|
1814
|
+
**Don't:** Collect unrelated or destructive commands behind the trigger.
|
|
1815
|
+
|
|
1816
|
+
```tsx
|
|
1817
|
+
/**
|
|
1818
|
+
* Don't example for "Keep Alternatives Related" on the SplitButton page.
|
|
1819
|
+
* Don't collect unrelated or destructive commands behind the trigger.
|
|
1820
|
+
* @module
|
|
1821
|
+
*/
|
|
1822
|
+
import { Menu, SplitButton, style, variants } from '@tempoxyz/ds'
|
|
1823
|
+
|
|
1824
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1825
|
+
export function Demo() {
|
|
1826
|
+
return (
|
|
1827
|
+
<div {...styles.stack()}>
|
|
1828
|
+
<SplitButton.Root aria-label="Export" variant="secondary">
|
|
1829
|
+
<SplitButton.Action>Export CSV</SplitButton.Action>
|
|
1830
|
+
<Menu.Root>
|
|
1831
|
+
<SplitButton.Trigger aria-label="More options" />
|
|
1832
|
+
</Menu.Root>
|
|
1833
|
+
</SplitButton.Root>
|
|
1834
|
+
<div {...styles.popup()}>
|
|
1835
|
+
<div {...styles.item()}>Rename dashboard</div>
|
|
1836
|
+
<div {...styles.item()}>Share</div>
|
|
1837
|
+
<div {...styles.item({ intent: 'negative' })}>Delete dashboard</div>
|
|
1838
|
+
</div>
|
|
1839
|
+
</div>
|
|
1840
|
+
)
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
namespace styles {
|
|
1844
|
+
export const item = variants({
|
|
1845
|
+
base: {
|
|
1846
|
+
alignItems: 'center',
|
|
1847
|
+
borderRadius: 'xs',
|
|
1848
|
+
color: 'content.primary',
|
|
1849
|
+
display: 'flex',
|
|
1850
|
+
minHeight: '40',
|
|
1851
|
+
paddingInline: '12',
|
|
1852
|
+
typography: 'body.b2Strong',
|
|
1853
|
+
},
|
|
1854
|
+
defaultVariants: { intent: 'default' },
|
|
1855
|
+
variants: {
|
|
1856
|
+
intent: {
|
|
1857
|
+
default: {},
|
|
1858
|
+
negative: { color: 'content.negative' },
|
|
1859
|
+
},
|
|
1860
|
+
},
|
|
1861
|
+
})
|
|
1862
|
+
|
|
1863
|
+
export const popup = style({
|
|
1864
|
+
backgroundColor: 'background.elevated',
|
|
1865
|
+
borderRadius: 'sm',
|
|
1866
|
+
boxShadow: 'regular',
|
|
1867
|
+
boxSizing: 'border-box',
|
|
1868
|
+
minWidth: '14rem !custom',
|
|
1869
|
+
padding: '12',
|
|
1870
|
+
})
|
|
1871
|
+
|
|
1872
|
+
export const stack = style({
|
|
1873
|
+
alignItems: 'flex-end',
|
|
1874
|
+
display: 'flex',
|
|
1875
|
+
flexDirection: 'column',
|
|
1876
|
+
rowGap: '4',
|
|
1877
|
+
})
|
|
1878
|
+
}
|
|
1879
|
+
```
|
|
1880
|
+
|
|
1881
|
+
#### Match the Buttons Around It
|
|
1882
|
+
|
|
1883
|
+
Set `variant` and `size` on `SplitButton.Root`, and both buttons follow. A split button counts toward the one `primary` action per section, so use `secondary` when the view already has one. Use `small` in toolbars and table headers.
|
|
1884
|
+
|
|
1885
|
+
**Do:** Match the size of nearby buttons, and leave `primary` to the main action.
|
|
1886
|
+
|
|
1887
|
+
```tsx
|
|
1888
|
+
/**
|
|
1889
|
+
* Do example for "Match the Buttons Around It" on the SplitButton page.
|
|
1890
|
+
* Match the size of nearby buttons, and leave `primary` to the main action.
|
|
1891
|
+
* @module
|
|
1892
|
+
*/
|
|
1893
|
+
import { Button, Menu, SplitButton, style } from '@tempoxyz/ds'
|
|
1894
|
+
|
|
1895
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1896
|
+
export function Demo() {
|
|
1897
|
+
return (
|
|
1898
|
+
<div {...styles.row()}>
|
|
1899
|
+
<SplitButton.Root aria-label="Export" size="small" variant="secondary">
|
|
1900
|
+
<SplitButton.Action>Export CSV</SplitButton.Action>
|
|
1901
|
+
<Menu.Root>
|
|
1902
|
+
<SplitButton.Trigger aria-label="More export options" />
|
|
1903
|
+
</Menu.Root>
|
|
1904
|
+
</SplitButton.Root>
|
|
1905
|
+
<Button size="small">Send payment</Button>
|
|
1906
|
+
</div>
|
|
1907
|
+
)
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
namespace styles {
|
|
1911
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '8' })
|
|
1912
|
+
}
|
|
1913
|
+
```
|
|
1914
|
+
|
|
1915
|
+
**Don't:** Add a second `primary` action, or a size that differs from its neighbors.
|
|
1916
|
+
|
|
1917
|
+
```tsx
|
|
1918
|
+
/**
|
|
1919
|
+
* Don't example for "Match the Buttons Around It" on the SplitButton page.
|
|
1920
|
+
* Don't add a second `primary` action, or a size that differs from its neighbors.
|
|
1921
|
+
* @module
|
|
1922
|
+
*/
|
|
1923
|
+
import { Button, Menu, SplitButton, style } from '@tempoxyz/ds'
|
|
1924
|
+
|
|
1925
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
1926
|
+
export function Demo() {
|
|
1927
|
+
return (
|
|
1928
|
+
<div {...styles.row()}>
|
|
1929
|
+
<SplitButton.Root aria-label="Export">
|
|
1930
|
+
<SplitButton.Action>Export CSV</SplitButton.Action>
|
|
1931
|
+
<Menu.Root>
|
|
1932
|
+
<SplitButton.Trigger aria-label="More export options" />
|
|
1933
|
+
</Menu.Root>
|
|
1934
|
+
</SplitButton.Root>
|
|
1935
|
+
<Button size="small">Send payment</Button>
|
|
1936
|
+
</div>
|
|
1937
|
+
)
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
namespace styles {
|
|
1941
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '8' })
|
|
1942
|
+
}
|
|
1943
|
+
```
|
|
1944
|
+
|
|
1945
|
+
### Content
|
|
1946
|
+
|
|
1947
|
+
#### Name the Action and Its Object
|
|
1948
|
+
|
|
1949
|
+
Label `SplitButton.Action` with a verb and an object, such as Export CSV. A bare Export hides which variation runs.
|
|
1950
|
+
|
|
1951
|
+
#### Make Each Item Stand Alone
|
|
1952
|
+
|
|
1953
|
+
Repeat the verb in each menu item, such as Export JSON, not JSON, so each item reads as a complete action.
|
|
1954
|
+
|
|
1955
|
+
### Accessibility
|
|
1956
|
+
|
|
1957
|
+
`SplitButton` renders a group with a primary [Button](#button) and a menu trigger. The trigger follows the [WAI-ARIA menu button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/).
|
|
1958
|
+
|
|
1959
|
+
#### Semantics
|
|
1960
|
+
|
|
1961
|
+
* **SplitButton.Root (group):** Holds both buttons, named by its `aria-label`.
|
|
1962
|
+
* **SplitButton.Action (button):** The primary action, as a native button.
|
|
1963
|
+
* **SplitButton.Trigger (aria-haspopup):** A native button that announces its menu and open state.
|
|
1964
|
+
* **Menu (menu):** Named by the trigger. Items are announced as menu items.
|
|
1965
|
+
* **Chevron (reduced motion):** Rotates while the menu is open. Flips without animation under reduced motion.
|
|
1966
|
+
|
|
1967
|
+
#### Keyboard
|
|
1968
|
+
|
|
1969
|
+
* **Move Between Buttons (Tab):** Moves focus to the action, then to the trigger.
|
|
1970
|
+
* **Run the Action (Enter or Space):** On the action, runs the primary action.
|
|
1971
|
+
* **Open to the First Item (Enter, Space, or Down Arrow):** Opens the menu and focuses the first item.
|
|
1972
|
+
* **Open to the Last Item (Up Arrow):** Opens the menu and focuses the last item.
|
|
1973
|
+
* **Move Between Items (Down Arrow and Up Arrow):** Move between items, and wrap at the ends.
|
|
1974
|
+
* **Jump to the Ends (Home and End):** Move to the first and last item.
|
|
1975
|
+
* **Activate an Item (Enter):** Activates the focused item and closes the menu.
|
|
1976
|
+
* **Close the Menu (Escape):** Closes the menu.
|
|
1977
|
+
|
|
1978
|
+
#### Your Responsibilities
|
|
1979
|
+
|
|
1980
|
+
* **Name the Group (aria-label):** Name the root, such as "Save", so the pair reads as one group.
|
|
1981
|
+
* **Name the Trigger (aria-label):** Name the alternatives, such as "More save options". The chevron is the trigger's only content.
|
|
1982
|
+
* **Keep Actions Reachable:** If the primary action fails or is disabled, keep every menu action reachable another way.
|
|
1983
|
+
|
|
1984
|
+
### Related
|
|
1985
|
+
|
|
1986
|
+
[Button](#button)
|
|
1987
|
+
|
|
1988
|
+
Use for single actions.
|
|
1989
|
+
|
|
1990
|
+
[Menu](overlays.md#menu)
|
|
1991
|
+
|
|
1992
|
+
Use for lists of actions without a default.
|
|
1993
|
+
|
|
1994
|
+
[AlertDialog](overlays.md#alertdialog)
|
|
1995
|
+
|
|
1996
|
+
Use for confirming destructive actions.
|
|
1997
|
+
|
|
1998
|
+
[Forms](../patterns.md#forms)
|
|
1999
|
+
|
|
2000
|
+
Covers placing actions.
|
|
2001
|
+
|
|
2002
|
+
### Examples
|
|
2003
|
+
|
|
2004
|
+
#### Basic
|
|
2005
|
+
|
|
2006
|
+
```tsx
|
|
2007
|
+
import { Menu, SplitButton } from '@tempoxyz/ds'
|
|
2008
|
+
|
|
2009
|
+
export function Demo() {
|
|
2010
|
+
return (
|
|
2011
|
+
<SplitButton.Root aria-label="Save">
|
|
2012
|
+
<SplitButton.Action>Save</SplitButton.Action>
|
|
2013
|
+
<Menu.Root>
|
|
2014
|
+
<SplitButton.Trigger aria-label="More save options" />
|
|
2015
|
+
<Menu.Popup align="end">
|
|
2016
|
+
<Menu.Item>Save as draft</Menu.Item>
|
|
2017
|
+
<Menu.Item>Save and close</Menu.Item>
|
|
2018
|
+
</Menu.Popup>
|
|
2019
|
+
</Menu.Root>
|
|
2020
|
+
</SplitButton.Root>
|
|
2021
|
+
)
|
|
2022
|
+
}
|
|
2023
|
+
```
|
|
2024
|
+
|
|
2025
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/SplitButton/Basic.tsx)
|
|
2026
|
+
|
|
2027
|
+
#### Variant
|
|
2028
|
+
|
|
2029
|
+
Set `variant` on `SplitButton.Root` to `primary` (default), `secondary`, or `tertiary`.
|
|
2030
|
+
|
|
2031
|
+
```tsx
|
|
2032
|
+
import { Menu, SplitButton, style } from '@tempoxyz/ds'
|
|
2033
|
+
|
|
2034
|
+
export function Demo() {
|
|
2035
|
+
return (
|
|
2036
|
+
<div {...styles.row()}>
|
|
2037
|
+
{(['primary', 'secondary', 'tertiary'] as const).map((variant) => (
|
|
2038
|
+
<SplitButton.Root key={variant} variant={variant}>
|
|
2039
|
+
<SplitButton.Action>Save</SplitButton.Action>
|
|
2040
|
+
<Menu.Root>
|
|
2041
|
+
<SplitButton.Trigger aria-label="More save options" />
|
|
2042
|
+
<Menu.Popup align="end">
|
|
2043
|
+
<Menu.Item>Save as draft</Menu.Item>
|
|
2044
|
+
<Menu.Item>Save and close</Menu.Item>
|
|
2045
|
+
</Menu.Popup>
|
|
2046
|
+
</Menu.Root>
|
|
2047
|
+
</SplitButton.Root>
|
|
2048
|
+
))}
|
|
2049
|
+
</div>
|
|
2050
|
+
)
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
namespace styles {
|
|
2054
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '12' })
|
|
2055
|
+
}
|
|
2056
|
+
```
|
|
2057
|
+
|
|
2058
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/SplitButton/Variant.tsx)
|