@vendure-io/ui 3.0.0-next.2 → 3.0.0-next.3

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.
@@ -0,0 +1,377 @@
1
+ 'use client';
2
+
3
+ import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox';
4
+ import { CheckboxGroup as CheckboxGroupPrimitive } from '@base-ui/react/checkbox-group';
5
+ import { Radio as RadioPrimitive } from '@base-ui/react/radio';
6
+ import { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';
7
+ import { Badge } from '@vendure-io/ui/components/atoms/badge';
8
+ import { useFieldControlProps } from '@vendure-io/ui/components/atoms/field';
9
+ import { cn } from '@vendure-io/ui/lib/utils';
10
+ import { cva } from 'class-variance-authority';
11
+ import { CheckIcon } from 'lucide-react';
12
+ import * as React from 'react';
13
+
14
+ import { interactiveCardVariants } from './interactive-card.tsx';
15
+
16
+ // A card the user picks from a set: a plan, a shipping method, an address, an
17
+ // asset. The card itself is the control. In a single-choice group it is a Base
18
+ // UI Radio (arrow keys move the choice, role="radio"); in a multiple-choice
19
+ // group a Base UI Checkbox (Space toggles, role="checkbox"). Base UI sets the
20
+ // role, aria-checked, the disabled state and the hidden form input.
21
+ //
22
+ // The look is the shared interactive card (interactive-card.tsx). Selected
23
+ // draws one 2px primary edge on ::after, on the border box, so it reads as one
24
+ // stroke with no layout shift and stays over a media image; the focus
25
+ // ring is an outline outside it, so both show together. The indicator (a radio
26
+ // dot or a check box) shows the state in shape too, not only in colour.
27
+ //
28
+ // The card's accessible name is its title, and its description is the
29
+ // description plus the meta. Slots hold text and images only: a card is one
30
+ // control, so a link or button inside it is not reachable as its own control.
31
+
32
+ type ChoiceCardMode = 'single' | 'multiple';
33
+
34
+ const ChoiceCardGroupContext = React.createContext<ChoiceCardMode>('single');
35
+
36
+ type ChoiceCardGroupProps =
37
+ | ({ multiple?: false } & RadioGroupPrimitive.Props)
38
+ | ({ multiple: true } & CheckboxGroupPrimitive.Props);
39
+
40
+ const groupClassName = 'grid w-full gap-3';
41
+
42
+ /**
43
+ * A set of ChoiceCards. Single choice by default (a radio group); `multiple`
44
+ * makes it a checkbox group, with `value` as an array. Give it an
45
+ * `aria-label` or `aria-labelledby`.
46
+ */
47
+ function ChoiceCardGroup(props: ChoiceCardGroupProps) {
48
+ const fieldProps = useFieldControlProps(props);
49
+ if (fieldProps.multiple) {
50
+ const { multiple: _, className, ...rest } = fieldProps;
51
+ return (
52
+ <ChoiceCardGroupContext.Provider value="multiple">
53
+ <CheckboxGroupPrimitive
54
+ data-slot="choice-card-group"
55
+ data-mode="multiple"
56
+ className={(state) =>
57
+ cn(groupClassName, typeof className === 'function' ? className(state) : className)
58
+ }
59
+ {...rest}
60
+ />
61
+ </ChoiceCardGroupContext.Provider>
62
+ );
63
+ }
64
+ const { multiple: _, className, ...rest } = fieldProps;
65
+ return (
66
+ <ChoiceCardGroupContext.Provider value="single">
67
+ <RadioGroupPrimitive
68
+ data-slot="choice-card-group"
69
+ data-mode="single"
70
+ className={(state) =>
71
+ cn(groupClassName, typeof className === 'function' ? className(state) : className)
72
+ }
73
+ {...rest}
74
+ />
75
+ </ChoiceCardGroupContext.Provider>
76
+ );
77
+ }
78
+
79
+ // The ids the card points its aria-labelledby and aria-describedby at. The
80
+ // title is the name from the first render, so a card without a ChoiceCardTitle
81
+ // needs an aria-label (the media variant). The description and the meta
82
+ // register their ids once they mount, so the card never points at a missing
83
+ // element.
84
+ interface ChoiceCardParts {
85
+ titleId: string;
86
+ descriptionId: string;
87
+ metaId: string;
88
+ register: (part: 'title' | 'description' | 'meta') => () => void;
89
+ }
90
+
91
+ const ChoiceCardPartsContext = React.createContext<ChoiceCardParts | null>(null);
92
+
93
+ function useChoiceCardPart(part: 'title' | 'description' | 'meta') {
94
+ const parts = React.useContext(ChoiceCardPartsContext);
95
+ const register = parts?.register;
96
+ React.useEffect(() => register?.(part), [register, part]);
97
+ if (!parts) return undefined;
98
+ return part === 'title'
99
+ ? parts.titleId
100
+ : part === 'description'
101
+ ? parts.descriptionId
102
+ : parts.metaId;
103
+ }
104
+
105
+ const choiceCardVariants = cva(
106
+ [
107
+ 'group/choice-card flex text-start',
108
+ // Selected: one 2px inset primary stroke on ::after. The ::after sits on
109
+ // the border box (-inset-px) with the card's radius, so it covers the
110
+ // border and adds the inner pixel in one curve. On the padding box
111
+ // (inset-0) its corners would take the outer radius and leave a gap
112
+ // between two strokes. So the card never clips its children: the media
113
+ // variant rounds the image itself to the padding box instead.
114
+ 'after:pointer-events-none after:absolute after:-inset-px after:z-10 after:rounded-[inherit] after:[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft)] data-checked:border-primary data-checked:hover:border-primary data-checked:after:shadow-[inset_0_0_0_2px_var(--primary)]',
115
+ ],
116
+ {
117
+ variants: {
118
+ variant: {
119
+ default: 'items-start gap-3',
120
+ // An image tile: the image fills the card, the indicator sits in the
121
+ // start corner over it. The image takes the padding-box radius (the
122
+ // card radius minus the 1px border) rather than the card clipping it,
123
+ // which would cut the selected stroke at the border's inner edge.
124
+ media:
125
+ 'aspect-square p-0 [&_img]:size-full [&_img]:rounded-[calc(var(--radius-2xl)-1px)] [&_img]:object-cover [&_video]:size-full [&_video]:rounded-[calc(var(--radius-2xl)-1px)] [&_video]:object-cover',
126
+ },
127
+ size: {
128
+ default: '',
129
+ sm: '',
130
+ },
131
+ },
132
+ compoundVariants: [
133
+ { variant: 'default', size: 'default', className: 'p-4' },
134
+ { variant: 'default', size: 'sm', className: 'gap-2.5 p-3' },
135
+ ],
136
+ defaultVariants: { variant: 'default', size: 'default' },
137
+ },
138
+ );
139
+
140
+ // The indicator box: a radio circle or a check box, 16px like the form
141
+ // controls. Unchecked it is the control outline; checked it fills primary. In
142
+ // the media variant it sits in the corner on a background disc so it reads on
143
+ // any image, and while unchecked it shows only on hover or keyboard focus
144
+ // (always on a touch screen, where there is no hover).
145
+ // Motion: colours and the corner reveal fade in `fast`. The radio dot grows
146
+ // from half size on the strong ease-out (never from 0) while it fades in;
147
+ // reduced motion keeps the fade and drops the growth.
148
+ const indicatorClassName = [
149
+ 'relative z-20 flex size-4 shrink-0 items-center justify-center border border-control-border bg-background text-primary-foreground [transition:background-color_var(--transition-duration-fast)_var(--ease-soft),border-color_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-fast)_var(--ease-soft)] group-data-checked/choice-card:border-primary group-data-checked/choice-card:bg-primary',
150
+ // Lines the box up with the first line of the title.
151
+ 'group-data-[variant=default]/choice-card:mt-0.5',
152
+ 'group-data-[variant=media]/choice-card:absolute group-data-[variant=media]/choice-card:top-2 group-data-[variant=media]/choice-card:start-2 group-data-[variant=media]/choice-card:shadow-control group-data-[variant=media]/choice-card:group-data-unchecked/choice-card:opacity-0 group-hover/choice-card:opacity-100! group-focus-visible/choice-card:opacity-100! pointer-coarse:opacity-100!',
153
+ ].join(' ');
154
+
155
+ function ChoiceCardIndicator({ mode }: { mode: ChoiceCardMode }) {
156
+ if (mode === 'single') {
157
+ return (
158
+ <span
159
+ data-slot="choice-card-indicator"
160
+ aria-hidden="true"
161
+ className={cn(indicatorClassName, 'rounded-full')}
162
+ >
163
+ <span className="size-1.5 scale-50 rounded-full bg-primary-foreground opacity-0 [transition:scale_var(--transition-duration-moderate)_var(--ease-out),opacity_var(--transition-duration-fast)_var(--ease-soft)] group-data-checked/choice-card:scale-100 group-data-checked/choice-card:opacity-100 motion-reduce:scale-100" />
164
+ </span>
165
+ );
166
+ }
167
+ return (
168
+ <span
169
+ data-slot="choice-card-indicator"
170
+ aria-hidden="true"
171
+ className={cn(indicatorClassName, 'rounded-md')}
172
+ >
173
+ <CheckIcon
174
+ aria-hidden="true"
175
+ strokeWidth={2.5}
176
+ className="size-3.5 opacity-0 [transition:opacity_var(--transition-duration-fast)_var(--ease-soft)] group-data-checked/choice-card:opacity-100"
177
+ />
178
+ </span>
179
+ );
180
+ }
181
+
182
+ // The props both Base UI roots share. State-function forms of className and
183
+ // style are left out: the card renders either root.
184
+ type ChoiceCardProps = Omit<
185
+ RadioPrimitive.Root.Props<string>,
186
+ 'value' | 'render' | 'className' | 'style' | 'nativeButton' | 'inputRef'
187
+ > & {
188
+ className?: string;
189
+ style?: React.CSSProperties;
190
+ /** Identifies the card in its group. */
191
+ value: string;
192
+ disabled?: boolean;
193
+ /** `media`: an image tile that the image fills. Give it an `aria-label`. */
194
+ variant?: 'default' | 'media';
195
+ size?: 'default' | 'sm';
196
+ };
197
+
198
+ /**
199
+ * One choice in a ChoiceCardGroup: a radio card in a single-choice group, a
200
+ * checkbox card in a multiple-choice group.
201
+ */
202
+ function ChoiceCard({
203
+ className,
204
+ variant = 'default',
205
+ size = 'default',
206
+ value,
207
+ disabled,
208
+ children,
209
+ ...props
210
+ }: ChoiceCardProps) {
211
+ const mode = React.useContext(ChoiceCardGroupContext);
212
+ const id = React.useId();
213
+ const [mounted, setMounted] = React.useState<ReadonlySet<string>>(new Set());
214
+ const register = React.useCallback((part: string) => {
215
+ setMounted((current) => new Set(current).add(part));
216
+ return () =>
217
+ setMounted((current) => {
218
+ const next = new Set(current);
219
+ next.delete(part);
220
+ return next;
221
+ });
222
+ }, []);
223
+ const parts = React.useMemo(
224
+ () => ({
225
+ titleId: `${id}-title`,
226
+ descriptionId: `${id}-description`,
227
+ metaId: `${id}-meta`,
228
+ register,
229
+ }),
230
+ [id, register],
231
+ );
232
+
233
+ const describedBy = [
234
+ props['aria-describedby'],
235
+ mounted.has('description') ? parts.descriptionId : undefined,
236
+ mounted.has('meta') ? parts.metaId : undefined,
237
+ ]
238
+ .filter(Boolean)
239
+ .join(' ');
240
+ const ariaProps = {
241
+ 'aria-labelledby':
242
+ props['aria-labelledby'] ?? (props['aria-label'] ? undefined : parts.titleId),
243
+ 'aria-describedby': describedBy || undefined,
244
+ };
245
+
246
+ const rootProps = {
247
+ ...props,
248
+ ...ariaProps,
249
+ 'data-slot': 'choice-card',
250
+ 'data-variant': variant,
251
+ 'data-size': size,
252
+ className: cn(interactiveCardVariants(), choiceCardVariants({ variant, size }), className),
253
+ render: <div />,
254
+ value,
255
+ disabled,
256
+ };
257
+
258
+ const content = (
259
+ <ChoiceCardPartsContext.Provider value={parts}>
260
+ <ChoiceCardIndicator mode={mode} />
261
+ {children}
262
+ </ChoiceCardPartsContext.Provider>
263
+ );
264
+
265
+ return mode === 'multiple' ? (
266
+ <CheckboxPrimitive.Root {...rootProps}>{content}</CheckboxPrimitive.Root>
267
+ ) : (
268
+ <RadioPrimitive.Root {...rootProps}>{content}</RadioPrimitive.Root>
269
+ );
270
+ }
271
+
272
+ const choiceCardMediaVariants = cva('flex shrink-0 items-center justify-center', {
273
+ variants: {
274
+ variant: {
275
+ // A product image or logo beside the text.
276
+ image: 'size-10 overflow-hidden rounded-lg [&_img]:size-full [&_img]:object-cover',
277
+ // An icon, quieter than the title.
278
+ icon: 'mt-px [&_svg]:pointer-events-none [&_svg:not([class*=size-])]:size-4 [&_svg:not([class*=stroke-])]:stroke-[1.75] text-muted-foreground',
279
+ },
280
+ },
281
+ defaultVariants: { variant: 'icon' },
282
+ });
283
+
284
+ /** Leading media of a default card: an icon, or an image or logo. */
285
+ function ChoiceCardMedia({
286
+ className,
287
+ variant = 'icon',
288
+ ...props
289
+ }: React.ComponentProps<'div'> & { variant?: 'icon' | 'image' }) {
290
+ return (
291
+ <div
292
+ data-slot="choice-card-media"
293
+ data-variant={variant}
294
+ className={cn(choiceCardMediaVariants({ variant }), className)}
295
+ {...props}
296
+ />
297
+ );
298
+ }
299
+
300
+ /** Holds the title and the description. Takes the free width. */
301
+ function ChoiceCardContent({ className, ...props }: React.ComponentProps<'div'>) {
302
+ return (
303
+ <div
304
+ data-slot="choice-card-content"
305
+ className={cn('flex min-w-0 flex-1 flex-col gap-0.5', className)}
306
+ {...props}
307
+ />
308
+ );
309
+ }
310
+
311
+ /** The card's name. A ChoiceCardBadge inside it sits on the title line. */
312
+ function ChoiceCardTitle({ className, id, ...props }: React.ComponentProps<'div'>) {
313
+ const partId = useChoiceCardPart('title');
314
+ return (
315
+ <div
316
+ id={id ?? partId}
317
+ data-slot="choice-card-title"
318
+ className={cn(
319
+ 'flex flex-wrap items-center gap-x-2 gap-y-1 text-sm font-medium text-foreground',
320
+ className,
321
+ )}
322
+ {...props}
323
+ />
324
+ );
325
+ }
326
+
327
+ function ChoiceCardDescription({ className, id, ...props }: React.ComponentProps<'p'>) {
328
+ const partId = useChoiceCardPart('description');
329
+ return (
330
+ <p
331
+ id={id ?? partId}
332
+ data-slot="choice-card-description"
333
+ className={cn('text-sm text-muted-foreground', className)}
334
+ {...props}
335
+ />
336
+ );
337
+ }
338
+
339
+ /** Trailing detail, such as a price or a delivery time. */
340
+ function ChoiceCardMeta({ className, id, ...props }: React.ComponentProps<'div'>) {
341
+ const partId = useChoiceCardPart('meta');
342
+ return (
343
+ <div
344
+ id={id ?? partId}
345
+ data-slot="choice-card-meta"
346
+ className={cn(
347
+ 'ms-auto shrink-0 text-end text-sm text-foreground-secondary tabular-nums',
348
+ className,
349
+ )}
350
+ {...props}
351
+ />
352
+ );
353
+ }
354
+
355
+ /**
356
+ * A marker on the title line, such as "Current" on the plan the customer is
357
+ * on. It says nothing about selection: the current plan can be unselected
358
+ * while the user picks another one.
359
+ */
360
+ function ChoiceCardBadge({ className, ...props }: React.ComponentProps<typeof Badge>) {
361
+ return (
362
+ <Badge data-slot="choice-card-badge" className={cn('font-medium', className)} {...props} />
363
+ );
364
+ }
365
+
366
+ export {
367
+ ChoiceCard,
368
+ ChoiceCardBadge,
369
+ ChoiceCardContent,
370
+ ChoiceCardDescription,
371
+ ChoiceCardGroup,
372
+ ChoiceCardMedia,
373
+ ChoiceCardMeta,
374
+ ChoiceCardTitle,
375
+ type ChoiceCardGroupProps,
376
+ type ChoiceCardProps,
377
+ };
@@ -107,17 +107,18 @@ function CollapsibleSection({
107
107
  />
108
108
  </CollapsibleTrigger>
109
109
  </Heading>
110
- {/* Height runs on the height curve; under reduced motion it snaps and
111
- only the rows fade. */}
110
+ {/* The panel's height motion comes from CollapsibleContent; the card
111
+ clips the rows to its corners. */}
112
112
  <CollapsibleContent
113
113
  data-slot="collapsible-section-panel"
114
- className="group/collapsible-section-panel h-(--collapsible-panel-height) overflow-hidden border-t border-border data-ending-style:h-0 data-starting-style:h-0 motion-safe:transition-[height] motion-safe:duration-slow motion-safe:ease-height"
114
+ className="group/collapsible-section-panel border-t border-border"
115
115
  >
116
116
  {/* Opening, the rows fade in over the second half of the height;
117
- closing, they leave at once so the height settles on nothing. */}
117
+ closing, they leave at once so the height settles on nothing.
118
+ Under reduced motion the panel's own fade replaces this. */}
118
119
  <div
119
120
  data-slot="collapsible-section-rows"
120
- className="transition-opacity delay-(--transition-duration-moderate) duration-moderate ease-out group-data-ending-style/collapsible-section-panel:opacity-0 group-data-ending-style/collapsible-section-panel:delay-0 group-data-ending-style/collapsible-section-panel:duration-fast group-data-starting-style/collapsible-section-panel:opacity-0"
121
+ className="motion-safe:transition-opacity motion-safe:delay-(--transition-duration-moderate) motion-safe:duration-moderate motion-safe:ease-out motion-safe:group-data-ending-style/collapsible-section-panel:opacity-0 motion-safe:group-data-ending-style/collapsible-section-panel:delay-0 motion-safe:group-data-ending-style/collapsible-section-panel:duration-fast motion-safe:group-data-starting-style/collapsible-section-panel:opacity-0"
121
122
  >
122
123
  {children}
123
124
  </div>
@@ -0,0 +1,45 @@
1
+ import { cva } from 'class-variance-authority';
2
+
3
+ // The look of a whole card the user acts on: a card they pick (ChoiceCard) or
4
+ // a card that opens a page (a Card with a CardLink). One place, so every
5
+ // interactive card hovers, presses and takes focus the same way.
6
+ // - Surface: the Card panel (card fill, hairline border, 12px radius,
7
+ // shadow-control).
8
+ // - Hover: the border darkens. No fill, so the card reads as one object.
9
+ // - Pressed: the card shrinks to 99.5% on the press curve, for a pointer press
10
+ // only (`:active:not(:focus-visible)`): holding Space or Enter on a focused
11
+ // card does not animate. Reduced motion keeps it still.
12
+ // - Focus: the design-system ring, 2px at a 2px offset, outside the border.
13
+ // - Disabled (`data-disabled` or `aria-disabled`): half opacity, no hover, no
14
+ // press.
15
+ // Selection is not part of it: a card that opens a page has none. Only
16
+ // colours and the scale transition, never `transition-all`.
17
+ //
18
+ // `target` says which element is the control:
19
+ // - `self`: the card itself (ChoiceCard). The states read the card's own
20
+ // :hover, :active and :focus-visible.
21
+ // - `link`: a stretched CardLink inside a Card. Every class is gated on
22
+ // `has-data-[slot=card-link]`, so a Card without a link stays static. Hover
23
+ // is the card's (the link covers it). Press and focus read the link's
24
+ // :active and :focus-visible, so pressing a menu inside the card does not
25
+ // press the card. The link target only transitions what changes: the
26
+ // border and the scale.
27
+ const SURFACE = 'rounded-2xl border border-border bg-card text-card-foreground shadow-control';
28
+
29
+ const SELF_STATES =
30
+ 'relative outline-none cursor-pointer select-none [transition:border-color_var(--transition-duration-fast)_var(--ease-soft),background-color_var(--transition-duration-fast)_var(--ease-soft),box-shadow_var(--transition-duration-fast)_var(--ease-soft),scale_var(--transition-duration-fast)_var(--ease-press)] hover:border-foreground/25 active:not-focus-visible:scale-[0.995] motion-reduce:active:not-focus-visible:scale-100 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring data-disabled:cursor-not-allowed data-disabled:opacity-50 data-disabled:hover:border-border data-disabled:active:not-focus-visible:scale-100 aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:hover:border-border aria-disabled:active:not-focus-visible:scale-100';
31
+
32
+ const LINK_STATES =
33
+ 'has-data-[slot=card-link]:relative has-data-[slot=card-link]:cursor-pointer has-data-[slot=card-link]:[transition:border-color_var(--transition-duration-fast)_var(--ease-soft),scale_var(--transition-duration-fast)_var(--ease-press)] has-data-[slot=card-link]:hover:border-foreground/25 has-[[data-slot=card-link]:active:not(:focus-visible)]:scale-[0.995] motion-reduce:has-[[data-slot=card-link]:active:not(:focus-visible)]:scale-100 has-[[data-slot=card-link]:focus-visible]:outline-solid has-[[data-slot=card-link]:focus-visible]:outline-2 has-[[data-slot=card-link]:focus-visible]:outline-offset-2 has-[[data-slot=card-link]:focus-visible]:outline-ring';
34
+
35
+ const interactiveCardVariants = cva(SURFACE, {
36
+ variants: {
37
+ target: {
38
+ self: SELF_STATES,
39
+ link: LINK_STATES,
40
+ },
41
+ },
42
+ defaultVariants: { target: 'self' },
43
+ });
44
+
45
+ export { interactiveCardVariants };
@@ -199,7 +199,8 @@ const triggerFocus =
199
199
  const spinnerClass = 'animate-spin-slow motion-reduce:animate-none';
200
200
 
201
201
  // The icon a chip shows when the caller passes none comes from `toneIcons`,
202
- // the map the toast reads too. `progress` always spins its loader.
202
+ // the map the toast reads too. `progress` spins its loader unless the caller
203
+ // passes `icon={false}`: that is pending, blue and without an icon.
203
204
  const ProgressIcon = toneIcons.progress;
204
205
 
205
206
  interface StatusBadgeProps extends useRender.ComponentProps<'span'> {
@@ -227,19 +228,22 @@ interface StatusBadgeProps extends useRender.ComponentProps<'span'> {
227
228
  * Show a leading dot in the tone colour in place of the tone icon, for a
228
229
  * group of chips that is not a list column (a list column uses
229
230
  * `appearance="icon"`). Only for `appearance="chip"` and `"bare"`. `progress` keeps its
230
- * spinner, regardless of this prop.
231
+ * spinner, regardless of this prop, unless `icon={false}`.
231
232
  */
232
233
  dot?: boolean;
233
234
  /**
234
235
  * The leading icon, in the tone colour. Only for `appearance="chip"`, `"bare"` and `"icon"`.
235
236
  * - Leave it out for the tone's own icon: `CircleCheck` (success),
236
237
  * `TriangleAlert` (warning), `CircleX` (critical), `CircleDot` (info),
237
- * `CircleDashed` (neutral) and a spinning `Loader` (progress).
238
+ * `CircleDashed` (neutral) and a spinning `Loader` (progress, for work that
239
+ * runs right now).
238
240
  * - Pass a lucide icon element for a state whose shape says more, e.g.
239
241
  * `<MoonStarIcon />` for Asleep. It replaces the dot and the spinner too.
240
242
  * - Pass `false` or `null` for no icon, on an inline chip whose label
241
- * already names the tone. `progress` still shows its spinner, and `dot`
242
- * still shows the dot. `appearance="icon"` always shows an icon.
243
+ * already names the tone, or for pending (`progress` without its spinner:
244
+ * waiting on the system or another person, not running). `dot` still
245
+ * shows the dot. `appearance="icon"` always shows a marker: the tone icon,
246
+ * or for pending a still dot. A `bare` pending badge shows that dot too.
243
247
  *
244
248
  * Put the icon here, not in `children`: the chip sizes and colours it. An
245
249
  * `<svg>` in `children` (code written for 2.x) hides the tone icon, so the
@@ -287,6 +291,7 @@ function StatusBadge({
287
291
  // dictionary is a fallback the caller resolves, not something rendered here.
288
292
  let classes: string;
289
293
  let content: React.ReactNode;
294
+ const isPending = tone === 'progress' && icon !== undefined && !isValidElement(icon);
290
295
  const hasDetail =
291
296
  appearance === 'icon' && detail !== undefined && detail !== null && detail !== false;
292
297
 
@@ -306,9 +311,10 @@ function StatusBadge({
306
311
  <StatusBadgeMarker
307
312
  tone={tone}
308
313
  size="icon"
309
- dot={false}
310
- // The icon always shows here: it carries the tone.
311
- icon={isValidElement(icon) ? icon : undefined}
314
+ // The icon always shows here: it carries the tone. Pending
315
+ // (`progress` with `icon={false}`) shows a still dot in its place.
316
+ icon={isValidElement(icon) ? icon : isPending ? false : undefined}
317
+ dot={isPending}
312
318
  className={hasDetail ? 'row-span-2' : undefined}
313
319
  />
314
320
  <span data-slot="status-badge-label" className={hasDetail ? 'leading-4.5' : undefined}>
@@ -337,7 +343,7 @@ function StatusBadge({
337
343
  content = (
338
344
  <>
339
345
  {children}
340
- {tone === 'progress' ? (
346
+ {tone === 'progress' && icon === undefined ? (
341
347
  <ProgressIcon aria-hidden className={cn('size-3 shrink-0 stroke-2', spinnerClass)} />
342
348
  ) : null}
343
349
  </>
@@ -351,7 +357,15 @@ function StatusBadge({
351
357
  );
352
358
  content = (
353
359
  <>
354
- <StatusBadgeMarker tone={tone} size={size} dot={dot} icon={icon} />
360
+ <StatusBadgeMarker
361
+ tone={tone}
362
+ size={size}
363
+ dot={dot || (isPending && appearance === 'bare')}
364
+ // Pending in a bare badge has no box to carry the blue, so its dot
365
+ // takes the icon's slot.
366
+ slot={isPending && appearance === 'bare'}
367
+ icon={icon}
368
+ />
355
369
  {children}
356
370
  </>
357
371
  );
@@ -396,12 +410,15 @@ function StatusBadgeMarker({
396
410
  tone,
397
411
  size,
398
412
  dot,
413
+ slot = false,
399
414
  icon,
400
415
  className,
401
416
  }: {
402
417
  tone: Tone;
403
418
  size: StatusBadgeSize | 'icon';
404
419
  dot: boolean;
420
+ /** The dot takes the size of an icon, so it sits where the spinner would. */
421
+ slot?: boolean;
405
422
  icon: React.ReactNode;
406
423
  className?: string;
407
424
  }) {
@@ -430,9 +447,9 @@ function StatusBadgeMarker({
430
447
  );
431
448
  }
432
449
 
433
- // `progress` keeps its spinner over a dot and without an icon: the motion is
434
- // its meaning, and without it the chip looks like `info`.
435
- if (tone === 'progress') {
450
+ // `progress` keeps its spinner over a dot and when no icon is passed: the
451
+ // motion is its meaning. `icon={false}` is pending: the blue tone, no spinner.
452
+ if (tone === 'progress' && icon === undefined) {
436
453
  return (
437
454
  <span aria-hidden data-marker="icon" data-slot="status-badge-marker" className={iconClasses}>
438
455
  <ProgressIcon className={spinnerClass} />
@@ -452,7 +469,7 @@ function StatusBadgeMarker({
452
469
  );
453
470
  }
454
471
 
455
- return (
472
+ const dotMarker = (
456
473
  <span
457
474
  aria-hidden
458
475
  data-marker="dot"
@@ -460,6 +477,22 @@ function StatusBadgeMarker({
460
477
  className={cn('size-1.5 shrink-0 rounded-full bg-current', toneDot[tone])}
461
478
  />
462
479
  );
480
+ // In the `icon` appearance and in a bare pending badge the dot takes the
481
+ // slot of an icon, so the labels start on the same edge as with a spinner.
482
+ return size === 'icon' || slot ? (
483
+ <span
484
+ aria-hidden
485
+ className={cn(
486
+ 'inline-flex shrink-0 items-center justify-center',
487
+ size === 'icon' ? 'size-4' : size === 'lg' ? 'size-3.5' : 'size-3.25',
488
+ className,
489
+ )}
490
+ >
491
+ {dotMarker}
492
+ </span>
493
+ ) : (
494
+ dotMarker
495
+ );
463
496
  }
464
497
 
465
498
  export { StatusBadge, statusBadgeVariants };