@hitachivantara/uikit-react-lab
Version:
Contributed React components to UI Kit by the community.
87 lines (86 loc) • 2.24 kB
JavaScript
import { useClasses } from "./Wizard.styles.js";
import HvWizardContext from "./WizardContext/WizardContext.js";
import { HvWizardActions } from "./WizardActions/WizardActions.js";
import { HvWizardContainer } from "./WizardContainer/WizardContainer.js";
import { HvWizardContent } from "./WizardContent/WizardContent.js";
import { HvWizardTitle } from "./WizardTitle/WizardTitle.js";
import { useCallback, useEffect, useMemo, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/Wizard/Wizard.tsx
var HvWizard = ({ className, children, onClose, handleSubmit, title, open, skippable = true, loading = false, hasSummary = false, summaryContent, labels = {
cancel: "Cancel",
next: "Next",
previous: "Previous",
skip: "Skip",
submit: "Submit",
summary: "Summary"
}, fixedHeight = false, customStep, classes: classesProp, ...others }) => {
const { classes, cx } = useClasses(classesProp);
const [context, setContext] = useState({});
const [summary, setSummary] = useState(false);
const [tab, setTab] = useState(0);
const handleClose = useCallback((evt, reason) => {
if (reason !== "backdropClick") onClose?.(evt, reason);
}, [onClose]);
useEffect(() => {
return () => {
if (!open) {
setContext((c) => Object.entries(c).reduce((acc, [key, child]) => {
acc[+key] = {
...child,
touched: false
};
return acc;
}, {}));
setTab(0);
}
};
}, [open]);
const value = useMemo(() => ({
context,
setContext,
summary,
setSummary,
tab,
setTab
}), [
context,
setContext,
summary,
setSummary,
tab,
setTab
]);
return /* @__PURE__ */ jsx(HvWizardContext.Provider, {
value,
children: /* @__PURE__ */ jsxs(HvWizardContainer, {
className: cx(classes.root, className),
onClose: handleClose,
open,
...others,
children: [
/* @__PURE__ */ jsx(HvWizardTitle, {
title,
hasSummary,
labels,
customStep
}),
/* @__PURE__ */ jsx(HvWizardContent, {
loading,
fixedHeight,
summaryContent,
children
}),
/* @__PURE__ */ jsx(HvWizardActions, {
loading,
skippable,
labels,
handleClose,
handleSubmit
})
]
})
});
};
//#endregion
export { HvWizard };