@sanity/ui 5.0.0-alpha.22 → 5.0.0-alpha.23

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.
Files changed (127) hide show
  1. package/README.md +10 -0
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/styles.css +1 -1
  5. package/docs/components/avatar-counter.dsds.yaml +78 -0
  6. package/docs/components/avatar-stack.dsds.yaml +96 -0
  7. package/docs/components/avatar.dsds.yaml +115 -0
  8. package/docs/components/badge.dsds.yaml +126 -0
  9. package/docs/components/box.dsds.yaml +223 -0
  10. package/docs/components/button.dsds.yaml +284 -0
  11. package/docs/components/card.dsds.yaml +317 -0
  12. package/docs/components/checkbox.dsds.yaml +204 -0
  13. package/docs/components/code.dsds.yaml +167 -0
  14. package/docs/components/container.dsds.yaml +189 -0
  15. package/docs/components/dialog.dsds.yaml +343 -0
  16. package/docs/components/divider.dsds.yaml +93 -0
  17. package/docs/components/eyebrow.dsds.yaml +217 -0
  18. package/docs/components/flex.dsds.yaml +237 -0
  19. package/docs/components/grid.dsds.yaml +217 -0
  20. package/docs/components/h-stack.dsds.yaml +127 -0
  21. package/docs/components/heading.dsds.yaml +233 -0
  22. package/docs/components/hotkeys.dsds.yaml +60 -0
  23. package/docs/components/icon-button.dsds.yaml +220 -0
  24. package/docs/components/icon.dsds.yaml +275 -0
  25. package/docs/components/indicator-stack.dsds.yaml +98 -0
  26. package/docs/components/indicator.dsds.yaml +108 -0
  27. package/docs/components/inline.dsds.yaml +127 -0
  28. package/docs/components/kbd.dsds.yaml +59 -0
  29. package/docs/components/link.dsds.yaml +108 -0
  30. package/docs/components/list-button-item.dsds.yaml +103 -0
  31. package/docs/components/list-item-image.dsds.yaml +82 -0
  32. package/docs/components/list-item-text.dsds.yaml +80 -0
  33. package/docs/components/list-item.dsds.yaml +148 -0
  34. package/docs/components/list.dsds.yaml +162 -0
  35. package/docs/components/popover.dsds.yaml +208 -0
  36. package/docs/components/press-area.dsds.yaml +279 -0
  37. package/docs/components/radio.dsds.yaml +198 -0
  38. package/docs/components/select.dsds.yaml +214 -0
  39. package/docs/components/skip-to-content.dsds.yaml +110 -0
  40. package/docs/components/spinner.dsds.yaml +119 -0
  41. package/docs/components/switch.dsds.yaml +202 -0
  42. package/docs/components/tab.dsds.yaml +54 -0
  43. package/docs/components/tabs-list.dsds.yaml +56 -0
  44. package/docs/components/tabs-panel.dsds.yaml +54 -0
  45. package/docs/components/tabs.dsds.yaml +104 -0
  46. package/docs/components/text-area.dsds.yaml +170 -0
  47. package/docs/components/text-input.dsds.yaml +189 -0
  48. package/docs/components/text.dsds.yaml +268 -0
  49. package/docs/components/tooltip-group.dsds.yaml +90 -0
  50. package/docs/components/tooltip.dsds.yaml +216 -0
  51. package/docs/components/v-stack.dsds.yaml +155 -0
  52. package/docs/components/visually-hidden.dsds.yaml +112 -0
  53. package/docs/evals/cases.yaml +1319 -0
  54. package/docs/examples/checkbox-2.tsx +57 -0
  55. package/docs/examples/confirmation-dialogs-1.tsx +27 -0
  56. package/docs/examples/confirmation-dialogs-2.tsx +55 -0
  57. package/docs/examples/confirmation-dialogs-3.tsx +28 -0
  58. package/docs/examples/confirmation-dialogs-4.tsx +38 -0
  59. package/docs/examples/popover-1.tsx +48 -0
  60. package/docs/examples/popover-2.tsx +53 -0
  61. package/docs/foundations/accessibility-guidelines.dsds.yaml +301 -0
  62. package/docs/foundations/color-guidelines.dsds.yaml +308 -0
  63. package/docs/foundations/content-guidelines.dsds.yaml +285 -0
  64. package/docs/foundations/semantics.dsds.yaml +125 -0
  65. package/docs/foundations/spacing-guidelines.dsds.yaml +226 -0
  66. package/docs/foundations/typography-guidelines.dsds.yaml +322 -0
  67. package/docs/icons.dsds.yaml +2513 -0
  68. package/docs/index.dsds.yaml +515 -0
  69. package/docs/overview/api-essentials.dsds.yaml +221 -0
  70. package/docs/overview/component-reference.dsds.yaml +215 -0
  71. package/docs/overview/designer-contribution-model.dsds.yaml +77 -0
  72. package/docs/overview/developer-contribution-model.dsds.yaml +362 -0
  73. package/docs/overview/installation.dsds.yaml +238 -0
  74. package/docs/overview/quick-start.dsds.yaml +317 -0
  75. package/docs/overview/resources.dsds.yaml +34 -0
  76. package/docs/patterns/confirmation-dialogs.dsds.yaml +140 -0
  77. package/docs/patterns/error-messaging.dsds.yaml +58 -0
  78. package/docs/patterns/forms.dsds.yaml +356 -0
  79. package/docs/patterns/layouts.dsds.yaml +403 -0
  80. package/docs/patterns/loading-states.dsds.yaml +41 -0
  81. package/docs/patterns/messaging.dsds.yaml +72 -0
  82. package/docs/patterns/navigation.dsds.yaml +153 -0
  83. package/docs/patterns/responsive.dsds.yaml +590 -0
  84. package/docs/tokens/color.dsds.yaml +1158 -0
  85. package/docs/tokens/container-widths.dsds.yaml +131 -0
  86. package/docs/tokens/content.dsds.yaml +258 -0
  87. package/docs/tokens/content.tokens.json +180 -0
  88. package/docs/tokens/dtcg/README.md +39 -0
  89. package/docs/tokens/dtcg/css/color.css +107 -0
  90. package/docs/tokens/dtcg/css/container.css +12 -0
  91. package/docs/tokens/dtcg/css/fontFamily.css +10 -0
  92. package/docs/tokens/dtcg/css/fontWeight.css +10 -0
  93. package/docs/tokens/dtcg/css/index.css +13 -0
  94. package/docs/tokens/dtcg/css/radius.css +14 -0
  95. package/docs/tokens/dtcg/css/semantic.css +42 -0
  96. package/docs/tokens/dtcg/css/shadow.css +22 -0
  97. package/docs/tokens/dtcg/css/space.css +16 -0
  98. package/docs/tokens/dtcg/css/typography.css +69 -0
  99. package/docs/tokens/dtcg/json/color.tokens.json +911 -0
  100. package/docs/tokens/dtcg/json/container.tokens.json +44 -0
  101. package/docs/tokens/dtcg/json/fontFamily.tokens.json +10 -0
  102. package/docs/tokens/dtcg/json/fontWeight.tokens.json +18 -0
  103. package/docs/tokens/dtcg/json/radius.tokens.json +58 -0
  104. package/docs/tokens/dtcg/json/semantic.tokens.json +372 -0
  105. package/docs/tokens/dtcg/json/shadow.tokens.json +599 -0
  106. package/docs/tokens/dtcg/json/space.tokens.json +72 -0
  107. package/docs/tokens/dtcg/json/typography.tokens.json +354 -0
  108. package/docs/tokens/font-family.dsds.yaml +79 -0
  109. package/docs/tokens/font-weight.dsds.yaml +103 -0
  110. package/docs/tokens/radius.dsds.yaml +153 -0
  111. package/docs/tokens/semantic.dsds.yaml +397 -0
  112. package/docs/tokens/shadow.dsds.yaml +125 -0
  113. package/docs/tokens/space.dsds.yaml +185 -0
  114. package/docs/tokens/typography.dsds.yaml +316 -0
  115. package/llms.txt +108 -0
  116. package/package.json +5 -2
  117. package/skills/sanity-ui-5/SKILL.md +158 -0
  118. package/skills/sanity-ui-5/references/component-choice.md +37 -0
  119. package/skills/sanity-ui-5/references/components.md +145 -0
  120. package/skills/sanity-ui-5/references/forms-and-accessibility.md +189 -0
  121. package/skills/sanity-ui-5/references/migrating-from-v3.md +250 -0
  122. package/skills/sanity-ui-5/references/props-and-imports.md +169 -0
  123. package/skills/sanity-ui-5/references/setup.md +177 -0
  124. package/skills/sanity-ui-5/references/silent-failures.md +33 -0
  125. package/skills/sanity-ui-5/references/taste.md +53 -0
  126. package/skills/sanity-ui-5/references/tone-and-color.md +55 -0
  127. package/src/version.ts +2 -2
