@szum-tech/design-system 3.12.3 → 3.14.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.
Files changed (94) hide show
  1. package/dist/chunk-4IGU5SVP.js +54 -0
  2. package/dist/{chunk-XJZOANXX.cjs → chunk-6HX7ETL3.cjs} +1 -1
  3. package/dist/chunk-7OD2NBSV.cjs +50 -0
  4. package/dist/chunk-B4M7Q5KX.cjs +25 -0
  5. package/dist/{chunk-S2BCU6WG.cjs → chunk-CAIAZGSW.cjs} +5 -4
  6. package/dist/chunk-EOTQVIA5.js +993 -0
  7. package/dist/chunk-EZCWHR56.cjs +2355 -0
  8. package/dist/chunk-G24PWQKG.js +20 -0
  9. package/dist/chunk-GEDBA3JU.cjs +49 -0
  10. package/dist/chunk-IZU3KULT.js +41 -0
  11. package/dist/{chunk-KQ6QE7BT.cjs → chunk-MNDQXDV4.cjs} +4 -4
  12. package/dist/chunk-N4TYSZSU.cjs +44 -0
  13. package/dist/chunk-OZSNSRLV.cjs +1027 -0
  14. package/dist/{chunk-DL54DIMD.js → chunk-Q2MJKFIE.js} +2 -1
  15. package/dist/chunk-S3ZUFD6U.js +23 -0
  16. package/dist/{chunk-WXZE35FK.js → chunk-VK2FJ65F.js} +1 -1
  17. package/dist/chunk-VL3TPVSB.js +2299 -0
  18. package/dist/chunk-X5O7GP4S.js +48 -0
  19. package/dist/{chunk-E5TYGWGE.js → chunk-XKCLVPUC.js} +1 -1
  20. package/dist/{chunk-XIQUR62A.cjs → chunk-XY3ZNUWR.cjs} +32 -20
  21. package/dist/color-picker.types-GI7dq2Ig.d.cts +42 -0
  22. package/dist/color-picker.types-GI7dq2Ig.d.ts +42 -0
  23. package/dist/components/badge-overflow/index.cjs +3 -2
  24. package/dist/components/badge-overflow/index.js +2 -1
  25. package/dist/components/button/index.cjs +16 -12
  26. package/dist/components/button/index.d.cts +1 -0
  27. package/dist/components/button/index.d.ts +1 -0
  28. package/dist/components/button/index.js +15 -11
  29. package/dist/components/carousel/index.cjs +17 -13
  30. package/dist/components/carousel/index.d.cts +1 -0
  31. package/dist/components/carousel/index.d.ts +1 -0
  32. package/dist/components/carousel/index.js +15 -11
  33. package/dist/components/color-picker/index.cjs +88 -0
  34. package/dist/components/color-picker/index.d.cts +71 -0
  35. package/dist/components/color-picker/index.d.ts +71 -0
  36. package/dist/components/color-picker/index.js +39 -0
  37. package/dist/components/dialog/index.d.cts +1 -0
  38. package/dist/components/dialog/index.d.ts +1 -0
  39. package/dist/components/file-upload/index.cjs +60 -0
  40. package/dist/components/file-upload/index.d.cts +131 -0
  41. package/dist/components/file-upload/index.d.ts +131 -0
  42. package/dist/components/file-upload/index.js +3 -0
  43. package/dist/components/index.cjs +216 -84
  44. package/dist/components/index.d.cts +8 -1
  45. package/dist/components/index.d.ts +8 -1
  46. package/dist/components/index.js +15 -11
  47. package/dist/components/input/index.cjs +2 -2
  48. package/dist/components/input/index.js +1 -1
  49. package/dist/components/item/index.d.cts +1 -0
  50. package/dist/components/item/index.d.ts +1 -0
  51. package/dist/components/masonry/index.cjs +5 -4
  52. package/dist/components/masonry/index.js +3 -2
  53. package/dist/components/popover/index.cjs +35 -0
  54. package/dist/components/popover/index.d.cts +18 -0
  55. package/dist/components/popover/index.d.ts +18 -0
  56. package/dist/components/popover/index.js +2 -0
  57. package/dist/components/select/index.cjs +7 -7
  58. package/dist/components/select/index.d.cts +8 -14
  59. package/dist/components/select/index.d.ts +8 -14
  60. package/dist/components/select/index.js +1 -1
  61. package/dist/components/sheet/index.d.cts +2 -1
  62. package/dist/components/sheet/index.d.ts +2 -1
  63. package/dist/components/stepper/index.cjs +34 -30
  64. package/dist/components/stepper/index.d.cts +1 -0
  65. package/dist/components/stepper/index.d.ts +1 -0
  66. package/dist/components/stepper/index.js +15 -11
  67. package/dist/components/switch/index.cjs +11 -0
  68. package/dist/components/switch/index.d.cts +19 -0
  69. package/dist/components/switch/index.d.ts +19 -0
  70. package/dist/components/switch/index.js +2 -0
  71. package/dist/components/timeline/index.cjs +12 -11
  72. package/dist/components/timeline/index.d.cts +1 -0
  73. package/dist/components/timeline/index.d.ts +1 -0
  74. package/dist/components/timeline/index.js +3 -2
  75. package/dist/components/toaster/index.cjs +17 -13
  76. package/dist/components/toaster/index.js +15 -11
  77. package/dist/components/typing-text/index.d.cts +1 -0
  78. package/dist/components/typing-text/index.d.ts +1 -0
  79. package/dist/components/word-rotate/index.d.cts +1 -0
  80. package/dist/components/word-rotate/index.d.ts +1 -0
  81. package/dist/hooks/index.cjs +17 -8
  82. package/dist/hooks/index.d.cts +15 -4
  83. package/dist/hooks/index.d.ts +15 -4
  84. package/dist/hooks/index.js +2 -1
  85. package/dist/popover-trigger-Cf4PPj0z.d.cts +14 -0
  86. package/dist/popover-trigger-Cf4PPj0z.d.ts +14 -0
  87. package/dist/select-Bf6XQtt-.d.cts +12 -0
  88. package/dist/select-Bf6XQtt-.d.ts +12 -0
  89. package/package.json +1 -1
  90. package/dist/chunk-5AA4IE2T.cjs +0 -27
  91. package/dist/chunk-CP43WJCN.cjs +0 -1065
  92. package/dist/chunk-QTYNFISP.js +0 -1020
  93. package/dist/chunk-SB5UG7OC.js +0 -41
  94. package/dist/chunk-UGSNASZM.js +0 -25
