@dt-dds/react-stepper 1.0.0-beta.46 → 1.0.0-beta.48
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/CHANGELOG.md +20 -0
- package/README.md +157 -23
- package/dist/index.d.mts +39 -22
- package/dist/index.d.ts +39 -22
- package/dist/index.js +463 -157
- package/dist/index.mjs +465 -158
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,211 +16,516 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
|
|
18
|
-
// src/Stepper.
|
|
21
|
+
// src/Stepper.tsx
|
|
22
|
+
import { Children, cloneElement } from "react";
|
|
23
|
+
|
|
24
|
+
// src/components/Step/Step.styled.ts
|
|
19
25
|
import styled from "@emotion/styled";
|
|
20
|
-
|
|
26
|
+
|
|
27
|
+
// src/constants/index.ts
|
|
28
|
+
var VERTICAL_TRAIL_LINE_MIN_HEIGHT = 24;
|
|
29
|
+
var HORIZONTAL_TRAIL_LINE_MIN_WIDTH = 80;
|
|
30
|
+
var STEP_MIN_WIDTH = 120;
|
|
31
|
+
var STEP_CONTENT_MAX_WIDTH = 112;
|
|
32
|
+
var VERTICAL_LAST_STEP_INDICATOR_MIN_HEIGHT = 24;
|
|
33
|
+
var VERTICAL_STEP_INDICATOR_MIN_HEIGHT = 56;
|
|
34
|
+
var HORIZONTAL_TRAIL_LINE_START_OFFSET = 20;
|
|
35
|
+
var VERTICAL_TRAIL_LINE_TOP_OFFSET = 32;
|
|
36
|
+
var VERTICAL_TRAIL_LINE_LEFT_OFFSET = 12;
|
|
37
|
+
|
|
38
|
+
// src/components/Step/Step.styled.ts
|
|
39
|
+
var StepContainer = styled.div`
|
|
40
|
+
display: flex;
|
|
41
|
+
position: relative;
|
|
42
|
+
overflow: visible;
|
|
43
|
+
gap: 8px;
|
|
44
|
+
|
|
45
|
+
${({ orientation, isLast, isDisabled }) => {
|
|
46
|
+
if (orientation === "horizontal") {
|
|
47
|
+
return `
|
|
48
|
+
flex-direction: column;
|
|
49
|
+
align-items: center;
|
|
50
|
+
flex: 1 1 0;
|
|
51
|
+
min-width: ${STEP_MIN_WIDTH}px;
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
return `
|
|
55
|
+
flex-direction: row;
|
|
56
|
+
padding-bottom: ${isLast ? "0" : "8px"};
|
|
57
|
+
cursor: ${isDisabled ? "not-allowed" : "pointer"};
|
|
58
|
+
`;
|
|
59
|
+
}}
|
|
60
|
+
`;
|
|
61
|
+
var StepIndicatorWrapper = styled.div`
|
|
62
|
+
display: flex;
|
|
63
|
+
position: relative;
|
|
64
|
+
|
|
65
|
+
${({ orientation, isLast }) => {
|
|
66
|
+
if (orientation === "horizontal") {
|
|
67
|
+
return `
|
|
68
|
+
width: 100%;
|
|
69
|
+
flex-direction: row;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
return `
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
align-self: flex-start;
|
|
76
|
+
min-height: ${isLast ? `${VERTICAL_LAST_STEP_INDICATOR_MIN_HEIGHT}px` : `${VERTICAL_STEP_INDICATOR_MIN_HEIGHT}px`};
|
|
77
|
+
`;
|
|
78
|
+
}}
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
// src/components/StepContent/StepContent.tsx
|
|
82
|
+
import { useRef, useEffect, useState } from "react";
|
|
83
|
+
import { Tooltip } from "@dt-dds/react-tooltip";
|
|
84
|
+
|
|
85
|
+
// src/components/StepContent/StepContent.styled.ts
|
|
86
|
+
import styled2 from "@emotion/styled";
|
|
87
|
+
var StepContentStyled = styled2.div`
|
|
21
88
|
display: flex;
|
|
22
89
|
flex-direction: column;
|
|
23
|
-
gap:
|
|
24
|
-
|
|
90
|
+
gap: 4px;
|
|
91
|
+
max-width: ${STEP_CONTENT_MAX_WIDTH}px;
|
|
25
92
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
93
|
+
& > * {
|
|
94
|
+
min-width: 0;
|
|
95
|
+
max-width: 100%;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
${({ orientation }) => orientation === "horizontal" ? `
|
|
99
|
+
align-items: center;
|
|
100
|
+
text-align: center;
|
|
101
|
+
` : `
|
|
102
|
+
align-items: flex-start;
|
|
103
|
+
text-align: left;
|
|
104
|
+
padding-top: 4px;
|
|
105
|
+
`}
|
|
106
|
+
`;
|
|
107
|
+
var StepTitleStyled = styled2.span`
|
|
108
|
+
${({ theme, state, isActive }) => {
|
|
109
|
+
const getColor = () => {
|
|
110
|
+
if (state === "disabled") return theme.palette.content.light;
|
|
111
|
+
if (state === "error") return theme.palette.error.default;
|
|
112
|
+
return theme.palette.content.dark;
|
|
113
|
+
};
|
|
114
|
+
return `
|
|
115
|
+
${isActive ? theme.fontStyles.bodyMdBold : theme.fontStyles.bodyMdRegular}
|
|
116
|
+
color: ${getColor()};
|
|
117
|
+
white-space: nowrap;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
text-overflow: ellipsis;
|
|
120
|
+
`;
|
|
121
|
+
}}
|
|
122
|
+
`;
|
|
123
|
+
var StepDescriptionStyled = styled2.span`
|
|
124
|
+
${({ theme, state }) => {
|
|
125
|
+
const getColor = () => {
|
|
126
|
+
if (state === "disabled") return theme.palette.content.light;
|
|
127
|
+
if (state === "error") return theme.palette.error.default;
|
|
128
|
+
if (state === "warning") return theme.palette.content.default;
|
|
129
|
+
return theme.palette.primary.medium;
|
|
130
|
+
};
|
|
131
|
+
return `
|
|
132
|
+
${theme.fontStyles.bodySmRegular}
|
|
133
|
+
color: ${getColor()};
|
|
134
|
+
display: -webkit-box;
|
|
135
|
+
-webkit-line-clamp: 2;
|
|
136
|
+
-webkit-box-orient: vertical;
|
|
137
|
+
overflow: hidden;
|
|
138
|
+
text-overflow: ellipsis;
|
|
139
|
+
`;
|
|
140
|
+
}}
|
|
31
141
|
`;
|
|
32
142
|
|
|
33
|
-
// src/
|
|
34
|
-
import { jsx } from "react/jsx-runtime";
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
143
|
+
// src/components/StepContent/StepContent.tsx
|
|
144
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
145
|
+
var StepContent = ({
|
|
146
|
+
title,
|
|
147
|
+
description,
|
|
148
|
+
state,
|
|
149
|
+
isActive,
|
|
38
150
|
orientation
|
|
39
151
|
}) => {
|
|
40
|
-
const
|
|
41
|
-
|
|
152
|
+
const titleRef = useRef(null);
|
|
153
|
+
const descRef = useRef(null);
|
|
154
|
+
const [showTitleTooltip, setShowTitleTooltip] = useState(false);
|
|
155
|
+
const [showDescTooltip, setShowDescTooltip] = useState(false);
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (titleRef.current && title) {
|
|
158
|
+
const element = titleRef.current;
|
|
159
|
+
setShowTitleTooltip(element.scrollWidth > element.clientWidth);
|
|
160
|
+
}
|
|
161
|
+
if (descRef.current && description) {
|
|
162
|
+
const element = descRef.current;
|
|
163
|
+
setShowDescTooltip(element.scrollHeight > element.clientHeight);
|
|
164
|
+
}
|
|
165
|
+
}, [title, description, orientation]);
|
|
166
|
+
if (!title && !description) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const renderContent = (content, ref, showTooltip, Component, componentProps) => {
|
|
170
|
+
if (!content) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const element = /* @__PURE__ */ jsx(Component, __spreadProps(__spreadValues({}, componentProps), { ref, children: content }));
|
|
174
|
+
if (showTooltip) {
|
|
175
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
176
|
+
element,
|
|
177
|
+
/* @__PURE__ */ jsx(Tooltip.Content, { direction: "right", children: content })
|
|
178
|
+
] });
|
|
179
|
+
}
|
|
180
|
+
return element;
|
|
181
|
+
};
|
|
182
|
+
return /* @__PURE__ */ jsxs(StepContentStyled, { orientation, children: [
|
|
183
|
+
renderContent(title, titleRef, showTitleTooltip, StepTitleStyled, {
|
|
184
|
+
state,
|
|
185
|
+
isActive
|
|
186
|
+
}),
|
|
187
|
+
renderContent(
|
|
188
|
+
description,
|
|
189
|
+
descRef,
|
|
190
|
+
showDescTooltip,
|
|
191
|
+
StepDescriptionStyled,
|
|
192
|
+
{ state }
|
|
193
|
+
)
|
|
194
|
+
] });
|
|
42
195
|
};
|
|
43
196
|
|
|
44
|
-
// src/components/
|
|
45
|
-
import { Children, cloneElement, useMemo } from "react";
|
|
197
|
+
// src/components/StepIndicator/StepIndicator.tsx
|
|
46
198
|
import { useTheme } from "@emotion/react";
|
|
47
199
|
import { Icon } from "@dt-dds/react-icon";
|
|
48
|
-
import { Typography } from "@dt-dds/react-typography";
|
|
49
200
|
|
|
50
|
-
// src/components/
|
|
51
|
-
import
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
201
|
+
// src/components/StepIndicator/StepIndicator.styled.ts
|
|
202
|
+
import styled3 from "@emotion/styled";
|
|
203
|
+
var StepIndicatorStyled = styled3.div`
|
|
204
|
+
display: flex;
|
|
205
|
+
align-items: center;
|
|
206
|
+
justify-content: center;
|
|
207
|
+
width: 24px;
|
|
208
|
+
height: 24px;
|
|
209
|
+
border-radius: 50%;
|
|
210
|
+
flex-shrink: 0;
|
|
211
|
+
transition: transform 0.2s ease;
|
|
212
|
+
|
|
213
|
+
${({ theme, state, isActive, variant }) => {
|
|
214
|
+
const activeBgColor = isActive ? theme.palette.primary.light : theme.palette.content.contrast;
|
|
215
|
+
const colorMap = {
|
|
216
|
+
completed: {
|
|
217
|
+
bg: theme.palette.primary.default,
|
|
218
|
+
border: theme.palette.primary.default
|
|
219
|
+
},
|
|
220
|
+
warning: {
|
|
221
|
+
bg: theme.palette.warning.default,
|
|
222
|
+
border: "transparent"
|
|
223
|
+
},
|
|
224
|
+
error: {
|
|
225
|
+
bg: theme.palette.error.default,
|
|
226
|
+
border: "transparent"
|
|
227
|
+
},
|
|
228
|
+
disabled: {
|
|
229
|
+
bg: theme.palette.content.contrast,
|
|
230
|
+
border: theme.palette.border.medium,
|
|
231
|
+
text: theme.palette.content.light
|
|
232
|
+
},
|
|
233
|
+
incomplete: {
|
|
234
|
+
bg: activeBgColor,
|
|
235
|
+
border: theme.palette.primary.default,
|
|
236
|
+
text: theme.palette.primary.default
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const colors = colorMap[state] || colorMap.incomplete;
|
|
240
|
+
const disabledBorderColor = state === "disabled" ? theme.palette.border.medium : theme.palette.primary.default;
|
|
241
|
+
if (variant === "bullet" && (state === "incomplete" || state === "disabled")) {
|
|
242
|
+
return `
|
|
243
|
+
background-color: ${activeBgColor};
|
|
244
|
+
border: 1px solid ${disabledBorderColor};
|
|
245
|
+
|
|
246
|
+
&::after {
|
|
247
|
+
content: '';
|
|
248
|
+
width: 10px;
|
|
249
|
+
height: 10px;
|
|
250
|
+
border-radius: 50%;
|
|
251
|
+
background-color: ${state === "disabled" ? theme.palette.content.light : theme.palette.primary.default};
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
}
|
|
255
|
+
if (variant === "icon" && state === "disabled") {
|
|
256
|
+
return `
|
|
257
|
+
border: 1px solid ${disabledBorderColor};
|
|
258
|
+
|
|
259
|
+
> i {
|
|
260
|
+
color: ${theme.palette.content.light};
|
|
261
|
+
}
|
|
262
|
+
`;
|
|
263
|
+
}
|
|
264
|
+
return `
|
|
265
|
+
background-color: ${colors.bg};
|
|
266
|
+
border: 1px solid ${colors.border};
|
|
267
|
+
color: ${colors.text};
|
|
268
|
+
${theme.fontStyles.bodySmBold}
|
|
269
|
+
`;
|
|
270
|
+
}}
|
|
71
271
|
`;
|
|
72
272
|
|
|
73
|
-
// src/components/
|
|
273
|
+
// src/components/StepIndicator/StepIndicator.tsx
|
|
74
274
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
isLarge = false
|
|
275
|
+
var StepIndicator = ({
|
|
276
|
+
index,
|
|
277
|
+
state,
|
|
278
|
+
variant,
|
|
279
|
+
isActive,
|
|
280
|
+
icon
|
|
82
281
|
}) => {
|
|
282
|
+
const theme = useTheme();
|
|
283
|
+
const getIndicatorContent = () => {
|
|
284
|
+
const iconMap = {
|
|
285
|
+
completed: "check",
|
|
286
|
+
warning: "warning",
|
|
287
|
+
error: "error"
|
|
288
|
+
};
|
|
289
|
+
if (iconMap[state]) {
|
|
290
|
+
return /* @__PURE__ */ jsx2(
|
|
291
|
+
Icon,
|
|
292
|
+
{
|
|
293
|
+
code: iconMap[state],
|
|
294
|
+
color: theme.palette.content.contrast,
|
|
295
|
+
size: "small"
|
|
296
|
+
}
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
if (variant === "bullet") {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
if (variant === "icon" && icon) {
|
|
303
|
+
return icon;
|
|
304
|
+
}
|
|
305
|
+
return index + 1;
|
|
306
|
+
};
|
|
83
307
|
return /* @__PURE__ */ jsx2(
|
|
84
|
-
|
|
308
|
+
StepIndicatorStyled,
|
|
85
309
|
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
children
|
|
310
|
+
"data-testid": "step-indicator",
|
|
311
|
+
isActive,
|
|
312
|
+
state,
|
|
313
|
+
variant,
|
|
314
|
+
children: getIndicatorContent()
|
|
92
315
|
}
|
|
93
316
|
);
|
|
94
317
|
};
|
|
95
318
|
|
|
96
|
-
// src/components/
|
|
97
|
-
import
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
319
|
+
// src/components/TrailLine/TrailLine.styled.ts
|
|
320
|
+
import styled4 from "@emotion/styled";
|
|
321
|
+
var TrailLineStyled = styled4.span`
|
|
322
|
+
position: absolute;
|
|
323
|
+
transition: background-color 0.3s ease;
|
|
324
|
+
|
|
325
|
+
${({ state, orientation, theme }) => {
|
|
326
|
+
const color = state === "completed" ? `${theme.palette.primary.default}` : `${theme.palette.primary.light}`;
|
|
327
|
+
if (orientation === "horizontal") {
|
|
328
|
+
return `
|
|
329
|
+
top: 50%;
|
|
330
|
+
transform: translateY(-50%);
|
|
331
|
+
left: calc(50% + ${HORIZONTAL_TRAIL_LINE_START_OFFSET}px);
|
|
332
|
+
right: calc(-50% + ${HORIZONTAL_TRAIL_LINE_START_OFFSET}px);
|
|
333
|
+
min-width: ${HORIZONTAL_TRAIL_LINE_MIN_WIDTH}px;
|
|
334
|
+
height: ${state === "completed" ? "2px" : "1px"};
|
|
335
|
+
background-color: ${color};
|
|
336
|
+
`;
|
|
337
|
+
}
|
|
338
|
+
return `
|
|
339
|
+
top: ${VERTICAL_TRAIL_LINE_TOP_OFFSET}px;
|
|
340
|
+
left: ${VERTICAL_TRAIL_LINE_LEFT_OFFSET}px;
|
|
341
|
+
width: ${state === "completed" ? "2px" : "1px"};
|
|
342
|
+
min-height: ${VERTICAL_TRAIL_LINE_MIN_HEIGHT}px;
|
|
343
|
+
background-color: ${color};
|
|
344
|
+
`;
|
|
345
|
+
}}
|
|
108
346
|
`;
|
|
109
347
|
|
|
110
|
-
// src/components/
|
|
348
|
+
// src/components/TrailLine/TrailLine.tsx
|
|
111
349
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
() => Children.map(children, (child) => {
|
|
121
|
-
return child && cloneElement(child, __spreadValues({
|
|
122
|
-
isActive,
|
|
123
|
-
isCompleted,
|
|
124
|
-
isDisabled,
|
|
125
|
-
isError
|
|
126
|
-
}, child.props));
|
|
127
|
-
}),
|
|
128
|
-
[children, isActive, isCompleted, isDisabled, isError]
|
|
350
|
+
var TrailLine = ({ state, orientation }) => {
|
|
351
|
+
return /* @__PURE__ */ jsx3(
|
|
352
|
+
TrailLineStyled,
|
|
353
|
+
{
|
|
354
|
+
"data-testid": "trail-line",
|
|
355
|
+
orientation,
|
|
356
|
+
state
|
|
357
|
+
}
|
|
129
358
|
);
|
|
130
|
-
return /* @__PURE__ */ jsx3(StepStyled, { children: clonedChildren });
|
|
131
359
|
};
|
|
132
|
-
|
|
133
|
-
|
|
360
|
+
|
|
361
|
+
// src/components/Step/Step.tsx
|
|
362
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
363
|
+
var Step = ({
|
|
364
|
+
index = 0,
|
|
365
|
+
title,
|
|
366
|
+
description,
|
|
367
|
+
state = "incomplete",
|
|
134
368
|
isActive = false,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
369
|
+
variant = "number",
|
|
370
|
+
icon,
|
|
371
|
+
isLast = false,
|
|
372
|
+
orientation,
|
|
373
|
+
dataTestId
|
|
138
374
|
}) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const bgColor = isError ? theme.palette.error.light : theme.palette.primary.light;
|
|
142
|
-
return /* @__PURE__ */ jsx3(
|
|
143
|
-
Counter,
|
|
375
|
+
return /* @__PURE__ */ jsxs2(
|
|
376
|
+
StepContainer,
|
|
144
377
|
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
378
|
+
isDisabled: state === "disabled",
|
|
379
|
+
isLast,
|
|
380
|
+
orientation,
|
|
381
|
+
children: [
|
|
382
|
+
/* @__PURE__ */ jsxs2(
|
|
383
|
+
StepIndicatorWrapper,
|
|
384
|
+
{
|
|
385
|
+
"data-testid": dataTestId != null ? dataTestId : `step-${index}`,
|
|
386
|
+
isLast,
|
|
387
|
+
orientation,
|
|
388
|
+
children: [
|
|
389
|
+
/* @__PURE__ */ jsx4(
|
|
390
|
+
StepIndicator,
|
|
391
|
+
{
|
|
392
|
+
icon,
|
|
393
|
+
index,
|
|
394
|
+
isActive,
|
|
395
|
+
state,
|
|
396
|
+
variant
|
|
397
|
+
}
|
|
398
|
+
),
|
|
399
|
+
!isLast && /* @__PURE__ */ jsx4(TrailLine, { orientation, state })
|
|
400
|
+
]
|
|
401
|
+
}
|
|
402
|
+
),
|
|
403
|
+
/* @__PURE__ */ jsx4(
|
|
404
|
+
StepContent,
|
|
405
|
+
{
|
|
406
|
+
description,
|
|
407
|
+
isActive,
|
|
408
|
+
orientation,
|
|
409
|
+
state,
|
|
410
|
+
title
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
]
|
|
167
414
|
}
|
|
168
415
|
);
|
|
169
416
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}) =>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
Step.Label = ({
|
|
417
|
+
|
|
418
|
+
// src/Stepper.styled.ts
|
|
419
|
+
import styled5 from "@emotion/styled";
|
|
420
|
+
var StepperStyled = styled5.div`
|
|
421
|
+
display: flex;
|
|
422
|
+
|
|
423
|
+
${({ orientation = "vertical" }) => `
|
|
424
|
+
flex-direction: ${orientation === "horizontal" ? "row" : "column"};
|
|
425
|
+
width: ${orientation === "horizontal" ? "100%" : "fit-content"};
|
|
426
|
+
align-items: stretch;
|
|
427
|
+
`}
|
|
428
|
+
`;
|
|
429
|
+
|
|
430
|
+
// src/Stepper.tsx
|
|
431
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
432
|
+
var Stepper = ({
|
|
188
433
|
children,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
434
|
+
orientation = "vertical",
|
|
435
|
+
variant = "number",
|
|
436
|
+
activeStep,
|
|
437
|
+
dataTestId
|
|
193
438
|
}) => {
|
|
194
|
-
const
|
|
195
|
-
|
|
439
|
+
const childrenArray = Children.toArray(children);
|
|
440
|
+
const enhancedChildren = childrenArray.map((child, index) => {
|
|
441
|
+
var _a;
|
|
442
|
+
if (child.type !== Step) {
|
|
443
|
+
return child;
|
|
444
|
+
}
|
|
445
|
+
return cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
446
|
+
index,
|
|
447
|
+
variant,
|
|
448
|
+
orientation,
|
|
449
|
+
isLast: index === childrenArray.length - 1,
|
|
450
|
+
isActive: (_a = child.props.isActive) != null ? _a : activeStep === index
|
|
451
|
+
}));
|
|
452
|
+
});
|
|
453
|
+
return /* @__PURE__ */ jsx5(
|
|
454
|
+
StepperStyled,
|
|
455
|
+
{
|
|
456
|
+
"data-testid": dataTestId != null ? dataTestId : "stepper",
|
|
457
|
+
orientation,
|
|
458
|
+
children: enhancedChildren
|
|
459
|
+
}
|
|
460
|
+
);
|
|
196
461
|
};
|
|
197
|
-
|
|
462
|
+
Stepper.Step = Step;
|
|
198
463
|
|
|
199
464
|
// src/hooks/useStepper.ts
|
|
200
|
-
import { useCallback, useState } from "react";
|
|
201
|
-
var useStepper = () => {
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
465
|
+
import { useCallback, useState as useState2 } from "react";
|
|
466
|
+
var useStepper = (options) => {
|
|
467
|
+
const { initialStep = 0, totalSteps } = options || {};
|
|
468
|
+
const [activeStep, setActiveStep] = useState2(initialStep);
|
|
469
|
+
const [completedSteps, setCompletedSteps] = useState2(/* @__PURE__ */ new Set());
|
|
470
|
+
const isFirstStep = activeStep === 0;
|
|
471
|
+
const isLastStep = totalSteps !== void 0 ? activeStep === totalSteps - 1 : false;
|
|
472
|
+
const canGoNext = totalSteps !== void 0 ? activeStep < totalSteps - 1 : true;
|
|
473
|
+
const canGoBack = activeStep > 0;
|
|
474
|
+
const handleNext = useCallback(() => {
|
|
475
|
+
if (canGoNext) {
|
|
476
|
+
setActiveStep((prev) => prev + 1);
|
|
477
|
+
}
|
|
478
|
+
}, [canGoNext]);
|
|
479
|
+
const handleBack = useCallback(() => {
|
|
480
|
+
if (canGoBack) {
|
|
481
|
+
setActiveStep((prev) => prev - 1);
|
|
482
|
+
}
|
|
483
|
+
}, [canGoBack]);
|
|
484
|
+
const handleChangeStep = useCallback(
|
|
485
|
+
(step) => {
|
|
486
|
+
const isValidStep = step >= 0 && (totalSteps === void 0 || step < totalSteps);
|
|
487
|
+
if (isValidStep) {
|
|
488
|
+
setActiveStep(step);
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
[totalSteps]
|
|
492
|
+
);
|
|
493
|
+
const handleReset = useCallback(() => {
|
|
494
|
+
setActiveStep(initialStep);
|
|
495
|
+
setCompletedSteps(/* @__PURE__ */ new Set());
|
|
496
|
+
}, [initialStep]);
|
|
497
|
+
const markStepComplete = useCallback((step) => {
|
|
498
|
+
setCompletedSteps((prev) => new Set(prev).add(step));
|
|
499
|
+
}, []);
|
|
500
|
+
const markStepIncomplete = useCallback((step) => {
|
|
501
|
+
setCompletedSteps((prev) => {
|
|
502
|
+
const newSet = new Set(prev);
|
|
503
|
+
newSet.delete(step);
|
|
504
|
+
return newSet;
|
|
505
|
+
});
|
|
211
506
|
}, []);
|
|
507
|
+
const isStepComplete = useCallback(
|
|
508
|
+
(step) => completedSteps.has(step),
|
|
509
|
+
[completedSteps]
|
|
510
|
+
);
|
|
212
511
|
return {
|
|
213
512
|
activeStep,
|
|
214
|
-
|
|
513
|
+
isFirstStep,
|
|
514
|
+
isLastStep,
|
|
515
|
+
canGoNext,
|
|
516
|
+
canGoBack,
|
|
517
|
+
completedSteps,
|
|
215
518
|
handleNext,
|
|
216
|
-
handleBack
|
|
519
|
+
handleBack,
|
|
520
|
+
handleChangeStep,
|
|
521
|
+
handleReset,
|
|
522
|
+
markStepComplete,
|
|
523
|
+
markStepIncomplete,
|
|
524
|
+
isStepComplete
|
|
217
525
|
};
|
|
218
526
|
};
|
|
219
527
|
export {
|
|
220
|
-
|
|
221
|
-
Step_default as Step,
|
|
528
|
+
Step,
|
|
222
529
|
Stepper,
|
|
223
530
|
useStepper
|
|
224
531
|
};
|