UNPKG

@hitachivantara/uikit-react-lab

Version:

Contributed React components for the NEXT UI Kit.

110 lines (109 loc) 2.68 kB
import { jsx, jsxs } from "react/jsx-runtime"; import { useState, useCallback, useEffect, useMemo } from "react"; import { useClasses } from "./Wizard.styles.js"; import { staticClasses } from "./Wizard.styles.js"; import HvWizardContext from "./WizardContext/WizardContext.js"; import { HvWizardContainer } from "./WizardContainer/WizardContainer.js"; import { HvWizardTitle } from "./WizardTitle/WizardTitle.js"; import { HvWizardContent } from "./WizardContent/WizardContent.js"; import { HvWizardActions } from "./WizardActions/WizardActions.js"; const 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), 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 } ) ] } ) }); }; export { HvWizard, staticClasses as wizardClasses };