UNPKG

@hitachivantara/uikit-react-lab

Version:

Contributed React components for the NEXT UI Kit.

109 lines (108 loc) 2.88 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const react = require("react"); const Wizard_styles = require("./Wizard.styles.cjs"); const WizardContext = require("./WizardContext/WizardContext.cjs"); const WizardContainer = require("./WizardContainer/WizardContainer.cjs"); const WizardTitle = require("./WizardTitle/WizardTitle.cjs"); const WizardContent = require("./WizardContent/WizardContent.cjs"); const WizardActions = require("./WizardActions/WizardActions.cjs"); 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 } = Wizard_styles.useClasses(classesProp); const [context, setContext] = react.useState({}); const [summary, setSummary] = react.useState(false); const [tab, setTab] = react.useState(0); const handleClose = react.useCallback( (evt, reason) => { if (reason !== "backdropClick") { onClose?.(evt, reason); } }, [onClose] ); react.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 = react.useMemo( () => ({ context, setContext, summary, setSummary, tab, setTab }), [context, setContext, summary, setSummary, tab, setTab] ); return /* @__PURE__ */ jsxRuntime.jsx(WizardContext.default.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsxs( WizardContainer.HvWizardContainer, { className: cx(classes.root, className), handleClose, open, ...others, children: [ /* @__PURE__ */ jsxRuntime.jsx( WizardTitle.HvWizardTitle, { title, hasSummary, labels, customStep } ), /* @__PURE__ */ jsxRuntime.jsx( WizardContent.HvWizardContent, { loading, fixedHeight, summaryContent, children } ), /* @__PURE__ */ jsxRuntime.jsx( WizardActions.HvWizardActions, { loading, skippable, labels, handleClose, handleSubmit } ) ] } ) }); }; exports.wizardClasses = Wizard_styles.staticClasses; exports.HvWizard = HvWizard;