@ttoss/react-wizard 0.8.8 → 0.10.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/dist/index.cjs +156 -74
- package/dist/index.d.cts +5 -14
- package/dist/index.d.mts +5 -15
- package/dist/index.mjs +152 -69
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
23
|
}
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
27
27
|
value: mod,
|
|
28
28
|
enumerable: true
|
|
29
29
|
}) : target, mod));
|
|
@@ -32,8 +32,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
let _ttoss_react_i18n = require("@ttoss/react-i18n");
|
|
33
33
|
let _ttoss_ui = require("@ttoss/ui");
|
|
34
34
|
let react = require("react");
|
|
35
|
-
|
|
36
|
-
react = __toESM(react);
|
|
35
|
+
react = __toESM(react, 1);
|
|
37
36
|
let _chakra_ui_react = require("@chakra-ui/react");
|
|
38
37
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
39
38
|
|
|
@@ -49,17 +48,60 @@ var gradientFlow = (0, _ttoss_ui.keyframes)({
|
|
|
49
48
|
backgroundPosition: "0% 50%"
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Reads a nested color from the theme, returning `undefined` when any segment
|
|
53
|
+
* of the path is missing.
|
|
54
|
+
*/
|
|
55
|
+
var getThemeColor = ({
|
|
56
|
+
theme,
|
|
57
|
+
path
|
|
58
|
+
}) => {
|
|
59
|
+
return path.split(".").reduce((current, key) => {
|
|
60
|
+
return current?.[key];
|
|
61
|
+
}, theme.colors);
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Returns the first truthy color among `paths`, mirroring an `a || b` chain.
|
|
65
|
+
*/
|
|
66
|
+
var getFirstThemeColor = ({
|
|
67
|
+
theme,
|
|
68
|
+
paths
|
|
69
|
+
}) => {
|
|
70
|
+
return paths.map(path => {
|
|
71
|
+
return getThemeColor({
|
|
72
|
+
theme,
|
|
73
|
+
path
|
|
74
|
+
});
|
|
75
|
+
}).find(Boolean);
|
|
76
|
+
};
|
|
77
|
+
var buildGradientBackground = ({
|
|
78
|
+
theme,
|
|
79
|
+
startPaths,
|
|
80
|
+
middlePaths
|
|
81
|
+
}) => {
|
|
82
|
+
const start = getFirstThemeColor({
|
|
83
|
+
theme,
|
|
84
|
+
paths: startPaths
|
|
85
|
+
});
|
|
55
86
|
if (!start) return void 0;
|
|
56
|
-
return `linear-gradient(270deg, ${start}, ${
|
|
87
|
+
return `linear-gradient(270deg, ${start}, ${getFirstThemeColor({
|
|
88
|
+
theme,
|
|
89
|
+
paths: middlePaths
|
|
90
|
+
}) || start}, ${start})`;
|
|
91
|
+
};
|
|
92
|
+
var getAccentGradientBackground = t => {
|
|
93
|
+
return buildGradientBackground({
|
|
94
|
+
theme: t,
|
|
95
|
+
startPaths: ["action.background.accent.default", "input.background.accent.default"],
|
|
96
|
+
middlePaths: ["action.background.accent.active", "input.background.accent.active"]
|
|
97
|
+
});
|
|
57
98
|
};
|
|
58
99
|
var getPrimaryGradientBackground = t => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
100
|
+
return buildGradientBackground({
|
|
101
|
+
theme: t,
|
|
102
|
+
startPaths: ["action.background.primary.default"],
|
|
103
|
+
middlePaths: ["action.background.secondary.default"]
|
|
104
|
+
});
|
|
63
105
|
};
|
|
64
106
|
var getVariantStyles = (variantType = "spotlight-accent") => {
|
|
65
107
|
const variants = {
|
|
@@ -196,12 +238,12 @@ var getWizardPrimaryButtonVariant = (variant = "spotlight-accent") => {
|
|
|
196
238
|
|
|
197
239
|
//#endregion
|
|
198
240
|
//#region src/WizardContext.ts
|
|
199
|
-
var WizardContext = react
|
|
241
|
+
var WizardContext = react.createContext(null);
|
|
200
242
|
/**
|
|
201
243
|
* Hook to access the wizard context from within step content.
|
|
202
244
|
*/
|
|
203
245
|
var useWizard = () => {
|
|
204
|
-
const context = react
|
|
246
|
+
const context = react.useContext(WizardContext);
|
|
205
247
|
if (!context) throw new Error("useWizard must be used within a Wizard component.");
|
|
206
248
|
return context;
|
|
207
249
|
};
|
|
@@ -361,36 +403,11 @@ var getFlexDirection = layout => {
|
|
|
361
403
|
return "row-reverse";
|
|
362
404
|
}
|
|
363
405
|
};
|
|
364
|
-
|
|
365
|
-
* Renders a multi-step wizard with step navigation, localized action labels,
|
|
366
|
-
* and support for completion, cancellation, and step changes.
|
|
367
|
-
*
|
|
368
|
-
* @param props - Wizard configuration and step content.
|
|
369
|
-
* @param props.steps - The ordered steps displayed in the wizard.
|
|
370
|
-
* @param props.onComplete - Called when the user finishes the last step.
|
|
371
|
-
* @param props.onCancel - Called when the user cancels the wizard.
|
|
372
|
-
* @param props.onStepChange - Called when the current step changes.
|
|
373
|
-
*/
|
|
374
|
-
var Wizard = ({
|
|
375
|
-
steps,
|
|
376
|
-
layout = "top",
|
|
377
|
-
variant = "spotlight-accent",
|
|
378
|
-
onComplete,
|
|
379
|
-
onCancel,
|
|
380
|
-
onStepChange,
|
|
381
|
-
initialStep = 0,
|
|
382
|
-
allowStepClick = true,
|
|
383
|
-
labels
|
|
384
|
-
}) => {
|
|
406
|
+
var useButtonLabels = labels => {
|
|
385
407
|
const {
|
|
386
408
|
intl
|
|
387
409
|
} = (0, _ttoss_react_i18n.useI18n)();
|
|
388
|
-
|
|
389
|
-
const stepValidationRef = react.useRef(null);
|
|
390
|
-
const totalSteps = steps.length;
|
|
391
|
-
const isFirstStep = currentStep === 0;
|
|
392
|
-
const isLastStep = currentStep === totalSteps - 1;
|
|
393
|
-
const buttonLabels = react.useMemo(() => {
|
|
410
|
+
return react.useMemo(() => {
|
|
394
411
|
return {
|
|
395
412
|
previous: labels?.previous ?? intl.formatMessage(messages.previous),
|
|
396
413
|
next: labels?.next ?? intl.formatMessage(messages.next),
|
|
@@ -398,6 +415,18 @@ var Wizard = ({
|
|
|
398
415
|
cancel: labels?.cancel ?? intl.formatMessage(messages.cancel)
|
|
399
416
|
};
|
|
400
417
|
}, [intl, labels]);
|
|
418
|
+
};
|
|
419
|
+
var useWizardNavigation = ({
|
|
420
|
+
steps,
|
|
421
|
+
initialStep,
|
|
422
|
+
onComplete,
|
|
423
|
+
onStepChange
|
|
424
|
+
}) => {
|
|
425
|
+
const [currentStep, setCurrentStep] = react.useState(initialStep);
|
|
426
|
+
const stepValidationRef = react.useRef(null);
|
|
427
|
+
const totalSteps = steps.length;
|
|
428
|
+
const isFirstStep = currentStep === 0;
|
|
429
|
+
const isLastStep = currentStep === totalSteps - 1;
|
|
401
430
|
const getStepStatus = react.useCallback(({
|
|
402
431
|
stepIndex
|
|
403
432
|
}) => {
|
|
@@ -446,7 +475,7 @@ var Wizard = ({
|
|
|
446
475
|
const setStepValidation = react.useCallback(validate => {
|
|
447
476
|
stepValidationRef.current = validate;
|
|
448
477
|
}, []);
|
|
449
|
-
|
|
478
|
+
return react.useMemo(() => {
|
|
450
479
|
return {
|
|
451
480
|
currentStep,
|
|
452
481
|
totalSteps,
|
|
@@ -459,6 +488,84 @@ var Wizard = ({
|
|
|
459
488
|
setStepValidation
|
|
460
489
|
};
|
|
461
490
|
}, [currentStep, totalSteps, goToNext, goToPrevious, goToStep, isFirstStep, isLastStep, getStepStatus, setStepValidation]);
|
|
491
|
+
};
|
|
492
|
+
var WizardNavigation = ({
|
|
493
|
+
variant,
|
|
494
|
+
onCancel,
|
|
495
|
+
labels,
|
|
496
|
+
isFirstStep,
|
|
497
|
+
isLastStep,
|
|
498
|
+
goToPrevious,
|
|
499
|
+
goToNext
|
|
500
|
+
}) => {
|
|
501
|
+
const buttonLabels = useButtonLabels(labels);
|
|
502
|
+
return /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
|
|
503
|
+
sx: {
|
|
504
|
+
justifyContent: "space-between",
|
|
505
|
+
alignItems: "center",
|
|
506
|
+
gap: "3"
|
|
507
|
+
},
|
|
508
|
+
children: [/* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Flex, {
|
|
509
|
+
sx: {
|
|
510
|
+
gap: "3"
|
|
511
|
+
},
|
|
512
|
+
children: onCancel && /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
|
|
513
|
+
variant: "secondary",
|
|
514
|
+
onClick: onCancel,
|
|
515
|
+
"aria-label": buttonLabels.cancel,
|
|
516
|
+
children: buttonLabels.cancel
|
|
517
|
+
})
|
|
518
|
+
}), /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
|
|
519
|
+
sx: {
|
|
520
|
+
gap: "3"
|
|
521
|
+
},
|
|
522
|
+
children: [/* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
|
|
523
|
+
variant: "secondary",
|
|
524
|
+
onClick: goToPrevious,
|
|
525
|
+
disabled: isFirstStep,
|
|
526
|
+
"aria-label": buttonLabels.previous,
|
|
527
|
+
children: buttonLabels.previous
|
|
528
|
+
}), /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
|
|
529
|
+
variant: getWizardPrimaryButtonVariant(variant),
|
|
530
|
+
onClick: goToNext,
|
|
531
|
+
"aria-label": isLastStep ? buttonLabels.finish : buttonLabels.next,
|
|
532
|
+
children: isLastStep ? buttonLabels.finish : buttonLabels.next
|
|
533
|
+
})]
|
|
534
|
+
})]
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Renders a multi-step wizard with step navigation, localized action labels,
|
|
539
|
+
* and support for completion, cancellation, and step changes.
|
|
540
|
+
*
|
|
541
|
+
* @param props - Wizard configuration and step content.
|
|
542
|
+
* @param props.steps - The ordered steps displayed in the wizard.
|
|
543
|
+
* @param props.onComplete - Called when the user finishes the last step.
|
|
544
|
+
* @param props.onCancel - Called when the user cancels the wizard.
|
|
545
|
+
* @param props.onStepChange - Called when the current step changes.
|
|
546
|
+
*/
|
|
547
|
+
var Wizard = ({
|
|
548
|
+
steps,
|
|
549
|
+
layout = "top",
|
|
550
|
+
variant = "spotlight-accent",
|
|
551
|
+
onComplete,
|
|
552
|
+
onCancel,
|
|
553
|
+
onStepChange,
|
|
554
|
+
initialStep = 0,
|
|
555
|
+
allowStepClick = true,
|
|
556
|
+
labels
|
|
557
|
+
}) => {
|
|
558
|
+
const contextValue = useWizardNavigation({
|
|
559
|
+
steps,
|
|
560
|
+
initialStep,
|
|
561
|
+
onComplete,
|
|
562
|
+
onStepChange
|
|
563
|
+
});
|
|
564
|
+
const {
|
|
565
|
+
currentStep,
|
|
566
|
+
getStepStatus,
|
|
567
|
+
goToStep
|
|
568
|
+
} = contextValue;
|
|
462
569
|
return /* @__PURE__ */(0, react_jsx_runtime.jsx)(WizardContext.Provider, {
|
|
463
570
|
value: contextValue,
|
|
464
571
|
children: /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
|
|
@@ -487,39 +594,14 @@ var Wizard = ({
|
|
|
487
594
|
marginBottom: "4"
|
|
488
595
|
},
|
|
489
596
|
children: steps[currentStep].content
|
|
490
|
-
}), /* @__PURE__ */(0, react_jsx_runtime.
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
gap: "3"
|
|
499
|
-
},
|
|
500
|
-
children: onCancel && /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
|
|
501
|
-
variant: "secondary",
|
|
502
|
-
onClick: onCancel,
|
|
503
|
-
"aria-label": buttonLabels.cancel,
|
|
504
|
-
children: buttonLabels.cancel
|
|
505
|
-
})
|
|
506
|
-
}), /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
|
|
507
|
-
sx: {
|
|
508
|
-
gap: "3"
|
|
509
|
-
},
|
|
510
|
-
children: [/* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
|
|
511
|
-
variant: "secondary",
|
|
512
|
-
onClick: goToPrevious,
|
|
513
|
-
disabled: isFirstStep,
|
|
514
|
-
"aria-label": buttonLabels.previous,
|
|
515
|
-
children: buttonLabels.previous
|
|
516
|
-
}), /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
|
|
517
|
-
variant: getWizardPrimaryButtonVariant(variant),
|
|
518
|
-
onClick: goToNext,
|
|
519
|
-
"aria-label": isLastStep ? buttonLabels.finish : buttonLabels.next,
|
|
520
|
-
children: isLastStep ? buttonLabels.finish : buttonLabels.next
|
|
521
|
-
})]
|
|
522
|
-
})]
|
|
597
|
+
}), /* @__PURE__ */(0, react_jsx_runtime.jsx)(WizardNavigation, {
|
|
598
|
+
variant,
|
|
599
|
+
onCancel,
|
|
600
|
+
labels,
|
|
601
|
+
isFirstStep: contextValue.isFirstStep,
|
|
602
|
+
isLastStep: contextValue.isLastStep,
|
|
603
|
+
goToPrevious: contextValue.goToPrevious,
|
|
604
|
+
goToNext: contextValue.goToNext
|
|
523
605
|
})]
|
|
524
606
|
})]
|
|
525
607
|
})
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import "@ttoss/ui";
|
|
3
4
|
//#region src/Wizard.styles.d.ts
|
|
4
5
|
type WizardVariant = 'spotlight-accent' | 'spotlight-primary' | 'primary' | 'secondary' | 'accent';
|
|
5
6
|
//#endregion
|
|
@@ -147,18 +148,8 @@ interface WizardContextValue {
|
|
|
147
148
|
* @param props.onCancel - Called when the user cancels the wizard.
|
|
148
149
|
* @param props.onStepChange - Called when the current step changes.
|
|
149
150
|
*/
|
|
150
|
-
declare const Wizard: {
|
|
151
|
-
({
|
|
152
|
-
steps,
|
|
153
|
-
layout,
|
|
154
|
-
variant,
|
|
155
|
-
onComplete,
|
|
156
|
-
onCancel,
|
|
157
|
-
onStepChange,
|
|
158
|
-
initialStep,
|
|
159
|
-
allowStepClick,
|
|
160
|
-
labels
|
|
161
|
-
}: WizardProps): import("react/jsx-runtime").JSX.Element;
|
|
151
|
+
export declare const Wizard: {
|
|
152
|
+
({ steps, layout, variant, onComplete, onCancel, onStepChange, initialStep, allowStepClick, labels }: WizardProps): React.JSX.Element;
|
|
162
153
|
displayName: string;
|
|
163
154
|
};
|
|
164
155
|
//#endregion
|
|
@@ -166,6 +157,6 @@ declare const Wizard: {
|
|
|
166
157
|
/**
|
|
167
158
|
* Hook to access the wizard context from within step content.
|
|
168
159
|
*/
|
|
169
|
-
declare const useWizard: () => WizardContextValue;
|
|
160
|
+
export declare const useWizard: () => WizardContextValue;
|
|
170
161
|
//#endregion
|
|
171
|
-
export {
|
|
162
|
+
export type { WizardContextValue, WizardLabels, WizardLayout, WizardProps, WizardStep, WizardStepStatus, WizardVariant };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
+
import "@ttoss/ui";
|
|
2
3
|
import * as React from "react";
|
|
3
|
-
|
|
4
4
|
//#region src/Wizard.styles.d.ts
|
|
5
5
|
type WizardVariant = 'spotlight-accent' | 'spotlight-primary' | 'primary' | 'secondary' | 'accent';
|
|
6
6
|
//#endregion
|
|
@@ -148,18 +148,8 @@ interface WizardContextValue {
|
|
|
148
148
|
* @param props.onCancel - Called when the user cancels the wizard.
|
|
149
149
|
* @param props.onStepChange - Called when the current step changes.
|
|
150
150
|
*/
|
|
151
|
-
declare const Wizard: {
|
|
152
|
-
({
|
|
153
|
-
steps,
|
|
154
|
-
layout,
|
|
155
|
-
variant,
|
|
156
|
-
onComplete,
|
|
157
|
-
onCancel,
|
|
158
|
-
onStepChange,
|
|
159
|
-
initialStep,
|
|
160
|
-
allowStepClick,
|
|
161
|
-
labels
|
|
162
|
-
}: WizardProps): import("react/jsx-runtime").JSX.Element;
|
|
151
|
+
export declare const Wizard: {
|
|
152
|
+
({ steps, layout, variant, onComplete, onCancel, onStepChange, initialStep, allowStepClick, labels }: WizardProps): React.JSX.Element;
|
|
163
153
|
displayName: string;
|
|
164
154
|
};
|
|
165
155
|
//#endregion
|
|
@@ -167,6 +157,6 @@ declare const Wizard: {
|
|
|
167
157
|
/**
|
|
168
158
|
* Hook to access the wizard context from within step content.
|
|
169
159
|
*/
|
|
170
|
-
declare const useWizard: () => WizardContextValue;
|
|
160
|
+
export declare const useWizard: () => WizardContextValue;
|
|
171
161
|
//#endregion
|
|
172
|
-
export {
|
|
162
|
+
export type { WizardContextValue, WizardLabels, WizardLayout, WizardProps, WizardStep, WizardStepStatus, WizardVariant };
|
package/dist/index.mjs
CHANGED
|
@@ -17,17 +17,60 @@ var gradientFlow = keyframes({
|
|
|
17
17
|
backgroundPosition: "0% 50%"
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Reads a nested color from the theme, returning `undefined` when any segment
|
|
22
|
+
* of the path is missing.
|
|
23
|
+
*/
|
|
24
|
+
var getThemeColor = ({
|
|
25
|
+
theme,
|
|
26
|
+
path
|
|
27
|
+
}) => {
|
|
28
|
+
return path.split(".").reduce((current, key) => {
|
|
29
|
+
return current?.[key];
|
|
30
|
+
}, theme.colors);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Returns the first truthy color among `paths`, mirroring an `a || b` chain.
|
|
34
|
+
*/
|
|
35
|
+
var getFirstThemeColor = ({
|
|
36
|
+
theme,
|
|
37
|
+
paths
|
|
38
|
+
}) => {
|
|
39
|
+
return paths.map(path => {
|
|
40
|
+
return getThemeColor({
|
|
41
|
+
theme,
|
|
42
|
+
path
|
|
43
|
+
});
|
|
44
|
+
}).find(Boolean);
|
|
45
|
+
};
|
|
46
|
+
var buildGradientBackground = ({
|
|
47
|
+
theme,
|
|
48
|
+
startPaths,
|
|
49
|
+
middlePaths
|
|
50
|
+
}) => {
|
|
51
|
+
const start = getFirstThemeColor({
|
|
52
|
+
theme,
|
|
53
|
+
paths: startPaths
|
|
54
|
+
});
|
|
23
55
|
if (!start) return void 0;
|
|
24
|
-
return `linear-gradient(270deg, ${start}, ${
|
|
56
|
+
return `linear-gradient(270deg, ${start}, ${getFirstThemeColor({
|
|
57
|
+
theme,
|
|
58
|
+
paths: middlePaths
|
|
59
|
+
}) || start}, ${start})`;
|
|
60
|
+
};
|
|
61
|
+
var getAccentGradientBackground = t => {
|
|
62
|
+
return buildGradientBackground({
|
|
63
|
+
theme: t,
|
|
64
|
+
startPaths: ["action.background.accent.default", "input.background.accent.default"],
|
|
65
|
+
middlePaths: ["action.background.accent.active", "input.background.accent.active"]
|
|
66
|
+
});
|
|
25
67
|
};
|
|
26
68
|
var getPrimaryGradientBackground = t => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
69
|
+
return buildGradientBackground({
|
|
70
|
+
theme: t,
|
|
71
|
+
startPaths: ["action.background.primary.default"],
|
|
72
|
+
middlePaths: ["action.background.secondary.default"]
|
|
73
|
+
});
|
|
31
74
|
};
|
|
32
75
|
var getVariantStyles = (variantType = "spotlight-accent") => {
|
|
33
76
|
const variants = {
|
|
@@ -344,36 +387,11 @@ var getFlexDirection = layout => {
|
|
|
344
387
|
return "row-reverse";
|
|
345
388
|
}
|
|
346
389
|
};
|
|
347
|
-
|
|
348
|
-
* Renders a multi-step wizard with step navigation, localized action labels,
|
|
349
|
-
* and support for completion, cancellation, and step changes.
|
|
350
|
-
*
|
|
351
|
-
* @param props - Wizard configuration and step content.
|
|
352
|
-
* @param props.steps - The ordered steps displayed in the wizard.
|
|
353
|
-
* @param props.onComplete - Called when the user finishes the last step.
|
|
354
|
-
* @param props.onCancel - Called when the user cancels the wizard.
|
|
355
|
-
* @param props.onStepChange - Called when the current step changes.
|
|
356
|
-
*/
|
|
357
|
-
var Wizard = ({
|
|
358
|
-
steps,
|
|
359
|
-
layout = "top",
|
|
360
|
-
variant = "spotlight-accent",
|
|
361
|
-
onComplete,
|
|
362
|
-
onCancel,
|
|
363
|
-
onStepChange,
|
|
364
|
-
initialStep = 0,
|
|
365
|
-
allowStepClick = true,
|
|
366
|
-
labels
|
|
367
|
-
}) => {
|
|
390
|
+
var useButtonLabels = labels => {
|
|
368
391
|
const {
|
|
369
392
|
intl
|
|
370
393
|
} = useI18n();
|
|
371
|
-
|
|
372
|
-
const stepValidationRef = React.useRef(null);
|
|
373
|
-
const totalSteps = steps.length;
|
|
374
|
-
const isFirstStep = currentStep === 0;
|
|
375
|
-
const isLastStep = currentStep === totalSteps - 1;
|
|
376
|
-
const buttonLabels = React.useMemo(() => {
|
|
394
|
+
return React.useMemo(() => {
|
|
377
395
|
return {
|
|
378
396
|
previous: labels?.previous ?? intl.formatMessage(messages.previous),
|
|
379
397
|
next: labels?.next ?? intl.formatMessage(messages.next),
|
|
@@ -381,6 +399,18 @@ var Wizard = ({
|
|
|
381
399
|
cancel: labels?.cancel ?? intl.formatMessage(messages.cancel)
|
|
382
400
|
};
|
|
383
401
|
}, [intl, labels]);
|
|
402
|
+
};
|
|
403
|
+
var useWizardNavigation = ({
|
|
404
|
+
steps,
|
|
405
|
+
initialStep,
|
|
406
|
+
onComplete,
|
|
407
|
+
onStepChange
|
|
408
|
+
}) => {
|
|
409
|
+
const [currentStep, setCurrentStep] = React.useState(initialStep);
|
|
410
|
+
const stepValidationRef = React.useRef(null);
|
|
411
|
+
const totalSteps = steps.length;
|
|
412
|
+
const isFirstStep = currentStep === 0;
|
|
413
|
+
const isLastStep = currentStep === totalSteps - 1;
|
|
384
414
|
const getStepStatus = React.useCallback(({
|
|
385
415
|
stepIndex
|
|
386
416
|
}) => {
|
|
@@ -429,7 +459,7 @@ var Wizard = ({
|
|
|
429
459
|
const setStepValidation = React.useCallback(validate => {
|
|
430
460
|
stepValidationRef.current = validate;
|
|
431
461
|
}, []);
|
|
432
|
-
|
|
462
|
+
return React.useMemo(() => {
|
|
433
463
|
return {
|
|
434
464
|
currentStep,
|
|
435
465
|
totalSteps,
|
|
@@ -442,6 +472,84 @@ var Wizard = ({
|
|
|
442
472
|
setStepValidation
|
|
443
473
|
};
|
|
444
474
|
}, [currentStep, totalSteps, goToNext, goToPrevious, goToStep, isFirstStep, isLastStep, getStepStatus, setStepValidation]);
|
|
475
|
+
};
|
|
476
|
+
var WizardNavigation = ({
|
|
477
|
+
variant,
|
|
478
|
+
onCancel,
|
|
479
|
+
labels,
|
|
480
|
+
isFirstStep,
|
|
481
|
+
isLastStep,
|
|
482
|
+
goToPrevious,
|
|
483
|
+
goToNext
|
|
484
|
+
}) => {
|
|
485
|
+
const buttonLabels = useButtonLabels(labels);
|
|
486
|
+
return /* @__PURE__ */jsxs(Flex, {
|
|
487
|
+
sx: {
|
|
488
|
+
justifyContent: "space-between",
|
|
489
|
+
alignItems: "center",
|
|
490
|
+
gap: "3"
|
|
491
|
+
},
|
|
492
|
+
children: [/* @__PURE__ */jsx(Flex, {
|
|
493
|
+
sx: {
|
|
494
|
+
gap: "3"
|
|
495
|
+
},
|
|
496
|
+
children: onCancel && /* @__PURE__ */jsx(Button, {
|
|
497
|
+
variant: "secondary",
|
|
498
|
+
onClick: onCancel,
|
|
499
|
+
"aria-label": buttonLabels.cancel,
|
|
500
|
+
children: buttonLabels.cancel
|
|
501
|
+
})
|
|
502
|
+
}), /* @__PURE__ */jsxs(Flex, {
|
|
503
|
+
sx: {
|
|
504
|
+
gap: "3"
|
|
505
|
+
},
|
|
506
|
+
children: [/* @__PURE__ */jsx(Button, {
|
|
507
|
+
variant: "secondary",
|
|
508
|
+
onClick: goToPrevious,
|
|
509
|
+
disabled: isFirstStep,
|
|
510
|
+
"aria-label": buttonLabels.previous,
|
|
511
|
+
children: buttonLabels.previous
|
|
512
|
+
}), /* @__PURE__ */jsx(Button, {
|
|
513
|
+
variant: getWizardPrimaryButtonVariant(variant),
|
|
514
|
+
onClick: goToNext,
|
|
515
|
+
"aria-label": isLastStep ? buttonLabels.finish : buttonLabels.next,
|
|
516
|
+
children: isLastStep ? buttonLabels.finish : buttonLabels.next
|
|
517
|
+
})]
|
|
518
|
+
})]
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Renders a multi-step wizard with step navigation, localized action labels,
|
|
523
|
+
* and support for completion, cancellation, and step changes.
|
|
524
|
+
*
|
|
525
|
+
* @param props - Wizard configuration and step content.
|
|
526
|
+
* @param props.steps - The ordered steps displayed in the wizard.
|
|
527
|
+
* @param props.onComplete - Called when the user finishes the last step.
|
|
528
|
+
* @param props.onCancel - Called when the user cancels the wizard.
|
|
529
|
+
* @param props.onStepChange - Called when the current step changes.
|
|
530
|
+
*/
|
|
531
|
+
var Wizard = ({
|
|
532
|
+
steps,
|
|
533
|
+
layout = "top",
|
|
534
|
+
variant = "spotlight-accent",
|
|
535
|
+
onComplete,
|
|
536
|
+
onCancel,
|
|
537
|
+
onStepChange,
|
|
538
|
+
initialStep = 0,
|
|
539
|
+
allowStepClick = true,
|
|
540
|
+
labels
|
|
541
|
+
}) => {
|
|
542
|
+
const contextValue = useWizardNavigation({
|
|
543
|
+
steps,
|
|
544
|
+
initialStep,
|
|
545
|
+
onComplete,
|
|
546
|
+
onStepChange
|
|
547
|
+
});
|
|
548
|
+
const {
|
|
549
|
+
currentStep,
|
|
550
|
+
getStepStatus,
|
|
551
|
+
goToStep
|
|
552
|
+
} = contextValue;
|
|
445
553
|
return /* @__PURE__ */jsx(WizardContext.Provider, {
|
|
446
554
|
value: contextValue,
|
|
447
555
|
children: /* @__PURE__ */jsxs(Flex, {
|
|
@@ -470,39 +578,14 @@ var Wizard = ({
|
|
|
470
578
|
marginBottom: "4"
|
|
471
579
|
},
|
|
472
580
|
children: steps[currentStep].content
|
|
473
|
-
}), /* @__PURE__ */
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
gap: "3"
|
|
482
|
-
},
|
|
483
|
-
children: onCancel && /* @__PURE__ */jsx(Button, {
|
|
484
|
-
variant: "secondary",
|
|
485
|
-
onClick: onCancel,
|
|
486
|
-
"aria-label": buttonLabels.cancel,
|
|
487
|
-
children: buttonLabels.cancel
|
|
488
|
-
})
|
|
489
|
-
}), /* @__PURE__ */jsxs(Flex, {
|
|
490
|
-
sx: {
|
|
491
|
-
gap: "3"
|
|
492
|
-
},
|
|
493
|
-
children: [/* @__PURE__ */jsx(Button, {
|
|
494
|
-
variant: "secondary",
|
|
495
|
-
onClick: goToPrevious,
|
|
496
|
-
disabled: isFirstStep,
|
|
497
|
-
"aria-label": buttonLabels.previous,
|
|
498
|
-
children: buttonLabels.previous
|
|
499
|
-
}), /* @__PURE__ */jsx(Button, {
|
|
500
|
-
variant: getWizardPrimaryButtonVariant(variant),
|
|
501
|
-
onClick: goToNext,
|
|
502
|
-
"aria-label": isLastStep ? buttonLabels.finish : buttonLabels.next,
|
|
503
|
-
children: isLastStep ? buttonLabels.finish : buttonLabels.next
|
|
504
|
-
})]
|
|
505
|
-
})]
|
|
581
|
+
}), /* @__PURE__ */jsx(WizardNavigation, {
|
|
582
|
+
variant,
|
|
583
|
+
onCancel,
|
|
584
|
+
labels,
|
|
585
|
+
isFirstStep: contextValue.isFirstStep,
|
|
586
|
+
isLastStep: contextValue.isLastStep,
|
|
587
|
+
goToPrevious: contextValue.goToPrevious,
|
|
588
|
+
goToNext: contextValue.goToNext
|
|
506
589
|
})]
|
|
507
590
|
})]
|
|
508
591
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-wizard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A React wizard component for guiding users through multi-step flows with configurable step list layouts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"React",
|
|
@@ -36,23 +36,23 @@
|
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "^30.0.0",
|
|
39
|
-
"@types/react": "^19.
|
|
40
|
-
"jest": "^30.
|
|
41
|
-
"react": "^19.
|
|
42
|
-
"tsdown": "^0.
|
|
43
|
-
"@ttoss/config": "^
|
|
44
|
-
"@ttoss/
|
|
45
|
-
"@ttoss/react-i18n": "^
|
|
46
|
-
"@ttoss/
|
|
47
|
-
"@ttoss/
|
|
48
|
-
"@ttoss/
|
|
39
|
+
"@types/react": "^19.3.0",
|
|
40
|
+
"jest": "^30.5.2",
|
|
41
|
+
"react": "^19.3.0",
|
|
42
|
+
"tsdown": "^0.23.1",
|
|
43
|
+
"@ttoss/config": "^3.0.0",
|
|
44
|
+
"@ttoss/forms": "^0.52.0",
|
|
45
|
+
"@ttoss/react-i18n": "^3.0.1",
|
|
46
|
+
"@ttoss/ui": "^8.0.0",
|
|
47
|
+
"@ttoss/test-utils": "^6.0.0",
|
|
48
|
+
"@ttoss/i18n-cli": "^0.14.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@chakra-ui/react": "^3",
|
|
52
52
|
"react": ">=16.8.0",
|
|
53
53
|
"react-icons": "^5",
|
|
54
|
-
"@ttoss/react-i18n": "^
|
|
55
|
-
"@ttoss/ui": "^
|
|
54
|
+
"@ttoss/react-i18n": "^3.0.1",
|
|
55
|
+
"@ttoss/ui": "^8.0.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public",
|