@@ -1,1020 +0,0 @@
1
- import { useDirection, useComposedRefs } from './chunk-WXZE35FK.js';
2
- import { Spinner } from './chunk-P5IUC7HJ.js';
3
- import { useLazyRef, useIsomorphicLayoutEffect } from './chunk-SB5UG7OC.js';
4
- import { cn } from './chunk-ZD2QRAOX.js';
5
- import * as React5 from 'react';
6
- import { Slot } from '@radix-ui/react-slot';
7
- import { jsx, jsxs } from 'react/jsx-runtime';
8
- import { OctagonXIcon, TriangleAlertIcon, InfoIcon, CircleCheckIcon } from 'lucide-react';
9
- import { Toaster as Toaster$1 } from 'sonner';
10
- export { toast } from 'sonner';
11
- import { cva } from 'class-variance-authority';
12
-
13
- // src/components/stepper/stepper.constants.ts
14
- var STEPPER_ROOT_NAME = "Stepper";
15
- var STEPPER_NAV_NAME = "StepperNav";
16
- var STEPPER_ITEM_NAME = "StepperItem";
17
- var STEPPER_TRIGGER_NAME = "StepperTrigger";
18
- var STEPPER_INDICATOR_NAME = "StepperIndicator";
19
- var STEPPER_TITLE_NAME = "StepperTitle";
20
- var STEPPER_DESCRIPTION_NAME = "StepperDescription";
21
- var STEPPER_CONTENT_NAME = "StepperContent";
22
- var STEPPER_PREV_TRIGGER_NAME = "StepperPrevTrigger";
23
- var STEPPER_NEXT_TRIGGER_NAME = "StepperNextTrigger";
24
- var STEPPER_ENTRY_FOCUS = "stepperFocusGroup.onEntryFocus";
25
- var STEPPER_EVENT_OPTIONS = { bubbles: false, cancelable: true };
26
- var STEPPER_ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
27
- var STEPPER_MAP_KEY_TO_FOCUS_INTENT = {
28
- ArrowLeft: "prev",
29
- ArrowUp: "prev",
30
- ArrowRight: "next",
31
- ArrowDown: "next",
32
- PageUp: "first",
33
- Home: "first",
34
- PageDown: "last",
35
- End: "last"
36
- };
37
-
38
- // src/components/stepper/stepper.context.tsx
39
- var StepperContext = React5.createContext(null);
40
- function useStepperContext(consumerName) {
41
- const context = React5.useContext(StepperContext);
42
- if (!context) {
43
- throw new Error(`\`${consumerName}\` must be used within \`${STEPPER_ROOT_NAME}\``);
44
- }
45
- return context;
46
- }
47
- function createStepperStore(listenersRef, stateRef, onValueChange, onValueComplete, onValueAdd, onValueRemove, onValidate) {
48
- const store = {
49
- subscribe: (cb) => {
50
- if (listenersRef.current) {
51
- listenersRef.current.add(cb);
52
- return () => listenersRef.current?.delete(cb);
53
- }
54
- return () => {
55
- };
56
- },
57
- getState: () => stateRef.current ?? {
58
- steps: /* @__PURE__ */ new Map(),
59
- value: void 0
60
- },
61
- setState: (key, value) => {
62
- const state = stateRef.current;
63
- if (!state || Object.is(state[key], value)) return;
64
- if (key === "value" && typeof value === "string") {
65
- state.value = value;
66
- onValueChange?.(value);
67
- } else {
68
- state[key] = value;
69
- }
70
- store.notify();
71
- },
72
- setStateWithValidation: async (value, direction) => {
73
- if (!onValidate) {
74
- store.setState("value", value);
75
- return true;
76
- }
77
- try {
78
- const isValid = await onValidate(value, direction);
79
- if (isValid) {
80
- store.setState("value", value);
81
- }
82
- return isValid;
83
- } catch {
84
- return false;
85
- }
86
- },
87
- hasValidation: () => !!onValidate,
88
- addStep: (newStep) => {
89
- const state = stateRef.current;
90
- if (state) {
91
- state.steps = new Map(state.steps);
92
- state.steps.set(newStep.value, newStep);
93
- onValueAdd?.(newStep.value);
94
- store.notify();
95
- }
96
- },
97
- removeStep: (value) => {
98
- const state = stateRef.current;
99
- if (state) {
100
- state.steps = new Map(state.steps);
101
- state.steps.delete(value);
102
- onValueRemove?.(value);
103
- store.notify();
104
- }
105
- },
106
- setStep: ({ value, disabled, loading, completed }) => {
107
- const state = stateRef.current;
108
- if (state) {
109
- const step = state.steps.get(value);
110
- if (step) {
111
- const updatedStep = { ...step, completed, disabled, loading };
112
- state.steps = new Map(state.steps);
113
- state.steps.set(value, updatedStep);
114
- if (completed !== step.completed) {
115
- onValueComplete?.(value, completed);
116
- }
117
- store.notify();
118
- }
119
- }
120
- },
121
- notify: () => {
122
- if (listenersRef.current) {
123
- for (const cb of listenersRef.current) {
124
- cb();
125
- }
126
- }
127
- }
128
- };
129
- return store;
130
- }
131
- var StepperStoreContext = React5.createContext(null);
132
- function useStepperStoreContext(consumerName) {
133
- const context = React5.useContext(StepperStoreContext);
134
- if (!context) {
135
- throw new Error(`\`${consumerName}\` must be used within \`${STEPPER_ROOT_NAME}\``);
136
- }
137
- return context;
138
- }
139
- function useStepperStore(selector) {
140
- const store = useStepperStoreContext("useStore");
141
- const getSnapshot = React5.useCallback(() => selector(store.getState()), [selector, store]);
142
- return React5.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
143
- }
144
- function Stepper({
145
- value,
146
- defaultValue,
147
- onValueChange,
148
- onValueComplete,
149
- onValueAdd,
150
- onValueRemove,
151
- onValidate,
152
- id: idProp,
153
- dir: dirProp,
154
- orientation = "horizontal",
155
- activationMode = "automatic",
156
- asChild,
157
- disabled = false,
158
- nonInteractive = false,
159
- loop = false,
160
- className,
161
- indicators = {},
162
- ...rootProps
163
- }) {
164
- const id = React5.useId();
165
- const rootId = idProp ?? id;
166
- const listenersRef = useLazyRef(() => /* @__PURE__ */ new Set());
167
- const stateRef = useLazyRef(() => ({
168
- steps: /* @__PURE__ */ new Map(),
169
- value: value ?? defaultValue
170
- }));
171
- const store = React5.useMemo(
172
- () => createStepperStore(listenersRef, stateRef, onValueChange, onValueComplete, onValueAdd, onValueRemove, onValidate),
173
- [listenersRef, stateRef, onValueChange, onValueComplete, onValueAdd, onValueRemove, onValidate]
174
- );
175
- useIsomorphicLayoutEffect(() => {
176
- if (value !== void 0) {
177
- store.setState("value", value);
178
- }
179
- }, [value]);
180
- const dir = useDirection(dirProp);
181
- const contextValue = React5.useMemo(
182
- () => ({
183
- id: rootId,
184
- dir,
185
- orientation,
186
- activationMode,
187
- disabled,
188
- nonInteractive,
189
- loop,
190
- indicators
191
- }),
192
- [rootId, dir, orientation, activationMode, disabled, nonInteractive, loop, indicators]
193
- );
194
- const RootPrimitive = asChild ? Slot : "div";
195
- return /* @__PURE__ */ jsx(StepperStoreContext.Provider, { value: store, children: /* @__PURE__ */ jsx(StepperContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
196
- RootPrimitive,
197
- {
198
- id: rootId,
199
- "data-disabled": disabled ? "" : void 0,
200
- "data-orientation": orientation,
201
- "data-slot": "stepper",
202
- dir,
203
- ...rootProps,
204
- className: cn("flex w-full flex-col gap-4 data-[orientation=vertical]:flex-row", className)
205
- }
206
- ) }) });
207
- }
208
-
209
- // src/components/stepper/stepper.types.ts
210
- var StepperFocusIntent = {
211
- FIRST: "first",
212
- LAST: "last",
213
- PREV: "prev",
214
- NEXT: "next"
215
- };
216
- var StepperOrientation = {
217
- HORIZONTAL: "horizontal",
218
- VERTICAL: "vertical"
219
- };
220
- var StepperNavigationDirection = {
221
- NEXT: "next",
222
- PREV: "prev"
223
- };
224
- var StepperActivationMode = {
225
- AUTOMATIC: "automatic",
226
- MANUAL: "manual"
227
- };
228
- var StepperDataState = {
229
- INACTIVE: "inactive",
230
- ACTIVE: "active",
231
- COMPLETED: "completed"
232
- };
233
- var StepperFocusContext = React5.createContext(null);
234
- function useStepperFocusContext(consumerName) {
235
- const context = React5.useContext(StepperFocusContext);
236
- if (!context) {
237
- throw new Error(`\`${consumerName}\` must be used within \`FocusProvider\``);
238
- }
239
- return context;
240
- }
241
-
242
- // src/components/stepper/stepper.utils.tsx
243
- function focusFirst(candidates, preventScroll = false) {
244
- const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
245
- for (const candidateRef of candidates) {
246
- const candidate = candidateRef.current;
247
- if (!candidate) continue;
248
- if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
249
- candidate.focus({ preventScroll });
250
- if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
251
- }
252
- }
253
- function getDataState(value, itemValue, stepState, steps, variant = "item") {
254
- const stepKeys = Array.from(steps.keys());
255
- const currentIndex = stepKeys.indexOf(itemValue);
256
- if (stepState?.completed) {
257
- return StepperDataState.COMPLETED;
258
- }
259
- if (value === itemValue) {
260
- return variant === "separator" ? StepperDataState.INACTIVE : StepperDataState.ACTIVE;
261
- }
262
- if (value) {
263
- const activeIndex = stepKeys.indexOf(value);
264
- if (activeIndex > currentIndex) {
265
- return StepperDataState.COMPLETED;
266
- }
267
- }
268
- return StepperDataState.INACTIVE;
269
- }
270
- function getId(id, variant, value) {
271
- return `${id}-${variant}-${value}`;
272
- }
273
- function wrapArray(array, startIndex) {
274
- return array.map((_, index) => array[(startIndex + index) % array.length]);
275
- }
276
- function getDirectionAwareKey(key, dir) {
277
- if (dir !== "rtl") return key;
278
- return key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
279
- }
280
- function getFocusIntent(event, dir, orientation) {
281
- const key = getDirectionAwareKey(event.key, dir);
282
- if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)) return void 0;
283
- if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) return void 0;
284
- return STEPPER_MAP_KEY_TO_FOCUS_INTENT[key];
285
- }
286
- function StepperNav({ className, children, asChild, ref, ...listProps }) {
287
- const context = useStepperContext(STEPPER_NAV_NAME);
288
- const orientation = context.orientation;
289
- const currentValue = useStepperStore((state) => state.value);
290
- const [tabStopId, setTabStopId] = React5.useState(null);
291
- const [isTabbingBackOut, setIsTabbingBackOut] = React5.useState(false);
292
- const [focusableItemCount, setFocusableItemCount] = React5.useState(0);
293
- const isClickFocusRef = React5.useRef(false);
294
- const itemsRef = React5.useRef(/* @__PURE__ */ new Map());
295
- const listRef = React5.useRef(null);
296
- const composedRef = useComposedRefs(ref, listRef);
297
- const onItemFocus = React5.useCallback((tabStopId2) => {
298
- setTabStopId(tabStopId2);
299
- }, []);
300
- const onItemShiftTab = React5.useCallback(() => {
301
- setIsTabbingBackOut(true);
302
- }, []);
303
- const onFocusableItemAdd = React5.useCallback(() => {
304
- setFocusableItemCount((prevCount) => prevCount + 1);
305
- }, []);
306
- const onFocusableItemRemove = React5.useCallback(() => {
307
- setFocusableItemCount((prevCount) => prevCount - 1);
308
- }, []);
309
- const onItemRegister = React5.useCallback((item) => {
310
- itemsRef.current.set(item.id, item);
311
- }, []);
312
- const onItemUnregister = React5.useCallback((id) => {
313
- itemsRef.current.delete(id);
314
- }, []);
315
- const getItems = React5.useCallback(() => {
316
- return Array.from(itemsRef.current.values()).filter((item) => item.ref.current).sort((a, b) => {
317
- const elementA = a.ref.current;
318
- const elementB = b.ref.current;
319
- if (!elementA || !elementB) return 0;
320
- const position = elementA.compareDocumentPosition(elementB);
321
- if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
322
- return -1;
323
- }
324
- if (position & Node.DOCUMENT_POSITION_PRECEDING) {
325
- return 1;
326
- }
327
- return 0;
328
- });
329
- }, []);
330
- const onBlur = React5.useCallback(
331
- (event) => {
332
- listProps.onBlur?.(event);
333
- if (event.defaultPrevented) return;
334
- setIsTabbingBackOut(false);
335
- },
336
- // eslint-disable-next-line react-hooks/exhaustive-deps
337
- [listProps.onBlur]
338
- );
339
- const onFocus = React5.useCallback(
340
- (event) => {
341
- listProps.onFocus?.(event);
342
- if (event.defaultPrevented) return;
343
- const isKeyboardFocus = !isClickFocusRef.current;
344
- if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
345
- const entryFocusEvent = new CustomEvent(STEPPER_ENTRY_FOCUS, STEPPER_EVENT_OPTIONS);
346
- event.currentTarget.dispatchEvent(entryFocusEvent);
347
- if (!entryFocusEvent.defaultPrevented) {
348
- const items = Array.from(itemsRef.current.values()).filter((item) => !item.disabled);
349
- const selectedItem = currentValue ? items.find((item) => item.value === currentValue) : void 0;
350
- const activeItem = items.find((item) => item.active);
351
- const currentItem = items.find((item) => item.id === tabStopId);
352
- const candidateItems = [selectedItem, activeItem, currentItem, ...items].filter(
353
- Boolean
354
- );
355
- const candidateRefs = candidateItems.map((item) => item.ref);
356
- focusFirst(candidateRefs, false);
357
- }
358
- }
359
- isClickFocusRef.current = false;
360
- },
361
- // eslint-disable-next-line react-hooks/exhaustive-deps
362
- [listProps.onFocus, isTabbingBackOut, currentValue, tabStopId]
363
- );
364
- const onMouseDown = React5.useCallback(
365
- (event) => {
366
- listProps.onMouseDown?.(event);
367
- if (event.defaultPrevented) return;
368
- isClickFocusRef.current = true;
369
- },
370
- // eslint-disable-next-line react-hooks/exhaustive-deps
371
- [listProps.onMouseDown]
372
- );
373
- const focusContextValue = React5.useMemo(
374
- () => ({
375
- tabStopId,
376
- onItemFocus,
377
- onItemShiftTab,
378
- onFocusableItemAdd,
379
- onFocusableItemRemove,
380
- onItemRegister,
381
- onItemUnregister,
382
- getItems
383
- }),
384
- [
385
- tabStopId,
386
- onItemFocus,
387
- onItemShiftTab,
388
- onFocusableItemAdd,
389
- onFocusableItemRemove,
390
- onItemRegister,
391
- onItemUnregister,
392
- getItems
393
- ]
394
- );
395
- const StepperNavPrimitive = asChild ? Slot : "nav";
396
- return /* @__PURE__ */ jsx(StepperFocusContext.Provider, { value: focusContextValue, children: /* @__PURE__ */ jsx(
397
- StepperNavPrimitive,
398
- {
399
- role: "tablist",
400
- "data-slot": "stepper-nav",
401
- "aria-orientation": orientation,
402
- "data-orientation": orientation,
403
- dir: context.dir,
404
- tabIndex: isTabbingBackOut || focusableItemCount === 0 ? -1 : 0,
405
- ref: composedRef,
406
- onBlur,
407
- onFocus,
408
- onMouseDown,
409
- className: cn(
410
- "group/stepper-nav inline-flex gap-4",
411
- "data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex-col",
412
- className
413
- ),
414
- ...listProps,
415
- children
416
- }
417
- ) });
418
- }
419
- var StepperItemContext = React5.createContext(null);
420
- function useStepperItemContext(consumerName) {
421
- const context = React5.useContext(StepperItemContext);
422
- if (!context) {
423
- throw new Error(`\`${consumerName}\` must be used within \`${STEPPER_ITEM_NAME}\``);
424
- }
425
- return context;
426
- }
427
- function StepperItem({
428
- value: itemValue,
429
- completed = false,
430
- disabled = false,
431
- loading = false,
432
- asChild,
433
- className,
434
- children,
435
- ...props
436
- }) {
437
- const { orientation, dir } = useStepperContext(STEPPER_ITEM_NAME);
438
- const store = useStepperStoreContext(STEPPER_ITEM_NAME);
439
- const value = useStepperStore((state) => state.value);
440
- useIsomorphicLayoutEffect(() => {
441
- store.addStep({ value: itemValue, completed, disabled, loading });
442
- return () => {
443
- store.removeStep(itemValue);
444
- };
445
- }, [itemValue, completed, disabled, loading]);
446
- useIsomorphicLayoutEffect(() => {
447
- store.setStep({ value: itemValue, completed, disabled, loading });
448
- }, [itemValue, completed, disabled, loading]);
449
- const stepState = useStepperStore((state) => state.steps.get(itemValue));
450
- const steps = useStepperStore((state) => state.steps);
451
- const dataState = getDataState(value, itemValue, stepState, steps);
452
- const itemContextValue = React5.useMemo(
453
- () => ({
454
- value: itemValue,
455
- stepState
456
- }),
457
- [itemValue, stepState]
458
- );
459
- const StepperItemPrimitive = asChild ? Slot : "div";
460
- return /* @__PURE__ */ jsx(StepperItemContext.Provider, { value: itemContextValue, children: /* @__PURE__ */ jsxs(
461
- StepperItemPrimitive,
462
- {
463
- "data-disabled": stepState?.disabled ? "" : void 0,
464
- "data-orientation": orientation,
465
- "data-state": dataState,
466
- "data-slot": "stepper-item",
467
- dir,
468
- className: cn(
469
- "group/step flex flex-1 flex-col justify-end data-[disabled]:opacity-50",
470
- "",
471
- // "group-data-[orientation=horizontal]/stepper-nav:flex-row group-data-[orientation=vertical]/stepper-nav:flex-col",
472
- className
473
- ),
474
- ...props,
475
- children: [
476
- children,
477
- /* @__PURE__ */ jsx(
478
- "div",
479
- {
480
- "data-state": dataState,
481
- className: cn(
482
- "bg-border h-1 w-full transition-colors duration-500",
483
- "data-[state=active]:bg-primary data-[state=completed]:bg-success"
484
- )
485
- }
486
- )
487
- ]
488
- }
489
- ) });
490
- }
491
- function StepperTrigger({ asChild, disabled, className, ref, ...triggerProps }) {
492
- const context = useStepperContext(STEPPER_TRIGGER_NAME);
493
- const itemContext = useStepperItemContext(STEPPER_TRIGGER_NAME);
494
- const store = useStepperStoreContext(STEPPER_TRIGGER_NAME);
495
- const focusContext = useStepperFocusContext(STEPPER_TRIGGER_NAME);
496
- const value = useStepperStore((state) => state.value);
497
- const itemValue = itemContext.value;
498
- const stepState = useStepperStore((state) => state.steps.get(itemValue));
499
- const activationMode = context.activationMode;
500
- const orientation = context.orientation;
501
- const loop = context.loop;
502
- const steps = useStepperStore((state) => state.steps);
503
- const stepIndex = Array.from(steps.keys()).indexOf(itemValue);
504
- const stepPosition = stepIndex + 1;
505
- const stepCount = steps.size;
506
- const triggerId = getId(context.id, "trigger", itemValue);
507
- const contentId = getId(context.id, "content", itemValue);
508
- const titleId = getId(context.id, "title", itemValue);
509
- const descriptionId = getId(context.id, "description", itemValue);
510
- const isDisabled = context.disabled || stepState?.disabled || disabled;
511
- const isActive = value === itemValue;
512
- const isTabStop = focusContext.tabStopId === triggerId;
513
- const dataState = getDataState(value, itemValue, stepState, steps);
514
- const triggerRef = React5.useRef(null);
515
- const composedRef = useComposedRefs(ref, triggerRef);
516
- const isArrowKeyPressedRef = React5.useRef(false);
517
- const isMouseClickRef = React5.useRef(false);
518
- React5.useEffect(() => {
519
- function onKeyDown2(event) {
520
- if (STEPPER_ARROW_KEYS.includes(event.key)) {
521
- isArrowKeyPressedRef.current = true;
522
- }
523
- }
524
- function onKeyUp() {
525
- isArrowKeyPressedRef.current = false;
526
- }
527
- document.addEventListener("keydown", onKeyDown2);
528
- document.addEventListener("keyup", onKeyUp);
529
- return () => {
530
- document.removeEventListener("keydown", onKeyDown2);
531
- document.removeEventListener("keyup", onKeyUp);
532
- };
533
- }, []);
534
- useIsomorphicLayoutEffect(() => {
535
- focusContext.onItemRegister({
536
- id: triggerId,
537
- ref: triggerRef,
538
- value: itemValue,
539
- active: isTabStop,
540
- disabled: !!isDisabled
541
- });
542
- if (!isDisabled) {
543
- focusContext.onFocusableItemAdd();
544
- }
545
- return () => {
546
- focusContext.onItemUnregister(triggerId);
547
- if (!isDisabled) {
548
- focusContext.onFocusableItemRemove();
549
- }
550
- };
551
- }, [focusContext, triggerId, itemValue, isTabStop, isDisabled]);
552
- const onClick = React5.useCallback(
553
- async (event) => {
554
- triggerProps.onClick?.(event);
555
- if (event.defaultPrevented) return;
556
- if (!isDisabled && !context.nonInteractive) {
557
- const currentStepIndex = Array.from(steps.keys()).indexOf(value ?? "");
558
- const targetStepIndex = Array.from(steps.keys()).indexOf(itemValue);
559
- const direction = targetStepIndex > currentStepIndex ? "next" : "prev";
560
- await store.setStateWithValidation(itemValue, direction);
561
- }
562
- },
563
- // eslint-disable-next-line react-hooks/exhaustive-deps
564
- [isDisabled, context.nonInteractive, store, itemValue, value, steps, triggerProps.onClick]
565
- );
566
- const onFocus = React5.useCallback(
567
- async (event) => {
568
- triggerProps.onFocus?.(event);
569
- if (event.defaultPrevented) return;
570
- focusContext.onItemFocus(triggerId);
571
- const isKeyboardFocus = !isMouseClickRef.current;
572
- if (!isActive && !isDisabled && activationMode !== "manual" && !context.nonInteractive && isKeyboardFocus) {
573
- const currentStepIndex = Array.from(steps.keys()).indexOf(value || "");
574
- const targetStepIndex = Array.from(steps.keys()).indexOf(itemValue);
575
- const direction = targetStepIndex > currentStepIndex ? "next" : "prev";
576
- await store.setStateWithValidation(itemValue, direction);
577
- }
578
- isMouseClickRef.current = false;
579
- },
580
- [
581
- triggerProps,
582
- focusContext,
583
- triggerId,
584
- isActive,
585
- isDisabled,
586
- activationMode,
587
- context.nonInteractive,
588
- steps,
589
- value,
590
- itemValue,
591
- store
592
- ]
593
- );
594
- const onKeyDown = React5.useCallback(
595
- async (event) => {
596
- triggerProps.onKeyDown?.(event);
597
- if (event.defaultPrevented) return;
598
- if (event.key === "Enter" && context.nonInteractive) {
599
- event.preventDefault();
600
- return;
601
- }
602
- if ((event.key === "Enter" || event.key === " ") && activationMode === "manual" && !context.nonInteractive) {
603
- event.preventDefault();
604
- if (!isDisabled && triggerRef.current) {
605
- triggerRef.current.click();
606
- }
607
- return;
608
- }
609
- if (event.key === "Tab" && event.shiftKey) {
610
- focusContext.onItemShiftTab();
611
- return;
612
- }
613
- if (event.target !== event.currentTarget) return;
614
- const focusIntent = getFocusIntent(event, context.dir, orientation);
615
- if (focusIntent !== void 0) {
616
- if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
617
- event.preventDefault();
618
- const items = focusContext.getItems().filter((item) => !item.disabled);
619
- let candidateRefs = items.map((item) => item.ref);
620
- if (focusIntent === "last") {
621
- candidateRefs.reverse();
622
- } else if (focusIntent === "prev" || focusIntent === "next") {
623
- if (focusIntent === "prev") candidateRefs.reverse();
624
- const currentIndex = candidateRefs.findIndex((ref2) => ref2.current === event.currentTarget);
625
- candidateRefs = loop ? wrapArray(candidateRefs, currentIndex + 1) : candidateRefs.slice(currentIndex + 1);
626
- }
627
- if (store.hasValidation() && candidateRefs.length > 0) {
628
- const nextRef = candidateRefs[0];
629
- const nextElement = nextRef?.current;
630
- const nextItem = items.find((item) => item.ref.current === nextElement);
631
- if (nextItem && nextItem.value !== itemValue) {
632
- const currentStepIndex = Array.from(steps.keys()).indexOf(value || "");
633
- const targetStepIndex = Array.from(steps.keys()).indexOf(nextItem.value);
634
- const direction = targetStepIndex > currentStepIndex ? "next" : "prev";
635
- if (direction === "next") {
636
- const isValid = await store.setStateWithValidation(nextItem.value, direction);
637
- if (!isValid) return;
638
- } else {
639
- store.setState("value", nextItem.value);
640
- }
641
- queueMicrotask(() => nextElement?.focus());
642
- return;
643
- }
644
- }
645
- queueMicrotask(() => focusFirst(candidateRefs));
646
- }
647
- },
648
- // eslint-disable-next-line react-hooks/exhaustive-deps
649
- [
650
- focusContext,
651
- context.nonInteractive,
652
- context.dir,
653
- activationMode,
654
- orientation,
655
- loop,
656
- isDisabled,
657
- triggerProps.onKeyDown,
658
- store,
659
- itemValue,
660
- value,
661
- steps
662
- ]
663
- );
664
- const onMouseDown = React5.useCallback(
665
- (event) => {
666
- triggerProps.onMouseDown?.(event);
667
- if (event.defaultPrevented) {
668
- return;
669
- }
670
- isMouseClickRef.current = true;
671
- if (isDisabled) {
672
- event.preventDefault();
673
- } else {
674
- focusContext.onItemFocus(triggerId);
675
- }
676
- },
677
- // eslint-disable-next-line react-hooks/exhaustive-deps
678
- [focusContext, triggerId, isDisabled, triggerProps.onMouseDown]
679
- );
680
- const TriggerPrimitive = asChild ? Slot : "button";
681
- return /* @__PURE__ */ jsx(
682
- TriggerPrimitive,
683
- {
684
- id: triggerId,
685
- role: "tab",
686
- type: "button",
687
- disabled: isDisabled,
688
- tabIndex: isTabStop ? 0 : -1,
689
- ref: composedRef,
690
- "data-slot": "stepper-trigger",
691
- "data-disabled": isDisabled ? "" : void 0,
692
- "data-state": dataState,
693
- "aria-controls": contentId,
694
- "aria-current": isActive ? "step" : void 0,
695
- "aria-describedby": `${titleId} ${descriptionId}`,
696
- "aria-posinset": stepPosition,
697
- "aria-selected": isActive,
698
- "aria-setsize": stepCount,
699
- className: cn(
700
- "inline-flex w-full cursor-pointer items-center gap-3 rounded text-left transition-colors duration-500 outline-none",
701
- "disabled:pointer-events-none",
702
- "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
703
- className
704
- ),
705
- onClick,
706
- onFocus,
707
- onKeyDown,
708
- onMouseDown,
709
- ...triggerProps
710
- }
711
- );
712
- }
713
- function StepperIndicator({ className, children, asChild, ref, ...props }) {
714
- const { indicators, dir } = useStepperContext(STEPPER_INDICATOR_NAME);
715
- const itemContext = useStepperItemContext(STEPPER_INDICATOR_NAME);
716
- const value = useStepperStore((state) => state.value);
717
- const itemValue = itemContext.value;
718
- const stepState = useStepperStore((state) => state.steps.get(itemValue));
719
- const steps = useStepperStore((state) => state.steps);
720
- const stepPosition = Array.from(steps.keys()).indexOf(itemValue) + 1;
721
- const dataState = getDataState(value, itemValue, stepState, steps);
722
- const StepperIndicatorPrimitive = asChild ? Slot : "div";
723
- return /* @__PURE__ */ jsx(
724
- StepperIndicatorPrimitive,
725
- {
726
- "data-slot": "stepper-indicator",
727
- "data-state": dataState,
728
- dir,
729
- ref,
730
- className: cn(
731
- "bg-muted border-border text-muted-foreground relative flex size-6 shrink-0 items-center justify-center self-end overflow-hidden rounded-t border-x border-t text-xs transition-colors duration-500",
732
- "data-[state=completed]:bg-success/50 data-[state=completed]:border-success data-[state=completed]:text-success-foreground",
733
- "data-[state=active]:bg-primary/50 data-[state=active]:border-primary data-[state=active]:text-primary-foreground",
734
- className
735
- ),
736
- ...props,
737
- children: /* @__PURE__ */ jsx("div", { className: "absolute", children: typeof children === "function" ? children(dataState) : indicators && (itemContext.stepState?.loading && indicators.loading || dataState === "completed" && indicators.completed || dataState === "active" && indicators.active || dataState === "inactive" && indicators.inactive) ? itemContext.stepState?.loading && indicators.loading || dataState === "completed" && indicators.completed || dataState === "active" && indicators.active || dataState === "inactive" && indicators.inactive : children ? children : stepPosition })
738
- }
739
- );
740
- }
741
- function StepperTitle({ className, asChild = false, ...props }) {
742
- const context = useStepperContext(STEPPER_TITLE_NAME);
743
- const itemContext = useStepperItemContext(STEPPER_TITLE_NAME);
744
- const titleId = getId(context.id, "title", itemContext.value);
745
- const TitlePrimitive = asChild ? Slot : "h3";
746
- return /* @__PURE__ */ jsx(
747
- TitlePrimitive,
748
- {
749
- id: titleId,
750
- "data-slot": "stepper-title",
751
- dir: context.dir,
752
- className: cn("text-sm leading-none font-medium", className),
753
- ...props
754
- }
755
- );
756
- }
757
- function StepperDescription({ className, asChild, ...props }) {
758
- const context = useStepperContext(STEPPER_DESCRIPTION_NAME);
759
- const itemContext = useStepperItemContext(STEPPER_DESCRIPTION_NAME);
760
- const descriptionId = getId(context.id, "description", itemContext.value);
761
- const StepperDescriptionPrimitive = asChild ? Slot : "span";
762
- return /* @__PURE__ */ jsx(
763
- StepperDescriptionPrimitive,
764
- {
765
- id: descriptionId,
766
- "data-slot": "stepper-description",
767
- dir: context.dir,
768
- className: cn("text-muted-foreground text-sm", className),
769
- ...props
770
- }
771
- );
772
- }
773
- function StepperPanel({ children, asChild = false, className, ...props }) {
774
- const currentValue = useStepperStore((state) => state.value);
775
- const StepperPanelPrimitive = asChild ? Slot : "div";
776
- return /* @__PURE__ */ jsx(
777
- StepperPanelPrimitive,
778
- {
779
- "data-slot": "stepper-panel",
780
- "data-state": currentValue,
781
- className: cn("w-full", className),
782
- ...props,
783
- children
784
- }
785
- );
786
- }
787
- function StepperContent({
788
- value: valueProp,
789
- asChild = false,
790
- forceMount = false,
791
- className,
792
- ...props
793
- }) {
794
- const context = useStepperContext(STEPPER_CONTENT_NAME);
795
- const value = useStepperStore((state) => state.value);
796
- const contentId = getId(context.id, "content", valueProp);
797
- const triggerId = getId(context.id, "trigger", valueProp);
798
- const isActive = value === valueProp;
799
- if (!isActive && !forceMount) {
800
- return null;
801
- }
802
- const ContentPrimitive = asChild ? Slot : "div";
803
- return /* @__PURE__ */ jsx(
804
- ContentPrimitive,
805
- {
806
- id: contentId,
807
- role: "tabpanel",
808
- "data-state": value,
809
- "aria-labelledby": triggerId,
810
- "data-slot": "stepper-content",
811
- dir: context.dir,
812
- className: cn("w-full", className, !isActive && forceMount && "hidden"),
813
- hidden: !isActive && forceMount,
814
- ...props
815
- }
816
- );
817
- }
818
- function StepperNextTrigger({ asChild = false, onClick, disabled, ...props }) {
819
- const store = useStepperStoreContext(STEPPER_NEXT_TRIGGER_NAME);
820
- const value = useStepperStore((state) => state.value);
821
- const steps = useStepperStore((state) => state.steps);
822
- const stepKeys = Array.from(steps.keys());
823
- const currentIndex = value ? stepKeys.indexOf(value) : -1;
824
- const isDisabled = disabled || currentIndex >= stepKeys.length - 1;
825
- const handleClick = React5.useCallback(
826
- async (event) => {
827
- onClick?.(event);
828
- if (event.defaultPrevented || isDisabled) {
829
- return;
830
- }
831
- const nextIndex = Math.min(currentIndex + 1, stepKeys.length - 1);
832
- const nextStepValue = stepKeys[nextIndex];
833
- if (nextStepValue) {
834
- await store.setStateWithValidation(nextStepValue, "next");
835
- }
836
- },
837
- [onClick, isDisabled, currentIndex, stepKeys, store]
838
- );
839
- const StepperNextTriggerPrimitive = asChild ? Slot : "button";
840
- return /* @__PURE__ */ jsx(
841
- StepperNextTriggerPrimitive,
842
- {
843
- type: "button",
844
- "data-slot": "stepper-next-trigger",
845
- disabled: isDisabled,
846
- onClick: handleClick,
847
- ...props
848
- }
849
- );
850
- }
851
- function StepperPrevTrigger({ asChild = false, disabled, onClick, ...props }) {
852
- const store = useStepperStoreContext(STEPPER_PREV_TRIGGER_NAME);
853
- const value = useStepperStore((state) => state.value);
854
- const steps = useStepperStore((state) => state.steps);
855
- const stepKeys = Array.from(steps.keys());
856
- const currentIndex = value ? stepKeys.indexOf(value) : -1;
857
- const isDisabled = disabled || currentIndex <= 0;
858
- const handleClick = React5.useCallback(
859
- async (event) => {
860
- onClick?.(event);
861
- if (event.defaultPrevented || isDisabled) {
862
- return;
863
- }
864
- const prevIndex = Math.max(currentIndex - 1, 0);
865
- const prevStepValue = stepKeys[prevIndex];
866
- if (prevStepValue) {
867
- store.setState("value", prevStepValue);
868
- }
869
- },
870
- [currentIndex, isDisabled, onClick, stepKeys, store]
871
- );
872
- const StepperPrevTriggerPrimitive = asChild ? Slot : "button";
873
- return /* @__PURE__ */ jsx(
874
- StepperPrevTriggerPrimitive,
875
- {
876
- type: "button",
877
- "data-slot": "stepper-prev-trigger",
878
- disabled: isDisabled,
879
- onClick: handleClick,
880
- ...props
881
- }
882
- );
883
- }
884
- var Toaster = ({ theme = "system", ...props }) => {
885
- return /* @__PURE__ */ jsx(
886
- Toaster$1,
887
- {
888
- className: "group",
889
- icons: {
890
- success: /* @__PURE__ */ jsx(CircleCheckIcon, { className: "size-4" }),
891
- info: /* @__PURE__ */ jsx(InfoIcon, { className: "size-4" }),
892
- warning: /* @__PURE__ */ jsx(TriangleAlertIcon, { className: "size-4" }),
893
- error: /* @__PURE__ */ jsx(OctagonXIcon, { className: "size-4" }),
894
- loading: /* @__PURE__ */ jsx(Spinner, {})
895
- },
896
- toastOptions: {
897
- classNames: {
898
- toast: "!bg-popover !text-popover-foreground !border !border-border !rounded",
899
- description: "!text-muted-foreground"
900
- }
901
- },
902
- theme,
903
- ...props
904
- }
905
- );
906
- };
907
- var buttonVariants = cva(
908
- [
909
- "inline-flex shrink-0 items-center justify-center gap-2 rounded text-sm font-medium whitespace-nowrap transition-all outline-none",
910
- "disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50",
911
- "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
912
- "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring",
913
- "aria-invalid:ring-error/20 dark:aria-invalid:ring-error/40 aria-invalid:border-error"
914
- ],
915
- {
916
- variants: {
917
- variant: {
918
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
919
- error: "bg-error hover:bg-error/90 focus-visible:ring-error/20 dark:focus-visible:ring-error/40 dark:bg-error/60 text-white",
920
- outline: "bg-background hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50 border shadow-xs",
921
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
922
- ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
923
- link: "text-primary underline-offset-4 hover:underline"
924
- },
925
- size: {
926
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
927
- sm: "h-8 gap-1.5 rounded px-3 has-[>svg]:px-2.5",
928
- lg: "h-10 rounded px-6 has-[>svg]:px-4",
929
- icon: "size-9",
930
- "icon-sm": "size-8",
931
- "icon-lg": "size-10"
932
- },
933
- fullWidth: {
934
- true: "w-full"
935
- }
936
- },
937
- defaultVariants: {
938
- variant: "default",
939
- size: "default",
940
- fullWidth: false
941
- }
942
- }
943
- );
944
- function Button({
945
- asChild = false,
946
- variant = "default",
947
- disabled = false,
948
- fullWidth = false,
949
- loadingPosition: loadingPositionProp = "start",
950
- children,
951
- type = "button",
952
- loading = false,
953
- size = "default",
954
- endIcon,
955
- startIcon,
956
- className,
957
- ...props
958
- }) {
959
- const Comp = asChild ? Slot : "button";
960
- const isDisabled = disabled || loading;
961
- const loadingPosition = size?.startsWith("icon") ? "center" : loadingPositionProp;
962
- return /* @__PURE__ */ jsx(
963
- Comp,
964
- {
965
- "data-slot": "button",
966
- "aria-disabled": isDisabled || void 0,
967
- className: cn(buttonVariants({ fullWidth, size, variant }), className),
968
- "data-state": loading ? "loading" : void 0,
969
- disabled: isDisabled,
970
- role: Comp !== "button" ? "button" : void 0,
971
- tabIndex: isDisabled ? -1 : 0,
972
- type: Comp === "button" ? type : void 0,
973
- "data-size": size,
974
- "data-variant": variant,
975
- ...props,
976
- children: /* @__PURE__ */ jsx(
977
- ButtonContent,
978
- {
979
- loading,
980
- size,
981
- loadingPosition,
982
- startIcon,
983
- endIcon,
984
- asChild,
985
- children
986
- }
987
- )
988
- }
989
- );
990
- }
991
- function ButtonContent({
992
- children,
993
- loading = false,
994
- loadingPosition = "start",
995
- startIcon,
996
- asChild,
997
- endIcon,
998
- ...props
999
- }) {
1000
- const isStartLoading = loading && loadingPosition === "start";
1001
- const StartIcon = isStartLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : startIcon || null;
1002
- const isEndLoading = loading && loadingPosition === "end";
1003
- const EndIcon = isEndLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : endIcon || null;
1004
- const isCenterLoading = loading && loadingPosition === "center";
1005
- return asChild && React5.isValidElement(children) ? React5.cloneElement(
1006
- children,
1007
- props,
1008
- /* @__PURE__ */ jsxs(React5.Fragment, { children: [
1009
- StartIcon,
1010
- isCenterLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : React5.isValidElement(children) ? children.props?.children : null,
1011
- EndIcon
1012
- ] })
1013
- ) : /* @__PURE__ */ jsxs(React5.Fragment, { children: [
1014
- StartIcon,
1015
- isCenterLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : children,
1016
- EndIcon
1017
- ] });
1018
- }
1019
-
1020
- export { Button, Stepper, StepperActivationMode, StepperContent, StepperDataState, StepperDescription, StepperFocusIntent, StepperIndicator, StepperItem, StepperNav, StepperNavigationDirection, StepperNextTrigger, StepperOrientation, StepperPanel, StepperPrevTrigger, StepperTitle, StepperTrigger, Toaster, useStepperContext, useStepperFocusContext, useStepperItemContext };