@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,204 @@
1
+ kind: component
2
+ id: checkbox
3
+ name: Checkbox
4
+ description: Enables the selection of an item or option.
5
+ metadata:
6
+ tags: [checkbox, form, input, selection, boolean, check, multi-select, toggle, indeterminate]
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 one or more items within a group in a multiselect context.
17
+ - level: should
18
+ statement: As a way to select or deselect every item from a list or table.
19
+ - level: should
20
+ statement: To toggle one or more boolean options within a form context.
21
+ - level: should-not
22
+ statement: When selection triggers immediate feedback. Use Switch instead.
23
+ alternatives:
24
+ - to: switch
25
+ - level: should-not
26
+ statement: 'When only one item from a group can be selected. Use Radio or Select (5–20 options) instead.'
27
+ alternatives:
28
+ - to: radio
29
+ - to: select
30
+ - kind: guidelines
31
+ for: all
32
+ framing: how-to-use
33
+ items:
34
+ - refs:
35
+ - to: forms#programmatic-name-required
36
+ rel: same-as
37
+ - level: must-not
38
+ statement: Use Checkbox without an accessible name. A nameless checkbox is announced as an unlabeled checkbox.
39
+ - level: must
40
+ statement: In table and list rows, name each Checkbox with aria-labelledby pointing at the cell that names the row. Use aria-label for a header checkbox such as select all, which has no visible text beside it.
41
+ example:
42
+ title: Row selection with aria-labelledby
43
+ description: Select-all and per-row checkboxes in a table. Each row checkbox points at its name cell.
44
+ ref:
45
+ href: ../examples/checkbox-2.tsx
46
+ rel: source
47
+ - refs:
48
+ - to: forms#pair-checked-with-onchange
49
+ rel: same-as
50
+ - refs:
51
+ - to: forms#stack-options-vertically
52
+ rel: same-as
53
+ - level: should
54
+ statement: Use indeterminate for a parent checkbox that controls a group with mixed state.
55
+ - level: should
56
+ statement: Use a fieldset and legend for groups of checkboxes.
57
+ - refs:
58
+ - to: forms#stack-fields-vertically
59
+ rel: same-as
60
+ - refs:
61
+ - to: shared-foundations#error-state-never-disabled
62
+ rel: same-as
63
+ - level: must-not
64
+ statement: "Don't use indeterminate for form options. It represents a mixed group state, not a value. Use it only for a 'select all' parent."
65
+ - refs:
66
+ - to: forms#no-mixed-controlled-uncontrolled
67
+ rel: same-as
68
+ - kind: guidelines
69
+ for: agent
70
+ framing: how-to-use
71
+ items:
72
+ - id: checkbox-has-accessible-name
73
+ level: must
74
+ statement: Every Checkbox has an accessible name from a linked label element, aria-label or aria-labelledby. Checkbox has no label prop.
75
+ checkedBy: manual
76
+ - refs:
77
+ - to: forms#error-prop-needs-visible-message
78
+ rel: same-as
79
+ - level: must-not
80
+ statement: "Using a checked state that represents a negative action ('Don't subscribe'). Instead: Map checked to the positive action ('Subscribe to the newsletter')."
81
+ - kind: guidelines
82
+ for: all
83
+ title: Content
84
+ tags: [content]
85
+ items:
86
+ - refs:
87
+ - to: content-guidelines#sentence-case-all-system-set
88
+ rel: same-as
89
+ - level: should
90
+ statement: Pair the checked state with the positive action ("Send me weekly digests", not "Don't send me weekly digests").
91
+ - refs:
92
+ - to: forms#label-no-trailing-period
93
+ rel: same-as
94
+ - kind: guidelines
95
+ for: all
96
+ title: Accessibility
97
+ description: 'Target conformance: WCAG Level AA.'
98
+ tags: [accessibility]
99
+ items:
100
+ - level: must
101
+ statement: The Checkbox has no name of its own (WCAG 4.1.2). Name it through a linked label element, aria-label or aria-labelledby.
102
+ - level: should
103
+ statement: 'With hasError, the Checkbox sets aria-invalid on the input and shows error styling on the mark. Pair it with a visible error message that the input describes.'
104
+ - refs:
105
+ - to: forms#aria-label-overrides-name
106
+ rel: same-as
107
+ - refs:
108
+ - to: forms#aria-labelledby-references-name
109
+ rel: same-as
110
+ - refs:
111
+ - to: forms#label-available-to-screen-readers
112
+ rel: same-as
113
+ - refs:
114
+ - to: forms#error-described-in-text
115
+ rel: same-as
116
+ - refs:
117
+ - to: forms#border-contrast
118
+ rel: same-as
119
+ - kind: section
120
+ for: all
121
+ freeform:
122
+ - title: Example — controlled value with a linked label
123
+ body: |-
124
+ ```
125
+ import { Checkbox } from '@sanity/ui'
126
+
127
+ <Checkbox
128
+ id="newsletter"
129
+ checked={subscribed}
130
+ onChange={(e) => setSubscribed(e.currentTarget.checked)}
131
+ />
132
+ <label htmlFor="newsletter">Subscribe to the newsletter</label>
133
+ ```
134
+
135
+ Use `checked` and `onChange` to control the checkbox from React state. `indeterminate` does not fire `onChange`. Set it imperatively to reflect a mixed group state, and toggle `checked` alongside it from the same handler. The `id` and `htmlFor` pair gives the checkbox its name. Use `aria-label` instead when the text can't be rendered visibly.
136
+ alternatives:
137
+ - to: switch
138
+ note: boolean toggle that takes effect immediately
139
+ - to: radio
140
+ note: single-select within a group
141
+ - to: select
142
+ note: single or multi-select dropdown when there are many options
143
+ refs:
144
+ - href: https://www.figma.com/design/5mhVqXlldJEEB2VWZeKQ4i/Sanity-UI?node-id=31897-66
145
+ rel: design
146
+ role: Figma component (v5)
147
+ sourceFiles:
148
+ - platform: react
149
+ file: packages/ui/src/components/checkbox/Checkbox.tsx
150
+ imports:
151
+ - platform: react
152
+ code: import { Checkbox } from '@sanity/ui'
153
+ package: '@sanity/ui'
154
+ traits:
155
+ - traitType: state
156
+ kind: boolean
157
+ id: enabled
158
+ description: Standard unchecked state.
159
+ - traitType: state
160
+ kind: boolean
161
+ id: focused
162
+ description: Focus ring on :focus-visible.
163
+ - traitType: state
164
+ kind: boolean
165
+ id: checked
166
+ description: Filled mark with a checkmark icon.
167
+ - traitType: state
168
+ kind: boolean
169
+ id: indeterminate
170
+ description: Filled mark with a horizontal-line icon for mixed group state.
171
+ - traitType: state
172
+ kind: boolean
173
+ id: disabled
174
+ description: Muted appearance, removed from tab order.
175
+ - traitType: state
176
+ kind: boolean
177
+ id: hasError
178
+ description: Red mark styling and aria-invalid on the input for a validation error.
179
+ $extensions:
180
+ com.sanity.ui:
181
+ implementationStatus:
182
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
183
+ implemented: true
184
+ migrationGuide:
185
+ 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.'
186
+ guidance: |-
187
+ The v5 Checkbox 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 Checkbox. In v5, link a label element with `id` and `htmlFor`, or use `aria-label` or `aria-labelledby`.
188
+
189
+ ### Detailed list of differences
190
+
191
+ | v3 pattern | v5 pattern | Notes |
192
+ | :---- | :---- | :---- |
193
+ | `<label htmlFor="x">Label</label><Checkbox id="x" />` | `<Checkbox id="x" /><label htmlFor="x">Label</label>` | Same association. Use `Text as="label"` if you need the Sanity UI text styles |
194
+ | `<Checkbox checked />` | `<Checkbox checked />` | Same `checked`/`onChange` API |
195
+ | `<Checkbox indeterminate />` | `<Checkbox indeterminate />` | Same, set imperatively on the underlying input |
196
+ | All native `<input>` attributes (`name`, `value`, `required`, `aria-*`) | Forwarded unchanged | Pass them as before |
197
+
198
+ ### Breaking changes
199
+
200
+ - **`customValidity` removed.** Handle validation outside the component, and pass `hasError` to show the error state.
201
+
202
+ ### Codemod
203
+
204
+ Run `pnpx @sanity/ui-codemod latest:checkbox --paths <paths> --toPackage @sanity/ui`. It updates the import and warns about `customValidity`. It does not rewrite `label` props or wrapping label elements. Fix those by hand.
@@ -0,0 +1,167 @@
1
+ kind: component
2
+ id: code
3
+ name: Code
4
+ description: Used for inline code snippets and multi-line code blocks.
5
+ metadata:
6
+ tags: [code, monospace, syntax, snippet, pre, file path, API, terminal]
7
+ status:
8
+ status: stable
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: Multi-line code blocks in documentation, changelogs, or developer-facing content.
17
+ - level: should
18
+ statement: Short inline code snippets in tooltips or descriptions.
19
+ - level: should
20
+ statement: Displaying API responses, file paths, or user-entered code strings.
21
+ - level: should-not
22
+ statement: For body copy, captions, or UI labels. Use Text instead.
23
+ alternatives:
24
+ - to: text
25
+ - level: should-not
26
+ statement: For keyboard shortcuts. Use KBD instead.
27
+ alternatives:
28
+ - to: kbd
29
+ - level: should-not
30
+ statement: As an editable input. Code is display-only.
31
+ - kind: guidelines
32
+ for: all
33
+ framing: how-to-use
34
+ items:
35
+ - level: should
36
+ statement: Pass language when the code has a known type to enable syntax highlighting.
37
+ - level: should
38
+ statement: Set `inline` for code inside a sentence. Block code renders as a `pre` element by default.
39
+ - level: must-not
40
+ statement: Don't wrap Code in a Box with fontFamily style — Code already uses a system monospace stack.
41
+ - level: must-not
42
+ statement: Don't add onClick or tabIndex to Code — it is not interactive.
43
+ - level: must-not
44
+ statement: Don't set maxWidth with inline styles — wrap Code in a Box with maxWidth instead.
45
+ - kind: guidelines
46
+ for: agent
47
+ framing: how-to-use
48
+ items:
49
+ - level: must-not
50
+ statement: "Setting inline fontFamily: 'monospace' on a Box to render code. Instead: Use the Code component, which provides the correct monospace stack and token colors."
51
+
52
+ - kind: guidelines
53
+ for: all
54
+ title: Accessibility
55
+ tags: [accessibility]
56
+ items:
57
+ - id: screen-readers-announce-text-inside
58
+ level: should
59
+ statement: Screen readers announce the text inside `<code>` but do not show syntax highlighting colors. Do not rely on token colors to convey meaning.
60
+ - level: should
61
+ statement: Code has no keyboard handling or focus management. Do not add `onClick` or `tabIndex`. Wrap in a Button or PressArea if the code needs a copy or select action.
62
+ alternatives:
63
+ - to: text
64
+ note: Body copy and UI labels
65
+ - to: kbd
66
+ note: Keyboard shortcut display
67
+ refs:
68
+ - to: heading
69
+ rel: relates-to
70
+ note: Semantic page headings
71
+ sourceFiles:
72
+ - platform: react
73
+ file: packages/ui/src/components/code/Code.tsx
74
+ imports:
75
+ - platform: react
76
+ code: import { Code } from '@sanity/ui'
77
+ package: '@sanity/ui'
78
+ traits:
79
+ - traitType: variant
80
+ kind: enum
81
+ id: size
82
+ description: CSS font-size property.
83
+ values:
84
+ - id: '0'
85
+ description: Smallest.
86
+ - id: '1'
87
+ description: Small.
88
+ - id: '2'
89
+ description: Medium (default).
90
+ - id: '3'
91
+ description: Large.
92
+ - id: '4'
93
+ description: Extra large.
94
+ - traitType: variant
95
+ kind: boolean
96
+ id: muted
97
+ description: Lowers the visual weight of secondary code text.
98
+ - traitType: variant
99
+ kind: boolean
100
+ id: trim
101
+ description: Removes extra whitespace above and below the text box for precise alignment with icons or badges.
102
+ - traitType: variant
103
+ kind: boolean
104
+ id: inline
105
+ description: Renders the code inside a sentence as a span. Block code renders as a pre element by default.
106
+ $extensions:
107
+ com.sanity.ui:
108
+ implementationStatus:
109
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
110
+ implemented: true
111
+ migrationGuide:
112
+ 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.'
113
+ codemod: |-
114
+ Code drops flex layout props and `maxWidth` entirely (removed, not renamed). Use `inline` for inline code in place of `as`. `muted` and `trim` are new additions.
115
+
116
+ Run the codemod: `pnpx @sanity/ui-codemod latest:code --paths <paths> --toPackage @sanity/ui`. It converts `flex`/`maxWidth`/`width` to an inline `style` object.
117
+ guidance: |-
118
+ Code in v3 had flex layout props, and a `maxWidth` prop. These are removed in v5\.
119
+
120
+ ### Key differences
121
+
122
+ - `as` is not a v5 prop. Use `inline` to render a span. Block code renders as a `pre` by default.
123
+ - `maxWidth` removed. Use a wrapping `Box` for width constraints.
124
+ - Flex props removed. Code is a block typography element, not a flex container.
125
+ - `muted` prop added to reduce visual contrast for secondary code content.
126
+ - `trim` prop added to remove leading and trailing whitespace from the text box.
127
+ - Refractor enables when `language` is set. When no `language` is set, v5 skips Refractor and renders right away.
128
+
129
+ ### Detailed list of differences
130
+
131
+ | v3 prop | v5 prop | Notes |
132
+ | :---- | :---- | :---- |
133
+ | `size` | `size` | Same scale (`0`–`4`). Default is `2` in both versions. |
134
+ | `weight` | — | Removed. Code renders at regular weight. |
135
+ | `as` | `inline` | Use `inline` for a span. Block code renders as a `pre` by default. |
136
+ | `maxWidth` | — | Removed. Wrap Code in `Box` with `maxWidth` instead. |
137
+ | Flex props | — | Removed. Code no longer extends flex layout props. |
138
+ | — | `muted` | New. Reduces visual contrast. |
139
+ | — | `trim` | New. Applies `text-box-trim` for precise vertical alignment. |
140
+
141
+ ### Breaking changes
142
+
143
+ - `as` is removed. Use `inline` for inline code. `<Code as="div">` fails to compile.
144
+ - `weight` is removed. Code renders at regular weight.
145
+ - `maxWidth` prop removed**.** `<Code maxWidth={4}>` does nothing. Wrap Code in a `Box` or `Container.`
146
+
147
+ ```
148
+ {/* v3 */}
149
+ <Code maxWidth={4}>...</Code>
150
+
151
+ {/* v5 */}
152
+ <Box maxWidth={4}>
153
+ <Code>...</Code>
154
+ </Box>
155
+ ```
156
+
157
+ - Flex layout props removed. `display`, `gap`, and other flex props from v3 no longer apply to Code.
158
+
159
+ ### Codemod
160
+
161
+ A codemod is available to ease the changes above. Run the command below with the path to the file or folder you want to migrate. Use spaces to pass more than one path.
162
+
163
+ ```
164
+ pnpx @sanity/ui-codemod latest:code --paths <paths> --toPackage @sanity/ui
165
+ ```
166
+
167
+ The codemod converts `flex`, `maxWidth`, and `width` to an inline `style` object, since Code no longer accepts them as props. If a component instance cannot be migrated or needs manual review, the codemod inserts a comment prefixed with "UI-POC-CODEMOD TODO".
@@ -0,0 +1,189 @@
1
+ kind: component
2
+ id: container
3
+ name: Container
4
+ description: A wrapper to constrain content to a maximum width and horizontally center it.
5
+ metadata:
6
+ tags: [layout, container, max-width, centering, responsive, page, width, constrain]
7
+ status:
8
+ status: stable
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 display a content block that is horizontally centered and limited to a maximum width.
17
+ - level: should-not
18
+ statement: As a general container for content. Use Box, Flex, or Grid instead.
19
+ alternatives:
20
+ - to: box
21
+ - to: flex
22
+ - to: grid
23
+ - level: should-not
24
+ statement: As a visual container to group related content. Use Card instead.
25
+ alternatives:
26
+ - to: card
27
+ - level: should-not
28
+ statement: When the content should fill the full viewport width (application chrome, sticky headers). Use Box or Flex.
29
+ alternatives:
30
+ - to: box
31
+ - to: flex
32
+ - kind: guidelines
33
+ for: all
34
+ framing: how-to-use
35
+ items:
36
+ - refs:
37
+ - to: api-essentials#sizing-is-a-css-string
38
+ rel: same-as
39
+ - id: content-size-prop-used
40
+ level: should
41
+ statement: Use size to choose a max-width from the design scale instead of setting maxWidth manually — the rendered Container's max-width should come from the size prop, not from an inline style or utility class with a hardcoded max-width value.
42
+ example:
43
+ title: How to satisfy this
44
+ description: Pass a size value (0–5) to the Container and confirm the rendered element carries no inline max-width style. Inspect the computed styles in browser DevTools and verify max-width resolves to a design-scale token rather than a literal pixel value set by the author.
45
+ checkedBy: manual
46
+ - id: semantic-element-for-primary-region
47
+ level: should
48
+ statement: Render Container as a semantic element via as when it represents the page's primary content region — typically as='main' or as='article' — so the rendered HTML element is <main> or <article>, not a generic <div>.
49
+ example:
50
+ title: How to satisfy this
51
+ description: Inspect the rendered DOM and confirm the element tag is 'main' or 'article' when the Container holds the page's primary content. Use browser DevTools or the Accessibility tree to verify the element exposes a landmark role (main or article) to assistive technology.
52
+ checkedBy: manual
53
+ - refs:
54
+ - to: shared-foundations#layout-primitive-no-text-styles
55
+ rel: same-as
56
+ tags: [content]
57
+ - id: no-nested-containers
58
+ level: must-not
59
+ statement: Don't nest Container components — the outer one already constrains the width, so no Container should render as a direct or indirect descendant of another Container in the same page subtree.
60
+ example:
61
+ title: How to satisfy this
62
+ description: Inspect the component tree in React DevTools and confirm no Container node appears inside another Container node. Review the JSX source for the page or layout and confirm Container is not used inside another Container's children.
63
+ checkedBy: manual
64
+ - kind: guidelines
65
+ for: agent
66
+ framing: how-to-use
67
+ items:
68
+ - level: must
69
+ statement: 'Size Container with size — exactly one of 0 | 1 | 2 | 3 | 4 | 5. Do not size it with width: width takes a raw CSS string, so width={4} means 4px, not a scale step. When you reach for width={n} on Container, you want size={n}.'
70
+ - level: must-not
71
+ statement: 'Using Box with a manual maxWidth style to constrain content. Instead: Use Container with size from the design scale.'
72
+
73
+ - kind: guidelines
74
+ for: all
75
+ title: Accessibility
76
+ tags: [accessibility]
77
+ items:
78
+ - refs:
79
+ - to: semantics#landmark-requirements
80
+ rel: same-as
81
+ - level: should
82
+ statement: '**Layout only.** Container provides width constraint and centering. It does not add keyboard handling, focus management, or ARIA state. If you render Container as a semantic element via `as`, you own the behavior that element requires.'
83
+ - refs:
84
+ - to: shared-foundations#layout-primitive-as-not-behavioral
85
+ rel: same-as
86
+ alternatives:
87
+ - to: box
88
+ note: Base spacing and structure container without max-width centering
89
+ - to: card
90
+ refs:
91
+ - to: space
92
+ rel: relates-to
93
+ - to: flex
94
+ rel: relates-to
95
+ note: Row or column layout with alignment and gap
96
+ sourceFiles:
97
+ - platform: react
98
+ file: packages/ui/src/components/container/Container.tsx
99
+ imports:
100
+ - platform: react
101
+ code: import { Container } from '@sanity/ui'
102
+ package: '@sanity/ui'
103
+ traits:
104
+ - traitType: variant
105
+ kind: enum
106
+ id: size
107
+ description: Named max-width from the design scale.
108
+ values:
109
+ - id: '0'
110
+ description: Width {container-0} — narrow column content.
111
+ - id: '1'
112
+ description: Width {container-1} — form-width content.
113
+ - id: '2'
114
+ description: Width {container-2} — standard article width.
115
+ - id: '3'
116
+ description: Width {container-3} — wide content area.
117
+ - id: '4'
118
+ description: Width {container-4} — extra wide content.
119
+ - id: '5'
120
+ description: Width {container-5} — full-screen wide content.
121
+ $extensions:
122
+ com.sanity.ui:
123
+ implementationStatus:
124
+ context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
125
+ implemented: true
126
+ migrationGuide:
127
+ 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.'
128
+ codemod: |-
129
+ `width` (a numeric scale prop) is renamed to `size`. The implicit `width: 100%` and hardcoded `margin: 0 auto` from v3 are gone — `marginX="auto"` is now an explicit, overridable default. The numeric scale also shifts: v3 `width={1}` maps to v5 `size={0}`.
130
+
131
+ Run the codemod: `pnpx @sanity/ui-codemod latest:container --paths <paths> --toPackage @sanity/ui`.
132
+ guidance: |-
133
+ v3 of `@sanity/ui` shipped a `Container` component that extended `BoxProps`. It added a single responsive `width` prop drawn from a numeric scale. It centered its children using `width: 100%` and `margin: 0 auto` baked into the base style.
134
+
135
+ ```
136
+ {/* v3 — Container with numeric width scale */}
137
+ import { Container } from '@sanity/ui'
138
+
139
+ <Container width={2} padding={4}>
140
+ <ArticleBody />
141
+ </Container>
142
+ ```
143
+
144
+ The new Container keeps the same purpose. It renames the responsive prop and trims the implicit defaults:
145
+
146
+ ```
147
+ {/* v5 — Container with size prop */}
148
+ import { Container } from '@sanity/ui'
149
+
150
+ <Container padding={4}>
151
+ <ArticleBody />
152
+ </Container>
153
+ ```
154
+
155
+ ### Key differences
156
+
157
+ - `width` replaced with `size`. The responsive max-width prop is renamed.
158
+ - v3 defaulted to `width={2}`, the width of {container-1}. v5 defaults to `size={2}`, the width of {container-2}. Set `size` when you want a different max-width.
159
+ - v3 hard-coded `margin: 0 auto`. v5 keeps the same default but as a changeable prop.
160
+ - No implicit `width: 100%`. v5 leaves `width` alone; pass it directly if you need it.
161
+ - `size={5}` is new — it adds a {container-5} step beyond v3's largest option, {container-4}.
162
+ - Added `as` prop. Use `as="main"` / `as="article"` directly. v3 required `forwardedAs` via styled-components.
163
+
164
+ | v3 prop | v5 prop | Notes |
165
+ | :---- | :---- | :---- |
166
+ | `width` default `2` | `size` default `2` | v5 Container defaults to `size={2}`, {container-2}. Set `size` for a different max-width. |
167
+ | Implicit `width: 100%` (CSS) | — | v5 does not set `width` at all. Add `width="100%"` only if you need fill behavior. |
168
+ | Implicit `margin: 0 auto` | `marginX="auto"` (default) | v5 keeps the centering default but exposes it as a prop you can override. |
169
+ | All `BoxProps` (padding, margin, tone, border, etc.) | All `LayoutProps` | v5 Container still inherits the full layout-prop surface (padding, margin, sizing, border, overflow, position, tone, flex-child, grid-child). |
170
+ | `forwardRef`, `styled-components` | Plain function component, CSS classes | v5 is a regular function component using static CSS classes. `styled(Container)` extensions from v3 will not work. |
171
+ | — | `as` prop | v5 Container accepts `as` directly to render any element type (for example, `as="main"`, `as="article"`). v3 used `forwardedAs` via `styled-components`. |
172
+ | — | `tone` | New. Sets a semantic background tint. Unset, Container has no background. Accepts `default`, `neutral`, `positive`, `suggest`, `caution`, and `critical`. |
173
+
174
+ ### Breaking changes
175
+
176
+ - **`width` prop renamed to `size`.** `<Container width={3}>` no longer accepts a numeric scale value. Use `<Container size={3}>`. v5 `width` accepts CSS strings only (for example, `width="100%"`) — passing a number is invalid.
177
+ - **Implicit `width: 100%` removed.** v3 baked `width: 100%` into the base style. v5 does not. The component fills the parent via the default `<div>` block-level behavior. If you relied on the implicit fill on a non-block parent, set `width="100%"` directly.
178
+ - **`width="auto"` no longer needed.** v3 used `width="auto"` to opt out of any max-width. In v5, omit the `size` prop.
179
+ - **Numeric scale shift.** v3 used `1`–`5`. v5 uses `0`–`5` and adds a `5` step, {container-5}. The pixel values for the range `1`–`5` are unchanged, but a v3 `width={1}`, the width of {container-0}, maps to v5 `size={0}`. Audit any literal `width={N}` changes.
180
+
181
+ ### Codemod
182
+
183
+ A codemod is available to ease the changes above. Run the command below with the path to the file or folder you want to migrate. Use spaces to pass more than one path.
184
+
185
+ ```
186
+ pnpx @sanity/ui-codemod latest:container --paths <paths> --toPackage @sanity/ui
187
+ ```
188
+
189
+ The codemod renames `width` to `size` and converts flex/grid layout props (`alignItems`, `flexDirection`, `flexWrap`, `gridTemplateColumns`, `gridTemplateRows`, `gridAutoColumns`, `gridAutoFlow`, `gridAutoRows`, `justifyContent`) to an inline `style` object. If a component instance cannot be migrated or needs manual review, the codemod inserts a comment prefixed with "UI-POC-CODEMOD TODO".