@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.
- package/README.md +10 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/docs/components/avatar-counter.dsds.yaml +78 -0
- package/docs/components/avatar-stack.dsds.yaml +96 -0
- package/docs/components/avatar.dsds.yaml +115 -0
- package/docs/components/badge.dsds.yaml +126 -0
- package/docs/components/box.dsds.yaml +223 -0
- package/docs/components/button.dsds.yaml +284 -0
- package/docs/components/card.dsds.yaml +317 -0
- package/docs/components/checkbox.dsds.yaml +204 -0
- package/docs/components/code.dsds.yaml +167 -0
- package/docs/components/container.dsds.yaml +189 -0
- package/docs/components/dialog.dsds.yaml +343 -0
- package/docs/components/divider.dsds.yaml +93 -0
- package/docs/components/eyebrow.dsds.yaml +217 -0
- package/docs/components/flex.dsds.yaml +237 -0
- package/docs/components/grid.dsds.yaml +217 -0
- package/docs/components/h-stack.dsds.yaml +127 -0
- package/docs/components/heading.dsds.yaml +233 -0
- package/docs/components/hotkeys.dsds.yaml +60 -0
- package/docs/components/icon-button.dsds.yaml +220 -0
- package/docs/components/icon.dsds.yaml +275 -0
- package/docs/components/indicator-stack.dsds.yaml +98 -0
- package/docs/components/indicator.dsds.yaml +108 -0
- package/docs/components/inline.dsds.yaml +127 -0
- package/docs/components/kbd.dsds.yaml +59 -0
- package/docs/components/link.dsds.yaml +108 -0
- package/docs/components/list-button-item.dsds.yaml +103 -0
- package/docs/components/list-item-image.dsds.yaml +82 -0
- package/docs/components/list-item-text.dsds.yaml +80 -0
- package/docs/components/list-item.dsds.yaml +148 -0
- package/docs/components/list.dsds.yaml +162 -0
- package/docs/components/popover.dsds.yaml +208 -0
- package/docs/components/press-area.dsds.yaml +279 -0
- package/docs/components/radio.dsds.yaml +198 -0
- package/docs/components/select.dsds.yaml +214 -0
- package/docs/components/skip-to-content.dsds.yaml +110 -0
- package/docs/components/spinner.dsds.yaml +119 -0
- package/docs/components/switch.dsds.yaml +202 -0
- package/docs/components/tab.dsds.yaml +54 -0
- package/docs/components/tabs-list.dsds.yaml +56 -0
- package/docs/components/tabs-panel.dsds.yaml +54 -0
- package/docs/components/tabs.dsds.yaml +104 -0
- package/docs/components/text-area.dsds.yaml +170 -0
- package/docs/components/text-input.dsds.yaml +189 -0
- package/docs/components/text.dsds.yaml +268 -0
- package/docs/components/tooltip-group.dsds.yaml +90 -0
- package/docs/components/tooltip.dsds.yaml +216 -0
- package/docs/components/v-stack.dsds.yaml +155 -0
- package/docs/components/visually-hidden.dsds.yaml +112 -0
- package/docs/evals/cases.yaml +1319 -0
- package/docs/examples/checkbox-2.tsx +57 -0
- package/docs/examples/confirmation-dialogs-1.tsx +27 -0
- package/docs/examples/confirmation-dialogs-2.tsx +55 -0
- package/docs/examples/confirmation-dialogs-3.tsx +28 -0
- package/docs/examples/confirmation-dialogs-4.tsx +38 -0
- package/docs/examples/popover-1.tsx +48 -0
- package/docs/examples/popover-2.tsx +53 -0
- package/docs/foundations/accessibility-guidelines.dsds.yaml +301 -0
- package/docs/foundations/color-guidelines.dsds.yaml +308 -0
- package/docs/foundations/content-guidelines.dsds.yaml +285 -0
- package/docs/foundations/semantics.dsds.yaml +125 -0
- package/docs/foundations/spacing-guidelines.dsds.yaml +226 -0
- package/docs/foundations/typography-guidelines.dsds.yaml +322 -0
- package/docs/icons.dsds.yaml +2513 -0
- package/docs/index.dsds.yaml +515 -0
- package/docs/overview/api-essentials.dsds.yaml +221 -0
- package/docs/overview/component-reference.dsds.yaml +215 -0
- package/docs/overview/designer-contribution-model.dsds.yaml +77 -0
- package/docs/overview/developer-contribution-model.dsds.yaml +362 -0
- package/docs/overview/installation.dsds.yaml +238 -0
- package/docs/overview/quick-start.dsds.yaml +317 -0
- package/docs/overview/resources.dsds.yaml +34 -0
- package/docs/patterns/confirmation-dialogs.dsds.yaml +140 -0
- package/docs/patterns/error-messaging.dsds.yaml +58 -0
- package/docs/patterns/forms.dsds.yaml +356 -0
- package/docs/patterns/layouts.dsds.yaml +403 -0
- package/docs/patterns/loading-states.dsds.yaml +41 -0
- package/docs/patterns/messaging.dsds.yaml +72 -0
- package/docs/patterns/navigation.dsds.yaml +153 -0
- package/docs/patterns/responsive.dsds.yaml +590 -0
- package/docs/tokens/color.dsds.yaml +1158 -0
- package/docs/tokens/container-widths.dsds.yaml +131 -0
- package/docs/tokens/content.dsds.yaml +258 -0
- package/docs/tokens/content.tokens.json +180 -0
- package/docs/tokens/dtcg/README.md +39 -0
- package/docs/tokens/dtcg/css/color.css +107 -0
- package/docs/tokens/dtcg/css/container.css +12 -0
- package/docs/tokens/dtcg/css/fontFamily.css +10 -0
- package/docs/tokens/dtcg/css/fontWeight.css +10 -0
- package/docs/tokens/dtcg/css/index.css +13 -0
- package/docs/tokens/dtcg/css/radius.css +14 -0
- package/docs/tokens/dtcg/css/semantic.css +42 -0
- package/docs/tokens/dtcg/css/shadow.css +22 -0
- package/docs/tokens/dtcg/css/space.css +16 -0
- package/docs/tokens/dtcg/css/typography.css +69 -0
- package/docs/tokens/dtcg/json/color.tokens.json +911 -0
- package/docs/tokens/dtcg/json/container.tokens.json +44 -0
- package/docs/tokens/dtcg/json/fontFamily.tokens.json +10 -0
- package/docs/tokens/dtcg/json/fontWeight.tokens.json +18 -0
- package/docs/tokens/dtcg/json/radius.tokens.json +58 -0
- package/docs/tokens/dtcg/json/semantic.tokens.json +372 -0
- package/docs/tokens/dtcg/json/shadow.tokens.json +599 -0
- package/docs/tokens/dtcg/json/space.tokens.json +72 -0
- package/docs/tokens/dtcg/json/typography.tokens.json +354 -0
- package/docs/tokens/font-family.dsds.yaml +79 -0
- package/docs/tokens/font-weight.dsds.yaml +103 -0
- package/docs/tokens/radius.dsds.yaml +153 -0
- package/docs/tokens/semantic.dsds.yaml +397 -0
- package/docs/tokens/shadow.dsds.yaml +125 -0
- package/docs/tokens/space.dsds.yaml +185 -0
- package/docs/tokens/typography.dsds.yaml +316 -0
- package/llms.txt +108 -0
- package/package.json +5 -2
- package/skills/sanity-ui-5/SKILL.md +158 -0
- package/skills/sanity-ui-5/references/component-choice.md +37 -0
- package/skills/sanity-ui-5/references/components.md +145 -0
- package/skills/sanity-ui-5/references/forms-and-accessibility.md +189 -0
- package/skills/sanity-ui-5/references/migrating-from-v3.md +250 -0
- package/skills/sanity-ui-5/references/props-and-imports.md +169 -0
- package/skills/sanity-ui-5/references/setup.md +177 -0
- package/skills/sanity-ui-5/references/silent-failures.md +33 -0
- package/skills/sanity-ui-5/references/taste.md +53 -0
- package/skills/sanity-ui-5/references/tone-and-color.md +55 -0
- package/src/version.ts +2 -2
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: flex
|
|
3
|
+
name: Flex
|
|
4
|
+
description: The lowest-level building block for laying out UI elements along a single axis.
|
|
5
|
+
metadata:
|
|
6
|
+
tags:
|
|
7
|
+
- layout
|
|
8
|
+
- flex
|
|
9
|
+
- alignment
|
|
10
|
+
- row
|
|
11
|
+
- column
|
|
12
|
+
- responsive
|
|
13
|
+
- flexbox
|
|
14
|
+
- gap
|
|
15
|
+
- wrap
|
|
16
|
+
- direction
|
|
17
|
+
- justify
|
|
18
|
+
- align
|
|
19
|
+
- alignItems
|
|
20
|
+
- justifyContent
|
|
21
|
+
- flexDirection
|
|
22
|
+
- flexWrap
|
|
23
|
+
status:
|
|
24
|
+
status: stable
|
|
25
|
+
sections:
|
|
26
|
+
- kind: guidelines
|
|
27
|
+
for: all
|
|
28
|
+
framing: when-to-use
|
|
29
|
+
title: When to use
|
|
30
|
+
items:
|
|
31
|
+
- level: should
|
|
32
|
+
statement: To stack items vertically or horizontally. Flex defaults to horizontal.
|
|
33
|
+
- level: should
|
|
34
|
+
statement: 'To control alignment: center children, space them apart, or push one to the end.'
|
|
35
|
+
- level: should
|
|
36
|
+
statement: To create responsive layouts that change direction at breakpoints.
|
|
37
|
+
- level: should-not
|
|
38
|
+
statement: To stack items in a simple vertical column with even spacing — use VStack instead.
|
|
39
|
+
alternatives:
|
|
40
|
+
- to: v-stack
|
|
41
|
+
- level: should-not
|
|
42
|
+
statement: To group a few items in a horizontal row with even spacing — use HStack instead.
|
|
43
|
+
alternatives:
|
|
44
|
+
- to: h-stack
|
|
45
|
+
- level: should-not
|
|
46
|
+
statement: To create a two-axis grid — use Grid instead.
|
|
47
|
+
alternatives:
|
|
48
|
+
- to: grid
|
|
49
|
+
- level: should-not
|
|
50
|
+
statement: To wrap a single child with spacing or visual styling — use Box instead.
|
|
51
|
+
alternatives:
|
|
52
|
+
- to: box
|
|
53
|
+
- kind: guidelines
|
|
54
|
+
for: all
|
|
55
|
+
framing: how-to-use
|
|
56
|
+
items:
|
|
57
|
+
- refs:
|
|
58
|
+
- to: api-essentials#sizing-is-a-css-string
|
|
59
|
+
rel: same-as
|
|
60
|
+
- id: flex-start-alignment-default
|
|
61
|
+
level: should
|
|
62
|
+
statement: Bias toward start-aligned content over center alignment for most interface elements. By default, children of a Flex container should use start alignment (alignItems='flex-start' or justifyContent='flex-start') unless center alignment is deliberately required by the design.
|
|
63
|
+
example:
|
|
64
|
+
title: How to satisfy this
|
|
65
|
+
description: 'Inspect the rendered layout and confirm that text, icons, and controls are left- or top-aligned by default. Check that center alignment is only applied where the design explicitly calls for it (for example, a dialog button row, a centered hero).'
|
|
66
|
+
checkedBy: manual
|
|
67
|
+
- id: flex-wrap-uses-gap
|
|
68
|
+
level: should
|
|
69
|
+
statement: Pair flexWrap='wrap' with the gap prop, not margin on child elements, to prevent item clipping in variable-count rows.
|
|
70
|
+
example:
|
|
71
|
+
title: How to satisfy this
|
|
72
|
+
description: Inspect the Flex element in the source and confirm it carries a gap prop alongside flexWrap='wrap'. Verify that child elements do not carry margin-top, margin-left, or equivalent shorthand values intended to create inter-item spacing.
|
|
73
|
+
checkedBy: manual
|
|
74
|
+
- refs:
|
|
75
|
+
- to: shared-foundations#layout-primitive-no-text-styles
|
|
76
|
+
rel: same-as
|
|
77
|
+
tags: [content]
|
|
78
|
+
- id: flex-no-inline-styles
|
|
79
|
+
level: must-not
|
|
80
|
+
statement: Flex elements carry no `style` attribute for anything a Flex prop or a dedicated component already provides.
|
|
81
|
+
example:
|
|
82
|
+
title: How to satisfy this
|
|
83
|
+
description: Review the JSX source and confirm the Flex element has no style={…} attribute. Where layout or visual adjustments are needed, use Flex props (gap, alignItems, etc.) or replace Flex with the appropriate component (Box, Card, etc.).
|
|
84
|
+
checks:
|
|
85
|
+
- href: ../evals/cases.yaml
|
|
86
|
+
role: agent-test
|
|
87
|
+
checkedBy: assisted
|
|
88
|
+
$extensions:
|
|
89
|
+
io.jev:
|
|
90
|
+
type: boolean
|
|
91
|
+
- id: flex-reverse-dom-order-matches-visual
|
|
92
|
+
level: must-not
|
|
93
|
+
statement: Don't use row-reverse or column-reverse to change sort order — these only change visual order, not tab order. When a reverse direction is used, the DOM order of child elements must still match the intended reading and tab order.
|
|
94
|
+
example:
|
|
95
|
+
title: How to satisfy this
|
|
96
|
+
description: Tab through the Flex container using only the keyboard and confirm focus moves in the same sequence a sighted user would read the content. Inspect the DOM in browser DevTools and verify the source order of children reflects the correct reading sequence, not the reversed visual sequence.
|
|
97
|
+
checkedBy: manual
|
|
98
|
+
- id: flex-no-onclick
|
|
99
|
+
level: must-not
|
|
100
|
+
statement: 'Flex carries no `onClick` handler; it is a layout element, not an interactive one. Use Button for interactive surfaces.'
|
|
101
|
+
example:
|
|
102
|
+
title: How to satisfy this
|
|
103
|
+
description: Inspect the JSX source and confirm no onClick prop is present on any Flex element. If a clickable surface is needed, wrap the content in a Button component instead.
|
|
104
|
+
checks:
|
|
105
|
+
- href: ../evals/cases.yaml
|
|
106
|
+
role: agent-test
|
|
107
|
+
checkedBy: assisted
|
|
108
|
+
$extensions:
|
|
109
|
+
io.jev:
|
|
110
|
+
type: boolean
|
|
111
|
+
- kind: guidelines
|
|
112
|
+
for: agent
|
|
113
|
+
framing: how-to-use
|
|
114
|
+
items:
|
|
115
|
+
- level: should
|
|
116
|
+
statement: Use VStack or HStack for common vertical/horizontal layouts; reserve Flex for cases needing custom alignment or wrapping.
|
|
117
|
+
- level: must-not
|
|
118
|
+
statement: >-
|
|
119
|
+
Do not use `align` or `justify` as prop names. Use `alignItems` and `justifyContent`. Other names silently do nothing — no error, no effect.
|
|
120
|
+
- level: must-not
|
|
121
|
+
statement: Do not use `direction` or `wrap` as prop names. Use `flexDirection` and `flexWrap`.
|
|
122
|
+
- level: must-not
|
|
123
|
+
statement: 'Applying flex styles via inline styles on Box. Instead: Use the Flex component.'
|
|
124
|
+
|
|
125
|
+
- kind: guidelines
|
|
126
|
+
for: all
|
|
127
|
+
title: Accessibility
|
|
128
|
+
tags: [accessibility]
|
|
129
|
+
items:
|
|
130
|
+
- refs:
|
|
131
|
+
- to: semantics#landmark-requirements
|
|
132
|
+
rel: same-as
|
|
133
|
+
- refs:
|
|
134
|
+
- to: semantics#list-semantics
|
|
135
|
+
rel: same-as
|
|
136
|
+
- refs:
|
|
137
|
+
- to: api-essentials#responsive-array-undefined-slot
|
|
138
|
+
rel: same-as
|
|
139
|
+
- level: should
|
|
140
|
+
statement: Flex provides layout along an axis. It does not add keyboard handling, focus management, or ARIA state. If you render Flex as a semantic element via `as`, you own the behavior that element requires.
|
|
141
|
+
- refs:
|
|
142
|
+
- to: shared-foundations#layout-primitive-as-not-behavioral
|
|
143
|
+
rel: same-as
|
|
144
|
+
- level: must-not
|
|
145
|
+
statement: 'Do not use `flex-direction: row-reverse` or `flex-direction: column-reverse` when children contain content users interact with or read. Do not use CSS `order` on Flex children. Screen readers and keyboard follow DOM order, not visual order (WCAG 1.3.2 A, WCAG 2.4.3 A). If visual reordering cannot be avoided, confirm the DOM order produces a logical reading sequence.'
|
|
146
|
+
- kind: section
|
|
147
|
+
for: agent
|
|
148
|
+
freeform:
|
|
149
|
+
- title: Responsive array breakpoints
|
|
150
|
+
body: |-
|
|
151
|
+
Every Flex prop that accepts `Responsive<T>` takes a breakpoint array. The Responsive pattern (`responsive`) has the breakpoint table and the rules for undefined slots.
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
// Column on mobile → row at 600px
|
|
155
|
+
<Flex
|
|
156
|
+
flexDirection={['column', undefined, 'row']}
|
|
157
|
+
gap={[2, undefined, 3]}
|
|
158
|
+
alignItems={['flex-start', undefined, 'center']}
|
|
159
|
+
>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
alternatives:
|
|
163
|
+
- to: v-stack
|
|
164
|
+
note: Vertical list with an even gap between items
|
|
165
|
+
- to: h-stack
|
|
166
|
+
- to: grid
|
|
167
|
+
note: Two-axis layout for card grids and dashboards
|
|
168
|
+
- to: box
|
|
169
|
+
note: Simpler container for spacing and structure
|
|
170
|
+
refs:
|
|
171
|
+
- to: responsive
|
|
172
|
+
rel: relates-to
|
|
173
|
+
note: Owns the breakpoint table for responsive arrays
|
|
174
|
+
- to: space
|
|
175
|
+
rel: relates-to
|
|
176
|
+
sourceFiles:
|
|
177
|
+
- platform: react
|
|
178
|
+
file: packages/ui/src/components/flex/Flex.tsx
|
|
179
|
+
imports:
|
|
180
|
+
- platform: react
|
|
181
|
+
code: import { Flex } from '@sanity/ui'
|
|
182
|
+
package: '@sanity/ui'
|
|
183
|
+
$extensions:
|
|
184
|
+
com.sanity.ui:
|
|
185
|
+
implementationStatus:
|
|
186
|
+
context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
|
|
187
|
+
implemented: true
|
|
188
|
+
migrationGuide:
|
|
189
|
+
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.'
|
|
190
|
+
codemod: |-
|
|
191
|
+
Props are renamed to match CSS: `direction`→`flexDirection`, `align`→`alignItems`, `justify`→`justifyContent`, `wrap`→`flexWrap`, `gapX`/`gapY`→`columnGap`/`rowGap`. The old names are silent no-ops, not TypeScript errors — do not assume they still work.
|
|
192
|
+
|
|
193
|
+
Run the codemod: `pnpx @sanity/ui-codemod latest:flex --paths <paths> --toPackage @sanity/ui`.
|
|
194
|
+
guidance: |-
|
|
195
|
+
Flex in the new system replaces the `@sanity/ui` Flex. Core layout behavior is the same.
|
|
196
|
+
|
|
197
|
+
### Key differences
|
|
198
|
+
|
|
199
|
+
- v5 components use CSS classes with a static stylesheet instead of `styled-components`.
|
|
200
|
+
- Props are named to match their CSS forms. `direction` → `flexDirection`, `align` → `alignItems`, `justify` → `justifyContent`, `wrap` → `flexWrap`.
|
|
201
|
+
- The new Flex sets `display` to `'flex'` by default.
|
|
202
|
+
- The new API has direct props for width, height, position, border, and similar attributes.
|
|
203
|
+
- `gapX`/`gapY` props renamed to `columnGap` and `rowGap`.
|
|
204
|
+
|
|
205
|
+
### Detailed list of differences
|
|
206
|
+
|
|
207
|
+
| v3 prop | v5 prop | Notes |
|
|
208
|
+
| :---- | :---- | :---- |
|
|
209
|
+
| `direction="column"` | `flexDirection="column"` | Renamed from `direction` to `flexDirection`. |
|
|
210
|
+
| `align="center"` | `alignItems="center"` | Renamed from `align` to `alignItems`. |
|
|
211
|
+
| `justify="space-between"` | `justifyContent="space-between"` | Renamed from `justify` to `justifyContent`. |
|
|
212
|
+
| `wrap="wrap"` | `flexWrap="wrap"` | Renamed from `wrap` to `flexWrap`. |
|
|
213
|
+
| `flex={1}` | `flexGrow={1}` | v3 used a `flex` shorthand on Box. Split into `flexGrow`, `flexShrink`, `flexBasis`. |
|
|
214
|
+
| — | `rowGap`, `columnGap` | New. Separate row and column gap control. |
|
|
215
|
+
| — | `tone` | New. Sets a semantic background tint. Unset, Flex has no background. Accepts `default`, `neutral`, `positive`, `suggest`, `caution`, and `critical`. |
|
|
216
|
+
| — | `width`, `minWidth`, `maxWidth` | New. Accept any CSS string. |
|
|
217
|
+
| — | `position`, `zIndex` | New. |
|
|
218
|
+
| — | `border`, `radius` | New. |
|
|
219
|
+
|
|
220
|
+
### Breaking changes
|
|
221
|
+
|
|
222
|
+
- **`direction` renamed to `flexDirection`.** `<Flex direction="column">` does nothing. Use `<Flex flexDirection="column">`.
|
|
223
|
+
- **`align` renamed to `alignItems`.** `<Flex align="center">` does nothing. Use `<Flex alignItems="center">`.
|
|
224
|
+
- **`justify` renamed to `justifyContent`.** `<Flex justify="space-between">` does nothing. Use `<Flex justifyContent="space-between">`.
|
|
225
|
+
- **`wrap` renamed to `flexWrap`.** `<Flex wrap="wrap">` does nothing. Use `<Flex flexWrap="wrap">`. This is the most common source of 320px reflow failures.
|
|
226
|
+
- **`flex` prop removed.** `<Flex flex={1}>` does nothing. Use `flexGrow={1}`, `flexShrink={1}`, `flexBasis="0"` separately.
|
|
227
|
+
- **`styled-components` no longer used.** Custom styled-components extensions like `styled(Flex)` will not work.
|
|
228
|
+
|
|
229
|
+
### Codemod
|
|
230
|
+
|
|
231
|
+
A codemod is available to make the changes above less painful. Run the following command with the path (or a space-separated list of paths) to the file or directory you want to migrate.
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
pnpx @sanity/ui-codemod latest:flex --paths <paths> --toPackage @sanity/ui
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
If an instance cannot be migrated or needs manual review, the codemod inserts a comment prefixed with “UI-POC-CODEMOD TODO”.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: grid
|
|
3
|
+
name: Grid
|
|
4
|
+
description: Renders a CSS grid layout container. Supports named props for all CSS grid properties with responsive arrays.
|
|
5
|
+
metadata:
|
|
6
|
+
tags: [layout, grid, columns, rows, two-axis, responsive, dashboard, card-grid, CSS grid]
|
|
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 non-tabular content in multiple rows and columns.
|
|
17
|
+
- level: should
|
|
18
|
+
statement: To build fixed-column layouts where items should align on a shared grid (dashboards, card grids, settings panels).
|
|
19
|
+
- level: should
|
|
20
|
+
statement: When you need precise control over row and column sizing, spanning, or placement.
|
|
21
|
+
- level: should-not
|
|
22
|
+
statement: When content flows in a single direction. Use Flex, VStack, or HStack instead.
|
|
23
|
+
alternatives:
|
|
24
|
+
- to: flex
|
|
25
|
+
- to: v-stack
|
|
26
|
+
- to: h-stack
|
|
27
|
+
- level: should-not
|
|
28
|
+
statement: When you need wrapping rows of variable-width items. Use Flex with flexWrap='wrap' instead.
|
|
29
|
+
alternatives:
|
|
30
|
+
- to: flex
|
|
31
|
+
- level: should-not
|
|
32
|
+
statement: When you need to constrain and center content at a max width. Use Container instead.
|
|
33
|
+
alternatives:
|
|
34
|
+
- to: container
|
|
35
|
+
- kind: guidelines
|
|
36
|
+
for: all
|
|
37
|
+
framing: how-to-use
|
|
38
|
+
items:
|
|
39
|
+
- refs:
|
|
40
|
+
- to: api-essentials#sizing-is-a-css-string
|
|
41
|
+
rel: same-as
|
|
42
|
+
- id: grid-template-columns-uses-fr-or-minmax
|
|
43
|
+
level: should
|
|
44
|
+
statement: 'Use gridTemplateColumns with repeat() and fr units, minmax(), auto, or responsive arrays to build layouts that adapt gracefully — avoid bare pixel values.'
|
|
45
|
+
example:
|
|
46
|
+
title: How to satisfy this
|
|
47
|
+
description: "Review the JSX source and confirm gridTemplateColumns values use expressions like 'repeat(3, 1fr)', 'minmax(200px, 1fr)', or 'auto 1fr'. Pass an array to gridTemplateColumns for responsive breakpoints (for example, ['1fr', 'repeat(2, 1fr)', 'repeat(3, 1fr)']) and verify the rendered grid adapts at each breakpoint."
|
|
48
|
+
checkedBy: manual
|
|
49
|
+
- id: gap-used-not-child-margin
|
|
50
|
+
level: should
|
|
51
|
+
statement: Use gap, columnGap, or rowGap on the Grid component to control the gap between grid cells, not padding or margin on child elements.
|
|
52
|
+
example:
|
|
53
|
+
title: How to satisfy this
|
|
54
|
+
description: Inspect the JSX source and confirm child elements inside Grid have no margin or padding props intended to create inter-cell spacing. In browser DevTools, inspect the computed styles of grid children and verify there is no margin contributing to the gap between cells.
|
|
55
|
+
checkedBy: manual
|
|
56
|
+
- refs:
|
|
57
|
+
- to: shared-foundations#layout-primitive-no-text-styles
|
|
58
|
+
rel: same-as
|
|
59
|
+
tags: [content]
|
|
60
|
+
- id: no-visual-reorder-via-grid-placement
|
|
61
|
+
level: must-not
|
|
62
|
+
statement: Don't use CSS order, gridColumn, or gridRow to visually reorder items away from their DOM order — screen readers follow DOM order, so the visual order of grid items should match their DOM source order.
|
|
63
|
+
example:
|
|
64
|
+
title: How to satisfy this
|
|
65
|
+
description: Tab through the grid with keyboard-only navigation and confirm focus moves in the same sequence as the visual reading order. Inspect the rendered DOM in browser DevTools and confirm the sequence of child nodes matches the left-to-right, top-to-bottom visual order of the grid. Use a screen reader and verify the announced order of items matches what a sighted user would read.
|
|
66
|
+
checkedBy: manual
|
|
67
|
+
- id: no-hardcoded-px-in-grid-template-columns
|
|
68
|
+
level: must-not
|
|
69
|
+
statement: Don't hardcode pixel values in gridTemplateColumns when a fluid unit like fr, minmax(), or auto would serve the same purpose more resiliently.
|
|
70
|
+
example:
|
|
71
|
+
title: How to satisfy this
|
|
72
|
+
description: "Review the JSX source and confirm gridTemplateColumns does not contain values like '200px 200px' or '33% 33% 33%' where 'repeat(3, 1fr)' or 'repeat(3, minmax(0, 1fr))' would work. If a minimum width is needed, verify it is expressed as the lower bound of minmax() (for example, 'minmax(160px, 1fr)') rather than as a fixed column width."
|
|
73
|
+
checkedBy: manual
|
|
74
|
+
- kind: guidelines
|
|
75
|
+
for: all
|
|
76
|
+
title: Accessibility
|
|
77
|
+
tags: [accessibility]
|
|
78
|
+
items:
|
|
79
|
+
- level: must
|
|
80
|
+
statement: If Grid is used for an interactive widget (calendar, data grid, color picker), you must implement the WAI-ARIA grid pattern yourself. This means `role="grid"` with `role="row"` and `role="gridcell"` children, roving tabindex, and full keyboard navigation. Grid the component provides none of this. See the WAI-ARIA Authoring Practices Guide for the `grid` pattern.
|
|
81
|
+
- refs:
|
|
82
|
+
- to: semantics#landmark-requirements
|
|
83
|
+
rel: same-as
|
|
84
|
+
- refs:
|
|
85
|
+
- to: semantics#list-semantics
|
|
86
|
+
rel: same-as
|
|
87
|
+
- refs:
|
|
88
|
+
- to: api-essentials#responsive-array-undefined-slot
|
|
89
|
+
rel: same-as
|
|
90
|
+
- level: should
|
|
91
|
+
statement: 'CSS grid placement (`gridColumn`, `gridRow`, `gridAutoFlow: "column dense"`) can visually reorder items without touching the DOM. Screen readers and keyboard users follow DOM order, not visual order. Never use grid placement to change the logical reading or focus sequence — keep visual order and DOM order in sync (WCAG 1.3.2 A).'
|
|
92
|
+
- level: should
|
|
93
|
+
statement: '`gridAutoFlow: "row dense"` and `"column dense"` fill holes in the grid by pulling later items forward. This can produce a visual order that diverges from DOM order. Only use dense packing for purely decorative or non-interactive content (for example, image mosaics) where reading order does not matter.'
|
|
94
|
+
- level: should
|
|
95
|
+
statement: Take Grid gap values from the spacing scale. Do not use fixed `px` values for gap where a step exists — a fixed value drifts from the scale when the token values change.
|
|
96
|
+
- refs:
|
|
97
|
+
- to: shared-foundations#layout-primitive-as-not-behavioral
|
|
98
|
+
rel: same-as
|
|
99
|
+
- kind: section
|
|
100
|
+
for: agent
|
|
101
|
+
freeform:
|
|
102
|
+
- title: Responsive array breakpoints
|
|
103
|
+
body: |-
|
|
104
|
+
Every Grid prop that accepts `Responsive<T>` takes a breakpoint array. The Responsive pattern (`responsive`) has the breakpoint table and the rules for undefined slots.
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
// 1 col → 2 col at 600px → 3 col at 1200px
|
|
108
|
+
<Grid
|
|
109
|
+
gridTemplateColumns={['1fr', '1fr', '1fr 1fr', '1fr 1fr', 'repeat(3, 1fr)']}
|
|
110
|
+
gap={[2, undefined, 3]}
|
|
111
|
+
>
|
|
112
|
+
```
|
|
113
|
+
- title: gridTemplateColumns templates
|
|
114
|
+
body: |-
|
|
115
|
+
Grid uses CSS string syntax for columns — there is no numeric columns prop.
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
// 1 column
|
|
119
|
+
<Grid gridTemplateColumns="1fr" gap={3}>
|
|
120
|
+
|
|
121
|
+
// 2 equal columns
|
|
122
|
+
<Grid gridTemplateColumns="1fr 1fr" gap={3}>
|
|
123
|
+
|
|
124
|
+
// 3 equal columns
|
|
125
|
+
<Grid gridTemplateColumns="repeat(3, 1fr)" gap={3}>
|
|
126
|
+
|
|
127
|
+
// 4 equal columns
|
|
128
|
+
<Grid gridTemplateColumns="repeat(4, 1fr)" gap={3}>
|
|
129
|
+
|
|
130
|
+
// Auto-fit: fill row with as many columns as fit at min 240px
|
|
131
|
+
<Grid gridTemplateColumns="repeat(auto-fit, minmax(240px, 1fr))" gap={3}>
|
|
132
|
+
|
|
133
|
+
// Responsive: 1 col mobile → 2 col at 600px → 3 col at 1200px
|
|
134
|
+
<Grid
|
|
135
|
+
gridTemplateColumns={['1fr', '1fr', '1fr 1fr', '1fr 1fr', 'repeat(3, 1fr)']}
|
|
136
|
+
gap={3}
|
|
137
|
+
>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
alternatives:
|
|
141
|
+
- to: flex
|
|
142
|
+
note: One-axis layout for rows or columns
|
|
143
|
+
- to: container
|
|
144
|
+
refs:
|
|
145
|
+
- to: responsive
|
|
146
|
+
rel: relates-to
|
|
147
|
+
note: Owns the breakpoint table for responsive arrays
|
|
148
|
+
- to: space
|
|
149
|
+
rel: relates-to
|
|
150
|
+
- to: box
|
|
151
|
+
rel: relates-to
|
|
152
|
+
note: Single container for spacing and structure
|
|
153
|
+
sourceFiles:
|
|
154
|
+
- platform: react
|
|
155
|
+
file: packages/ui/src/components/grid/Grid.tsx
|
|
156
|
+
imports:
|
|
157
|
+
- platform: react
|
|
158
|
+
code: import { Grid } from '@sanity/ui'
|
|
159
|
+
package: '@sanity/ui'
|
|
160
|
+
$extensions:
|
|
161
|
+
com.sanity.ui:
|
|
162
|
+
implementationStatus:
|
|
163
|
+
context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
|
|
164
|
+
implemented: true
|
|
165
|
+
migrationGuide:
|
|
166
|
+
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.'
|
|
167
|
+
codemod: |-
|
|
168
|
+
`columns`/`rows` are removed — use `gridTemplateColumns`/`gridTemplateRows` with CSS grid syntax (`columns={3}` → `gridTemplateColumns="repeat(3, 1fr)"`). `autoRows`/`autoCols`/`autoFlow`/`gapX`/`gapY` and child props (`column`, `row`, etc.) all gain a `grid` prefix.
|
|
169
|
+
|
|
170
|
+
Run the codemod: `pnpx @sanity/ui-codemod latest:grid --paths <paths> --toPackage @sanity/ui`.
|
|
171
|
+
guidance: |-
|
|
172
|
+
Grid in the new system replaces the `@sanity/ui` Grid. The core grid layout behavior is the same.
|
|
173
|
+
|
|
174
|
+
### Key differences
|
|
175
|
+
|
|
176
|
+
- v5 components use CSS classes with a static stylesheet as opposed to `styled-components`.
|
|
177
|
+
- `columns` and `rows` props have been removed. Use `gridTemplateColumns` and `gridTemplateRows` with CSS grid syntax. `columns={3}` becomes `gridTemplateColumns="repeat(3, 1fr)"`.
|
|
178
|
+
- Props are named to match their CSS equivalents. `autoRows` → `gridAutoRows`, `autoCols` → `gridAutoColumns`, `autoFlow` → `gridAutoFlow`, `gapX` → `columnGap`, `gapY` → `rowGap`. On child elements: `column` → `gridColumn`, `row` → `gridRow`, `columnStart` → `gridColumnStart`, etc.
|
|
179
|
+
- Responsive arrays work on grid-related props. Use `gridTemplateColumns={['1fr', '1fr', '1fr 1fr', 'repeat(3, 1fr)']}` for responsive column counts.
|
|
180
|
+
|
|
181
|
+
### Detailed list of differences
|
|
182
|
+
|
|
183
|
+
| v3 prop | v5 prop | Notes |
|
|
184
|
+
| :---- | :---- | :---- |
|
|
185
|
+
| `columns={3}` | `gridTemplateColumns="repeat(3, 1fr)"` | v3 accepted a number. The new version uses the CSS `grid-template-columns` string. |
|
|
186
|
+
| `rows={2}` | `gridTemplateRows="repeat(2, 1fr)"` | Same change — numeric shorthand replaced by CSS string. |
|
|
187
|
+
| `autoRows="min"` | `gridAutoRows="min-content"` | v3 used shorthand values (`'min'`, `'max'`, `'fr'`). New uses CSS values. |
|
|
188
|
+
| `autoCols="auto"` | `gridAutoColumns="auto"` | Renamed from `autoCols` to `gridAutoColumns`. |
|
|
189
|
+
| `autoFlow="column"` | `gridAutoFlow="column"` | Renamed from `autoFlow` to `gridAutoFlow`. |
|
|
190
|
+
| `gapX={2}` | `columnGap={2}` | Renamed from `gapX` to `columnGap`. |
|
|
191
|
+
| `gapY={4}` | `rowGap={4}` | Renamed from `gapY` to `rowGap`. |
|
|
192
|
+
| — | `tone` | New. Sets a semantic background tint. Unset, Grid has no background. Accepts `default`, `neutral`, `positive`, `suggest`, `caution`, and `critical`. |
|
|
193
|
+
| — | `width`, `minWidth`, `maxWidth` | New. Accept any CSS string. |
|
|
194
|
+
| — | `position`, `zIndex` | New. |
|
|
195
|
+
| — | `border`, `radius` | New. |
|
|
196
|
+
|
|
197
|
+
### Breaking changes
|
|
198
|
+
|
|
199
|
+
- **`columns` prop removed.** `<Grid columns={3}>` does nothing. Use `<Grid gridTemplateColumns="repeat(3, 1fr)">`.
|
|
200
|
+
- **`rows` prop removed.** `<Grid rows={2}>` does nothing. Use `<Grid gridTemplateRows="repeat(2, 1fr)">`.
|
|
201
|
+
- **`autoRows` renamed to `gridAutoRows`.** The old prop name does nothing.
|
|
202
|
+
- **`autoCols` renamed to `gridAutoColumns`.** The old prop name does nothing.
|
|
203
|
+
- **`autoFlow` renamed to `gridAutoFlow`.** The old prop name does nothing.
|
|
204
|
+
- **`gapX` renamed to `columnGap`.** The old prop name does nothing.
|
|
205
|
+
- **`gapY` renamed to `rowGap`.** The old prop name does nothing.
|
|
206
|
+
- **Grid child props renamed on child elements.** `column` → `gridColumn`, `row` → `gridRow`, `columnStart` → `gridColumnStart`, `columnEnd` → `gridColumnEnd`, `rowStart` → `gridRowStart`, `rowEnd` → `gridRowEnd`. The old names do nothing.
|
|
207
|
+
- **`styled-components` no longer used.** Custom styled-components extensions like `styled(Grid)` will not work.
|
|
208
|
+
|
|
209
|
+
### Codemod
|
|
210
|
+
|
|
211
|
+
A codemod is ready to make the changes above less painful. To get started, run the following command with the path to the file or directory you want to migrate.
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
pnpx @sanity/ui-codemod latest:grid --paths <paths> --toPackage @sanity/ui
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
If a component instance cannot be migrated, includes unclear changes, or needs manual review, the codemod inserts a comment prefixed with “UI-POC-CODEMOD TODO”.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: h-stack
|
|
3
|
+
name: HStack
|
|
4
|
+
description: HStack provides an opinionated horizontal layout with uniform gaps for simple use cases.
|
|
5
|
+
metadata:
|
|
6
|
+
tags: [layout, horizontal, row, stack, gap, icon-label, hstack, inline, toolbar, flex]
|
|
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 horizontally lay out items for common use cases: icon-label pairs, toolbar groups, badges, and filters.'
|
|
17
|
+
- level: should-not
|
|
18
|
+
statement: For vertical stacking. Use VStack or Flex instead.
|
|
19
|
+
alternatives:
|
|
20
|
+
- to: v-stack
|
|
21
|
+
- to: flex
|
|
22
|
+
- level: should-not
|
|
23
|
+
statement: For full-width rows that stretch across their container. Use Flex instead.
|
|
24
|
+
alternatives:
|
|
25
|
+
- to: flex
|
|
26
|
+
- id: horizontal-layouts-need-custom-alignment
|
|
27
|
+
level: should-not
|
|
28
|
+
statement: For horizontal layouts that need custom alignment, or that must stay on one line. Use Flex instead.
|
|
29
|
+
alternatives:
|
|
30
|
+
- to: flex
|
|
31
|
+
- kind: guidelines
|
|
32
|
+
for: agent
|
|
33
|
+
framing: when-to-use
|
|
34
|
+
title: When to use
|
|
35
|
+
items:
|
|
36
|
+
- level: should-not
|
|
37
|
+
statement: Inline is deprecated — use HStack instead.
|
|
38
|
+
alternatives:
|
|
39
|
+
- to: inline
|
|
40
|
+
- kind: guidelines
|
|
41
|
+
for: all
|
|
42
|
+
framing: how-to-use
|
|
43
|
+
items:
|
|
44
|
+
- id: h-stack-defaults
|
|
45
|
+
level: must
|
|
46
|
+
statement: "Expect HStack's three fixed defaults. It renders an inline flex row (`display: inline-flex`), so it sizes to its content and does not stretch to fill its container. It centers children on the cross axis (`alignItems: center`). It wraps children onto a new line when they run out of room (`flexWrap: wrap`). None of these can be changed through props — use Flex when you need a different value."
|
|
47
|
+
- level: should
|
|
48
|
+
statement: "Size the gap to the content: {space-1} between an icon and its text, {space-2} for a row of buttons or toolbar items, and {space-3} or more between separate groups. The full scale is in the Space scale entry's table (`space`)."
|
|
49
|
+
- level: should
|
|
50
|
+
statement: Use HStack for icon+label pairs, button groups, and compact inline groups.
|
|
51
|
+
- level: must-not
|
|
52
|
+
statement: "Don't use HStack when you need alignItems, justifyContent, flexWrap, or any flex prop — use Flex instead. HStack only accepts `as` and `gap`. Passing any other prop is a TypeScript error."
|
|
53
|
+
alternatives:
|
|
54
|
+
- to: flex
|
|
55
|
+
- level: must-not
|
|
56
|
+
statement: Don't add margin to children for spacing — use gap.
|
|
57
|
+
- kind: guidelines
|
|
58
|
+
for: agent
|
|
59
|
+
framing: how-to-use
|
|
60
|
+
items:
|
|
61
|
+
- level: must-not
|
|
62
|
+
statement: "HStack accepts only as and gap. Don't pass any other prop as a JSX attribute."
|
|
63
|
+
- level: must-not
|
|
64
|
+
statement: 'Do not use HStack for a row that must stay on one line. HStack wraps by default (`flexWrap: wrap`) and has no prop to turn it off. Use Flex, which does not wrap unless you set `flexWrap`.'
|
|
65
|
+
|
|
66
|
+
- kind: guidelines
|
|
67
|
+
for: all
|
|
68
|
+
title: Accessibility
|
|
69
|
+
tags: [accessibility]
|
|
70
|
+
items:
|
|
71
|
+
- id: h-stack-dom-order-not-css-order
|
|
72
|
+
level: must-not
|
|
73
|
+
statement: Don’t use CSS to change the visual order of HStack's children. Children render in DOM order — screen readers do not detect CSS order changes.
|
|
74
|
+
- kind: section
|
|
75
|
+
for: agent
|
|
76
|
+
freeform:
|
|
77
|
+
- title: HStack vs Flex
|
|
78
|
+
body: |-
|
|
79
|
+
HStack only accepts `as` and `gap`. Passing any other prop directly is a TypeScript error.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
// correct — gap is the only spacing control
|
|
83
|
+
<HStack gap={3}>
|
|
84
|
+
<Button text="Save" />
|
|
85
|
+
<Button level="tertiary" text="Cancel" />
|
|
86
|
+
</HStack>
|
|
87
|
+
|
|
88
|
+
// wrong — TS2322: alignItems and padding do not exist on HStack
|
|
89
|
+
<HStack gap={3} padding={4}>
|
|
90
|
+
...
|
|
91
|
+
</HStack>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
When you need alignment, distribution, or wrapping, use `Flex`:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
<Flex gap={3} alignItems="center" justifyContent="space-between">
|
|
98
|
+
<Text>Label</Text>
|
|
99
|
+
<Button>Action</Button>
|
|
100
|
+
</Flex>
|
|
101
|
+
```
|
|
102
|
+
alternatives:
|
|
103
|
+
- to: flex
|
|
104
|
+
note: Row or column layout with full flex control
|
|
105
|
+
- to: v-stack
|
|
106
|
+
note: Vertical stack with uniform spacing
|
|
107
|
+
- to: inline
|
|
108
|
+
note: Deprecated. Replaced by HStack.
|
|
109
|
+
refs:
|
|
110
|
+
- href: https://www.figma.com/design/5mhVqXlldJEEB2VWZeKQ4i/Sanity-UI?node-id=32600-2633
|
|
111
|
+
rel: design
|
|
112
|
+
role: Figma component (v5)
|
|
113
|
+
- to: space
|
|
114
|
+
rel: relates-to
|
|
115
|
+
sourceFiles:
|
|
116
|
+
- platform: react
|
|
117
|
+
file: packages/ui/src/components/h-stack/HStack.tsx
|
|
118
|
+
imports:
|
|
119
|
+
- platform: react
|
|
120
|
+
code: import { HStack } from '@sanity/ui'
|
|
121
|
+
package: '@sanity/ui'
|
|
122
|
+
|
|
123
|
+
$extensions:
|
|
124
|
+
com.sanity.ui:
|
|
125
|
+
implementationStatus:
|
|
126
|
+
context: Implementation status. Lets a tool tell a component that is coming from one that does not exist, without parsing the status note.
|
|
127
|
+
implemented: true
|