@homebound/beam 2.137.9 → 2.138.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.
|
@@ -10,19 +10,14 @@ function Stepper({ steps, currentStep, onChange }) {
|
|
|
10
10
|
if (steps.length === 0) {
|
|
11
11
|
throw new Error("Stepper must be initialized with at least one step");
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const currentStepIndex = steps.findIndex((s) => s.value === currentStep) || 0;
|
|
16
|
-
if (currentStepIndex > progressBarStep) {
|
|
17
|
-
setProgressBarStep(currentStepIndex);
|
|
18
|
-
}
|
|
19
|
-
}, [currentStep]);
|
|
13
|
+
// calc progress based on last completed step - return -1 when no steps completed
|
|
14
|
+
const lastCompletedStep = steps.map((step) => step.state).lastIndexOf("complete");
|
|
20
15
|
return ((0, jsx_runtime_1.jsxs)("nav", Object.assign({ "aria-label": "steps", css: Css_1.Css.df.fdc.$ }, { children: [(0, jsx_runtime_1.jsx)("ol", Object.assign({ css: Css_1.Css.listReset.df.$ }, { children: steps.map((step) => {
|
|
21
16
|
const isCurrent = currentStep === step.value;
|
|
22
17
|
return ((0, jsx_runtime_1.jsx)("li", Object.assign({ css: Css_1.Css.df.fdc.wPx(200).$, "aria-current": isCurrent }, { children: (0, jsx_runtime_1.jsx)(StepButton, Object.assign({}, step, { onClick: () => onChange(step.value), isCurrent: isCurrent }), void 0) }), step.label));
|
|
23
18
|
}) }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.mt1.bgGray300.hPx(4).w(`${steps.length * 200}px`).$ }, { children: (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.bgLightBlue600
|
|
24
19
|
.add("transition", "width 200ms")
|
|
25
|
-
.h100.w(`${((
|
|
20
|
+
.h100.w(`${((lastCompletedStep + 1) / steps.length) * 100}%`).$ }, void 0) }), void 0)] }), void 0));
|
|
26
21
|
}
|
|
27
22
|
exports.Stepper = Stepper;
|
|
28
23
|
function StepButton({ label, disabled, state, isCurrent, onClick }) {
|
|
@@ -45,9 +45,9 @@ function StepperForm({ formState }) {
|
|
|
45
45
|
const onBack = (0, react_1.useCallback)(() => {
|
|
46
46
|
const currentStepIndex = steps.findIndex((s) => s.value === currentStep);
|
|
47
47
|
setActiveStep(steps[currentStepIndex === 0 ? 0 : currentStepIndex - 1].value);
|
|
48
|
-
}, [currentStep]);
|
|
48
|
+
}, [currentStep, steps]);
|
|
49
49
|
(0, react_1.useEffect)(() => {
|
|
50
|
-
const disposer = (0, mobx_1.reaction)(() => [formState.firstName.valid && formState.lastName.valid, formState.books.valid], ([step1Valid, step2Valid], [wasStep1Valid, wasStep2Valid]) => {
|
|
50
|
+
const disposer = (0, mobx_1.reaction)(() => [formState.firstName.valid && formState.lastName.valid, formState.books.valid, formState.birthday.valid], ([step1Valid, step2Valid, step3Valid], [wasStep1Valid, wasStep2Valid, wasStep3Valid]) => {
|
|
51
51
|
if (step1Valid && step1Valid !== wasStep1Valid) {
|
|
52
52
|
setStep("books", { disabled: !step1Valid });
|
|
53
53
|
return;
|
|
@@ -56,10 +56,14 @@ function StepperForm({ formState }) {
|
|
|
56
56
|
setStep("misc", { disabled: !step2Valid });
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
+
if (step3Valid && step3Valid !== wasStep3Valid) {
|
|
60
|
+
setStep("misc", { state: "complete" });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
59
63
|
});
|
|
60
64
|
// Return the disposer in order to clean up useEffect.
|
|
61
65
|
return disposer;
|
|
62
|
-
}, [setStep]);
|
|
66
|
+
}, [setStep, formState.birthday.valid, formState.books.valid, formState.firstName.valid, formState.lastName.valid]);
|
|
63
67
|
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(Stepper_1.Stepper, { steps: steps, currentStep: currentStep, onChange: setActiveStep }, void 0), (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.mt2.$ }, { children: [currentStep === "author" && (0, jsx_runtime_1.jsx)(AuthorDetails, { formState: formState, onNext: onNext }, void 0), currentStep === "books" && (0, jsx_runtime_1.jsx)(BookList, { formState: formState, onNext: onNext, onBack: onBack }, void 0), currentStep === "misc" && (0, jsx_runtime_1.jsx)(MiscAuthorDetails, { formState: formState, onBack: onBack }, void 0)] }), void 0)] }, void 0));
|
|
64
68
|
}
|
|
65
69
|
function AuthorDetails({ formState, onNext }) {
|