@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,590 @@
|
|
|
1
|
+
kind: sanity.pattern
|
|
2
|
+
id: responsive
|
|
3
|
+
name: Responsive
|
|
4
|
+
description: A complete reference for building responsive Sanity UI layouts using spacing tokens, breakpoint arrays, reflow patterns, grid columns, sizing props, text overflow, and overflow portal rules.
|
|
5
|
+
metadata:
|
|
6
|
+
tags:
|
|
7
|
+
- tutorial
|
|
8
|
+
- responsive
|
|
9
|
+
- layout
|
|
10
|
+
- breakpoints
|
|
11
|
+
- spacing
|
|
12
|
+
- grid
|
|
13
|
+
- flexbox
|
|
14
|
+
- overflow
|
|
15
|
+
- wcag
|
|
16
|
+
- accessibility
|
|
17
|
+
- tokens
|
|
18
|
+
- Responsive<T>
|
|
19
|
+
- flexWrap
|
|
20
|
+
- minHeight
|
|
21
|
+
- spacing tokens
|
|
22
|
+
- truncate
|
|
23
|
+
- portal
|
|
24
|
+
- 320px reflow
|
|
25
|
+
- gridTemplateColumns
|
|
26
|
+
status:
|
|
27
|
+
status: stable
|
|
28
|
+
sections:
|
|
29
|
+
- kind: guidelines
|
|
30
|
+
for: all
|
|
31
|
+
framing: how-to-use
|
|
32
|
+
items:
|
|
33
|
+
- level: must
|
|
34
|
+
statement: Add `flexWrap="wrap"` to every horizontal `Flex` row (toolbar, action bar, card actions) so layouts reflow at 320px without horizontal scrolling.
|
|
35
|
+
- level: must
|
|
36
|
+
statement: Add `minWidth="0"` to any flex child that contains text. Without it the child cannot shrink below its content size, causing overflow past the viewport.
|
|
37
|
+
- id: inside-scrollable-container-must-failure
|
|
38
|
+
level: must
|
|
39
|
+
statement: >-
|
|
40
|
+
Tooltip and Popover render in the browser's top layer, so a scrollable or `overflow: hidden` ancestor does not clip them. Set their boolean `portal` prop only when an ancestor with `transform`, `filter` or `contain` breaks their positioning.
|
|
41
|
+
- level: must
|
|
42
|
+
statement: Use spacing scale tokens (0–9) for all `padding`, `margin`, `gap`, `rowGap`, and `columnGap` props — never guess with inline pixel styles.
|
|
43
|
+
- level: must
|
|
44
|
+
statement: Use `minHeight="100vh"` on the outermost layout container, not `height="100vh"`. `height` clips content that is taller than the viewport.
|
|
45
|
+
- level: should
|
|
46
|
+
statement: Use `truncate` prop on `Text` and `Heading` for text truncation.
|
|
47
|
+
- level: should
|
|
48
|
+
statement: Use `maxWidth` instead of `width` for sidebars, so the element can collapse responsively.
|
|
49
|
+
- level: should
|
|
50
|
+
statement: Use `gridTemplateColumns={['1fr', '1fr', '1fr 1fr', 'repeat(3, 1fr)']}` for responsive card grids, or `repeat(auto-fill, minmax(240px, 1fr))` for fluid grids.
|
|
51
|
+
- level: should
|
|
52
|
+
statement: 'Use `truncate` with a responsive array to show more lines on wider viewports, for example `truncate={[1, 1, 2]}`. It takes a number, so an `undefined` slot would turn truncation off at that breakpoint; fill every slot up to the last one you set.'
|
|
53
|
+
- level: should
|
|
54
|
+
statement: Inline styles are acceptable only for values with no prop or token equivalent, such as arbitrary `gridTemplateColumns` strings, `transform` offsets, or CSS custom property overrides.
|
|
55
|
+
- level: must-not
|
|
56
|
+
statement: "Do not use `style={{ padding: '12px' }}` or similar inline styles for values that map to a spacing token prop."
|
|
57
|
+
- level: must-not
|
|
58
|
+
statement: "Do not use `style={{ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}` — use `truncate={1}` on `Heading` or `Text` instead."
|
|
59
|
+
- level: must-not
|
|
60
|
+
statement: Do not use fixed pixel widths in `gridTemplateColumns`. Use `fr`, `auto`, or `minmax()` units.
|
|
61
|
+
- level: must-not
|
|
62
|
+
statement: >-
|
|
63
|
+
Do not give a sidebar a fixed `width` with `flexShrink={0}` at every width. It never collapses below that width, and the layout fails reflow at 320px. Use responsive `flexBasis`, `['100%', '100%', '100%', '260px']`, so the sidebar stacks on narrow screens, or switch it to an overlay below the desktop breakpoint. Write every slot in the array: an `undefined` slot resets a string prop like `flexBasis` to its default instead of inheriting the previous value.
|
|
64
|
+
- kind: section
|
|
65
|
+
for: all
|
|
66
|
+
freeform:
|
|
67
|
+
- title: Overview
|
|
68
|
+
body: Sanity UI experiences should work across all devices. A Sanity interface isn't done until it's responsive. This document covers spacing tokens, breakpoint arrays, reflow patterns, grid columns, sizing props, text overflow, and overflow portal rules for building responsive layouts.
|
|
69
|
+
- kind: section
|
|
70
|
+
for: all
|
|
71
|
+
freeform:
|
|
72
|
+
- title: 'Quick reference: breakpoints'
|
|
73
|
+
body: |-
|
|
74
|
+
Every layout prop accepting `Responsive<T>` also accepts an array. Each array position maps to a `min-width` breakpoint. Position `0` is the base (no media query — applies from 0px up, including 320px).
|
|
75
|
+
|
|
76
|
+
| Array index | Min-width | Typical target |
|
|
77
|
+
|-------------|-----------|----------------|
|
|
78
|
+
| `[0]` | none (base) | 320px — narrow mobile, 400% zoom |
|
|
79
|
+
| `[1]` | `360px` | Standard mobile |
|
|
80
|
+
| `[2]` | `600px` | Large phone / small tablet |
|
|
81
|
+
| `[3]` | `900px` | Tablet / small laptop |
|
|
82
|
+
| `[4]` | `1200px` | Desktop |
|
|
83
|
+
| `[5]` | `1800px` | Large desktop and ultra-wide |
|
|
84
|
+
|
|
85
|
+
An array has at most six slots; anything past `[5]` is ignored. `undefined` in a slot inherits the previous breakpoint's value only for props that take a keyword or a step: spacing and position steps, `flexDirection`, `flexWrap`, `alignItems`, `justifyContent`, `display`, `overflow`, `radius` and `size`. For props that take a CSS string or a number — `flexBasis`, `width`, `height`, the min and max sizes, the `grid*` template and placement props, `flexGrow`, `flexShrink`, `zIndex` and Text's `truncate` — and for the border, `muted`, `trim` and `fullWidth` toggles, an `undefined` slot resets the prop to its default. Write every slot for those.
|
|
86
|
+
- kind: section
|
|
87
|
+
for: all
|
|
88
|
+
freeform:
|
|
89
|
+
- title: 1. Spacing scale
|
|
90
|
+
body: |-
|
|
91
|
+
Every `padding`, `margin`, `gap`, `rowGap`, and `columnGap` prop maps to a CSS token. Use them — never guess with inline styles.
|
|
92
|
+
|
|
93
|
+
The steps and their common uses are in the Space scale entry's table (`space`).
|
|
94
|
+
|
|
95
|
+
**Most common values in practice:**
|
|
96
|
+
- `gap={2}`, {space-2} — toolbar icon-button rows
|
|
97
|
+
- `gap={3}`, {space-3} — standard flex row gaps
|
|
98
|
+
- `padding={3}`, {space-3} — default card / nav item padding
|
|
99
|
+
- `padding={4}`, {space-4} — content area padding
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
{/* ✗ Undiscoverable pixel values via inline style */}
|
|
103
|
+
<Box style={{ padding: '12px', gap: '8px' }} />
|
|
104
|
+
|
|
105
|
+
{/* ✓ Token-based — scales with user font-size settings */}
|
|
106
|
+
<Box padding={3} />
|
|
107
|
+
<Flex gap={2} />
|
|
108
|
+
```
|
|
109
|
+
- kind: section
|
|
110
|
+
for: all
|
|
111
|
+
freeform:
|
|
112
|
+
- title: 2. Breakpoints and responsive arrays
|
|
113
|
+
body: |-
|
|
114
|
+
See the **Quick reference: breakpoints** table for the pixel values. This section covers syntax and patterns.
|
|
115
|
+
|
|
116
|
+
### Syntax
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
{/* Single value — applies at all breakpoints */}
|
|
120
|
+
<Box padding={3} />
|
|
121
|
+
|
|
122
|
+
{/* Array — different value per breakpoint */}
|
|
123
|
+
<Box padding={[2, undefined, 3, 4]} />
|
|
124
|
+
{/* ^ ^ ^ ^
|
|
125
|
+
base 360px 600px 900px */}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**`undefined` inherits only for keyword and step props.** On `padding`, `gap`, `flexDirection` and the other props that take a keyword or a step, `undefined` skips a breakpoint and keeps the previous value. On a prop that takes a CSS string or a number, such as `flexBasis`, `width` or `gridTemplateColumns`, an `undefined` slot resets the prop to its default at that breakpoint. Write every slot for those props.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
{/* ✓ Correct — undefined skips 360px, uses 'row' from 600px up */}
|
|
132
|
+
<Flex flexDirection={['column', undefined, 'row']} />
|
|
133
|
+
|
|
134
|
+
{/* ✗ Wrong — flexBasis falls back to auto from 360px to 599px */}
|
|
135
|
+
<Box flexBasis={['100%', undefined, '260px']} />
|
|
136
|
+
|
|
137
|
+
{/* ✓ Correct — every slot written */}
|
|
138
|
+
<Box flexBasis={['100%', '100%', '260px']} />
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Common responsive patterns
|
|
142
|
+
|
|
143
|
+
**Layout direction — column on mobile, row on desktop:**
|
|
144
|
+
```tsx
|
|
145
|
+
<Flex flexDirection={['column', undefined, 'row']} gap={[2, undefined, 4]}>
|
|
146
|
+
<Box flexBasis={['100%', '100%', '260px']} flexShrink={0}>Sidebar</Box>
|
|
147
|
+
<Box flexGrow={1} minWidth="0">Content</Box>
|
|
148
|
+
</Flex>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Padding — tighter on mobile:**
|
|
152
|
+
```tsx
|
|
153
|
+
<Box padding={[2, undefined, 4]}>
|
|
154
|
+
{/* 8px on mobile, 20px on 600px+ */}
|
|
155
|
+
</Box>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Text size — larger at wider viewports:**
|
|
159
|
+
```tsx
|
|
160
|
+
<Heading as="h1" size={[1, undefined, undefined, 3]} />
|
|
161
|
+
{/* size 1 on mobile, size 3 on 900px+ */}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Alignment — centered on mobile, start on desktop:**
|
|
165
|
+
```tsx
|
|
166
|
+
<Text align={['center', undefined, 'start']} />
|
|
167
|
+
```
|
|
168
|
+
- kind: section
|
|
169
|
+
for: all
|
|
170
|
+
freeform:
|
|
171
|
+
- title: 3. 320px reflow (WCAG 1.4.10)
|
|
172
|
+
body: |-
|
|
173
|
+
Layouts must work at 320px with no horizontal scrolling. This section covers two responsive-specific cases: the wrap that never triggers, and the overlay-sidebar alternative.
|
|
174
|
+
|
|
175
|
+
### Fixed sidebar widths — the wrap that never triggers
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
{/* ✗ FAILS — sidebar won't collapse below 260px (no flexWrap, no flexShrink) */}
|
|
179
|
+
<Flex>
|
|
180
|
+
<Box width="260px" flexShrink={0}>Sidebar</Box>
|
|
181
|
+
<Box flexGrow={1}>Content</Box>
|
|
182
|
+
</Flex>
|
|
183
|
+
|
|
184
|
+
{/* ✗ ALSO FAILS — flexWrap is set, but the wrap never triggers at 375px */}
|
|
185
|
+
<Flex flexWrap="wrap" minHeight="100vh">
|
|
186
|
+
<Box width="260px">Sidebar</Box>
|
|
187
|
+
<Box flexGrow={1} minWidth="0">Content</Box>
|
|
188
|
+
</Flex>
|
|
189
|
+
|
|
190
|
+
{/* ✓ PASSES — both children claim a full row at narrow widths; sidebar takes 260px from 900px up */}
|
|
191
|
+
<Flex flexWrap="wrap" minHeight="100vh">
|
|
192
|
+
<Box
|
|
193
|
+
flexBasis={['100%', '100%', '100%', '260px']}
|
|
194
|
+
flexShrink={0}
|
|
195
|
+
>
|
|
196
|
+
Sidebar
|
|
197
|
+
</Box>
|
|
198
|
+
<Box
|
|
199
|
+
flexBasis={['100%', '100%', '100%', '0']}
|
|
200
|
+
flexGrow={1}
|
|
201
|
+
minWidth="0"
|
|
202
|
+
overflow="hidden"
|
|
203
|
+
>
|
|
204
|
+
Content
|
|
205
|
+
</Box>
|
|
206
|
+
</Flex>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**Why "ALSO FAILS" fails.** At 375px, the 260px sidebar and main column fit on one row. The main column gets only 115px. `flexWrap` moves a child to a new row only when it can't fit. Here the sizes sum to less than the viewport, so no wrap occurs.
|
|
210
|
+
|
|
211
|
+
**The fix needs responsive `flexBasis` on both children.** At narrow widths both children want a full row (basis `"100%"`), summing to 200% and forcing the wrap. At a desktop breakpoint the sidebar wants `"260px"` and main wants `"0"` plus `flexGrow`, and they sit side-by-side.
|
|
212
|
+
|
|
213
|
+
> The stack pattern keeps the sidebar visible — full-width above the main content — on mobile. For app shells where the sidebar should be hidden by default and shown via a toggle, see the popover pattern below.
|
|
214
|
+
|
|
215
|
+
### Toolbars with many buttons
|
|
216
|
+
|
|
217
|
+
The basic toolbar rule — `flexWrap="wrap"` and `gap={2}` on the heading-plus-buttons Flex. One case not covered by the basics: a toolbar with five or more buttons can still overflow at ≤375px even with `flexWrap`. Two fixes:
|
|
218
|
+
|
|
219
|
+
- Collapse labeled buttons to icon-only on mobile with a conditional render. Button's `text` is a plain string, not a responsive prop.
|
|
220
|
+
- Move secondary actions (Filter, Sort) into a `Popover` overflow.
|
|
221
|
+
|
|
222
|
+
### Mobile navigation: popover instead of stack
|
|
223
|
+
|
|
224
|
+
For app shells with sidebars hidden by default on mobile, put the nav in a Popover opened from a menu button. This is the standard for mobile navigation. The browser handles Escape and outside clicks. Requires React state for `isDesktop` plus `window.matchMedia`, not pure CSS. The example below shows only the nav logic.
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
import { useEffect, useState } from 'react'
|
|
228
|
+
import type { ReactNode } from 'react'
|
|
229
|
+
import { Box, Flex, IconButton, Popover } from '@sanity/ui'
|
|
230
|
+
import { MenuIcon } from '@sanity/icons/Menu'
|
|
231
|
+
|
|
232
|
+
const DESKTOP_QUERY = '(min-width: 900px)'
|
|
233
|
+
const NAV_ID = 'app-nav'
|
|
234
|
+
|
|
235
|
+
function matchesDesktop() {
|
|
236
|
+
return typeof window !== 'undefined' && window.matchMedia(DESKTOP_QUERY).matches
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const closeNav = () => document.getElementById(NAV_ID)?.hidePopover()
|
|
240
|
+
|
|
241
|
+
function AppShell({ nav, children }: { nav: (closeNav: () => void) => ReactNode; children: ReactNode }) {
|
|
242
|
+
const [isDesktop, setIsDesktop] = useState(matchesDesktop)
|
|
243
|
+
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
const mq = window.matchMedia(DESKTOP_QUERY)
|
|
246
|
+
const onChange = (e: MediaQueryListEvent) => {
|
|
247
|
+
setIsDesktop(e.matches)
|
|
248
|
+
if (e.matches) closeNav() // the inline nav replaces the Popover on desktop
|
|
249
|
+
}
|
|
250
|
+
mq.addEventListener('change', onChange)
|
|
251
|
+
return () => mq.removeEventListener('change', onChange)
|
|
252
|
+
}, [])
|
|
253
|
+
|
|
254
|
+
const navContent = (
|
|
255
|
+
<Box as="nav" aria-label="Main navigation" padding={2}>
|
|
256
|
+
{nav(closeNav)}
|
|
257
|
+
</Box>
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
<Flex minHeight="100vh">
|
|
262
|
+
{isDesktop && (
|
|
263
|
+
<Flex flexDirection="column" flexBasis="260px" flexShrink={0} tone="neutral" borderRight overflowY="auto">
|
|
264
|
+
{navContent}
|
|
265
|
+
</Flex>
|
|
266
|
+
)}
|
|
267
|
+
|
|
268
|
+
<Flex as="main" id="main" flexGrow={1} flexBasis="0" minWidth="0" overflow="hidden">
|
|
269
|
+
{!isDesktop && (
|
|
270
|
+
<Popover id={NAV_ID} placement="bottom-start" content={navContent}>
|
|
271
|
+
<IconButton icon={MenuIcon} level="tertiary" aria-label="Show navigation" />
|
|
272
|
+
</Popover>
|
|
273
|
+
)}
|
|
274
|
+
{children}
|
|
275
|
+
</Flex>
|
|
276
|
+
</Flex>
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Why each piece matters:**
|
|
282
|
+
|
|
283
|
+
- `DESKTOP_QUERY = '(min-width: 900px)'` matches the §2 breakpoint table at index `[3]` ("tablet / small laptop"). Below 900px is "tablet and mobile."
|
|
284
|
+
- `useState(matchesDesktop)` starts the layout in the right mode, so there is no flash of the wrong nav on first render.
|
|
285
|
+
- The `onChange` handler closes the Popover when the viewport widens to desktop, because the inline nav replaces it.
|
|
286
|
+
- `closeNav` calls `hidePopover()` on the Popover by its `id`. Passing it to the nav means picking an item closes the Popover.
|
|
287
|
+
- Escape and outside clicks close the Popover natively, so the example needs no Escape handler.
|
|
288
|
+
- `flexBasis="260px"` and `flexShrink={0}` keep the sidebar at 260px from 900px up. Below 900px the nav is in the Popover, so the fixed size never blocks reflow.
|
|
289
|
+
- `tone="neutral"` on the nav applies the design system's theme-aware background. Do not use `style={{ background: 'var(--card-bg-color, #fff)' }}`. The `#fff` fallback breaks dark mode.
|
|
290
|
+
- `borderRight` shows a border on the inline nav only.
|
|
291
|
+
- `{!isDesktop && <Popover>}` limits the menu button to mobile and tablet.
|
|
292
|
+
|
|
293
|
+
**When to choose which:**
|
|
294
|
+
|
|
295
|
+
- **VStack** — reading-first layouts, dashboards, content pages where the sidebar above the main content on mobile is acceptable.
|
|
296
|
+
- **Popover** — app-like UIs where mobile users expect navigation hidden until summoned.
|
|
297
|
+
|
|
298
|
+
### Secondary panels: the same rule applies
|
|
299
|
+
|
|
300
|
+
The popover pattern governs the primary sidebar. The same rule applies to every secondary panel — inspector panels, detail drawers, filter columns. Any panel that should be hidden on mobile must initialize with `matchesDesktop()`, not `true`.
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
{/* ✗ Inspector stays open on mobile — never hides */}
|
|
304
|
+
const [inspectorOpen, setInspectorOpen] = useState(true)
|
|
305
|
+
|
|
306
|
+
{/* ✓ Inspector defaults to closed on mobile, open on desktop */}
|
|
307
|
+
const [inspectorOpen, setInspectorOpen] = useState(matchesDesktop)
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
The `onChange` handler should close all such panels when the viewport narrows:
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
const onChange = (e: MediaQueryListEvent) => {
|
|
314
|
+
setIsDesktop(e.matches)
|
|
315
|
+
if (!e.matches) {
|
|
316
|
+
setSidebarOpen(false)
|
|
317
|
+
setInspectorOpen(false) // close every secondary panel on resize to mobile
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Toggle buttons for secondary panels follow the same rule as the menu button: gate them on `!isDesktop` if the panel should only be togglable on mobile and tablet.
|
|
323
|
+
- kind: section
|
|
324
|
+
for: all
|
|
325
|
+
freeform:
|
|
326
|
+
- title: 4. Responsive Grid columns
|
|
327
|
+
body: |-
|
|
328
|
+
Grid's `gridTemplateColumns` prop accepts a responsive array. Use `fr` units and `repeat()` — never hardcode pixel widths.
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
{/* ✓ 1 column on mobile, 2 on tablet, 3 on desktop */}
|
|
332
|
+
<Grid
|
|
333
|
+
gridTemplateColumns={['1fr', '1fr', '1fr 1fr', 'repeat(3, 1fr)']}
|
|
334
|
+
gap={3}
|
|
335
|
+
>
|
|
336
|
+
{items.map(item => (
|
|
337
|
+
<Card key={item.id}>{item.title}</Card>
|
|
338
|
+
))}
|
|
339
|
+
</Grid>
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
**Use `minmax()` for fluid grids that don't require exact breakpoints:**
|
|
343
|
+
```tsx
|
|
344
|
+
{/* Auto-fills columns, minimum 240px each, maximum 1fr */}
|
|
345
|
+
<Grid
|
|
346
|
+
gridTemplateColumns="repeat(auto-fill, minmax(240px, 1fr))"
|
|
347
|
+
gap={3}
|
|
348
|
+
>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Common column patterns:**
|
|
352
|
+
|
|
353
|
+
| Layout | `gridTemplateColumns` |
|
|
354
|
+
|--------|----------------------|
|
|
355
|
+
| Full-width single column | `'1fr'` |
|
|
356
|
+
| Two even columns | `'1fr 1fr'` or `'repeat(2, 1fr)'` |
|
|
357
|
+
| Sidebar + content | `'260px 1fr'` |
|
|
358
|
+
| Responsive 1→2→3 | `['1fr', '1fr', '1fr 1fr', 'repeat(3, 1fr)']` |
|
|
359
|
+
| Auto-fill fluid | `'repeat(auto-fill, minmax(240px, 1fr))'` |
|
|
360
|
+
|
|
361
|
+
**`gridColumn` on children for spanning:**
|
|
362
|
+
```tsx
|
|
363
|
+
{/* Featured item spans all 3 columns */}
|
|
364
|
+
<Grid gridTemplateColumns="repeat(3, 1fr)" gap={3}>
|
|
365
|
+
<Box gridColumn="1 / -1"><Card>Featured</Card></Box>
|
|
366
|
+
<Card>Item A</Card>
|
|
367
|
+
<Card>Item B</Card>
|
|
368
|
+
</Grid>
|
|
369
|
+
```
|
|
370
|
+
- kind: section
|
|
371
|
+
for: all
|
|
372
|
+
freeform:
|
|
373
|
+
- title: '5. Sizing: width, minWidth, maxWidth'
|
|
374
|
+
body: |-
|
|
375
|
+
Prefer `min-width` and `max-width` over fixed `width` whenever content may overflow or the container needs to collapse responsively.
|
|
376
|
+
|
|
377
|
+
### Width vs minWidth vs maxWidth
|
|
378
|
+
|
|
379
|
+
| Prop | Use when |
|
|
380
|
+
|------|----------|
|
|
381
|
+
| `width` | The element must be exactly this size (icons, avatars, fixed UI chrome) |
|
|
382
|
+
| `minWidth` | The element must be at least this size but can grow |
|
|
383
|
+
| `maxWidth` | The element must not exceed this size but can shrink |
|
|
384
|
+
| `minWidth="0"` | The element is a flex child containing text that may overflow |
|
|
385
|
+
|
|
386
|
+
### `minWidth="0"` on flex children
|
|
387
|
+
|
|
388
|
+
This is the most commonly missed prop. By default, a flex child's minimum size is its content size — it won't shrink below the longest word in a heading. Setting `minWidth="0"` allows the child to shrink past its content size, enabling text truncation and preventing overflow.
|
|
389
|
+
|
|
390
|
+
```tsx
|
|
391
|
+
{/* ✗ Long heading in flex row pushes layout past viewport */}
|
|
392
|
+
<Flex gap={3}>
|
|
393
|
+
<Heading as="h2">A very long document title that overflows</Heading>
|
|
394
|
+
<IconButton icon={CloseIcon} aria-label="Close" />
|
|
395
|
+
</Flex>
|
|
396
|
+
|
|
397
|
+
{/* ✓ Heading container can shrink; text truncates instead of overflowing */}
|
|
398
|
+
<Flex gap={3}>
|
|
399
|
+
<Box flexGrow={1} minWidth="0">
|
|
400
|
+
<Heading as="h2" truncate={1}>A very long document title that overflows</Heading>
|
|
401
|
+
</Box>
|
|
402
|
+
<Box flexShrink={0}>
|
|
403
|
+
<IconButton icon={CloseIcon} aria-label="Close" />
|
|
404
|
+
</Box>
|
|
405
|
+
</Flex>
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### When a positive `minWidth` is the right choice
|
|
409
|
+
|
|
410
|
+
`minWidth="0"` lets a flex child shrink to nothing. For "let this row wrap when content can't fit on one line," use a positive `minWidth`:
|
|
411
|
+
|
|
412
|
+
```tsx
|
|
413
|
+
{/* ✗ minWidth="0" lets the title squash to nothing and overlap the actions */}
|
|
414
|
+
<Flex gap={2}>
|
|
415
|
+
<Box flexGrow={1} minWidth="0">
|
|
416
|
+
<Heading as="h2">Document title</Heading>
|
|
417
|
+
</Box>
|
|
418
|
+
<Button text="Edit" />
|
|
419
|
+
<Button text="Delete" />
|
|
420
|
+
</Flex>
|
|
421
|
+
|
|
422
|
+
{/* ✓ minWidth="200px" forces the row to wrap when content can't fit */}
|
|
423
|
+
<Flex gap={2} flexWrap="wrap">
|
|
424
|
+
<Box flexGrow={1} minWidth="200px">
|
|
425
|
+
<Heading as="h2">Document title</Heading>
|
|
426
|
+
</Box>
|
|
427
|
+
<Button text="Edit" />
|
|
428
|
+
<Button text="Delete" />
|
|
429
|
+
</Flex>
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Decision rule:**
|
|
433
|
+
|
|
434
|
+
- Truncate text to one line: `minWidth="0"` plus `truncate={1}` on the heading or text.
|
|
435
|
+
- Wrap the row to a new line when content doesn't fit: a positive `minWidth` like `"200px"` or `"160px"`, plus `flexWrap="wrap"` on the parent.
|
|
436
|
+
|
|
437
|
+
### height vs minHeight
|
|
438
|
+
|
|
439
|
+
| Prop | Behavior |
|
|
440
|
+
|------|----------|
|
|
441
|
+
| `height="100vh"` | Container is exactly 100vh — content that overflows is clipped or causes scroll on the inner element only |
|
|
442
|
+
| `minHeight="100vh"` | Container is at least 100vh but grows when stacked content is taller |
|
|
443
|
+
|
|
444
|
+
Always use `minHeight="100vh"` on the outermost layout container. `height="100vh"` is appropriate only when the container must scroll internally (for example, a sidebar with `overflowY="auto"`).
|
|
445
|
+
|
|
446
|
+
```tsx
|
|
447
|
+
{/* ✗ Sidebar stacks above content but container clips at 100vh */}
|
|
448
|
+
<Flex flexWrap="wrap" height="100vh">
|
|
449
|
+
|
|
450
|
+
{/* ✓ Container grows to fit stacked content at narrow widths */}
|
|
451
|
+
<Flex flexWrap="wrap" minHeight="100vh">
|
|
452
|
+
```
|
|
453
|
+
- kind: section
|
|
454
|
+
for: all
|
|
455
|
+
freeform:
|
|
456
|
+
- title: 6. Text overflow
|
|
457
|
+
body: |-
|
|
458
|
+
Use the `truncate` prop on `Text`, `Heading`, and `Eyebrow` to limit text to a set number of lines. `truncate={1}` clips to one line with an ellipsis using `text-overflow`. Values above `1` clamp with CSS `-webkit-line-clamp`. Both work inside flex and grid containers.
|
|
459
|
+
|
|
460
|
+
Truncate metadata and support labels only: titles, file names, authors, dates. Never truncate body text, including a preview of it in a list row. Clipping changes meaning. In a list row, show the title and metadata, and leave the body for the detail view.
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
{/* ✗ Inline overflow styles bypass the spacing scale and break in flex containers */}
|
|
464
|
+
<Heading
|
|
465
|
+
as="h2"
|
|
466
|
+
style={{ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}
|
|
467
|
+
>
|
|
468
|
+
Long title
|
|
469
|
+
</Heading>
|
|
470
|
+
|
|
471
|
+
{/* ✓ Single-line truncation */}
|
|
472
|
+
<Heading as="h2" truncate={1}>Long title</Heading>
|
|
473
|
+
|
|
474
|
+
{/* ✓ Multi-line clamp on a long title in a list row */}
|
|
475
|
+
<Text size={1} weight="semibold" truncate={2}>
|
|
476
|
+
{document.title}
|
|
477
|
+
</Text>
|
|
478
|
+
|
|
479
|
+
{/* ✗ Clamped body text. The preview cuts the sentence mid-thought. */}
|
|
480
|
+
<Text size={1} truncate={2} as="p">
|
|
481
|
+
{document.bodyPreview}
|
|
482
|
+
</Text>
|
|
483
|
+
|
|
484
|
+
{/* ✓ The row shows the title and metadata. The body stays in the detail view. */}
|
|
485
|
+
<VStack gap={2}>
|
|
486
|
+
<Text size={1} weight="semibold" truncate={1}>{document.title}</Text>
|
|
487
|
+
<Text size={1} muted truncate={1}>{document.author} · {document.updatedAt}</Text>
|
|
488
|
+
</VStack>
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
**`truncate` accepts a responsive array** — you can show more lines on wider viewports:
|
|
492
|
+
|
|
493
|
+
```tsx
|
|
494
|
+
{/* A title: 1 line on mobile, 2 on tablet, unclamped on desktop */}
|
|
495
|
+
<Text size={1} weight="semibold" truncate={[1, 1, 2]}>
|
|
496
|
+
{document.title}
|
|
497
|
+
</Text>
|
|
498
|
+
```
|
|
499
|
+
- kind: section
|
|
500
|
+
for: all
|
|
501
|
+
freeform:
|
|
502
|
+
- title: 7. Inline styles — when they are and are not appropriate
|
|
503
|
+
body: |-
|
|
504
|
+
In nearly every case where an inline style appears in generated code, a prop or component already handles it.
|
|
505
|
+
|
|
506
|
+
### Never use inline styles for these — use the prop instead
|
|
507
|
+
|
|
508
|
+
| Inline style | Replace with |
|
|
509
|
+
|---|---|
|
|
510
|
+
| `style={{ padding: '12px' }}` | `padding={3}` |
|
|
511
|
+
| `style={{ gap: '8px' }}` | `gap={2}` (on Flex or Grid) |
|
|
512
|
+
| `style={{ width: '260px' }}` | `width="260px"` |
|
|
513
|
+
| `style={{ minWidth: '0' }}` | `minWidth="0"` |
|
|
514
|
+
| `style={{ height: '100vh' }}` | `height="100vh"` |
|
|
515
|
+
| `style={{ minHeight: '100vh' }}` | `minHeight="100vh"` |
|
|
516
|
+
| `style={{ overflow: 'hidden' }}` | `overflow="hidden"` |
|
|
517
|
+
| `style={{ overflowY: 'auto' }}` | `overflowY="auto"` |
|
|
518
|
+
| `style={{ flexGrow: 1 }}` | `flexGrow={1}` |
|
|
519
|
+
| `style={{ flexShrink: 0 }}` | `flexShrink={0}` |
|
|
520
|
+
| `style={{ display: 'flex' }}` | Use `<Flex>` instead of `<Box>` |
|
|
521
|
+
| `style={{ flexDirection: 'column' }}` | `flexDirection="column"` on Flex |
|
|
522
|
+
| `style={{ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}` | `truncate={1}` on Heading or Text |
|
|
523
|
+
| `style={{ fontSize: '24px' }}` on an icon | Wrap in `<Text as="span" size={3}>` |
|
|
524
|
+
| `style={{ borderRadius: '4px' }}` | `radius={2}` on Box or use Card `density` |
|
|
525
|
+
| `style={{ background: 'var(--card-bg)' }}` on Box | Use a Card ancestor or `tone` on Box |
|
|
526
|
+
|
|
527
|
+
### When inline styles are acceptable
|
|
528
|
+
|
|
529
|
+
Inline styles are appropriate only for values that have no prop equivalent and cannot be expressed with a spacing token:
|
|
530
|
+
|
|
531
|
+
```tsx
|
|
532
|
+
{/* Acceptable — no prop for arbitrary string-based grid template */}
|
|
533
|
+
<Grid style={{ gridTemplateColumns: 'auto 1fr auto' }} />
|
|
534
|
+
|
|
535
|
+
{/* Acceptable — position offsets for custom absolute positioned elements */}
|
|
536
|
+
<Box position="absolute" style={{ top: '50%', transform: 'translateY(-50%)' }} />
|
|
537
|
+
|
|
538
|
+
{/* Acceptable — CSS custom property override for a specific instance */}
|
|
539
|
+
<Box style={{ '--border-color': 'var(--blue-500)' }} />
|
|
540
|
+
```
|
|
541
|
+
- kind: section
|
|
542
|
+
for: all
|
|
543
|
+
freeform:
|
|
544
|
+
- title: '8. `overflow: hidden` and portal-dependent components'
|
|
545
|
+
body: |-
|
|
546
|
+
Tooltip and Popover render in the browser's top layer, so a container with `overflow="hidden"` or `overflowY="auto"` does not clip them. Set their boolean `portal` prop only when an ancestor with `transform`, `filter` or `contain` breaks their positioning.
|
|
547
|
+
- kind: section
|
|
548
|
+
for: all
|
|
549
|
+
freeform:
|
|
550
|
+
- title: 9. Responsive layout checklist
|
|
551
|
+
body: |-
|
|
552
|
+
Run through this before shipping any layout. A single missed item causes `spacing-and-reflow` to fail.
|
|
553
|
+
|
|
554
|
+
**Container**
|
|
555
|
+
- [ ] Outer layout Flex uses `minHeight` (not `height`)
|
|
556
|
+
- [ ] Outer layout Flex has `flexWrap="wrap"`
|
|
557
|
+
|
|
558
|
+
**Sidebar**
|
|
559
|
+
- [ ] A fixed sidebar width applies only from the desktop breakpoint up
|
|
560
|
+
- [ ] Below that, the sidebar stacks above the content (responsive `flexBasis`) or moves into a Popover
|
|
561
|
+
- [ ] Has `overflowY="auto"` if content scrolls
|
|
562
|
+
|
|
563
|
+
**Main content area**
|
|
564
|
+
- [ ] `flexGrow={1} flexShrink={1} flexBasis="0"` to fill remaining space
|
|
565
|
+
- [ ] `minWidth="0"` to prevent text overflow
|
|
566
|
+
- [ ] `overflow="hidden"` to contain long words and headings
|
|
567
|
+
|
|
568
|
+
**Every horizontal Flex row (toolbar, action bar, card actions)**
|
|
569
|
+
- [ ] `flexWrap="wrap"` present
|
|
570
|
+
- [ ] `gap={2}` or higher present (wrapping without gap creates collapsed-looking rows)
|
|
571
|
+
|
|
572
|
+
**Typography**
|
|
573
|
+
- [ ] Long headings inside flex rows are in a `minWidth="0"` wrapper
|
|
574
|
+
- [ ] Truncated text uses `truncate` prop, not inline overflow styles
|
|
575
|
+
|
|
576
|
+
**Spacing**
|
|
577
|
+
- [ ] All padding and margin use scale tokens (0–9), not inline px values
|
|
578
|
+
- [ ] All gap values use scale tokens, not inline px values
|
|
579
|
+
|
|
580
|
+
**Menus and popovers**
|
|
581
|
+
- [ ] Any Tooltip or Popover under a `transform`, `filter` or `contain` ancestor sets `portal`
|
|
582
|
+
|
|
583
|
+
**Grid**
|
|
584
|
+
- [ ] `gridTemplateColumns` uses `fr`, `auto`, or `minmax()` — not fixed pixel widths
|
|
585
|
+
- [ ] Responsive column count uses responsive array, not a single fixed value
|
|
586
|
+
- kind: section
|
|
587
|
+
for: agent
|
|
588
|
+
freeform:
|
|
589
|
+
- title: Intent
|
|
590
|
+
body: Use this guide to produce responsive Sanity UI layouts that pass WCAG 1.4.10 reflow at 320px, apply spacing tokens, use correct responsive array syntax, and configure portals for floating components in overflow containers.
|