oa-componentbook 1.0.1-stage.348 → 1.0.1-stage.349
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.
|
@@ -37,7 +37,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
37
37
|
/**
|
|
38
38
|
* ProgressiveStepsWidget: Advanced progressive question stepper with answer capturing
|
|
39
39
|
* - Shows questions progressively as user answers previous ones
|
|
40
|
-
* - Handles different answer types (
|
|
40
|
+
* - Handles different answer types (singleSelect, text, upload, etc.)
|
|
41
41
|
* - Manages internal state and emits complete answers
|
|
42
42
|
* - Uses the original CustomSteps component for step display
|
|
43
43
|
*/
|
|
@@ -57,16 +57,6 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
57
57
|
const [visibleSteps, setVisibleSteps] = (0, _react.useState)(1);
|
|
58
58
|
const steps = (data === null || data === void 0 ? void 0 : data.steps) || [];
|
|
59
59
|
|
|
60
|
-
// Helper function to find step index by ID
|
|
61
|
-
const findStepIndexById = stepId => {
|
|
62
|
-
return steps.findIndex(step => (step.key || steps.indexOf(step)) === stepId);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Helper function to find step by ID
|
|
66
|
-
const findStepById = stepId => {
|
|
67
|
-
return steps.find(step => (step.key || steps.indexOf(step)) === stepId);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
60
|
// Update current step when external prop changes
|
|
71
61
|
(0, _react.useEffect)(() => {
|
|
72
62
|
if (externalCurrent !== undefined) {
|
|
@@ -83,7 +73,7 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
83
73
|
|
|
84
74
|
// Calculate visible steps based on current step
|
|
85
75
|
(0, _react.useEffect)(() => {
|
|
86
|
-
//
|
|
76
|
+
// Show current step + 1 (for the disabled next step)
|
|
87
77
|
const maxVisible = Math.min(currentStep + 2, steps.length);
|
|
88
78
|
setVisibleSteps(maxVisible);
|
|
89
79
|
}, [currentStep, steps.length]);
|
|
@@ -130,7 +120,7 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
130
120
|
const stepId = step.key || stepIndex;
|
|
131
121
|
const currentAnswer = answers[stepId];
|
|
132
122
|
switch (answerType) {
|
|
133
|
-
case '
|
|
123
|
+
case 'singleSelect':
|
|
134
124
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
135
125
|
style: {
|
|
136
126
|
display: 'flex',
|
|
@@ -144,6 +134,24 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
144
134
|
label: option.label || option,
|
|
145
135
|
"data-test": dataTest ? "".concat(dataTest, "--button-").concat(stepIndex, "-").concat(idx) : undefined
|
|
146
136
|
})));
|
|
137
|
+
case 'button':
|
|
138
|
+
return /*#__PURE__*/_react.default.createElement("div", null, answerOptions === null || answerOptions === void 0 ? void 0 : answerOptions.map((option, idx) => /*#__PURE__*/_react.default.createElement(_CustomButton.default, {
|
|
139
|
+
key: idx,
|
|
140
|
+
type: option.type || 'primary',
|
|
141
|
+
onClick: () => {
|
|
142
|
+
// Execute custom click function if provided
|
|
143
|
+
if (option.onClick) {
|
|
144
|
+
option.onClick(option.value || option, stepIndex, answers);
|
|
145
|
+
}
|
|
146
|
+
// Optionally also save the answer if needed
|
|
147
|
+
if (option.saveAnswer !== false) {
|
|
148
|
+
handleAnswer(stepIndex, option.value || option);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
label: option.label || option,
|
|
152
|
+
size: option.size || 'default',
|
|
153
|
+
"data-test": dataTest ? "".concat(dataTest, "--button-").concat(stepIndex, "-").concat(idx) : undefined
|
|
154
|
+
})));
|
|
147
155
|
case 'custom':
|
|
148
156
|
// Render custom component with props for integration
|
|
149
157
|
if (customComponent) {
|
|
@@ -275,7 +283,7 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
275
283
|
return steps.map((step, stepIndex) => {
|
|
276
284
|
const stepId = step.key || stepIndex;
|
|
277
285
|
const isActive = stepIndex === currentStep;
|
|
278
|
-
const isCompleted = stepIndex < currentStep
|
|
286
|
+
const isCompleted = stepIndex < currentStep && answers[stepId] !== undefined;
|
|
279
287
|
const isDisabled = stepIndex > currentStep;
|
|
280
288
|
const isVisible = stepIndex < visibleSteps;
|
|
281
289
|
const hasAnswer = answers[stepId] !== undefined;
|
|
@@ -326,7 +334,6 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
326
334
|
return {
|
|
327
335
|
key: step.key || stepIndex,
|
|
328
336
|
title: stepContent,
|
|
329
|
-
status: isCompleted ? 'finish' : isActive ? 'process' : isDisabled ? 'wait' : 'wait',
|
|
330
337
|
disabled: isDisabled
|
|
331
338
|
};
|
|
332
339
|
}).filter(Boolean); // Remove null entries
|
|
@@ -354,7 +361,7 @@ ProgressiveStepsWidget.propTypes = {
|
|
|
354
361
|
key: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
355
362
|
title: _propTypes.default.node,
|
|
356
363
|
description: _propTypes.default.node,
|
|
357
|
-
answerType: _propTypes.default.oneOf(['
|
|
364
|
+
answerType: _propTypes.default.oneOf(['singleSelect', 'button', 'paymentOptions', 'text', 'textarea', 'upload', 'radio', 'checkbox', 'select', 'custom']),
|
|
358
365
|
answerOptions: _propTypes.default.array,
|
|
359
366
|
placeholder: _propTypes.default.string,
|
|
360
367
|
customComponent: _propTypes.default.elementType,
|
|
@@ -373,8 +380,6 @@ ProgressiveStepsWidget.propTypes = {
|
|
|
373
380
|
initialAnswers: _propTypes.default.object,
|
|
374
381
|
onComplete: _propTypes.default.func,
|
|
375
382
|
onStepChange: _propTypes.default.func,
|
|
376
|
-
showBackButton: _propTypes.default.bool,
|
|
377
|
-
onBack: _propTypes.default.func,
|
|
378
383
|
style: _propTypes.default.object
|
|
379
384
|
};
|
|
380
385
|
ProgressiveStepsWidget.defaultProps = {
|
|
@@ -386,8 +391,6 @@ ProgressiveStepsWidget.defaultProps = {
|
|
|
386
391
|
initialAnswers: {},
|
|
387
392
|
onComplete: undefined,
|
|
388
393
|
onStepChange: undefined,
|
|
389
|
-
showBackButton: false,
|
|
390
|
-
onBack: undefined,
|
|
391
394
|
style: {}
|
|
392
395
|
};
|
|
393
396
|
var _default = exports.default = ProgressiveStepsWidget;
|