@ttoss/react-wizard 0.9.0 → 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.
Files changed (3) hide show
  1. package/dist/index.cjs +152 -69
  2. package/dist/index.mjs +152 -69
  3. package/package.json +9 -9
package/dist/index.cjs CHANGED
@@ -48,17 +48,60 @@ var gradientFlow = (0, _ttoss_ui.keyframes)({
48
48
  backgroundPosition: "0% 50%"
49
49
  }
50
50
  });
51
- var getAccentGradientBackground = t => {
52
- const theme = t;
53
- const start = theme.colors?.action?.background?.accent?.default || theme.colors?.input?.background?.accent?.default;
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
+ });
54
86
  if (!start) return void 0;
55
- return `linear-gradient(270deg, ${start}, ${theme.colors?.action?.background?.accent?.active || theme.colors?.input?.background?.accent?.active || start}, ${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
+ });
56
98
  };
57
99
  var getPrimaryGradientBackground = t => {
58
- const theme = t;
59
- const start = theme.colors?.action?.background?.primary?.default;
60
- if (!start) return void 0;
61
- return `linear-gradient(270deg, ${start}, ${theme.colors?.action?.background?.secondary?.default || start}, ${start})`;
100
+ return buildGradientBackground({
101
+ theme: t,
102
+ startPaths: ["action.background.primary.default"],
103
+ middlePaths: ["action.background.secondary.default"]
104
+ });
62
105
  };
63
106
  var getVariantStyles = (variantType = "spotlight-accent") => {
64
107
  const variants = {
@@ -360,36 +403,11 @@ var getFlexDirection = layout => {
360
403
  return "row-reverse";
361
404
  }
362
405
  };
363
- /**
364
- * Renders a multi-step wizard with step navigation, localized action labels,
365
- * and support for completion, cancellation, and step changes.
366
- *
367
- * @param props - Wizard configuration and step content.
368
- * @param props.steps - The ordered steps displayed in the wizard.
369
- * @param props.onComplete - Called when the user finishes the last step.
370
- * @param props.onCancel - Called when the user cancels the wizard.
371
- * @param props.onStepChange - Called when the current step changes.
372
- */
373
- var Wizard = ({
374
- steps,
375
- layout = "top",
376
- variant = "spotlight-accent",
377
- onComplete,
378
- onCancel,
379
- onStepChange,
380
- initialStep = 0,
381
- allowStepClick = true,
382
- labels
383
- }) => {
406
+ var useButtonLabels = labels => {
384
407
  const {
385
408
  intl
386
409
  } = (0, _ttoss_react_i18n.useI18n)();
387
- const [currentStep, setCurrentStep] = react.useState(initialStep);
388
- const stepValidationRef = react.useRef(null);
389
- const totalSteps = steps.length;
390
- const isFirstStep = currentStep === 0;
391
- const isLastStep = currentStep === totalSteps - 1;
392
- const buttonLabels = react.useMemo(() => {
410
+ return react.useMemo(() => {
393
411
  return {
394
412
  previous: labels?.previous ?? intl.formatMessage(messages.previous),
395
413
  next: labels?.next ?? intl.formatMessage(messages.next),
@@ -397,6 +415,18 @@ var Wizard = ({
397
415
  cancel: labels?.cancel ?? intl.formatMessage(messages.cancel)
398
416
  };
399
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;
400
430
  const getStepStatus = react.useCallback(({
401
431
  stepIndex
402
432
  }) => {
@@ -445,7 +475,7 @@ var Wizard = ({
445
475
  const setStepValidation = react.useCallback(validate => {
446
476
  stepValidationRef.current = validate;
447
477
  }, []);
448
- const contextValue = react.useMemo(() => {
478
+ return react.useMemo(() => {
449
479
  return {
450
480
  currentStep,
451
481
  totalSteps,
@@ -458,6 +488,84 @@ var Wizard = ({
458
488
  setStepValidation
459
489
  };
460
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;
461
569
  return /* @__PURE__ */(0, react_jsx_runtime.jsx)(WizardContext.Provider, {
462
570
  value: contextValue,
463
571
  children: /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
@@ -486,39 +594,14 @@ var Wizard = ({
486
594
  marginBottom: "4"
487
595
  },
488
596
  children: steps[currentStep].content
489
- }), /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
490
- sx: {
491
- justifyContent: "space-between",
492
- alignItems: "center",
493
- gap: "3"
494
- },
495
- children: [/* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Flex, {
496
- sx: {
497
- gap: "3"
498
- },
499
- children: onCancel && /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
500
- variant: "secondary",
501
- onClick: onCancel,
502
- "aria-label": buttonLabels.cancel,
503
- children: buttonLabels.cancel
504
- })
505
- }), /* @__PURE__ */(0, react_jsx_runtime.jsxs)(_ttoss_ui.Flex, {
506
- sx: {
507
- gap: "3"
508
- },
509
- children: [/* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
510
- variant: "secondary",
511
- onClick: goToPrevious,
512
- disabled: isFirstStep,
513
- "aria-label": buttonLabels.previous,
514
- children: buttonLabels.previous
515
- }), /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_ui.Button, {
516
- variant: getWizardPrimaryButtonVariant(variant),
517
- onClick: goToNext,
518
- "aria-label": isLastStep ? buttonLabels.finish : buttonLabels.next,
519
- children: isLastStep ? buttonLabels.finish : buttonLabels.next
520
- })]
521
- })]
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
522
605
  })]
523
606
  })]
524
607
  })
package/dist/index.mjs CHANGED
@@ -17,17 +17,60 @@ var gradientFlow = keyframes({
17
17
  backgroundPosition: "0% 50%"
18
18
  }
19
19
  });
20
- var getAccentGradientBackground = t => {
21
- const theme = t;
22
- const start = theme.colors?.action?.background?.accent?.default || theme.colors?.input?.background?.accent?.default;
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}, ${theme.colors?.action?.background?.accent?.active || theme.colors?.input?.background?.accent?.active || start}, ${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
- const theme = t;
28
- const start = theme.colors?.action?.background?.primary?.default;
29
- if (!start) return void 0;
30
- return `linear-gradient(270deg, ${start}, ${theme.colors?.action?.background?.secondary?.default || start}, ${start})`;
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
- const [currentStep, setCurrentStep] = React.useState(initialStep);
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
- const contextValue = React.useMemo(() => {
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__ */jsxs(Flex, {
474
- sx: {
475
- justifyContent: "space-between",
476
- alignItems: "center",
477
- gap: "3"
478
- },
479
- children: [/* @__PURE__ */jsx(Flex, {
480
- sx: {
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.9.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",
@@ -40,19 +40,19 @@
40
40
  "jest": "^30.5.2",
41
41
  "react": "^19.3.0",
42
42
  "tsdown": "^0.23.1",
43
- "@ttoss/config": "^2.0.0",
44
- "@ttoss/forms": "^0.51.0",
45
- "@ttoss/react-i18n": "^3.0.0",
46
- "@ttoss/test-utils": "^5.0.0",
47
- "@ttoss/ui": "^7.0.0",
48
- "@ttoss/i18n-cli": "^0.14.0"
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": "^3.0.0",
55
- "@ttoss/ui": "^7.0.0"
54
+ "@ttoss/react-i18n": "^3.0.1",
55
+ "@ttoss/ui": "^8.0.0"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public",