@brightlocal/ui-components 2.14.0 → 2.16.0
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 +3 -2
- package/component-meta.json +155 -13
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +20 -4
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +95 -72
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.js +33 -33
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +8 -2
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +24 -21
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +326 -307
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +21 -15
- package/dist/map.cjs +1 -1
- package/dist/map.d.ts +402 -46
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +615 -184
- package/dist/stepper.cjs +1 -0
- package/dist/stepper.d.ts +176 -0
- package/dist/stepper.d.ts.map +1 -0
- package/dist/stepper.js +351 -0
- package/package.json +12 -2
- package/src/components/card.tsx +62 -8
- package/src/components/combobox.tsx +1 -1
- package/src/components/field.tsx +7 -1
- package/src/components/global-layout.tsx +4 -1
- package/src/components/list.tsx +8 -2
- package/src/components/map.tsx +1068 -135
- package/src/components/stepper.tsx +708 -0
- package/src/index.ts +1 -0
- package/src/types/assets.d.ts +9 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { cva } from "class-variance-authority";
|
|
6
|
+
import { Check, LoaderCircle, X } from "@brightlocal/icons";
|
|
7
|
+
|
|
8
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Orientation of the stepper layout.
|
|
12
|
+
*/
|
|
13
|
+
type StepperOrientation = "horizontal" | "vertical";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Placement of step labels relative to the indicator in horizontal orientation.
|
|
17
|
+
* `"below"` centers the label under the indicator; `"inline"` places it to the
|
|
18
|
+
* right (best with title-only steps). Ignored when orientation is vertical.
|
|
19
|
+
*/
|
|
20
|
+
type StepperLabelPlacement = "below" | "inline";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Visual/interaction state of a single step, derived from the active step
|
|
24
|
+
* (and any explicit `completed` / `error` overrides on the item).
|
|
25
|
+
*/
|
|
26
|
+
type StepperItemState = "active" | "completed" | "inactive" | "error";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A single step descriptor. Consumers may attach any extra fields they need
|
|
30
|
+
* (e.g. `title`, `href`); only `id` is required for ordering and state.
|
|
31
|
+
*/
|
|
32
|
+
interface StepperStep {
|
|
33
|
+
/** Stable, unique identifier for the step. */
|
|
34
|
+
id: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* -------------------------------------------------------------------------- */
|
|
39
|
+
/* Contexts */
|
|
40
|
+
/* -------------------------------------------------------------------------- */
|
|
41
|
+
|
|
42
|
+
interface StepperContextValue {
|
|
43
|
+
/** Id of the currently active step. */
|
|
44
|
+
activeId: string;
|
|
45
|
+
/** Index of the currently active step within `steps`. */
|
|
46
|
+
activeIndex: number;
|
|
47
|
+
/** Activate a step by its id. */
|
|
48
|
+
setActiveStep: (id: string) => void;
|
|
49
|
+
/** Ordered list of steps. */
|
|
50
|
+
steps: StepperStep[];
|
|
51
|
+
/** Layout orientation. */
|
|
52
|
+
orientation: StepperOrientation;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const StepperContext = React.createContext<StepperContextValue | null>(null);
|
|
56
|
+
|
|
57
|
+
function useStepper(): StepperContextValue {
|
|
58
|
+
const context = React.useContext(StepperContext);
|
|
59
|
+
if (!context) {
|
|
60
|
+
throw new Error("Stepper components must be used within <Stepper>");
|
|
61
|
+
}
|
|
62
|
+
return context;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface StepperItemContextValue {
|
|
66
|
+
/** Step id for this item. */
|
|
67
|
+
stepId: string;
|
|
68
|
+
/** Zero-based index of this item within `steps`. */
|
|
69
|
+
index: number;
|
|
70
|
+
/** Derived state for this item. */
|
|
71
|
+
state: StepperItemState;
|
|
72
|
+
/** Whether this is the last step (used to hide the trailing separator). */
|
|
73
|
+
isLast: boolean;
|
|
74
|
+
/** Whether the step is disabled. */
|
|
75
|
+
isDisabled: boolean;
|
|
76
|
+
/** Whether the step is currently loading. */
|
|
77
|
+
isLoading: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const StepperItemContext = React.createContext<StepperItemContextValue | null>(
|
|
81
|
+
null
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
function useStepperItem(): StepperItemContextValue {
|
|
85
|
+
const context = React.useContext(StepperItemContext);
|
|
86
|
+
if (!context) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"StepperItem sub-components must be used within <StepperItem>"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return context;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* -------------------------------------------------------------------------- */
|
|
95
|
+
/* Stepper */
|
|
96
|
+
/* -------------------------------------------------------------------------- */
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Props for the Stepper root component.
|
|
100
|
+
*/
|
|
101
|
+
interface StepperProps extends Omit<
|
|
102
|
+
React.ComponentPropsWithoutRef<"div">,
|
|
103
|
+
"onChange"
|
|
104
|
+
> {
|
|
105
|
+
/** Data hook for automated testing (required). */
|
|
106
|
+
dataHook: string;
|
|
107
|
+
/** Ordered list of steps. Defines step order, total count and id → index resolution. */
|
|
108
|
+
steps: StepperStep[];
|
|
109
|
+
/** Controlled active step id. */
|
|
110
|
+
value?: string;
|
|
111
|
+
/** Active step id for uncontrolled usage. Defaults to the first step. */
|
|
112
|
+
defaultValue?: string;
|
|
113
|
+
/** Called with the new active step id when the active step changes. */
|
|
114
|
+
onValueChange?: (id: string) => void;
|
|
115
|
+
/**
|
|
116
|
+
* Layout orientation.
|
|
117
|
+
* @default "horizontal"
|
|
118
|
+
*/
|
|
119
|
+
orientation?: StepperOrientation;
|
|
120
|
+
/**
|
|
121
|
+
* Where labels sit relative to the indicator in horizontal orientation.
|
|
122
|
+
* @default "below"
|
|
123
|
+
*/
|
|
124
|
+
labelPlacement?: StepperLabelPlacement;
|
|
125
|
+
/**
|
|
126
|
+
* Accessible label for the stepper region.
|
|
127
|
+
* @default "Progress"
|
|
128
|
+
*/
|
|
129
|
+
ariaLabel?: string;
|
|
130
|
+
/** Tracking element identifier for analytics. */
|
|
131
|
+
trackingEl?: string;
|
|
132
|
+
/** Tracking label for analytics context. */
|
|
133
|
+
trackingLabel?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Guides users through a multi-step process, showing progress and the current step.
|
|
138
|
+
* Tracks the active step (controlled or uncontrolled) and shares it with its
|
|
139
|
+
* sub-components via context.
|
|
140
|
+
*/
|
|
141
|
+
const Stepper = React.forwardRef<HTMLDivElement, StepperProps>(
|
|
142
|
+
(
|
|
143
|
+
{
|
|
144
|
+
className,
|
|
145
|
+
dataHook,
|
|
146
|
+
steps,
|
|
147
|
+
value,
|
|
148
|
+
defaultValue,
|
|
149
|
+
onValueChange,
|
|
150
|
+
orientation = "horizontal",
|
|
151
|
+
labelPlacement = "below",
|
|
152
|
+
ariaLabel,
|
|
153
|
+
trackingEl,
|
|
154
|
+
trackingLabel,
|
|
155
|
+
...props
|
|
156
|
+
},
|
|
157
|
+
ref
|
|
158
|
+
) => {
|
|
159
|
+
// Single layout token drives the orientation/placement-specific styles in
|
|
160
|
+
// the sub-components (CSS group-data selectors can't AND two attributes).
|
|
161
|
+
const layout =
|
|
162
|
+
orientation === "vertical"
|
|
163
|
+
? "vertical"
|
|
164
|
+
: labelPlacement === "inline"
|
|
165
|
+
? "horizontal-inline"
|
|
166
|
+
: "horizontal-below";
|
|
167
|
+
const isControlled = value !== undefined;
|
|
168
|
+
const [internalId, setInternalId] = React.useState(
|
|
169
|
+
defaultValue ?? steps[0]?.id ?? ""
|
|
170
|
+
);
|
|
171
|
+
const activeId = isControlled ? value : internalId;
|
|
172
|
+
const activeIndex = steps.findIndex((step) => step.id === activeId);
|
|
173
|
+
|
|
174
|
+
const setActiveStep = React.useCallback(
|
|
175
|
+
(id: string) => {
|
|
176
|
+
if (!isControlled) {
|
|
177
|
+
setInternalId(id);
|
|
178
|
+
}
|
|
179
|
+
onValueChange?.(id);
|
|
180
|
+
},
|
|
181
|
+
[isControlled, onValueChange]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const contextValue = React.useMemo<StepperContextValue>(
|
|
185
|
+
() => ({
|
|
186
|
+
activeId,
|
|
187
|
+
activeIndex,
|
|
188
|
+
setActiveStep,
|
|
189
|
+
steps,
|
|
190
|
+
orientation,
|
|
191
|
+
}),
|
|
192
|
+
[activeId, activeIndex, setActiveStep, steps, orientation]
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<StepperContext.Provider value={contextValue}>
|
|
197
|
+
<div
|
|
198
|
+
ref={ref}
|
|
199
|
+
aria-label={ariaLabel ?? "Progress"}
|
|
200
|
+
className={cn(
|
|
201
|
+
"group/stepper flex data-[orientation=vertical]:flex-col",
|
|
202
|
+
className
|
|
203
|
+
)}
|
|
204
|
+
data-hook={dataHook}
|
|
205
|
+
data-layout={layout}
|
|
206
|
+
data-orientation={orientation}
|
|
207
|
+
data-slot="stepper"
|
|
208
|
+
data-tracking-el={trackingEl}
|
|
209
|
+
data-tracking-label={trackingLabel}
|
|
210
|
+
role="group"
|
|
211
|
+
{...props}
|
|
212
|
+
/>
|
|
213
|
+
</StepperContext.Provider>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
Stepper.displayName = "Stepper";
|
|
218
|
+
|
|
219
|
+
/* -------------------------------------------------------------------------- */
|
|
220
|
+
/* StepperNav */
|
|
221
|
+
/* -------------------------------------------------------------------------- */
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Props for the StepperNav component.
|
|
225
|
+
*/
|
|
226
|
+
interface StepperNavProps extends React.ComponentPropsWithoutRef<"ol"> {
|
|
227
|
+
/** Data hook for automated testing. */
|
|
228
|
+
dataHook?: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Ordered list container that lays out the step indicators and separators.
|
|
233
|
+
*/
|
|
234
|
+
const StepperNav = React.forwardRef<HTMLOListElement, StepperNavProps>(
|
|
235
|
+
({ className, dataHook, ...props }, ref) => (
|
|
236
|
+
<ol
|
|
237
|
+
ref={ref}
|
|
238
|
+
className={cn(
|
|
239
|
+
"flex w-full",
|
|
240
|
+
// Top-align items so indicators (and the separators between them) stay
|
|
241
|
+
// on one line even when a step's description wraps to multiple lines.
|
|
242
|
+
"group-data-[orientation=horizontal]/stepper:flex-row group-data-[orientation=horizontal]/stepper:items-start",
|
|
243
|
+
"group-data-[orientation=vertical]/stepper:flex-col",
|
|
244
|
+
className
|
|
245
|
+
)}
|
|
246
|
+
data-hook={dataHook}
|
|
247
|
+
data-slot="stepper-nav"
|
|
248
|
+
{...props}
|
|
249
|
+
/>
|
|
250
|
+
)
|
|
251
|
+
);
|
|
252
|
+
StepperNav.displayName = "StepperNav";
|
|
253
|
+
|
|
254
|
+
/* -------------------------------------------------------------------------- */
|
|
255
|
+
/* StepperItem */
|
|
256
|
+
/* -------------------------------------------------------------------------- */
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Props for the StepperItem component.
|
|
260
|
+
*/
|
|
261
|
+
interface StepperItemProps extends React.ComponentPropsWithoutRef<"li"> {
|
|
262
|
+
/** Id of the step this item represents (must match an `id` in `steps`). */
|
|
263
|
+
stepId: string;
|
|
264
|
+
/** Force the completed state regardless of the active step. */
|
|
265
|
+
completed?: boolean;
|
|
266
|
+
/** Mark the step as errored (shows the error indicator). */
|
|
267
|
+
error?: boolean;
|
|
268
|
+
/** Disable interaction with the step. */
|
|
269
|
+
disabled?: boolean;
|
|
270
|
+
/** Show a loading spinner in the indicator while this step is active. */
|
|
271
|
+
loading?: boolean;
|
|
272
|
+
/** Data hook for automated testing. */
|
|
273
|
+
dataHook?: string;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* A single step. Derives its state from the active step and exposes it to its
|
|
278
|
+
* sub-components (indicator, trigger, separator) via context and `data-state`.
|
|
279
|
+
*/
|
|
280
|
+
const StepperItem = React.forwardRef<HTMLLIElement, StepperItemProps>(
|
|
281
|
+
(
|
|
282
|
+
{
|
|
283
|
+
className,
|
|
284
|
+
stepId,
|
|
285
|
+
completed = false,
|
|
286
|
+
error = false,
|
|
287
|
+
disabled = false,
|
|
288
|
+
loading = false,
|
|
289
|
+
dataHook,
|
|
290
|
+
...props
|
|
291
|
+
},
|
|
292
|
+
ref
|
|
293
|
+
) => {
|
|
294
|
+
const { activeIndex, steps } = useStepper();
|
|
295
|
+
const index = steps.findIndex((step) => step.id === stepId);
|
|
296
|
+
if (index === -1) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
`StepperItem stepId "${stepId}" was not found in the Stepper "steps" prop. ` +
|
|
299
|
+
`Each StepperItem's stepId must match a step id.`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
const isLast = index === steps.length - 1;
|
|
303
|
+
const isLoading = loading && !error && index === activeIndex;
|
|
304
|
+
|
|
305
|
+
const state: StepperItemState = error
|
|
306
|
+
? "error"
|
|
307
|
+
: completed || index < activeIndex
|
|
308
|
+
? "completed"
|
|
309
|
+
: index === activeIndex
|
|
310
|
+
? "active"
|
|
311
|
+
: "inactive";
|
|
312
|
+
|
|
313
|
+
const contextValue = React.useMemo<StepperItemContextValue>(
|
|
314
|
+
() => ({
|
|
315
|
+
stepId,
|
|
316
|
+
index,
|
|
317
|
+
state,
|
|
318
|
+
isLast,
|
|
319
|
+
isDisabled: disabled,
|
|
320
|
+
isLoading,
|
|
321
|
+
}),
|
|
322
|
+
[stepId, index, state, isLast, disabled, isLoading]
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<StepperItemContext.Provider value={contextValue}>
|
|
327
|
+
<li
|
|
328
|
+
ref={ref}
|
|
329
|
+
className={cn(
|
|
330
|
+
"group/step",
|
|
331
|
+
// Horizontal + labels below: equal-width centered columns. The
|
|
332
|
+
// separator is absolutely positioned between indicator centers (see
|
|
333
|
+
// StepperSeparator), so labels sit below the indicator without
|
|
334
|
+
// squeezing the connector or pushing indicators out of line.
|
|
335
|
+
"group-data-[layout=horizontal-below]/stepper:relative group-data-[layout=horizontal-below]/stepper:flex group-data-[layout=horizontal-below]/stepper:flex-1 group-data-[layout=horizontal-below]/stepper:flex-col group-data-[layout=horizontal-below]/stepper:items-center",
|
|
336
|
+
// Horizontal + inline labels: a row of indicator + label with an
|
|
337
|
+
// in-flow connector filling the gap to the next step.
|
|
338
|
+
"group-data-[layout=horizontal-inline]/stepper:flex group-data-[layout=horizontal-inline]/stepper:flex-row group-data-[layout=horizontal-inline]/stepper:items-center",
|
|
339
|
+
!isLast && "group-data-[layout=horizontal-inline]/stepper:flex-1",
|
|
340
|
+
// Vertical: indicator + labels in a row, separator below.
|
|
341
|
+
"group-data-[layout=vertical]/stepper:flex group-data-[layout=vertical]/stepper:flex-col group-data-[layout=vertical]/stepper:items-start",
|
|
342
|
+
className
|
|
343
|
+
)}
|
|
344
|
+
data-disabled={disabled ? "true" : undefined}
|
|
345
|
+
data-hook={dataHook}
|
|
346
|
+
data-loading={isLoading ? "true" : undefined}
|
|
347
|
+
data-slot="stepper-item"
|
|
348
|
+
data-state={state}
|
|
349
|
+
{...props}
|
|
350
|
+
/>
|
|
351
|
+
</StepperItemContext.Provider>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
StepperItem.displayName = "StepperItem";
|
|
356
|
+
|
|
357
|
+
/* -------------------------------------------------------------------------- */
|
|
358
|
+
/* StepperTrigger */
|
|
359
|
+
/* -------------------------------------------------------------------------- */
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Props for the StepperTrigger component.
|
|
363
|
+
*/
|
|
364
|
+
interface StepperTriggerProps extends React.ComponentPropsWithoutRef<"button"> {
|
|
365
|
+
/**
|
|
366
|
+
* Render as the child element instead of a button (Radix Slot pattern).
|
|
367
|
+
* Note: the disabled state is not applied automatically when `asChild` is
|
|
368
|
+
* true — the consumer must handle disabled styling/behavior on the child.
|
|
369
|
+
*/
|
|
370
|
+
asChild?: boolean;
|
|
371
|
+
/** Data hook for automated testing. */
|
|
372
|
+
dataHook?: string;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Clickable wrapper around a step's indicator and labels. Activates its step
|
|
377
|
+
* on click and exposes hover/focus affordances. Render as a non-interactive
|
|
378
|
+
* element with `asChild` when steps should not be navigable.
|
|
379
|
+
*/
|
|
380
|
+
const StepperTrigger = React.forwardRef<HTMLButtonElement, StepperTriggerProps>(
|
|
381
|
+
({ asChild = false, className, dataHook, ...props }, ref) => {
|
|
382
|
+
const { setActiveStep } = useStepper();
|
|
383
|
+
const { stepId, state, isDisabled } = useStepperItem();
|
|
384
|
+
|
|
385
|
+
const Comp = asChild ? Slot : "button";
|
|
386
|
+
|
|
387
|
+
return (
|
|
388
|
+
<Comp
|
|
389
|
+
ref={ref}
|
|
390
|
+
aria-current={state === "active" ? "step" : undefined}
|
|
391
|
+
className={cn(
|
|
392
|
+
// Focus is shown as a ring on the indicator (see StepperIndicator),
|
|
393
|
+
// not on the whole trigger, so it stays a circle around the badge.
|
|
394
|
+
"group/trigger inline-flex outline-none",
|
|
395
|
+
// Layout adapts automatically — no consumer classes needed. Labels
|
|
396
|
+
// stack below the indicator (horizontal/below) or sit beside it
|
|
397
|
+
// (horizontal/inline and vertical).
|
|
398
|
+
"group-data-[layout=horizontal-below]/stepper:flex-col group-data-[layout=horizontal-below]/stepper:items-center group-data-[layout=horizontal-below]/stepper:gap-2",
|
|
399
|
+
"group-data-[layout=horizontal-inline]/stepper:flex-row group-data-[layout=horizontal-inline]/stepper:items-center group-data-[layout=horizontal-inline]/stepper:gap-3",
|
|
400
|
+
"group-data-[layout=vertical]/stepper:flex-row group-data-[layout=vertical]/stepper:items-center group-data-[layout=vertical]/stepper:gap-3",
|
|
401
|
+
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
402
|
+
!asChild && !isDisabled && "cursor-pointer",
|
|
403
|
+
className
|
|
404
|
+
)}
|
|
405
|
+
data-hook={dataHook}
|
|
406
|
+
data-slot="stepper-trigger"
|
|
407
|
+
// Spread consumer props first, then enforce the internal handler/state
|
|
408
|
+
// so step activation can't be accidentally broken — while still
|
|
409
|
+
// invoking the consumer's onClick (and respecting preventDefault).
|
|
410
|
+
{...props}
|
|
411
|
+
{...(asChild
|
|
412
|
+
? {}
|
|
413
|
+
: {
|
|
414
|
+
type: "button" as const,
|
|
415
|
+
disabled: isDisabled || props.disabled,
|
|
416
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
417
|
+
props.onClick?.(event);
|
|
418
|
+
if (!event.defaultPrevented) {
|
|
419
|
+
setActiveStep(stepId);
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
})}
|
|
423
|
+
/>
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
StepperTrigger.displayName = "StepperTrigger";
|
|
428
|
+
|
|
429
|
+
/* -------------------------------------------------------------------------- */
|
|
430
|
+
/* StepperIndicator */
|
|
431
|
+
/* -------------------------------------------------------------------------- */
|
|
432
|
+
|
|
433
|
+
const stepperIndicatorStyles = cva(
|
|
434
|
+
[
|
|
435
|
+
"relative flex size-8 shrink-0 items-center justify-center rounded-full text-xs font-medium",
|
|
436
|
+
"transition-colors duration-200 ease-out",
|
|
437
|
+
// Hover overlay (only visible when wrapped by an interactive trigger).
|
|
438
|
+
"after:pointer-events-none after:absolute after:inset-0 after:rounded-full after:bg-white/10 after:opacity-0 after:transition-opacity after:duration-200 after:ease-out",
|
|
439
|
+
"group-hover/trigger:after:opacity-100",
|
|
440
|
+
// Focus ring is rendered here (around the circle) when the trigger is
|
|
441
|
+
// keyboard-focused, rather than around the whole trigger.
|
|
442
|
+
"group-focus-visible/trigger:shadow-default",
|
|
443
|
+
// Dim when the step is disabled.
|
|
444
|
+
"group-data-[disabled=true]/step:opacity-50",
|
|
445
|
+
],
|
|
446
|
+
{
|
|
447
|
+
variants: {
|
|
448
|
+
state: {
|
|
449
|
+
active: "bg-primary text-primary-foreground",
|
|
450
|
+
completed: "bg-primary text-primary-foreground",
|
|
451
|
+
// secondary-foreground (not muted-foreground) for AA contrast on the
|
|
452
|
+
// secondary background.
|
|
453
|
+
inactive: "bg-secondary text-secondary-foreground",
|
|
454
|
+
error: "bg-destructive text-destructive-foreground",
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
defaultVariants: {
|
|
458
|
+
state: "inactive",
|
|
459
|
+
},
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Props for the StepperIndicator component.
|
|
465
|
+
*/
|
|
466
|
+
interface StepperIndicatorProps extends React.ComponentPropsWithoutRef<"span"> {
|
|
467
|
+
/** Render arbitrary content instead of the built-in number/icon swap. */
|
|
468
|
+
asChild?: boolean;
|
|
469
|
+
/**
|
|
470
|
+
* Screen-reader label appended when the step is completed.
|
|
471
|
+
* @default "Completed"
|
|
472
|
+
*/
|
|
473
|
+
completedLabel?: string;
|
|
474
|
+
/**
|
|
475
|
+
* Screen-reader label appended when the step has an error.
|
|
476
|
+
* @default "Error"
|
|
477
|
+
*/
|
|
478
|
+
errorLabel?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Screen-reader label appended while the step is loading.
|
|
481
|
+
* @default "Loading"
|
|
482
|
+
*/
|
|
483
|
+
loadingLabel?: string;
|
|
484
|
+
/** Data hook for automated testing. */
|
|
485
|
+
dataHook?: string;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* The circular step indicator. Shows the step number by default, swapping to a
|
|
490
|
+
* check icon when completed, a cross when errored, and a spinner while loading.
|
|
491
|
+
* Pass `children` to override the number (e.g. a custom index or icon).
|
|
492
|
+
*/
|
|
493
|
+
const StepperIndicator = React.forwardRef<
|
|
494
|
+
HTMLSpanElement,
|
|
495
|
+
StepperIndicatorProps
|
|
496
|
+
>(
|
|
497
|
+
(
|
|
498
|
+
{
|
|
499
|
+
asChild = false,
|
|
500
|
+
className,
|
|
501
|
+
children,
|
|
502
|
+
completedLabel = "Completed",
|
|
503
|
+
errorLabel = "Error",
|
|
504
|
+
loadingLabel = "Loading",
|
|
505
|
+
dataHook,
|
|
506
|
+
...props
|
|
507
|
+
},
|
|
508
|
+
ref
|
|
509
|
+
) => {
|
|
510
|
+
const { state, index, isLoading } = useStepperItem();
|
|
511
|
+
|
|
512
|
+
// Screen-reader state text, rendered in both the default and asChild
|
|
513
|
+
// branches so custom indicator content keeps the icons + sr-only contract.
|
|
514
|
+
const stateLabel = (
|
|
515
|
+
<>
|
|
516
|
+
{state === "completed" && (
|
|
517
|
+
<span className="sr-only">{completedLabel}</span>
|
|
518
|
+
)}
|
|
519
|
+
{state === "error" && <span className="sr-only">{errorLabel}</span>}
|
|
520
|
+
{isLoading && <span className="sr-only">{loadingLabel}</span>}
|
|
521
|
+
</>
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
return (
|
|
525
|
+
<span
|
|
526
|
+
ref={ref}
|
|
527
|
+
className={cn(stepperIndicatorStyles({ state }), className)}
|
|
528
|
+
data-hook={dataHook}
|
|
529
|
+
data-slot="stepper-indicator"
|
|
530
|
+
data-state={state}
|
|
531
|
+
{...props}
|
|
532
|
+
>
|
|
533
|
+
{asChild ? (
|
|
534
|
+
<>
|
|
535
|
+
{children}
|
|
536
|
+
{stateLabel}
|
|
537
|
+
</>
|
|
538
|
+
) : (
|
|
539
|
+
<>
|
|
540
|
+
<span
|
|
541
|
+
className={cn(
|
|
542
|
+
"transition-opacity duration-200 ease-out",
|
|
543
|
+
(state === "completed" || state === "error" || isLoading) &&
|
|
544
|
+
"opacity-0"
|
|
545
|
+
)}
|
|
546
|
+
>
|
|
547
|
+
{children ?? index + 1}
|
|
548
|
+
</span>
|
|
549
|
+
{state === "completed" && !isLoading && (
|
|
550
|
+
<Check className="absolute" size={16} />
|
|
551
|
+
)}
|
|
552
|
+
{state === "error" && !isLoading && (
|
|
553
|
+
<X className="absolute" size={16} />
|
|
554
|
+
)}
|
|
555
|
+
{isLoading && (
|
|
556
|
+
<LoaderCircle className="absolute animate-spin" size={16} />
|
|
557
|
+
)}
|
|
558
|
+
{stateLabel}
|
|
559
|
+
</>
|
|
560
|
+
)}
|
|
561
|
+
</span>
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
);
|
|
565
|
+
StepperIndicator.displayName = "StepperIndicator";
|
|
566
|
+
|
|
567
|
+
/* -------------------------------------------------------------------------- */
|
|
568
|
+
/* StepperSeparator */
|
|
569
|
+
/* -------------------------------------------------------------------------- */
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Props for the StepperSeparator component.
|
|
573
|
+
*/
|
|
574
|
+
interface StepperSeparatorProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
575
|
+
/** Data hook for automated testing. */
|
|
576
|
+
dataHook?: string;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Connector line between two steps. Renders nothing after the final step and
|
|
581
|
+
* fills with the primary color once its step is completed.
|
|
582
|
+
*/
|
|
583
|
+
const StepperSeparator = React.forwardRef<
|
|
584
|
+
HTMLDivElement,
|
|
585
|
+
StepperSeparatorProps
|
|
586
|
+
>(({ className, dataHook, ...props }, ref) => {
|
|
587
|
+
const { isLast } = useStepperItem();
|
|
588
|
+
|
|
589
|
+
if (isLast) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
return (
|
|
594
|
+
<div
|
|
595
|
+
ref={ref}
|
|
596
|
+
aria-hidden="true"
|
|
597
|
+
className={cn(
|
|
598
|
+
"bg-border shrink-0 rounded-full transition-colors duration-200",
|
|
599
|
+
"group-data-[state=completed]/step:bg-primary",
|
|
600
|
+
"group-data-[disabled=true]/step:opacity-50",
|
|
601
|
+
// Horizontal + labels below: absolute connector spanning this indicator
|
|
602
|
+
// center to the next, at the indicator's vertical center (top 15px =
|
|
603
|
+
// half the 32px indicator minus half the 2px line). 1.5rem gaps the ends.
|
|
604
|
+
"group-data-[layout=horizontal-below]/stepper:absolute group-data-[layout=horizontal-below]/stepper:top-[15px] group-data-[layout=horizontal-below]/stepper:right-[calc(-50%+1.5rem)] group-data-[layout=horizontal-below]/stepper:left-[calc(50%+1.5rem)] group-data-[layout=horizontal-below]/stepper:h-0.5",
|
|
605
|
+
// Horizontal + inline labels: in-flow connector filling the gap to the
|
|
606
|
+
// next step (vertically centered with the indicator by the item row).
|
|
607
|
+
"group-data-[layout=horizontal-inline]/stepper:mx-2 group-data-[layout=horizontal-inline]/stepper:h-0.5 group-data-[layout=horizontal-inline]/stepper:flex-1",
|
|
608
|
+
// Vertical: in-flow line below the indicator (ms aligns under center).
|
|
609
|
+
"group-data-[layout=vertical]/stepper:my-1 group-data-[layout=vertical]/stepper:ms-[15px] group-data-[layout=vertical]/stepper:h-8 group-data-[layout=vertical]/stepper:w-0.5",
|
|
610
|
+
className
|
|
611
|
+
)}
|
|
612
|
+
data-hook={dataHook}
|
|
613
|
+
data-slot="stepper-separator"
|
|
614
|
+
role="presentation"
|
|
615
|
+
{...props}
|
|
616
|
+
/>
|
|
617
|
+
);
|
|
618
|
+
});
|
|
619
|
+
StepperSeparator.displayName = "StepperSeparator";
|
|
620
|
+
|
|
621
|
+
/* -------------------------------------------------------------------------- */
|
|
622
|
+
/* StepperContent / Title / Description */
|
|
623
|
+
/* -------------------------------------------------------------------------- */
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Wraps a step's title and description with the correct alignment for the
|
|
627
|
+
* current orientation (centered below the indicator when horizontal, start-
|
|
628
|
+
* aligned beside it when vertical). Use inside a `StepperTrigger`.
|
|
629
|
+
*/
|
|
630
|
+
const StepperContent = React.forwardRef<
|
|
631
|
+
HTMLSpanElement,
|
|
632
|
+
React.ComponentPropsWithoutRef<"span">
|
|
633
|
+
>(({ className, ...props }, ref) => (
|
|
634
|
+
<span
|
|
635
|
+
ref={ref}
|
|
636
|
+
className={cn(
|
|
637
|
+
"flex flex-col gap-0.5",
|
|
638
|
+
"group-data-[layout=horizontal-below]/stepper:items-center group-data-[layout=horizontal-below]/stepper:text-center",
|
|
639
|
+
"group-data-[layout=horizontal-inline]/stepper:items-start group-data-[layout=horizontal-inline]/stepper:text-left",
|
|
640
|
+
"group-data-[layout=vertical]/stepper:items-start group-data-[layout=vertical]/stepper:text-left",
|
|
641
|
+
className
|
|
642
|
+
)}
|
|
643
|
+
data-slot="stepper-content"
|
|
644
|
+
{...props}
|
|
645
|
+
/>
|
|
646
|
+
));
|
|
647
|
+
StepperContent.displayName = "StepperContent";
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Title label for a step. Adapts color to the step state.
|
|
651
|
+
*/
|
|
652
|
+
const StepperTitle = React.forwardRef<
|
|
653
|
+
HTMLSpanElement,
|
|
654
|
+
React.ComponentPropsWithoutRef<"span">
|
|
655
|
+
>(({ className, ...props }, ref) => (
|
|
656
|
+
<span
|
|
657
|
+
ref={ref}
|
|
658
|
+
className={cn(
|
|
659
|
+
"text-foreground text-sm font-semibold",
|
|
660
|
+
"group-data-[state=inactive]/step:text-muted-foreground",
|
|
661
|
+
"group-data-[disabled=true]/step:text-muted-foreground",
|
|
662
|
+
className
|
|
663
|
+
)}
|
|
664
|
+
data-slot="stepper-title"
|
|
665
|
+
{...props}
|
|
666
|
+
/>
|
|
667
|
+
));
|
|
668
|
+
StepperTitle.displayName = "StepperTitle";
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Secondary description text for a step.
|
|
672
|
+
*/
|
|
673
|
+
const StepperDescription = React.forwardRef<
|
|
674
|
+
HTMLSpanElement,
|
|
675
|
+
React.ComponentPropsWithoutRef<"span">
|
|
676
|
+
>(({ className, ...props }, ref) => (
|
|
677
|
+
<span
|
|
678
|
+
ref={ref}
|
|
679
|
+
className={cn("text-muted-foreground text-xs font-normal", className)}
|
|
680
|
+
data-slot="stepper-description"
|
|
681
|
+
{...props}
|
|
682
|
+
/>
|
|
683
|
+
));
|
|
684
|
+
StepperDescription.displayName = "StepperDescription";
|
|
685
|
+
|
|
686
|
+
export {
|
|
687
|
+
Stepper,
|
|
688
|
+
StepperNav,
|
|
689
|
+
StepperItem,
|
|
690
|
+
StepperTrigger,
|
|
691
|
+
StepperIndicator,
|
|
692
|
+
StepperSeparator,
|
|
693
|
+
StepperContent,
|
|
694
|
+
StepperTitle,
|
|
695
|
+
StepperDescription,
|
|
696
|
+
};
|
|
697
|
+
export type {
|
|
698
|
+
StepperProps,
|
|
699
|
+
StepperNavProps,
|
|
700
|
+
StepperItemProps,
|
|
701
|
+
StepperTriggerProps,
|
|
702
|
+
StepperIndicatorProps,
|
|
703
|
+
StepperSeparatorProps,
|
|
704
|
+
StepperStep,
|
|
705
|
+
StepperItemState,
|
|
706
|
+
StepperOrientation,
|
|
707
|
+
StepperLabelPlacement,
|
|
708
|
+
};
|