@tempoxyz/ds 0.3.10 → 0.3.13
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 +7 -6
- package/dist/docs/AGENTS.md +12 -0
- package/dist/docs/index.md +145 -0
- package/dist/docs/marketing/introduction/getting-started.md +241 -0
- package/dist/docs/product/components/accordion.md +489 -0
- package/dist/docs/product/components/address-card.md +147 -0
- package/dist/docs/product/components/agent-logo.md +194 -0
- package/dist/docs/product/components/alert-dialog.md +631 -0
- package/dist/docs/product/components/alert.md +448 -0
- package/dist/docs/product/components/amount-input.md +305 -0
- package/dist/docs/product/components/amount.md +794 -0
- package/dist/docs/product/components/app-shell.md +559 -0
- package/dist/docs/product/components/asset-chip.md +294 -0
- package/dist/docs/product/components/autocomplete.md +620 -0
- package/dist/docs/product/components/avatar.md +321 -0
- package/dist/docs/product/components/badge.md +339 -0
- package/dist/docs/product/components/badged-logo.md +116 -0
- package/dist/docs/product/components/banner.md +379 -0
- package/dist/docs/product/components/bar-chart.md +208 -0
- package/dist/docs/product/components/breadcrumbs.md +380 -0
- package/dist/docs/product/components/button-group.md +286 -0
- package/dist/docs/product/components/button.md +650 -0
- package/dist/docs/product/components/calendar.md +375 -0
- package/dist/docs/product/components/callout.md +96 -0
- package/dist/docs/product/components/checkbox-group.md +521 -0
- package/dist/docs/product/components/checkbox.md +467 -0
- package/dist/docs/product/components/choice-group.md +516 -0
- package/dist/docs/product/components/choicebox.md +641 -0
- package/dist/docs/product/components/code.md +100 -0
- package/dist/docs/product/components/combobox.md +939 -0
- package/dist/docs/product/components/container.md +257 -0
- package/dist/docs/product/components/copy-button.md +642 -0
- package/dist/docs/product/components/date-picker.md +514 -0
- package/dist/docs/product/components/dialog.md +1332 -0
- package/dist/docs/product/components/drawer.md +966 -0
- package/dist/docs/product/components/empty.md +340 -0
- package/dist/docs/product/components/field.md +570 -0
- package/dist/docs/product/components/fieldset.md +398 -0
- package/dist/docs/product/components/frame.md +434 -0
- package/dist/docs/product/components/gauge.md +299 -0
- package/dist/docs/product/components/get-started-visual.md +117 -0
- package/dist/docs/product/components/grid.md +288 -0
- package/dist/docs/product/components/hero-visual.md +155 -0
- package/dist/docs/product/components/hex.md +487 -0
- package/dist/docs/product/components/icon-tile.md +292 -0
- package/dist/docs/product/components/identicon.md +371 -0
- package/dist/docs/product/components/inline.md +233 -0
- package/dist/docs/product/components/inset.md +225 -0
- package/dist/docs/product/components/kbd.md +423 -0
- package/dist/docs/product/components/list-group.md +981 -0
- package/dist/docs/product/components/loading-dots.md +237 -0
- package/dist/docs/product/components/menu.md +934 -0
- package/dist/docs/product/components/native-select.md +204 -0
- package/dist/docs/product/components/network-logo.md +248 -0
- package/dist/docs/product/components/number-field.md +543 -0
- package/dist/docs/product/components/otp-field.md +616 -0
- package/dist/docs/product/components/pagination.md +516 -0
- package/dist/docs/product/components/popover.md +544 -0
- package/dist/docs/product/components/progress.md +388 -0
- package/dist/docs/product/components/qr.md +314 -0
- package/dist/docs/product/components/radio-group.md +528 -0
- package/dist/docs/product/components/secret-value.md +406 -0
- package/dist/docs/product/components/select.md +751 -0
- package/dist/docs/product/components/separator.md +379 -0
- package/dist/docs/product/components/sidebar-menu.md +922 -0
- package/dist/docs/product/components/skeleton.md +517 -0
- package/dist/docs/product/components/slider.md +539 -0
- package/dist/docs/product/components/snippet.md +424 -0
- package/dist/docs/product/components/spinner.md +216 -0
- package/dist/docs/product/components/split-bar.md +139 -0
- package/dist/docs/product/components/split-button.md +464 -0
- package/dist/docs/product/components/stack.md +299 -0
- package/dist/docs/product/components/status-chip.md +226 -0
- package/dist/docs/product/components/status-indicator.md +119 -0
- package/dist/docs/product/components/status-row.md +174 -0
- package/dist/docs/product/components/stepper.md +451 -0
- package/dist/docs/product/components/success-hero.md +157 -0
- package/dist/docs/product/components/surface.md +639 -0
- package/dist/docs/product/components/switch.md +472 -0
- package/dist/docs/product/components/table.md +967 -0
- package/dist/docs/product/components/tabs.md +627 -0
- package/dist/docs/product/components/tempo-logo.md +185 -0
- package/dist/docs/product/components/text-input.md +624 -0
- package/dist/docs/product/components/textarea.md +352 -0
- package/dist/docs/product/components/toast.md +535 -0
- package/dist/docs/product/components/token-logo.md +371 -0
- package/dist/docs/product/components/token.md +247 -0
- package/dist/docs/product/components/tooltip.md +490 -0
- package/dist/docs/product/components/verification-code.md +116 -0
- package/dist/docs/product/components/visual.md +249 -0
- package/dist/docs/product/components.md +203 -0
- package/dist/docs/product/foundations/accessibility.md +377 -0
- package/dist/docs/product/foundations/agents.md +150 -0
- package/dist/docs/product/foundations/color.md +522 -0
- package/dist/docs/product/foundations/content/tone.md +194 -0
- package/dist/docs/product/foundations/content/voice.md +194 -0
- package/dist/docs/product/foundations/content/writing-style.md +406 -0
- package/dist/docs/product/foundations/iconography.md +282 -0
- package/dist/docs/product/foundations/intent.md +360 -0
- package/dist/docs/product/foundations/layout.md +508 -0
- package/dist/docs/product/foundations/linter.md +496 -0
- package/dist/docs/product/foundations/motion.md +151 -0
- package/dist/docs/product/foundations/radius-and-padding.md +86 -0
- package/dist/docs/product/foundations/typography.md +266 -0
- package/dist/docs/product/introduction/faq.md +133 -0
- package/dist/docs/product/introduction/getting-started.md +377 -0
- package/dist/docs/product/patterns/blockchain-values.md +709 -0
- package/dist/docs/product/patterns/dashboards.md +638 -0
- package/dist/docs/product/patterns/destructive-actions.md +626 -0
- package/dist/docs/product/patterns/empty-states.md +612 -0
- package/dist/docs/product/patterns/errors-and-validation.md +808 -0
- package/dist/docs/product/patterns/feedback-and-status.md +518 -0
- package/dist/docs/product/patterns/forms.md +679 -0
- package/dist/docs/product/patterns/loading.md +630 -0
- package/dist/docs/product/patterns/navigation.md +397 -0
- package/dist/docs/product/patterns/payments.md +765 -0
- package/dist/docs/product/patterns/responsive-layout.md +997 -0
- package/dist/docs/product/patterns/tables-and-lists.md +964 -0
- package/dist/docs/product/products/tempo-console.md +671 -0
- package/dist/docs/product/products/tempo-performance.md +437 -0
- package/dist/docs/product/products/tempo-wallet.md +438 -0
- package/dist/marketing/index.d.ts +4 -0
- package/dist/marketing/index.d.ts.map +1 -0
- package/dist/marketing/index.js +4 -0
- package/dist/marketing/index.js.map +1 -0
- package/dist/marketing/index.js.zyzz.json +1 -0
- package/dist/marketing/vars.d.ts +907 -0
- package/dist/marketing/vars.d.ts.map +1 -0
- package/dist/marketing/vars.js +15 -0
- package/dist/marketing/vars.js.map +1 -0
- package/dist/marketing/vars.js.zyzz.json +1 -0
- package/dist/marketing/zyzz.config.d.ts +4512 -0
- package/dist/marketing/zyzz.config.d.ts.map +1 -0
- package/dist/marketing/zyzz.config.js +63 -0
- package/dist/marketing/zyzz.config.js.map +1 -0
- package/dist/marketing/zyzz.config.js.zyzz.json +1 -0
- package/dist/oxlint/index.d.ts +12 -1
- package/dist/oxlint/index.d.ts.map +1 -1
- package/dist/oxlint/index.js +39 -1
- package/dist/oxlint/index.js.map +1 -1
- package/dist/oxlint/internal/Docs.d.ts +9 -0
- package/dist/oxlint/internal/Docs.d.ts.map +1 -0
- package/dist/oxlint/internal/Docs.js +15 -0
- package/dist/oxlint/internal/Docs.js.map +1 -0
- package/dist/oxlint/internal/Imports.d.ts +1 -1
- package/dist/oxlint/internal/Imports.d.ts.map +1 -1
- package/dist/oxlint/internal/Imports.js +2 -0
- package/dist/oxlint/internal/Imports.js.map +1 -1
- package/dist/oxlint/internal/Styles.d.ts +40 -0
- package/dist/oxlint/internal/Styles.d.ts.map +1 -0
- package/dist/oxlint/internal/Styles.js +194 -0
- package/dist/oxlint/internal/Styles.js.map +1 -0
- package/dist/oxlint/internal/Tokens.d.ts +16 -0
- package/dist/oxlint/internal/Tokens.d.ts.map +1 -0
- package/dist/oxlint/internal/Tokens.js +39 -0
- package/dist/oxlint/internal/Tokens.js.map +1 -0
- package/dist/oxlint/rules/NoCrossSurface.d.ts +2 -2
- package/dist/oxlint/rules/NoCrossSurface.js +3 -3
- package/dist/oxlint/rules/NoCrossSurface.js.map +1 -1
- package/dist/oxlint/rules/NoCustomValues.d.ts +11 -0
- package/dist/oxlint/rules/NoCustomValues.d.ts.map +1 -0
- package/dist/oxlint/rules/NoCustomValues.js +150 -0
- package/dist/oxlint/rules/NoCustomValues.js.map +1 -0
- package/dist/oxlint/rules/NoSingleKeyShortcuts.d.ts +11 -0
- package/dist/oxlint/rules/NoSingleKeyShortcuts.d.ts.map +1 -0
- package/dist/oxlint/rules/NoSingleKeyShortcuts.js +158 -0
- package/dist/oxlint/rules/NoSingleKeyShortcuts.js.map +1 -0
- package/dist/oxlint/rules/PreferComponent.d.ts +3 -2
- package/dist/oxlint/rules/PreferComponent.d.ts.map +1 -1
- package/dist/oxlint/rules/PreferComponent.js +11 -4
- package/dist/oxlint/rules/PreferComponent.js.map +1 -1
- package/dist/oxlint/rules/PreferLayout.d.ts +9 -0
- package/dist/oxlint/rules/PreferLayout.d.ts.map +1 -0
- package/dist/oxlint/rules/PreferLayout.js +90 -0
- package/dist/oxlint/rules/PreferLayout.js.map +1 -0
- package/dist/oxlint/rules/PreferProgress.d.ts +9 -0
- package/dist/oxlint/rules/PreferProgress.d.ts.map +1 -0
- package/dist/oxlint/rules/PreferProgress.js +43 -0
- package/dist/oxlint/rules/PreferProgress.js.map +1 -0
- package/dist/oxlint/rules/PreferSurface.d.ts +9 -0
- package/dist/oxlint/rules/PreferSurface.d.ts.map +1 -0
- package/dist/oxlint/rules/PreferSurface.js +55 -0
- package/dist/oxlint/rules/PreferSurface.js.map +1 -0
- package/dist/oxlint/rules/RequireAccessibleName.d.ts.map +1 -1
- package/dist/oxlint/rules/RequireAccessibleName.js +3 -1
- package/dist/oxlint/rules/RequireAccessibleName.js.map +1 -1
- package/dist/oxlint/rules/RequireScrollRegion.d.ts +11 -0
- package/dist/oxlint/rules/RequireScrollRegion.d.ts.map +1 -0
- package/dist/oxlint/rules/RequireScrollRegion.js +71 -0
- package/dist/oxlint/rules/RequireScrollRegion.js.map +1 -0
- package/dist/web/icons/index.js.zyzz.json +1 -0
- package/package.json +6 -1
- package/src/marketing/README.md +21 -0
- package/src/marketing/index.ts +3 -0
- package/src/marketing/vars.ts +751 -0
- package/src/marketing/zyzz.config.ts +376 -0
- package/src/oxlint/index.ts +40 -1
- package/src/oxlint/internal/Docs.ts +18 -0
- package/src/oxlint/internal/Imports.ts +2 -1
- package/src/oxlint/internal/Styles.ts +240 -0
- package/src/oxlint/internal/Tokens.ts +43 -0
- package/src/oxlint/rules/NoCrossSurface.ts +3 -3
- package/src/oxlint/rules/NoCustomValues.ts +170 -0
- package/src/oxlint/rules/NoSingleKeyShortcuts.ts +190 -0
- package/src/oxlint/rules/PreferComponent.ts +11 -4
- package/src/oxlint/rules/PreferLayout.ts +96 -0
- package/src/oxlint/rules/PreferProgress.ts +49 -0
- package/src/oxlint/rules/PreferSurface.ts +70 -0
- package/src/oxlint/rules/RequireAccessibleName.ts +3 -1
- package/src/oxlint/rules/RequireScrollRegion.ts +92 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
# Switch
|
|
2
|
+
|
|
3
|
+
Toggles a setting that applies immediately.
|
|
4
|
+
|
|
5
|
+
[View source and API](https://github.com/tempoxyz/ds/blob/main/src/web/components/Switch.tsx)
|
|
6
|
+
|
|
7
|
+
Figma: [Switch · Existing candidate](https://www.figma.com/design/yE96kcymnNR88PJp6G1sPs?node-id=1401-11548)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
A pill toggle whose thumb and track color both show the state.
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
### Basic
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Switch } from '@tempoxyz/ds'
|
|
19
|
+
|
|
20
|
+
export function Demo() {
|
|
21
|
+
return <Switch aria-label="Notifications" />
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Switch/Basic.tsx)
|
|
26
|
+
|
|
27
|
+
### Size
|
|
28
|
+
|
|
29
|
+
Set `size` to `small`, `medium`, or `large`. It defaults to `medium`, or `small` inside [ListGroup](list-group.md).
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { style, Switch } from '@tempoxyz/ds'
|
|
33
|
+
|
|
34
|
+
export function Demo() {
|
|
35
|
+
return (
|
|
36
|
+
<div {...styles.row()}>
|
|
37
|
+
{(['small', 'medium', 'large'] as const).map((size) => (
|
|
38
|
+
<Switch aria-label={size} key={size} size={size} />
|
|
39
|
+
))}
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
namespace styles {
|
|
45
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '24' })
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Switch/Size.tsx)
|
|
50
|
+
|
|
51
|
+
### Checked
|
|
52
|
+
|
|
53
|
+
Set `defaultChecked`, or control the state with `checked` and `onCheckedChange`.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { style, Switch } from '@tempoxyz/ds'
|
|
57
|
+
|
|
58
|
+
export function Demo() {
|
|
59
|
+
return (
|
|
60
|
+
<div {...styles.row()}>
|
|
61
|
+
{(['small', 'medium', 'large'] as const).map((size) => (
|
|
62
|
+
<Switch aria-label={`${size} on`} defaultChecked key={size} size={size} />
|
|
63
|
+
))}
|
|
64
|
+
</div>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
namespace styles {
|
|
69
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '24' })
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Switch/Checked.tsx)
|
|
74
|
+
|
|
75
|
+
### Disabled
|
|
76
|
+
|
|
77
|
+
Set `disabled` to block toggling.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { style, Switch } from '@tempoxyz/ds'
|
|
81
|
+
|
|
82
|
+
export function Demo() {
|
|
83
|
+
return (
|
|
84
|
+
<div {...styles.row()}>
|
|
85
|
+
{(['small', 'medium', 'large'] as const).map((size) => (
|
|
86
|
+
<Switch aria-label={`${size} disabled`} disabled key={size} size={size} />
|
|
87
|
+
))}
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
namespace styles {
|
|
93
|
+
export const row = style({ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '24' })
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Switch/Disabled.tsx)
|
|
98
|
+
|
|
99
|
+
### Field
|
|
100
|
+
|
|
101
|
+
Place the switch in a `Field.Root` below its `Field.Label`, with the `Field.Description` under it.
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { Field, style, Switch } from '@tempoxyz/ds'
|
|
105
|
+
|
|
106
|
+
export const fill = true
|
|
107
|
+
export function Demo() {
|
|
108
|
+
return (
|
|
109
|
+
<div {...styles.settings()}>
|
|
110
|
+
<Field.Root>
|
|
111
|
+
<Field.Label>Auto-convert</Field.Label>
|
|
112
|
+
<Switch defaultChecked />
|
|
113
|
+
<Field.Description>Swap incoming funds to USDC.</Field.Description>
|
|
114
|
+
</Field.Root>
|
|
115
|
+
<Field.Root>
|
|
116
|
+
<Field.Label>Notifications</Field.Label>
|
|
117
|
+
<Switch />
|
|
118
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
119
|
+
</Field.Root>
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
namespace styles {
|
|
125
|
+
export const settings = style({ display: 'grid', gap: '24', maxWidth: '480px !custom' })
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
[View example source](https://github.com/tempoxyz/ds/blob/main/docs/src/examples/demos/Switch/Field.tsx)
|
|
130
|
+
|
|
131
|
+
## Anatomy
|
|
132
|
+
|
|
133
|
+
Import the component and assemble its parts.
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { Switch } from '@tempoxyz/ds'
|
|
137
|
+
|
|
138
|
+
<Switch />
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Guidelines
|
|
142
|
+
|
|
143
|
+
### When to Use
|
|
144
|
+
|
|
145
|
+
* Turn a setting on or off at once, such as payment emails, hiding small balances, or pausing a webhook.
|
|
146
|
+
* List independent settings on a settings page, one per row.
|
|
147
|
+
|
|
148
|
+
### When Not to Use
|
|
149
|
+
|
|
150
|
+
* Use a [Checkbox](checkbox.md) for a choice that applies on form submit, or for agreeing to terms.
|
|
151
|
+
* Use a [RadioGroup](radio-group.md) or [ChoiceGroup](choice-group.md) when the two states aren't on and off, such as Daily and Weekly.
|
|
152
|
+
* Use a [Button](button.md) for a one-time action, such as Revoke key.
|
|
153
|
+
|
|
154
|
+
### Apply the Change Immediately
|
|
155
|
+
|
|
156
|
+
Save the new state in `onCheckedChange`, not on a Save button.
|
|
157
|
+
|
|
158
|
+
**Do:** Save each setting the moment its switch flips.
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
/**
|
|
162
|
+
* Do example for "Apply the Change Immediately" on the Switch page.
|
|
163
|
+
* Save each setting the moment its switch flips.
|
|
164
|
+
* @module
|
|
165
|
+
*/
|
|
166
|
+
import { Field, Fieldset, style, Switch } from '@tempoxyz/ds'
|
|
167
|
+
|
|
168
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
169
|
+
export function Demo() {
|
|
170
|
+
return (
|
|
171
|
+
<Fieldset.Root {...styles.settings()}>
|
|
172
|
+
<Field.Root>
|
|
173
|
+
<Field.Label>Payment emails</Field.Label>
|
|
174
|
+
<Switch defaultChecked />
|
|
175
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
176
|
+
</Field.Root>
|
|
177
|
+
<Field.Root>
|
|
178
|
+
<Field.Label>Hide small balances</Field.Label>
|
|
179
|
+
<Switch />
|
|
180
|
+
<Field.Description>Hide tokens worth under $1.</Field.Description>
|
|
181
|
+
</Field.Root>
|
|
182
|
+
</Fieldset.Root>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
namespace styles {
|
|
187
|
+
export const settings = style({ maxWidth: '20rem !custom', rowGap: '0', width: '100% !custom' })
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Don't:** Add a Save button to a group of switches. Use a [Checkbox](checkbox.md) in a
|
|
192
|
+
form instead.
|
|
193
|
+
|
|
194
|
+
```tsx
|
|
195
|
+
/**
|
|
196
|
+
* Don't example for "Apply the Change Immediately" on the Switch page.
|
|
197
|
+
* Don't add a Save button to a group of switches. Use a Checkbox in a form instead.
|
|
198
|
+
* @module
|
|
199
|
+
*/
|
|
200
|
+
import { Button, Field, Fieldset, style, Switch } from '@tempoxyz/ds'
|
|
201
|
+
|
|
202
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
203
|
+
export function Demo() {
|
|
204
|
+
return (
|
|
205
|
+
<div {...styles.column()}>
|
|
206
|
+
<Fieldset.Root {...styles.settings()}>
|
|
207
|
+
<Field.Root>
|
|
208
|
+
<Field.Label>Payment emails</Field.Label>
|
|
209
|
+
<Switch defaultChecked />
|
|
210
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
211
|
+
</Field.Root>
|
|
212
|
+
<Field.Root>
|
|
213
|
+
<Field.Label>Hide small balances</Field.Label>
|
|
214
|
+
<Switch />
|
|
215
|
+
<Field.Description>Hide tokens worth under $1.</Field.Description>
|
|
216
|
+
</Field.Root>
|
|
217
|
+
</Fieldset.Root>
|
|
218
|
+
<Button size="small">Save changes</Button>
|
|
219
|
+
</div>
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
namespace styles {
|
|
224
|
+
export const column = style({
|
|
225
|
+
alignItems: 'flex-end',
|
|
226
|
+
display: 'flex',
|
|
227
|
+
flexDirection: 'column',
|
|
228
|
+
gap: '8',
|
|
229
|
+
maxWidth: '20rem !custom',
|
|
230
|
+
width: '100% !custom',
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
export const settings = style({ rowGap: '0', width: '100% !custom' })
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
* **Failed saves:** Update `checked` optimistically. If the save fails, flip it back and explain why in a [Toast](toast.md).
|
|
238
|
+
* **Risky changes:** If a change needs confirmation, costs money, or can't be undone, use a [Button](button.md) and an [AlertDialog](alert-dialog.md).
|
|
239
|
+
* **Delayed changes:** If a change takes a few seconds to apply, state it in the description, such as Applies to new payments.
|
|
240
|
+
|
|
241
|
+
### Name the Setting, Not the State
|
|
242
|
+
|
|
243
|
+
Don't write Enabled or Turn on, and don't change the label with the state.
|
|
244
|
+
|
|
245
|
+
**Do:** Label the setting the switch controls, such as Payment emails.
|
|
246
|
+
|
|
247
|
+
```tsx
|
|
248
|
+
/**
|
|
249
|
+
* Do example for "Name the Setting, Not the State" on the Switch page.
|
|
250
|
+
* Label the setting the switch controls, such as Payment emails.
|
|
251
|
+
* @module
|
|
252
|
+
*/
|
|
253
|
+
import { Field, style, Switch } from '@tempoxyz/ds'
|
|
254
|
+
|
|
255
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
256
|
+
export function Demo() {
|
|
257
|
+
return (
|
|
258
|
+
<Field.Root {...styles.setting()}>
|
|
259
|
+
<Field.Label>Payment emails</Field.Label>
|
|
260
|
+
<Switch defaultChecked />
|
|
261
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
262
|
+
</Field.Root>
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
namespace styles {
|
|
267
|
+
export const setting = style({ maxWidth: '20rem !custom', width: '100% !custom' })
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**Don't:** Label the switch with its state.
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
/**
|
|
275
|
+
* Don't example for "Name the Setting, Not the State" on the Switch page.
|
|
276
|
+
* Don't label the switch with its state.
|
|
277
|
+
* @module
|
|
278
|
+
*/
|
|
279
|
+
import { Field, style, Switch } from '@tempoxyz/ds'
|
|
280
|
+
|
|
281
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
282
|
+
export function Demo() {
|
|
283
|
+
return (
|
|
284
|
+
<Field.Root {...styles.setting()}>
|
|
285
|
+
<Field.Label>Enabled</Field.Label>
|
|
286
|
+
<Switch defaultChecked />
|
|
287
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
288
|
+
</Field.Root>
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
namespace styles {
|
|
293
|
+
export const setting = style({ maxWidth: '20rem !custom', width: '100% !custom' })
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Put the Label Above the Switch
|
|
298
|
+
|
|
299
|
+
Place each switch in a `Field.Root` below its `Field.Label`, as a text field sits, with the description under it.
|
|
300
|
+
|
|
301
|
+
**Do:** Place each switch below its `Field.Label`, with the description under it.
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
/**
|
|
305
|
+
* Do example for "Apply the Change Immediately" on the Switch page.
|
|
306
|
+
* Save each setting the moment its switch flips.
|
|
307
|
+
* @module
|
|
308
|
+
*/
|
|
309
|
+
import { Field, Fieldset, style, Switch } from '@tempoxyz/ds'
|
|
310
|
+
|
|
311
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
312
|
+
export function Demo() {
|
|
313
|
+
return (
|
|
314
|
+
<Fieldset.Root {...styles.settings()}>
|
|
315
|
+
<Field.Root>
|
|
316
|
+
<Field.Label>Payment emails</Field.Label>
|
|
317
|
+
<Switch defaultChecked />
|
|
318
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
319
|
+
</Field.Root>
|
|
320
|
+
<Field.Root>
|
|
321
|
+
<Field.Label>Hide small balances</Field.Label>
|
|
322
|
+
<Switch />
|
|
323
|
+
<Field.Description>Hide tokens worth under $1.</Field.Description>
|
|
324
|
+
</Field.Root>
|
|
325
|
+
</Fieldset.Root>
|
|
326
|
+
)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
namespace styles {
|
|
330
|
+
export const settings = style({ maxWidth: '20rem !custom', rowGap: '0', width: '100% !custom' })
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**Don't:** Put the switch before its label, as a checkbox sits.
|
|
335
|
+
|
|
336
|
+
```tsx
|
|
337
|
+
/**
|
|
338
|
+
* Don't example for "Put the Label Above the Switch" on the Switch page.
|
|
339
|
+
* Don't put the switch before its label, as a checkbox sits.
|
|
340
|
+
* @module
|
|
341
|
+
*/
|
|
342
|
+
import { Field, style, Switch } from '@tempoxyz/ds'
|
|
343
|
+
|
|
344
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
345
|
+
export function Demo() {
|
|
346
|
+
return (
|
|
347
|
+
<div {...styles.column()}>
|
|
348
|
+
<Field.Root>
|
|
349
|
+
<Field.Item>
|
|
350
|
+
<Switch defaultChecked />
|
|
351
|
+
<Field.Label>Payment emails</Field.Label>
|
|
352
|
+
</Field.Item>
|
|
353
|
+
</Field.Root>
|
|
354
|
+
<Field.Root>
|
|
355
|
+
<Field.Item>
|
|
356
|
+
<Switch />
|
|
357
|
+
<Field.Label>Hide small balances</Field.Label>
|
|
358
|
+
</Field.Item>
|
|
359
|
+
</Field.Root>
|
|
360
|
+
</div>
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
namespace styles {
|
|
365
|
+
export const column = style({
|
|
366
|
+
display: 'flex',
|
|
367
|
+
flexDirection: 'column',
|
|
368
|
+
gap: '12',
|
|
369
|
+
maxWidth: '20rem !custom',
|
|
370
|
+
width: '100% !custom',
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Explain Unavailable Settings
|
|
376
|
+
|
|
377
|
+
**Do:** Set `disabled` and state why in `Field.Description`.
|
|
378
|
+
|
|
379
|
+
```tsx
|
|
380
|
+
/**
|
|
381
|
+
* Do example for "Explain Unavailable Settings" on the Switch page.
|
|
382
|
+
* Set `disabled` and state why in `Field.Description`.
|
|
383
|
+
* @module
|
|
384
|
+
*/
|
|
385
|
+
import { Field, style, Switch } from '@tempoxyz/ds'
|
|
386
|
+
|
|
387
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
388
|
+
export function Demo() {
|
|
389
|
+
return (
|
|
390
|
+
<Field.Root {...styles.setting()}>
|
|
391
|
+
<Field.Label>Payment emails</Field.Label>
|
|
392
|
+
<Switch disabled />
|
|
393
|
+
<Field.Description>Verify your email to turn this on.</Field.Description>
|
|
394
|
+
</Field.Root>
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
namespace styles {
|
|
399
|
+
export const setting = style({ maxWidth: '20rem !custom', width: '100% !custom' })
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
**Don't:** Dim a switch without a reason. It looks broken.
|
|
404
|
+
|
|
405
|
+
```tsx
|
|
406
|
+
/**
|
|
407
|
+
* Don't example for "Explain Unavailable Settings" on the Switch page.
|
|
408
|
+
* Don't dim a switch without a reason. It looks broken.
|
|
409
|
+
* @module
|
|
410
|
+
*/
|
|
411
|
+
import { Field, style, Switch } from '@tempoxyz/ds'
|
|
412
|
+
|
|
413
|
+
/** Renders the static preview, which the guideline card shows inert. */
|
|
414
|
+
export function Demo() {
|
|
415
|
+
return (
|
|
416
|
+
<Field.Root {...styles.setting()}>
|
|
417
|
+
<Field.Label>Payment emails</Field.Label>
|
|
418
|
+
<Switch disabled />
|
|
419
|
+
<Field.Description>Email me when a payment settles.</Field.Description>
|
|
420
|
+
</Field.Root>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
namespace styles {
|
|
425
|
+
export const setting = style({ maxWidth: '20rem !custom', width: '100% !custom' })
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Content
|
|
430
|
+
|
|
431
|
+
* Describe what happens when the switch is on, such as Email me when a payment settles.
|
|
432
|
+
* Don't phrase labels as questions. Don't use negative labels, such as Don't show testnet tokens, which make on mean off.
|
|
433
|
+
|
|
434
|
+
## Accessibility
|
|
435
|
+
|
|
436
|
+
A switch follows the [WAI-ARIA switch pattern](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).
|
|
437
|
+
|
|
438
|
+
### Semantics
|
|
439
|
+
|
|
440
|
+
* **Control (switch):** Announced with its on or off state.
|
|
441
|
+
* **Native TextInput (checkbox):** A hidden native input submits the value under `name`. It is outside the Tab order and the accessibility tree.
|
|
442
|
+
* **Label and Description (aria-labelledby):** In a field, the label names the switch and the field description describes it.
|
|
443
|
+
* **Disabled (aria-disabled):** Removes the switch from the Tab order.
|
|
444
|
+
* **Target Size (8px hit area):** The hit area reaches past the track on every side.
|
|
445
|
+
* **Reduced Motion (prefers-reduced-motion):** The thumb jumps instead of sliding, and only colors transition.
|
|
446
|
+
|
|
447
|
+
### Keyboard
|
|
448
|
+
|
|
449
|
+
* **Move Focus to the Switch (Tab):** Moves focus to the switch.
|
|
450
|
+
* **Toggle the Switch (Space or Enter):** Toggles the switch. A click toggles it too.
|
|
451
|
+
|
|
452
|
+
### Your Responsibilities
|
|
453
|
+
|
|
454
|
+
* **Keep the Thumb Visible:** The thumb position and the track color both show the state. Keep custom styles from hiding the thumb.
|
|
455
|
+
|
|
456
|
+
## Related
|
|
457
|
+
|
|
458
|
+
[Checkbox](checkbox.md)
|
|
459
|
+
|
|
460
|
+
Use for choices submitted with a form.
|
|
461
|
+
|
|
462
|
+
[Field](field.md)
|
|
463
|
+
|
|
464
|
+
Use for the label and description.
|
|
465
|
+
|
|
466
|
+
[Fieldset](fieldset.md)
|
|
467
|
+
|
|
468
|
+
Use for grouping settings rows.
|
|
469
|
+
|
|
470
|
+
[Toast](toast.md)
|
|
471
|
+
|
|
472
|
+
Use for reporting a failed save.
|