@ttoss/react-wizard 0.4.7 → 0.4.9

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.js DELETED
@@ -1,517 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import * as React from 'react';
3
- "use strict";
4
-
5
- var __create = Object.create;
6
- var __defProp = Object.defineProperty;
7
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
- var __getOwnPropNames = Object.getOwnPropertyNames;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __name = (target, value) => __defProp(target, "name", {
12
- value,
13
- configurable: true
14
- });
15
- var __export = (target, all) => {
16
- for (var name in all) __defProp(target, name, {
17
- get: all[name],
18
- enumerable: true
19
- });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
24
- get: () => from[key],
25
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
26
- });
27
- }
28
- return to;
29
- };
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
- // If the importer is in node compatibility mode or this is not an ESM
32
- // file that has been converted to a CommonJS file using a Babel-
33
- // compatible transform (i.e. "__esModule" has not been set), then set
34
- // "default" to the CommonJS "module.exports" for node compatibility.
35
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
36
- value: mod,
37
- enumerable: true
38
- }) : target, mod));
39
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
40
- value: true
41
- }), mod);
42
-
43
- // src/index.ts
44
- var index_exports = {};
45
- __export(index_exports, {
46
- Wizard: () => Wizard,
47
- useWizard: () => useWizard
48
- });
49
- module.exports = __toCommonJS(index_exports);
50
-
51
- // src/Wizard.tsx
52
- var import_react_i18n = require("@ttoss/react-i18n");
53
- var import_ui3 = require("@ttoss/ui");
54
- var React3 = __toESM(require("react"), 1);
55
-
56
- // src/Wizard.styles.ts
57
- var import_ui = require("@ttoss/ui");
58
- var gradientFlow = (0, import_ui.keyframes)({
59
- "0%": {
60
- backgroundPosition: "0% 50%"
61
- },
62
- "50%": {
63
- backgroundPosition: "100% 50%"
64
- },
65
- "100%": {
66
- backgroundPosition: "0% 50%"
67
- }
68
- });
69
- var getAccentGradientBackground = /* @__PURE__ */__name(t => {
70
- const theme = t;
71
- const start = theme.colors?.action?.background?.accent?.default || theme.colors?.input?.background?.accent?.default;
72
- if (!start) return void 0;
73
- const middle = theme.colors?.action?.background?.accent?.active || theme.colors?.input?.background?.accent?.active || start;
74
- return `linear-gradient(270deg, ${start}, ${middle}, ${start})`;
75
- }, "getAccentGradientBackground");
76
- var getPrimaryGradientBackground = /* @__PURE__ */__name(t => {
77
- const theme = t;
78
- const start = theme.colors?.action?.background?.primary?.default;
79
- if (!start) return void 0;
80
- const middle = theme.colors?.action?.background?.secondary?.default || start;
81
- return `linear-gradient(270deg, ${start}, ${middle}, ${start})`;
82
- }, "getPrimaryGradientBackground");
83
- var getVariantStyles = /* @__PURE__ */__name((variantType = "spotlight-accent") => {
84
- const variants = {
85
- "spotlight-accent": {
86
- accentColor: "action.background.accent.default",
87
- accentTextColor: "action.text.accent.default",
88
- borderColor: "display.border.muted.default",
89
- primaryButtonVariant: "accent",
90
- gradientBackground: getAccentGradientBackground
91
- },
92
- "spotlight-primary": {
93
- accentColor: "action.background.primary.default",
94
- accentTextColor: "display.text.accent.default",
95
- borderColor: "display.border.muted.default",
96
- primaryButtonVariant: "primary",
97
- gradientBackground: getPrimaryGradientBackground
98
- },
99
- primary: {
100
- accentColor: "action.background.primary.default",
101
- accentTextColor: "action.text.primary.default",
102
- borderColor: "display.border.muted.default",
103
- primaryButtonVariant: "primary"
104
- },
105
- secondary: {
106
- accentColor: "action.background.secondary.default",
107
- accentTextColor: "action.text.primary.default",
108
- borderColor: "display.border.muted.default",
109
- primaryButtonVariant: "secondary"
110
- },
111
- accent: {
112
- accentColor: "action.background.accent.default",
113
- accentTextColor: "action.text.accent.default",
114
- borderColor: "display.border.muted.default",
115
- primaryButtonVariant: "accent"
116
- }
117
- };
118
- return variants[variantType] ?? variants["spotlight-accent"];
119
- }, "getVariantStyles");
120
- var getWizardShellSx = /* @__PURE__ */__name((variant = "spotlight-accent") => {
121
- const variantStyles = getVariantStyles(variant);
122
- return {
123
- width: "100%",
124
- minHeight: "300px",
125
- border: "1px solid",
126
- borderColor: variantStyles.borderColor,
127
- borderRadius: "8px",
128
- overflow: "hidden"
129
- };
130
- }, "getWizardShellSx");
131
- var getWizardStepListSx = /* @__PURE__ */__name(({
132
- layout,
133
- variant = "spotlight-accent"
134
- }) => {
135
- const isHorizontal = layout === "top" || layout === "bottom";
136
- const isSpotlight = variant.startsWith("spotlight-");
137
- const variantStyles = getVariantStyles(variant);
138
- return {
139
- position: "relative",
140
- padding: "6",
141
- backgroundColor: variantStyles.accentColor,
142
- ...(isSpotlight ? {
143
- background: variantStyles.gradientBackground,
144
- backgroundSize: "400% 400%",
145
- animation: `${gradientFlow} 6s ease infinite`
146
- } : {}),
147
- ...(isHorizontal ? {
148
- width: "100%"
149
- } : {
150
- minWidth: "200px"
151
- })
152
- };
153
- }, "getWizardStepListSx");
154
- var getWizardStepIndicatorSx = /* @__PURE__ */__name(({
155
- status,
156
- variant = "spotlight-accent",
157
- isClickable
158
- }) => {
159
- const variantStyles = getVariantStyles(variant);
160
- const isCompleted = status === "completed";
161
- const isUpcoming = status === "upcoming";
162
- return {
163
- borderColor: variantStyles.accentTextColor,
164
- backgroundColor: isCompleted ? variantStyles.accentTextColor : "transparent",
165
- color: isCompleted ? variantStyles.accentColor : variantStyles.accentTextColor,
166
- opacity: isUpcoming ? 0.4 : 1,
167
- transition: "all 0.2s ease",
168
- ...(isClickable ? {
169
- _hover: {
170
- opacity: 1
171
- }
172
- } : {})
173
- };
174
- }, "getWizardStepIndicatorSx");
175
- var getWizardStepSeparatorSx = /* @__PURE__ */__name(({
176
- isCompleted,
177
- variant = "spotlight-accent"
178
- }) => {
179
- const variantStyles = getVariantStyles(variant);
180
- return {
181
- backgroundColor: variantStyles.accentTextColor,
182
- opacity: isCompleted ? 1 : 0.4
183
- };
184
- }, "getWizardStepSeparatorSx");
185
- var getWizardStepTitleSx = /* @__PURE__ */__name(({
186
- status,
187
- variant = "spotlight-accent"
188
- }) => {
189
- const variantStyles = getVariantStyles(variant);
190
- return {
191
- color: variantStyles.accentTextColor,
192
- textAlign: "center",
193
- fontWeight: status === "active" ? "bold" : "normal",
194
- opacity: status === "upcoming" ? 0.4 : 1
195
- };
196
- }, "getWizardStepTitleSx");
197
- var getWizardStepDescriptionSx = /* @__PURE__ */__name(({
198
- status,
199
- variant = "spotlight-accent"
200
- }) => {
201
- const variantStyles = getVariantStyles(variant);
202
- return {
203
- color: variantStyles.accentTextColor,
204
- textAlign: "center",
205
- opacity: status === "upcoming" ? 0.4 : 1
206
- };
207
- }, "getWizardStepDescriptionSx");
208
- var WizardStepDescriptionFlexSx = {
209
- flexDirection: "row",
210
- alignItems: "center",
211
- justifyContent: "center"
212
- };
213
- var WizardStepTextWrapperSx = {
214
- textAlign: "center"
215
- };
216
- var getWizardPrimaryButtonVariant = /* @__PURE__ */__name((variant = "spotlight-accent") => {
217
- return getVariantStyles(variant).primaryButtonVariant;
218
- }, "getWizardPrimaryButtonVariant");
219
-
220
- // src/WizardContext.ts
221
- var React2 = __toESM(require("react"), 1);
222
- var WizardContext = React2.createContext(null);
223
- var useWizard = /* @__PURE__ */__name(() => {
224
- const context = React2.useContext(WizardContext);
225
- if (!context) {
226
- throw new Error("useWizard must be used within a Wizard component.");
227
- }
228
- return context;
229
- }, "useWizard");
230
-
231
- // src/WizardStepList.tsx
232
- var import_react = require("@chakra-ui/react");
233
- var import_ui2 = require("@ttoss/ui");
234
- var WizardStepList = /* @__PURE__ */__name(({
235
- steps,
236
- currentStep,
237
- layout,
238
- variant,
239
- allowStepClick,
240
- getStepStatus,
241
- onStepClick
242
- }) => {
243
- const isHorizontal = layout === "top" || layout === "bottom";
244
- const orientation = isHorizontal ? "horizontal" : "vertical";
245
- return /* @__PURE__ */React.createElement(import_ui2.Flex, {
246
- role: "navigation",
247
- "aria-label": "Wizard steps",
248
- "data-variant": variant,
249
- sx: getWizardStepListSx({
250
- layout,
251
- variant
252
- })
253
- }, /* @__PURE__ */React.createElement(import_react.Steps.Root, {
254
- step: currentStep,
255
- count: steps.length,
256
- orientation
257
- }, /* @__PURE__ */React.createElement(import_react.Steps.List, null, steps.map((step, index) => {
258
- const status = getStepStatus({
259
- stepIndex: index
260
- });
261
- const isClickable = allowStepClick && status === "completed" && index !== currentStep;
262
- return /* @__PURE__ */React.createElement(import_react.Steps.Item, {
263
- key: index,
264
- index
265
- }, /* @__PURE__ */React.createElement(import_ui2.Flex, {
266
- sx: {
267
- flexDirection: isHorizontal ? "column" : "row",
268
- alignItems: "center",
269
- gap: "2"
270
- }
271
- }, /* @__PURE__ */React.createElement(import_ui2.Box, {
272
- role: "button",
273
- tabIndex: isClickable ? 0 : -1,
274
- onClick: /* @__PURE__ */__name(() => {
275
- if (isClickable) {
276
- onStepClick({
277
- stepIndex: index
278
- });
279
- }
280
- }, "onClick"),
281
- onKeyDown: /* @__PURE__ */__name(e => {
282
- if (isClickable && (e.key === "Enter" || e.key === " ")) {
283
- e.preventDefault();
284
- onStepClick({
285
- stepIndex: index
286
- });
287
- }
288
- }, "onKeyDown"),
289
- "aria-current": status === "active" ? "step" : void 0,
290
- sx: {
291
- cursor: isClickable ? "pointer" : "default"
292
- }
293
- }, /* @__PURE__ */React.createElement(import_react.Steps.Indicator, {
294
- css: getWizardStepIndicatorSx({
295
- status,
296
- variant,
297
- isClickable
298
- })
299
- }, /* @__PURE__ */React.createElement(import_react.Steps.Status, {
300
- complete: "\u2713",
301
- incomplete: /* @__PURE__ */React.createElement(import_react.Steps.Number, null)
302
- }))), (step.title || step.description) && /* @__PURE__ */React.createElement(import_ui2.Box, {
303
- sx: WizardStepTextWrapperSx
304
- }, step.title && /* @__PURE__ */React.createElement(import_react.Steps.Title, {
305
- css: getWizardStepTitleSx({
306
- status,
307
- variant
308
- })
309
- }, step.title), step.description && /* @__PURE__ */React.createElement(import_ui2.Flex, {
310
- sx: WizardStepDescriptionFlexSx
311
- }, /* @__PURE__ */React.createElement(import_react.Steps.Description, {
312
- css: getWizardStepDescriptionSx({
313
- status,
314
- variant
315
- })
316
- }, step.description)))), index < steps.length - 1 && /* @__PURE__ */React.createElement(import_react.Steps.Separator, {
317
- css: getWizardStepSeparatorSx({
318
- isCompleted: index < currentStep,
319
- variant
320
- })
321
- }));
322
- }))));
323
- }, "WizardStepList");
324
-
325
- // src/Wizard.tsx
326
- var messages = (0, import_react_i18n.defineMessages)({
327
- previous: {
328
- defaultMessage: "Previous",
329
- description: "Label for the previous step button in the wizard."
330
- },
331
- next: {
332
- defaultMessage: "Next",
333
- description: "Label for the next step button in the wizard."
334
- },
335
- finish: {
336
- defaultMessage: "Finish",
337
- description: "Label for the finish button on the last wizard step."
338
- },
339
- cancel: {
340
- defaultMessage: "Cancel",
341
- description: "Label for the cancel button in the wizard."
342
- }
343
- });
344
- var getFlexDirection = /* @__PURE__ */__name(layout => {
345
- switch (layout) {
346
- case "top":
347
- return "column";
348
- case "bottom":
349
- return "column-reverse";
350
- case "left":
351
- return "row";
352
- case "right":
353
- return "row-reverse";
354
- }
355
- }, "getFlexDirection");
356
- var Wizard = /* @__PURE__ */__name(({
357
- steps,
358
- layout = "top",
359
- variant = "spotlight-accent",
360
- onComplete,
361
- onCancel,
362
- onStepChange,
363
- initialStep = 0,
364
- allowStepClick = true,
365
- labels
366
- }) => {
367
- const {
368
- intl
369
- } = (0, import_react_i18n.useI18n)();
370
- const [currentStep, setCurrentStep] = React3.useState(initialStep);
371
- const stepValidationRef = React3.useRef(null);
372
- const totalSteps = steps.length;
373
- const isFirstStep = currentStep === 0;
374
- const isLastStep = currentStep === totalSteps - 1;
375
- const buttonLabels = React3.useMemo(() => {
376
- return {
377
- previous: labels?.previous ?? intl.formatMessage(messages.previous),
378
- next: labels?.next ?? intl.formatMessage(messages.next),
379
- finish: labels?.finish ?? intl.formatMessage(messages.finish),
380
- cancel: labels?.cancel ?? intl.formatMessage(messages.cancel)
381
- };
382
- }, [intl, labels]);
383
- const getStepStatus = React3.useCallback(({
384
- stepIndex
385
- }) => {
386
- if (stepIndex < currentStep) {
387
- return "completed";
388
- }
389
- if (stepIndex === currentStep) {
390
- return "active";
391
- }
392
- return "upcoming";
393
- }, [currentStep]);
394
- const goToNext = React3.useCallback(async () => {
395
- const step = steps[currentStep];
396
- if (stepValidationRef.current) {
397
- const canProceed = await stepValidationRef.current();
398
- if (!canProceed) {
399
- return;
400
- }
401
- }
402
- if (step.onNext) {
403
- const canProceed = await step.onNext();
404
- if (!canProceed) {
405
- return;
406
- }
407
- }
408
- if (isLastStep) {
409
- onComplete?.();
410
- } else {
411
- const nextStep = currentStep + 1;
412
- stepValidationRef.current = null;
413
- setCurrentStep(nextStep);
414
- onStepChange?.({
415
- stepIndex: nextStep
416
- });
417
- }
418
- }, [currentStep, steps, isLastStep, onComplete, onStepChange]);
419
- const goToPrevious = React3.useCallback(() => {
420
- if (!isFirstStep) {
421
- const prevStep = currentStep - 1;
422
- stepValidationRef.current = null;
423
- setCurrentStep(prevStep);
424
- onStepChange?.({
425
- stepIndex: prevStep
426
- });
427
- }
428
- }, [currentStep, isFirstStep, onStepChange]);
429
- const goToStep = React3.useCallback(({
430
- stepIndex
431
- }) => {
432
- if (stepIndex >= 0 && stepIndex < totalSteps && stepIndex <= currentStep) {
433
- stepValidationRef.current = null;
434
- setCurrentStep(stepIndex);
435
- onStepChange?.({
436
- stepIndex
437
- });
438
- }
439
- }, [currentStep, totalSteps, onStepChange]);
440
- const setStepValidation = React3.useCallback(validate => {
441
- stepValidationRef.current = validate;
442
- }, []);
443
- const contextValue = React3.useMemo(() => {
444
- return {
445
- currentStep,
446
- totalSteps,
447
- goToNext,
448
- goToPrevious,
449
- goToStep,
450
- isFirstStep,
451
- isLastStep,
452
- getStepStatus,
453
- setStepValidation
454
- };
455
- }, [currentStep, totalSteps, goToNext, goToPrevious, goToStep, isFirstStep, isLastStep, getStepStatus, setStepValidation]);
456
- return /* @__PURE__ */React3.createElement(WizardContext.Provider, {
457
- value: contextValue
458
- }, /* @__PURE__ */React3.createElement(import_ui3.Flex, {
459
- "data-variant": variant,
460
- sx: {
461
- flexDirection: getFlexDirection(layout),
462
- ...getWizardShellSx(variant)
463
- }
464
- }, /* @__PURE__ */React3.createElement(WizardStepList, {
465
- steps,
466
- currentStep,
467
- layout,
468
- variant,
469
- allowStepClick,
470
- getStepStatus,
471
- onStepClick: goToStep
472
- }), /* @__PURE__ */React3.createElement(import_ui3.Flex, {
473
- sx: {
474
- flexDirection: "column",
475
- flex: 1,
476
- padding: "6"
477
- }
478
- }, /* @__PURE__ */React3.createElement(import_ui3.Box, {
479
- sx: {
480
- flex: 1,
481
- marginBottom: "4"
482
- }
483
- }, steps[currentStep].content), /* @__PURE__ */React3.createElement(import_ui3.Flex, {
484
- sx: {
485
- justifyContent: "space-between",
486
- alignItems: "center",
487
- gap: "3"
488
- }
489
- }, /* @__PURE__ */React3.createElement(import_ui3.Flex, {
490
- sx: {
491
- gap: "3"
492
- }
493
- }, onCancel && /* @__PURE__ */React3.createElement(import_ui3.Button, {
494
- variant: "secondary",
495
- onClick: onCancel,
496
- "aria-label": buttonLabels.cancel
497
- }, buttonLabels.cancel)), /* @__PURE__ */React3.createElement(import_ui3.Flex, {
498
- sx: {
499
- gap: "3"
500
- }
501
- }, /* @__PURE__ */React3.createElement(import_ui3.Button, {
502
- variant: "secondary",
503
- onClick: goToPrevious,
504
- disabled: isFirstStep,
505
- "aria-label": buttonLabels.previous
506
- }, buttonLabels.previous), /* @__PURE__ */React3.createElement(import_ui3.Button, {
507
- variant: getWizardPrimaryButtonVariant(variant),
508
- onClick: goToNext,
509
- "aria-label": isLastStep ? buttonLabels.finish : buttonLabels.next
510
- }, isLastStep ? buttonLabels.finish : buttonLabels.next))))));
511
- }, "Wizard");
512
- Wizard.displayName = "Wizard";
513
- // Annotate the CommonJS export names for ESM import in node:
514
- 0 && (module.exports = {
515
- Wizard,
516
- useWizard
517
- });