oa-componentbook 1.0.1-stage.347 → 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
|
*/
|
|
@@ -73,13 +73,15 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
73
73
|
|
|
74
74
|
// Calculate visible steps based on current step
|
|
75
75
|
(0, _react.useEffect)(() => {
|
|
76
|
-
//
|
|
76
|
+
// Show current step + 1 (for the disabled next step)
|
|
77
77
|
const maxVisible = Math.min(currentStep + 2, steps.length);
|
|
78
78
|
setVisibleSteps(maxVisible);
|
|
79
79
|
}, [currentStep, steps.length]);
|
|
80
80
|
const handleAnswer = (stepIndex, answer) => {
|
|
81
|
+
const step = steps[stepIndex];
|
|
82
|
+
const stepId = step.key || stepIndex;
|
|
81
83
|
const newAnswers = _objectSpread(_objectSpread({}, answers), {}, {
|
|
82
|
-
[
|
|
84
|
+
[stepId]: answer
|
|
83
85
|
});
|
|
84
86
|
setAnswers(newAnswers);
|
|
85
87
|
|
|
@@ -88,11 +90,11 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
88
90
|
const nextStep = stepIndex + 1;
|
|
89
91
|
setCurrentStep(nextStep);
|
|
90
92
|
if (onStepChange) {
|
|
91
|
-
onStepChange(nextStep, newAnswers);
|
|
93
|
+
onStepChange(nextStep, newAnswers, stepId);
|
|
92
94
|
}
|
|
93
95
|
} else if (onStepChange) {
|
|
94
96
|
// For editing previous answers, just notify about the change
|
|
95
|
-
onStepChange(currentStep, newAnswers);
|
|
97
|
+
onStepChange(currentStep, newAnswers, stepId);
|
|
96
98
|
}
|
|
97
99
|
};
|
|
98
100
|
const handleSubmit = () => {
|
|
@@ -103,7 +105,10 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
103
105
|
|
|
104
106
|
// Check if all steps are completed (including pre-populated ones)
|
|
105
107
|
const isAllStepsCompleted = () => {
|
|
106
|
-
return steps.every((
|
|
108
|
+
return steps.every((step, index) => {
|
|
109
|
+
const stepId = step.key || index;
|
|
110
|
+
return answers[stepId] !== undefined;
|
|
111
|
+
});
|
|
107
112
|
};
|
|
108
113
|
const renderAnswerInput = (step, stepIndex) => {
|
|
109
114
|
const {
|
|
@@ -112,9 +117,10 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
112
117
|
placeholder,
|
|
113
118
|
customComponent
|
|
114
119
|
} = step;
|
|
115
|
-
const
|
|
120
|
+
const stepId = step.key || stepIndex;
|
|
121
|
+
const currentAnswer = answers[stepId];
|
|
116
122
|
switch (answerType) {
|
|
117
|
-
case '
|
|
123
|
+
case 'singleSelect':
|
|
118
124
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
119
125
|
style: {
|
|
120
126
|
display: 'flex',
|
|
@@ -128,6 +134,24 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
128
134
|
label: option.label || option,
|
|
129
135
|
"data-test": dataTest ? "".concat(dataTest, "--button-").concat(stepIndex, "-").concat(idx) : undefined
|
|
130
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
|
+
})));
|
|
131
155
|
case 'custom':
|
|
132
156
|
// Render custom component with props for integration
|
|
133
157
|
if (customComponent) {
|
|
@@ -257,11 +281,12 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
257
281
|
// Prepare steps data for CustomSteps component
|
|
258
282
|
const prepareStepsForCustomSteps = () => {
|
|
259
283
|
return steps.map((step, stepIndex) => {
|
|
284
|
+
const stepId = step.key || stepIndex;
|
|
260
285
|
const isActive = stepIndex === currentStep;
|
|
261
|
-
const isCompleted = stepIndex < currentStep
|
|
286
|
+
const isCompleted = stepIndex < currentStep && answers[stepId] !== undefined;
|
|
262
287
|
const isDisabled = stepIndex > currentStep;
|
|
263
288
|
const isVisible = stepIndex < visibleSteps;
|
|
264
|
-
const hasAnswer = answers[
|
|
289
|
+
const hasAnswer = answers[stepId] !== undefined;
|
|
265
290
|
if (!isVisible) return null;
|
|
266
291
|
|
|
267
292
|
// Get dynamic content based on answer state
|
|
@@ -270,11 +295,11 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
270
295
|
const dynamicContent = step.dynamicContent;
|
|
271
296
|
|
|
272
297
|
// Check if we should show dynamic content for this answer
|
|
273
|
-
const shouldShowDynamic = typeof dynamicContent.showFor === 'function' ? dynamicContent.showFor(answers[
|
|
298
|
+
const shouldShowDynamic = typeof dynamicContent.showFor === 'function' ? dynamicContent.showFor(answers[stepId]) : dynamicContent.showFor === answers[stepId] || dynamicContent.showFor === true;
|
|
274
299
|
if (!shouldShowDynamic) return null;
|
|
275
300
|
return {
|
|
276
301
|
title: dynamicContent.title || step.title,
|
|
277
|
-
description: typeof dynamicContent.description === 'function' ? dynamicContent.description(answers[
|
|
302
|
+
description: typeof dynamicContent.description === 'function' ? dynamicContent.description(answers[stepId]) : dynamicContent.description,
|
|
278
303
|
descriptionStyle: dynamicContent.descriptionStyle,
|
|
279
304
|
hideAnswerInput: dynamicContent.hideAnswerInput || false
|
|
280
305
|
};
|
|
@@ -309,7 +334,6 @@ function ProgressiveStepsWidget(_ref) {
|
|
|
309
334
|
return {
|
|
310
335
|
key: step.key || stepIndex,
|
|
311
336
|
title: stepContent,
|
|
312
|
-
status: isCompleted ? 'finish' : isActive ? 'process' : isDisabled ? 'wait' : 'wait',
|
|
313
337
|
disabled: isDisabled
|
|
314
338
|
};
|
|
315
339
|
}).filter(Boolean); // Remove null entries
|
|
@@ -337,7 +361,7 @@ ProgressiveStepsWidget.propTypes = {
|
|
|
337
361
|
key: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
338
362
|
title: _propTypes.default.node,
|
|
339
363
|
description: _propTypes.default.node,
|
|
340
|
-
answerType: _propTypes.default.oneOf(['
|
|
364
|
+
answerType: _propTypes.default.oneOf(['singleSelect', 'button', 'paymentOptions', 'text', 'textarea', 'upload', 'radio', 'checkbox', 'select', 'custom']),
|
|
341
365
|
answerOptions: _propTypes.default.array,
|
|
342
366
|
placeholder: _propTypes.default.string,
|
|
343
367
|
customComponent: _propTypes.default.elementType,
|
|
@@ -356,8 +380,6 @@ ProgressiveStepsWidget.propTypes = {
|
|
|
356
380
|
initialAnswers: _propTypes.default.object,
|
|
357
381
|
onComplete: _propTypes.default.func,
|
|
358
382
|
onStepChange: _propTypes.default.func,
|
|
359
|
-
showBackButton: _propTypes.default.bool,
|
|
360
|
-
onBack: _propTypes.default.func,
|
|
361
383
|
style: _propTypes.default.object
|
|
362
384
|
};
|
|
363
385
|
ProgressiveStepsWidget.defaultProps = {
|
|
@@ -369,8 +391,6 @@ ProgressiveStepsWidget.defaultProps = {
|
|
|
369
391
|
initialAnswers: {},
|
|
370
392
|
onComplete: undefined,
|
|
371
393
|
onStepChange: undefined,
|
|
372
|
-
showBackButton: false,
|
|
373
|
-
onBack: undefined,
|
|
374
394
|
style: {}
|
|
375
395
|
};
|
|
376
396
|
var _default = exports.default = ProgressiveStepsWidget;
|