@@ -0,0 +1,214 @@
1
+ kind: component
2
+ id: select
3
+ name: Select
4
+ description: Allows the user to choose one option from medium-size set (5-20) within a dropdown list.
5
+ metadata:
6
+ tags: [select, dropdown, form, input, single-select, option, picker, optgroup]
7
+ status:
8
+ status: beta
9
+ sections:
10
+ - kind: guidelines
11
+ for: all
12
+ framing: when-to-use
13
+ title: When to use
14
+ items:
15
+ - level: should
16
+ statement: To select from a medium set of options (5–20).
17
+ refines:
18
+ - to: forms#choose-control-by-option-count
19
+ - level: should
20
+ statement: To group related options under headings. Select renders native `optgroup` labels.
21
+ - refs:
22
+ - to: forms#choose-control-by-option-count
23
+ rel: same-as
24
+ - level: should-not
25
+ statement: When there are more than 20 options to choose from, or when the options are asynchronously loaded. Use a TextInput with a filtered list instead.
26
+ alternatives:
27
+ - to: text-input
28
+ - level: should-not
29
+ statement: When there are 4 or fewer options inside a form context. Use Radio instead.
30
+ alternatives:
31
+ - to: radio
32
+ - level: should-not
33
+ statement: To allow freeform text input. Use TextInput.
34
+ alternatives:
35
+ - to: text-input
36
+ - level: should-not
37
+ statement: When an option needs an icon, a description, or any markup beyond text. Options are native `option` elements and hold text only. Use a Popover with Buttons instead.
38
+ alternatives:
39
+ - to: popover
40
+ - level: should-not
41
+ statement: When selecting an option navigates to another location. Use Link instead.
42
+ alternatives:
43
+ - to: link
44
+ - kind: guidelines
45
+ for: all
46
+ framing: how-to-use
47
+ items:
48
+ - id: pass-options-children-select-renders
49
+ level: must
50
+ statement: Pass the options as children. Select renders a native `select`. Each option is an `option` element, and `optgroup` groups them.
51
+ checkedBy: manual
52
+ - refs:
53
+ - to: forms#pair-with-visible-label
54
+ rel: same-as
55
+ - refs:
56
+ - to: content-guidelines#sentence-case-all-system-set
57
+ rel: same-as
58
+ tags: [content]
59
+ - level: should
60
+ statement: Constrain the width from the parent. Select fills its container. Wrap it in a Box or a grid cell to size it.
61
+ - level: should
62
+ statement: Keep select option labels concise and lead with the word that distinguishes the option. Labels are scanned, not read, and a label longer than the field runs under the picker icon.
63
+ tags: [content]
64
+ - level: should
65
+ statement: Label an `optgroup` with the trait its options share, not with a verb.
66
+ tags: [content]
67
+ - level: should
68
+ statement: Pre-select a default option when a clear default exists.
69
+ - level: should
70
+ statement: Order select options logically. When in doubt, order alphabetically or numerically.
71
+ - level: should
72
+ statement: Use `density="loose"` in forms with wide spacing. `regular` is the default and sets padding to space 1; `loose` sets it to space 2.
73
+ - refs:
74
+ - to: forms#stack-fields-vertically
75
+ rel: same-as
76
+ - checkedBy: manual
77
+ refs:
78
+ - to: shared-foundations#error-state-never-disabled
79
+ rel: same-as
80
+ - level: must-not
81
+ statement: Don't add your own dropdown arrow. Select draws the picker icon itself, and the icon ignores pointer events.
82
+ checkedBy: manual
83
+ - level: must-not
84
+ statement: Don't mix Select and a Popover option list in a related group of filter UI — the group should exclusively use one pattern.
85
+ checkedBy: manual
86
+ - kind: guidelines
87
+ for: agent
88
+ framing: how-to-use
89
+ items:
90
+ - level: should
91
+ statement: Use a visible label in form contexts.
92
+ - level: must-not
93
+ statement: 'Do not pass `fontSize`, `padding`, `radius` or `space`. Select does not accept them. Instead: use `density` for padding; the type size and the radius are fixed.'
94
+ checkedBy: manual
95
+
96
+ - kind: guidelines
97
+ for: all
98
+ title: Accessibility
99
+ tags: [accessibility]
100
+ items:
101
+ - refs:
102
+ - to: forms#label-available-to-screen-readers
103
+ rel: same-as
104
+ - refs:
105
+ - to: forms#programmatic-name-required
106
+ rel: same-as
107
+ - level: should
108
+ statement: '**Border contrast.** The default border must reach 3:1 against the field background (WCAG 1.4.11) — check this in both light and dark themes.'
109
+ - level: should
110
+ statement: '**Error text, not error color alone.** `hasError` sets `aria-invalid="true"` and recolors the border and the text. None of that says what is wrong. Describe the problem in text and link it with `aria-describedby` (WCAG 3.3.1).'
111
+ - level: should
112
+ statement: '**A disabled Select cannot be focused or clicked.** It leaves the tab order and sets `pointer-events: none`, so no hover or click reaches it and it is hidden from screen readers. Never rely on a disabled field to explain why it is unavailable.'
113
+ - refs:
114
+ - to: forms#error-described-in-text
115
+ rel: same-as
116
+ - refs:
117
+ - to: forms#error-prop-needs-visible-message
118
+ rel: same-as
119
+ - refs:
120
+ - to: forms#border-contrast
121
+ rel: same-as
122
+ - kind: section
123
+ for: all
124
+ freeform:
125
+ - title: Example - Controlled value
126
+ body: |-
127
+ ```
128
+ import { Select } from '@sanity/ui'
129
+
130
+ <Select
131
+ aria-label="Choose a region"
132
+ value={region}
133
+ onChange={(e) => setRegion(e.currentTarget.value)}
134
+ >
135
+ <optgroup label="Europe">
136
+ <option value="eu-west">Ireland</option>
137
+ <option value="eu-central">Frankfurt</option>
138
+ </optgroup>
139
+ <option value="us-east">Virginia</option>
140
+ </Select>
141
+ ```
142
+
143
+ Select forwards the native `select` events. Use `value` and
144
+ `onChange` to drive the field from React state. Read the new
145
+ value from `event.currentTarget.value`. Use `defaultValue` to pre-select
146
+ an option and leave the field uncontrolled.
147
+
148
+ alternatives:
149
+ - to: radio
150
+ note: Single-select from 2–4 options, all visible at once
151
+ - to: text-input
152
+ note: Single-select from a large or async option set, with filtering
153
+ - to: checkbox
154
+ note: Multi-select from a small option set
155
+ - to: popover
156
+ note: A list whose items need icons, descriptions, or navigation
157
+ refs:
158
+ - href: https://www.figma.com/design/NWmchNlsNdG66VBaCsTdSL/pjo-ui4-component-buildout?node-id=29-1944
159
+ rel: design
160
+ role: Figma component
161
+ sourceFiles:
162
+ - platform: react
163
+ file: packages/ui/src/components/select/Select.tsx
164
+ imports:
165
+ - platform: react
166
+ code: import { Select } from '@sanity/ui'
167
+ package: '@sanity/ui'
168
+ traits:
169
+ - traitType: state
170
+ kind: boolean
171
+ id: enabled
172
+ description: Resting state. Backdrop background with a high separator border. The border carries the states below; the background only moves for `disabled`.
173
+ - traitType: state
174
+ kind: boolean
175
+ id: hovered
176
+ description: The border shifts one lightness step — darker in light mode, lighter in dark mode. In the error state it shifts from the error border.
177
+ - traitType: state
178
+ kind: boolean
179
+ id: focused
180
+ description: Focus outline on `:focus-visible`, offset from the border.
181
+ - traitType: state
182
+ kind: boolean
183
+ id: disabled
184
+ description: 'Inert background and a low separator border, with the text in the inert foreground color and the picker icon greyed to match. `pointer-events: none`, so the field is not focusable, not clickable, and leaves the tab order.'
185
+ - traitType: state
186
+ kind: boolean
187
+ id: error
188
+ description: Set with the `hasError` prop. The border turns the error separator color, the text turns the error foreground color, and the select gains `aria-invalid="true"`. It carries no message — supply that yourself.
189
+ $extensions:
190
+ com.sanity.ui:
191
+ implementationStatus:
192
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
193
+ implemented: true
194
+ migrationGuide:
195
+ context: 'Migration guide for this component, covering the codemod and the changes it cannot make. Held as an extension because it is temporary: migration tooling and porting agents read it, and it should be dropped when Sanity UI 3 support ends.'
196
+ guidance: |-
197
+ The sizing props are gone. One `density` prop replaces them, and validation is now a boolean named `hasError`.
198
+
199
+ ### Detailed list of differences
200
+
201
+ | v3 pattern | v5 pattern | Notes |
202
+ | :---- | :---- | :---- |
203
+ | `<Select fontSize={2} />` | `<Select />` | The type size is fixed by the component at body size 1 |
204
+ | `<Select padding={3} space={3} />` | `<Select density="loose" />` | `density` is `regular` or `loose`. It sets padding to space 1 or space 2, so neither value reproduces a v3 `padding={3}` exactly |
205
+ | `<Select radius={2} />` | `<Select />` | The radius is fixed at step 2, {radius-2} |
206
+ | `<Select customValidity="Pick one" />` | `<Select hasError />` plus your own message | `hasError` sets `aria-invalid` and recolors the border and text. It renders no text |
207
+ | `<Select icon={ChevronDownIcon} />` | `<Select />` | The picker icon is drawn by the component |
208
+ | All native `<select>` attributes | Forwarded unchanged | Pass them as before |
209
+
210
+ ### Breaking changes
211
+
212
+ - **No `fontSize`, `padding`, `radius` or `space`.** Passing them has no effect. Use `density` for padding.
213
+ - **`customValidity` is replaced by `hasError`.** The old prop set the native validation message. The new one is styling plus `aria-invalid`. You own the message and where it appears. The `has` prefix marks it as a validation boolean.
214
+ - **The width is no longer yours to set on the component.** Select fills its container. Size it from the parent.
@@ -0,0 +1,110 @@
1
+ kind: component
2
+ id: skip-to-content
3
+ name: SkipToContent
4
+ description: An accessibility helper that lets keyboard and screen-reader users skip past navigation to the main content.
5
+ metadata:
6
+ tags: [accessibility, skip-link, keyboard, navigation, WCAG, skip-to-content, bypass]
7
+ status:
8
+ status: beta
9
+ sections:
10
+ - kind: guidelines
11
+ for: all
12
+ framing: when-to-use
13
+ title: When to use
14
+ items:
15
+ - level: should
16
+ statement: On every page that contains repeated navigation (header, sidebar) before the main content. WCAG 2.4.1 (A) requires a way to bypass blocks of content.
17
+ - level: should
18
+ statement: As the first focusable element in the document so the first Tab press lands on it.
19
+ - level: should-not
20
+ statement: On single-page apps with no repeated navigation block — the skip link adds noise without value.
21
+ - level: should-not
22
+ statement: "For non-main destinations (for example, 'Skip to footer'). Use a regular Link for other jump targets."
23
+ alternatives:
24
+ - to: link
25
+ - kind: guidelines
26
+ for: agent
27
+ framing: when-to-use
28
+ title: When to use
29
+ items:
30
+ - level: should-not
31
+ statement: Don't use SkipToContent for visible navigation links. Use Link instead — SkipToContent is a specialized hidden skip-link that uses Link internally.
32
+ alternatives:
33
+ - to: link
34
+ - level: should-not
35
+ statement: Don't use SkipToContent for custom skip-link patterns. Use VisuallyHidden with `visibleOnFocus` instead.
36
+ alternatives:
37
+ - to: visually-hidden
38
+ - kind: guidelines
39
+ for: all
40
+ framing: how-to-use
41
+ items:
42
+ - level: must
43
+ statement: Place SkipToContent as the first child of body so it's the first thing Tab reaches.
44
+ - level: must
45
+ statement: Point href at a focusable element. The target (typically main) should have tabIndex={-1}.
46
+ - level: must-not
47
+ statement: "Don't hide SkipToContent with display: none or aria-hidden — the clip-rect technique keeps it focusable."
48
+ - level: must-not
49
+ statement: Don't link to a non-focusable element — focus stays at the top and the skip link fails its purpose.
50
+ - kind: guidelines
51
+ for: agent
52
+ framing: how-to-use
53
+ items:
54
+ - level: must
55
+ statement: The target element must have tabIndex={-1} for focus to move correctly on activation.
56
+ - level: must-not
57
+ statement: 'Do not hide with display: none — this breaks keyboard accessibility.'
58
+ - level: must-not
59
+ statement: 'Linking to a non-focusable element as the href target. Instead: Add tabIndex={-1} to the target element (for example, the main element) so focus moves correctly.'
60
+ - level: must-not
61
+ statement: 'Using `hash` instead of `href` on SkipToContent (for example, `<SkipToContent hash="#main" />`). `hash` is not a prop, so passing it is a TypeScript error. Use `<SkipToContent href="#main" label="Skip to content" />`. The `sanity-ui/no-skip-to-content-hash` ESLint rule autofixes `hash` to `href`.'
62
+ - level: must-not
63
+ statement: 'Omitting the leading ''#'' from href (for example, `href="main"` instead of `href="#main"`). `href` is passed straight through to the underlying anchor — without the ''#'' it compiles fine but links to a relative URL instead of jumping to the same-page fragment. This produces no build error, so it must be checked explicitly.'
64
+ - kind: guidelines
65
+ for: all
66
+ title: Content
67
+ tags: [content]
68
+ items:
69
+ - refs:
70
+ - to: content-guidelines#sentence-case-all-system-set
71
+ rel: same-as
72
+ - level: should
73
+ statement: '**"Skip to content"** or **"Skip to main content"** is the convention.'
74
+ - level: should
75
+ statement: '**No trailing period.**'
76
+
77
+ alternatives:
78
+ - to: link
79
+ note: The anchor primitive rendered inside SkipToContent
80
+ - to: visually-hidden
81
+ note: The hiding primitive SkipToContent composes; use `<VisuallyHidden visibleOnFocus>` directly for other skip-link patterns
82
+ sourceFiles:
83
+ - platform: react
84
+ file: packages/ui/src/components/skip-to-content/SkipToContent.tsx
85
+ imports:
86
+ - platform: react
87
+ code: import { SkipToContent } from '@sanity/ui'
88
+ package: '@sanity/ui'
89
+ traits:
90
+ - traitType: state
91
+ kind: boolean
92
+ id: hidden
93
+ description: Clipped to 1×1 pixel, removed from layout. Default state, invisible to sighted users.
94
+ - traitType: state
95
+ kind: boolean
96
+ id: revealed
97
+ description: Unclipped, positioned at top-left with high z-index. Shown when the link receives :focus-visible.
98
+ $extensions:
99
+ com.sanity.ui:
100
+ implementationStatus:
101
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
102
+ implemented: true
103
+ migrationGuide:
104
+ context: 'Migration guide for this component, covering the codemod and the changes it cannot make. Held as an extension because it is temporary: migration tooling and porting agents read it, and it should be dropped when Sanity UI 3 support ends.'
105
+ guidance: |-
106
+ There was no SkipToContent in v3 — teams hand-rolled the pattern with a `<Box>` and a `position: absolute` reveal trick. The new component bundles VisuallyHidden + Link with the right focus behavior.
107
+
108
+ | v3 pattern | New prop | Notes |
109
+ |---|---|---|
110
+ | `<Box className="skip-link">...</Box>` (custom) | `<SkipToContent href="#main" label="Skip to content" />` | Drop in as the first body child |
@@ -0,0 +1,119 @@
1
+ kind: component
2
+ id: spinner
3
+ name: Spinner
4
+ description: Displays a loading/processing indicator.
5
+ metadata:
6
+ tags: [spinner, loading, progress, async, indicator, busy, fetch]
7
+ status:
8
+ status: beta
9
+ sections:
10
+ - kind: guidelines
11
+ for: all
12
+ framing: when-to-use
13
+ title: When to use
14
+ items:
15
+ - level: should
16
+ statement: Content loading into a region of the page.
17
+ - level: should
18
+ statement: Async operations in progress (fetching data, uploading files).
19
+ - level: should
20
+ statement: Form submissions or other actions that take a long time.
21
+ - level: should-not
22
+ statement: To fill in placeholder content prior to loading. Use a skeleton placeholder instead.
23
+ alternatives:
24
+ - to: loading-states
25
+ - level: should-not
26
+ statement: When progress is known. Use a progress bar pattern instead.
27
+ - kind: guidelines
28
+ for: agent
29
+ framing: when-to-use
30
+ title: When to use
31
+ items:
32
+ - level: should-not
33
+ statement: Button has a built-in loading prop; use that for button-level loading states instead of composing a Spinner inside a Button.
34
+ alternatives:
35
+ - to: button
36
+ - kind: guidelines
37
+ for: all
38
+ framing: how-to-use
39
+ items:
40
+ - level: must
41
+ statement: Pair with a visible text label explaining what's loading. A spinner alone does not tell the user what is happening.
42
+ - level: must
43
+ statement: >-
44
+ Carry the loading state in text, not in the rotation. Under reduced motion, v5's global reset stops Spinner's animation after one short iteration, so the spinner renders still. The paired text label, or an `aria-live` announcement, is what tells the user that work is in progress.
45
+ - level: should
46
+ statement: Show the spinner only after a short delay (~200ms) to avoid a flash for operations that complete quickly. If the operation finishes before the delay, skip the spinner.
47
+ - level: should
48
+ statement: Place the spinner near the content region it relates to.
49
+ - level: must-not
50
+ statement: Don't show spinners for tasks that finish in under 200ms.
51
+ - level: must-not
52
+ statement: Don't use multiple spinners on the same screen — use a single spinner at a higher level or skeleton placeholders per region.
53
+ - kind: guidelines
54
+ for: agent
55
+ framing: how-to-use
56
+ items:
57
+ - level: must
58
+ statement: Spinner renders `role="status"` and `aria-label="Loading..."` by default. Don't wrap it in another status region. Pass your own `aria-label` to name the operation.
59
+ - level: must-not
60
+ statement: 'Showing a spinner without any text label. Instead: Always pair Spinner with a visible text label or aria-label describing the operation.'
61
+ - level: must-not
62
+ statement: 'Using a tone or muted prop on Spinner. Instead: Both props were removed in v5. Spinner color is CSS-driven via --foreground-high and --foreground-low. Set tone on the parent container to control color intensity.'
63
+ - kind: guidelines
64
+ for: all
65
+ title: Accessibility
66
+ description: 'Target conformance: WCAG Level AA.'
67
+ tags: [accessibility]
68
+ items:
69
+ - id: aria-busy
70
+ level: must
71
+ statement: Set aria-busy='true' on the container that is loading. Remove it when loading completes.
72
+ - id: role
73
+ level: must
74
+ statement: Wrap the Spinner and its label in a container with role='status'. Screen readers announce the loading message when it appears. The role implies aria-live='polite' so the announcement does not cut off the user.
75
+ - id: aria-label
76
+ level: must
77
+ statement: "Spinner ships with a built-in role='status' and aria-label='Loading...', so a bare <Spinner /> is announced by screen readers as 'Loading...' — it is not hidden from assistive technology. Pass your own aria-label to announce a more specific state (for example, 'Loading documents'); it overrides the default."
78
+
79
+ alternatives:
80
+ - to: button
81
+ refs:
82
+ - href: https://www.figma.com/design/5mhVqXlldJEEB2VWZeKQ4i/Sanity-UI?node-id=32600-2650
83
+ rel: design
84
+ role: Figma component (v5)
85
+ sourceFiles:
86
+ - platform: react
87
+ file: packages/ui/src/components/spinner/Spinner.tsx
88
+ imports:
89
+ - platform: react
90
+ code: import { Spinner } from '@sanity/ui'
91
+ package: '@sanity/ui'
92
+ $extensions:
93
+ com.sanity.ui:
94
+ implementationStatus:
95
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
96
+ implemented: true
97
+ migrationGuide:
98
+ context: 'Migration guide for this component, covering the codemod and the changes it cannot make. Held as an extension because it is temporary: migration tooling and porting agents read it, and it should be dropped when Sanity UI 3 support ends.'
99
+ guidance: |-
100
+ Spinner has two API changes in v5\. v5 drops `tone` and adds `size`.
101
+
102
+ ### **Key differences**
103
+
104
+ - v5 drops the `tone` and `muted` props.
105
+ - v5 adds a `size` prop. It controls the icon size on a scale of 0–4. Defaults to `2`.
106
+ - v5 drops `styled-components`. Custom extensions like `styled(Spinner)` will not work.
107
+
108
+ ### **Detailed list of differences**
109
+
110
+ | v3 prop | v5 prop | Notes |
111
+ | :---- | :---- | :---- |
112
+ | `tone` | — | Removed. |
113
+ | `muted` | — | Removed. |
114
+ | — | `size` | New. Controls the icon size (0–4, default `2`) |
115
+
116
+ ### **Breaking changes**
117
+
118
+ - v5 drops `tone` and `muted`. `<Spinner tone="critical" muted>` does nothing.
119
+ - v5 drops `styled-components`. `styled(Spinner)` will not work.
@@ -0,0 +1,202 @@
1
+ kind: component
2
+ id: switch
3
+ name: Switch
4
+ description: A toggle control for binary on/off settings that take immediate effect.
5
+ metadata:
6
+ tags: [switch, toggle, boolean, form, on/off, setting, enable, disable]
7
+ status:
8
+ status: beta
9
+ sections:
10
+ - kind: guidelines
11
+ for: all
12
+ framing: when-to-use
13
+ title: When to use
14
+ items:
15
+ - level: should
16
+ statement: "Toggling a boolean setting that takes effect immediately (for example, 'Enable notifications')."
17
+ - level: should-not
18
+ statement: When choosing between more than two options. Use Select or Radio instead.
19
+ alternatives:
20
+ - to: select
21
+ - to: radio
22
+ - level: should-not
23
+ statement: To display an indeterminate state. Switch only has two options. Use Checkbox instead.
24
+ alternatives:
25
+ - to: checkbox
26
+ - kind: guidelines
27
+ for: agent
28
+ framing: when-to-use
29
+ title: When to use
30
+ items:
31
+ - level: should-not
32
+ statement: Don't use Switch when changes are deferred until form submission, or when selection does not trigger an immediate reaction. Use Checkbox instead.
33
+ alternatives:
34
+ - to: checkbox
35
+ - level: should-not
36
+ statement: Don't use Switch for choosing between named options. Use Radio instead.
37
+ alternatives:
38
+ - to: radio
39
+ - kind: guidelines
40
+ for: all
41
+ framing: how-to-use
42
+ items:
43
+ - level: must
44
+ statement: Give every Switch an accessible name. Link a visible label element to it with id and htmlFor, or use aria-label or aria-labelledby when there is no visible text to link.
45
+ refines:
46
+ - to: forms#pair-with-visible-label
47
+ - level: must-not
48
+ statement: Use Switch without an accessible name. A nameless switch is announced as an unlabeled switch.
49
+ - level: must
50
+ statement: The label should describe the on state using present-tense verb phrases. 'Enable feature flags', 'Show archived items'.
51
+ - refs:
52
+ - to: forms#pair-checked-with-onchange
53
+ rel: same-as
54
+ - refs:
55
+ - to: forms#stack-fields-vertically
56
+ rel: same-as
57
+ - refs:
58
+ - to: shared-foundations#error-state-never-disabled
59
+ rel: same-as
60
+ - level: must-not
61
+ statement: Don't pair Switch with a confirm button or action. Toggling a switch should immediately trigger the action.
62
+ - refs:
63
+ - to: forms#no-mixed-controlled-uncontrolled
64
+ rel: same-as
65
+ - kind: guidelines
66
+ for: agent
67
+ framing: how-to-use
68
+ items:
69
+ - id: switch-has-accessible-name
70
+ level: must
71
+ statement: Every Switch has an accessible name from a linked label element, aria-label or aria-labelledby. Switch has no label prop.
72
+ checkedBy: manual
73
+ - level: must
74
+ statement: Changes commit on onChange. Don't defer them to a Save button, and don't add one beside a Switch.
75
+ - refs:
76
+ - to: forms#error-prop-needs-visible-message
77
+ rel: same-as
78
+ - level: must-not
79
+ statement: "Writing a label that describes the off state ('Hide notifications'). Instead: Write the label for the on state ('Enable notifications')."
80
+ - kind: guidelines
81
+ for: all
82
+ title: Content
83
+ tags: [content]
84
+ items:
85
+ - refs:
86
+ - to: content-guidelines#sentence-case-all-system-set
87
+ rel: same-as
88
+ - refs:
89
+ - to: forms#label-short
90
+ rel: same-as
91
+ - level: should
92
+ statement: Labels should use present-tense verbs. "Enable notifications" not "Notifications enabled". The label describes the action of turning it on.
93
+ - level: should
94
+ statement: Pair the on state with the positive outcome. ("Show archived items", not "Hide archived items".)
95
+ - refs:
96
+ - to: forms#label-no-trailing-period
97
+ rel: same-as
98
+ - refs:
99
+ - to: forms#label-no-trailing-colon
100
+ rel: same-as
101
+ - kind: guidelines
102
+ for: all
103
+ title: Accessibility
104
+ description: 'Target conformance: WCAG Level AA.'
105
+ tags: [accessibility]
106
+ items:
107
+ - level: must
108
+ statement: The Switch has no name of its own (WCAG 4.1.2). Name it through a linked label element, aria-label or aria-labelledby.
109
+ - level: should
110
+ statement: 'With hasError, the Switch sets aria-invalid on the input and shows error styling on the track. Pair it with a visible error message that the input describes.'
111
+ - refs:
112
+ - to: forms#aria-label-overrides-name
113
+ rel: same-as
114
+ - refs:
115
+ - to: forms#aria-labelledby-references-name
116
+ rel: same-as
117
+ - refs:
118
+ - to: forms#label-available-to-screen-readers
119
+ rel: same-as
120
+ - refs:
121
+ - to: forms#error-described-in-text
122
+ rel: same-as
123
+ - refs:
124
+ - to: forms#border-contrast
125
+ rel: same-as
126
+ - kind: section
127
+ for: all
128
+ freeform:
129
+ - title: Example — commit on toggle
130
+ body: |-
131
+ ```
132
+ import { Switch } from '@sanity/ui'
133
+
134
+ <Switch
135
+ id="notifications"
136
+ checked={settings.notifications}
137
+ onChange={(e) => save({ notifications: e.currentTarget.checked })}
138
+ />
139
+ <label htmlFor="notifications">Enable notifications</label>
140
+ ```
141
+
142
+ Use `checked` and `onChange` to control the switch from React state. A Switch commits on `onChange`. The `id` and `htmlFor` pair gives the switch its name. Use `aria-label` instead when the text can't be rendered visibly.
143
+ alternatives:
144
+ - to: checkbox
145
+ note: multi-select or boolean within a form that's submitted later
146
+ - to: radio
147
+ note: single-select within a small group
148
+ refs:
149
+ - href: https://www.figma.com/design/5mhVqXlldJEEB2VWZeKQ4i/Sanity-UI?node-id=31902-62
150
+ rel: design
151
+ role: Figma component (v5)
152
+ sourceFiles:
153
+ - platform: react
154
+ file: packages/ui/src/components/switch/Switch.tsx
155
+ imports:
156
+ - platform: react
157
+ code: import { Switch } from '@sanity/ui'
158
+ package: '@sanity/ui'
159
+ traits:
160
+ - traitType: state
161
+ kind: boolean
162
+ id: 'off'
163
+ description: Standard unchecked state with dot on the left.
164
+ - traitType: state
165
+ kind: boolean
166
+ id: 'on'
167
+ description: Track filled, dot on the right.
168
+ - traitType: state
169
+ kind: boolean
170
+ id: focused
171
+ description: Focus ring around the track on :focus-visible.
172
+ - traitType: state
173
+ kind: boolean
174
+ id: disabled
175
+ description: Muted track and dot, removed from tab order.
176
+ - traitType: state
177
+ kind: boolean
178
+ id: hasError
179
+ description: Red track styling and aria-invalid on the input for a validation error.
180
+ $extensions:
181
+ com.sanity.ui:
182
+ implementationStatus:
183
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
184
+ implemented: true
185
+ migrationGuide:
186
+ context: 'Migration guide for this component, covering the codemod and the changes it cannot make. Held as an extension because it is temporary: migration tooling and porting agents read it, and it should be dropped when Sanity UI 3 support ends.'
187
+ guidance: |-
188
+ The v5 Switch is the input itself, with no label wrapper. It has no visible text and no name of its own. In v3, a separate `<label htmlFor>` named the Switch. In v5, link a label element with `id` and `htmlFor`, or use `aria-label` or `aria-labelledby`.
189
+
190
+ | v3 pattern | v5 pattern | Notes |
191
+ | :---- | :---- | :---- |
192
+ | `<label htmlFor="x">Label</label><Switch id="x" />` | `<Switch id="x" /><label htmlFor="x">Label</label>` | Same association. Use `Text as="label"` if you need the Sanity UI text styles |
193
+ | `<Switch checked />` | `<Switch checked />` | Same `checked`/`onChange` API |
194
+ | All native `<input>` attributes (`name`, `value`, `required`, `aria-*`) | Forwarded unchanged | Pass them as before |
195
+
196
+ ### Breaking changes
197
+
198
+ - **`indeterminate` removed.** Switch has two states only. Use Checkbox for a mixed state.
199
+
200
+ ### Codemod
201
+
202
+ Run `pnpx @sanity/ui-codemod latest:switch --paths <paths> --toPackage @sanity/ui`. It updates the import and warns about `indeterminate`. It does not rewrite `label` props or wrapping label elements. Fix those by hand.