Skip to content

Commit 2e61b32

Browse files
feat(mosaic): simplify Item and add radio cards (#10665)
1 parent c0dde2d commit 2e61b32

24 files changed

Lines changed: 721 additions & 845 deletions

‎.changeset/item-one-look.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@clerk/mosaic': minor
3+
---
4+
5+
**Breaking:** Simplify `Item` to one size and one look. Rows are always bordered and size to their content. TypeScript flags the removed props.
6+
7+
| Before | After |
8+
| -------------------------------------------- | --------------------------- |
9+
| `<Item.Root size='xs' \| 'md' \| 'lg'>` | `<Item.Root>` |
10+
| `<Item.Root variant='outline' \| 'default'>` | `<Item.Root>` (bordered) |
11+
| `<Item.Group variant='outline' \| 'default'>`| `<Item.Group>` |
12+
| `<Item.Separator />` | Removed |
13+
| `.cl-item[data-size]`, `.cl-item-media[data-size]` | Removed |
14+
| `.cl-item[data-variant]`, `.cl-item-group[data-variant]` | Removed |
15+
16+
`Item.Label`'s `variant` is unchanged.
17+
18+
Find usages with `git grep -nE "Item\.(Root|Group)[^>]*(size|variant)=|Item\.Separator|cl-item(-media|-group)?\[data-(size|variant)"`.

‎.changeset/radio-cards.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/mosaic': patch
3+
---
4+
5+
Add `Radio.Card`, a radio laid out as an `Item` row that picks its `value` when clicked anywhere. Fill it with `Radio.Media` and `Radio.Content`, which holds `Radio.Label` and an optional `Radio.Description`. `Radio.Group` takes `layout='stack' | 'grid'`, and `Radio.Section` splits a group into titled sets.

‎packages/mosaic/docs/stylex.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ device, while touch devices look correct.
222222

223223
```tsx
224224
// item.tsx — the ring is an atom in the chain, not a property in the styles file
225-
stylex.props(reset.base, focusOutline.visible, slots.item.base, slots.item[size]);
225+
stylex.props(reset.base, focusOutline.visible, slots.item.base, xstyle);
226226
```
227227

228228
It uses `:focus-visible`, never bare `:focus`, and `:has(:focus-visible)` for the

‎packages/mosaic/src/components/item/item.styles.ts‎

Lines changed: 33 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ export const item = stylex.create({
1010
// `interactive` rather than gaining a hover branch here: StyleX resolves a property to the
1111
// last style that declares it, so the two can't merge.
1212
'--_cl-icon-color': colorVars['--cl-color-foreground-secondary'],
13+
padding: space['3'],
14+
borderColor: colorVars['--cl-color-border-subtle'],
1315
borderRadius: radiusVars['--cl-radius-lg'],
14-
paddingInline: space['1.5'],
16+
borderStyle: 'solid',
17+
borderWidth: '1px',
18+
gap: space['3'],
1519
alignItems: 'center',
1620
color: colorVars['--cl-color-foreground-secondary'],
1721
display: 'flex',
@@ -22,69 +26,56 @@ export const item = stylex.create({
2226
width: '100%',
2327
},
2428

25-
// interactive rows (rendered as a link/button via `render`) gain hover + cursor. Only these
26-
// promote on hover: a static row is not pointing at anything, so its icon and label hold.
27-
// A row that is standing down while another action runs keeps its look rather than dimming, so
28-
// it holds its opacity where `Button` drops to 0.5. The pointer still reaches it, which is what
29-
// shows `not-allowed`, so every hover branch has to exclude a standing-down row itself. Both
30-
// spellings count: a row that has to stay focusable while it waits carries `aria-disabled`
31-
// instead of the native attribute.
29+
// interactive rows (rendered as a link, button or radio card via `render`) gain hover + cursor.
30+
// Only these promote on hover: a static row is not pointing at anything, so its icon and label
31+
// hold. A row that is standing down while another action runs keeps its look rather than
32+
// dimming, so it holds its opacity where `Button` drops to 0.5. The pointer still reaches it,
33+
// which is what shows `not-allowed`, so every hover branch has to exclude a standing-down row
34+
// itself. Both spellings count: a row that has to stay focusable while it waits carries
35+
// `aria-disabled` instead of the native attribute. A radio card reflects its own state as
36+
// `data-checked` and `data-disabled`; only a `data-disabled` row dims.
3237
interactive: {
3338
'--_cl-icon-color': {
3439
default: colorVars['--cl-color-foreground-secondary'],
3540
'@media (hover: hover)': {
3641
default: null,
37-
':hover:not(:disabled, [aria-disabled="true"])': colorVars['--cl-color-neutral'],
42+
':hover:not(:disabled, [aria-disabled="true"], [data-disabled])': colorVars['--cl-color-neutral'],
43+
},
44+
},
45+
borderColor: {
46+
default: colorVars['--cl-color-border-subtle'],
47+
':where([data-checked])': colorVars['--cl-color-foreground'],
48+
'@media (hover: hover)': {
49+
default: null,
50+
':hover:not(:disabled, [aria-disabled="true"], [data-disabled], [data-checked])':
51+
colorVars['--cl-color-border'],
3852
},
3953
},
4054
backgroundColor: {
4155
default: null,
42-
':active:not(:disabled, [aria-disabled="true"])': colorVars['--cl-color-neutral-alpha-200'],
56+
':active:not(:disabled, [aria-disabled="true"], [data-disabled])': colorVars['--cl-color-neutral-alpha-200'],
57+
':where([data-checked])': colorVars['--cl-color-neutral-alpha-100'],
4358
'@media (hover: hover)': {
44-
':hover:not(:disabled, [aria-disabled="true"])': colorVars['--cl-color-neutral-alpha-100'],
59+
':hover:not(:disabled, [aria-disabled="true"], [data-disabled], [data-checked])':
60+
colorVars['--cl-color-neutral-alpha-100'],
4561
},
4662
},
4763
color: {
4864
default: colorVars['--cl-color-foreground-secondary'],
4965
'@media (hover: hover)': {
5066
default: null,
51-
':hover:not(:disabled, [aria-disabled="true"])': colorVars['--cl-color-foreground'],
67+
':hover:not(:disabled, [aria-disabled="true"], [data-disabled])': colorVars['--cl-color-foreground'],
5268
},
5369
},
5470
cursor: {
5571
default: 'pointer',
56-
':is(:disabled, [aria-disabled="true"])': 'not-allowed',
72+
':is(:disabled, [aria-disabled="true"], [data-disabled])': 'not-allowed',
5773
},
58-
},
59-
60-
outline: {
61-
borderColor: colorVars['--cl-color-border-subtle'],
62-
borderStyle: 'solid',
63-
borderWidth: '1px',
64-
},
65-
66-
interactiveOutline: {
67-
borderColor: {
74+
opacity: {
6875
default: null,
69-
'@media (hover: hover)': {
70-
default: null,
71-
':hover:not(:disabled, [aria-disabled="true"])': colorVars['--cl-color-border'],
72-
},
76+
':where([data-disabled])': 0.5,
7377
},
74-
},
75-
76-
xs: {
77-
gap: space['1.5'],
78-
height: space['8'],
79-
},
80-
md: {
81-
gap: space['3'],
82-
height: space['13'],
83-
},
84-
lg: {
85-
gap: space['3'],
86-
paddingInline: space['3'],
87-
height: space['16'],
78+
position: 'relative',
8879
},
8980
});
9081

@@ -95,11 +86,8 @@ export const media = stylex.create({
9586
display: 'flex',
9687
flexShrink: 0,
9788
justifyContent: 'center',
89+
width: space['10'],
9890
},
99-
100-
xs: { width: space['5'] },
101-
md: { width: space['10'] },
102-
lg: { width: space['10'] },
10391
});
10492

10593
export const content = stylex.create({
@@ -149,28 +137,9 @@ export const actions = stylex.create({
149137

150138
export const group = stylex.create({
151139
base: {
152-
width: '100%',
153-
},
154-
155-
// The gutter belongs to the variant rather than `base`: `outline` has none, and holding it here
156-
// keeps the two from overriding each other.
157-
default: {
158-
padding: space['1.5'],
159-
},
160-
// Bordered rows read as separate cards, so the group drops its gutter and spaces them instead.
161-
outline: {
162140
gap: space['2'],
163141
display: 'flex',
164142
flexDirection: 'column',
165-
},
166-
});
167-
168-
export const separator = stylex.create({
169-
base: {
170-
borderStyle: 'none',
171-
backgroundColor: colorVars['--cl-color-border-subtle'],
172-
flexShrink: 0,
173-
height: '1px',
174143
width: '100%',
175144
},
176145
});

‎packages/mosaic/src/components/item/item.test.tsx‎

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,6 @@ describe('Mosaic Item', () => {
2525
expect(item).not.toHaveAttribute('data-interactive');
2626
});
2727

28-
it('reflects the size prop as a data attribute, defaulting to md', () => {
29-
const { rerender } = render(<Item.Root>Hi</Item.Root>);
30-
expect(screen.getByText('Hi')).toHaveAttribute('data-size', 'md');
31-
rerender(<Item.Root size='xs'>Hi</Item.Root>);
32-
expect(screen.getByText('Hi')).toHaveAttribute('data-size', 'xs');
33-
});
34-
35-
it('reads the size from the root in media', () => {
36-
const { rerender } = render(
37-
<Item.Root size='xs'>
38-
<Item.Media data-testid='media' />
39-
</Item.Root>,
40-
);
41-
expect(screen.getByTestId('media')).toHaveAttribute('data-size', 'xs');
42-
rerender(
43-
<Item.Root size='md'>
44-
<Item.Media data-testid='media' />
45-
</Item.Root>,
46-
);
47-
expect(screen.getByTestId('media')).toHaveAttribute('data-size', 'md');
48-
});
49-
50-
it('falls back to the default size when media renders outside a root', () => {
51-
render(<Item.Media data-testid='media' />);
52-
expect(screen.getByTestId('media')).toHaveAttribute('data-size', 'md');
53-
});
54-
5528
it('reflects the label variant as a data attribute, defaulting to default', () => {
5629
const { rerender } = render(<Item.Label>Clerk</Item.Label>);
5730
expect(screen.getByText('Clerk')).toHaveAttribute('data-variant', 'default');
@@ -138,80 +111,16 @@ describe('Mosaic Item', () => {
138111
expect(screen.getByRole('button', { name: 'Manage' }).parentElement).toHaveClass('cl-item-actions');
139112
});
140113

141-
it('renders a group and a separator without imposing a role', () => {
114+
it('renders a group without imposing a role', () => {
142115
render(
143116
<Item.Group data-testid='group'>
144117
<Item.Root>One</Item.Root>
145-
<Item.Separator data-testid='sep' />
146118
<Item.Root>Two</Item.Root>
147119
</Item.Group>,
148120
);
149121
const group = screen.getByTestId('group');
150122
expect(group).toHaveClass('cl-item-group');
151123
expect(group).not.toHaveAttribute('role');
152-
expect(screen.getByTestId('sep')).toHaveClass('cl-item-separator');
153-
});
154-
155-
it('reflects the group variant as a data attribute, defaulting to default', () => {
156-
const { rerender } = render(<Item.Group data-testid='group'>One</Item.Group>);
157-
expect(screen.getByTestId('group')).toHaveAttribute('data-variant', 'default');
158-
rerender(
159-
<Item.Group
160-
data-testid='group'
161-
variant='outline'
162-
>
163-
One
164-
</Item.Group>,
165-
);
166-
expect(screen.getByTestId('group')).toHaveAttribute('data-variant', 'outline');
167-
});
168-
169-
it('reads the variant from the group in its rows', () => {
170-
render(
171-
<Item.Group variant='outline'>
172-
<Item.Root>Outlined</Item.Root>
173-
</Item.Group>,
174-
);
175-
expect(screen.getByText('Outlined')).toHaveAttribute('data-variant', 'outline');
176-
});
177-
178-
it('falls back to the default variant when a row renders outside a group', () => {
179-
render(<Item.Root>Hi</Item.Root>);
180-
expect(screen.getByText('Hi')).toHaveAttribute('data-variant', 'default');
181-
});
182-
183-
it('gives an outlined row a border atom a default row does not carry', () => {
184-
render(
185-
<>
186-
<Item.Root>Plain</Item.Root>
187-
<Item.Group variant='outline'>
188-
<Item.Root>Outlined</Item.Root>
189-
</Item.Group>
190-
</>,
191-
);
192-
193-
const atoms = (text: string) => screen.getByText(text).className.split(' ');
194-
expect(atoms('Outlined').filter(atom => !atoms('Plain').includes(atom))).not.toHaveLength(0);
195-
});
196-
197-
it('takes a variant of its own, outside any group', () => {
198-
render(<Item.Root variant='outline'>Hi</Item.Root>);
199-
expect(screen.getByText('Hi')).toHaveAttribute('data-variant', 'outline');
200-
});
201-
202-
it('lets a row override the variant its group provides, in both directions', () => {
203-
render(
204-
<>
205-
<Item.Group variant='outline'>
206-
<Item.Root variant='default'>Opted out</Item.Root>
207-
</Item.Group>
208-
<Item.Group>
209-
<Item.Root variant='outline'>Opted in</Item.Root>
210-
</Item.Group>
211-
</>,
212-
);
213-
expect(screen.getByText('Opted out')).toHaveAttribute('data-variant', 'default');
214-
expect(screen.getByText('Opted in')).toHaveAttribute('data-variant', 'outline');
215124
});
216125

217126
it('forwards the ref to the root element', () => {

0 commit comments

Comments
 (0)