UNPKG

@yamada-ui/stepper

Version:

Yamada UI stepper component

205 lines (200 loc) • 6.89 kB
"use client" "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/step-status.tsx var step_status_exports = {}; __export(step_status_exports, { StepIcon: () => StepIcon, StepNumber: () => StepNumber, StepStatus: () => StepStatus }); module.exports = __toCommonJS(step_status_exports); var import_core2 = require("@yamada-ui/core"); var import_icon = require("@yamada-ui/icon"); var import_utils3 = require("@yamada-ui/utils"); // src/step.tsx var import_core = require("@yamada-ui/core"); var import_utils2 = require("@yamada-ui/utils"); // src/use-stepper.ts var import_use_descendant = require("@yamada-ui/use-descendant"); var import_utils = require("@yamada-ui/utils"); var import_react = require("react"); var { DescendantsContextProvider: StepperDescendantsContextProvider, useDescendant: useStepperDescendant, useDescendants: useStepperDescendants } = (0, import_use_descendant.createDescendant)(); var [StepperProvider, useStepperContext] = (0, import_utils.createContext)({ name: "StepperContext", errorMessage: `useStepperContext returned is 'undefined'. Seems you forgot to wrap the components in "<Stepper />"` }); var useStep = () => { var _a; const { getStepStatus, orientation } = useStepperContext(); const { descendants, index, register } = useStepperDescendant(); const isFirst = index === 0; const isLast = index === ((_a = descendants.lastValue()) == null ? void 0 : _a.index); const status = getStepStatus(index); const getStepProps = (0, import_react.useCallback)( (props = {}, ref = null) => ({ ...props, ref: (0, import_utils.mergeRefs)(ref, register), "data-orientation": orientation, "data-status": status }), [orientation, register, status] ); return { index, isFirst, isLast, status, getStepProps }; }; // src/step.tsx var import_jsx_runtime = require("react/jsx-runtime"); var [StepProvider, useStepContext] = (0, import_utils2.createContext)({ name: "StepperContext", errorMessage: `useStepContext returned is 'undefined'. Seems you forgot to wrap the components in "<Step />"` }); var Step = (0, import_core.forwardRef)( ({ className, ...rest }, ref) => { const { orientation, showLastSeparator, styles } = useStepperContext(); const { index, isFirst, isLast, status, getStepProps } = useStep(); const css = { ...styles.step }; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StepProvider, { value: { index, isFirst, isLast, status }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_core.ui.div, { className: (0, import_utils2.cx)("ui-step", className), "data-orientation": orientation, "data-stretch": (0, import_utils2.dataAttr)(showLastSeparator), __css: css, ...getStepProps(rest, ref) } ) }); } ); Step.displayName = "Step"; Step.__ui__ = "Step"; // src/step-status.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var StepStatus = (0, import_core2.forwardRef)( ({ className, active = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StepNumber, {}), complete = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StepIcon, {}), incomplete = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StepNumber, {}), ...rest }, ref) => { const { styles } = useStepperContext(); const { status, ...props } = useStepContext(); const css = { ...styles.status }; let component = null; switch (status) { case "complete": component = (0, import_utils3.runIfFunc)(complete, props); break; case "incomplete": component = (0, import_utils3.runIfFunc)(incomplete, props); break; case "active": component = (0, import_utils3.runIfFunc)(active, props); break; } return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( import_core2.ui.div, { ref, className: (0, import_utils3.cx)("ui-step__status", className), "data-status": status, __css: css, ...rest, children: component ? component : null } ); } ); StepStatus.displayName = "StepStatus"; StepStatus.__ui__ = "StepStatus"; var StepNumber = (0, import_core2.forwardRef)( ({ className, children, ...rest }, ref) => { const { styles } = useStepperContext(); const { index, status } = useStepContext(); const css = { ...styles.number }; return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( import_core2.ui.div, { ref, className: (0, import_utils3.cx)("ui-step__number", className), "data-status": status, __css: css, ...rest, children: children || index + 1 } ); } ); StepNumber.displayName = "StepNumber"; StepNumber.__ui__ = "StepNumber"; var StepIcon = (0, import_core2.forwardRef)( ({ className, ...rest }, ref) => { const { styles } = useStepperContext(); const { status } = useStepContext(); const as = status === "complete" ? CheckIcon : void 0; const css = { ...styles.icon }; return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( import_icon.Icon, { ref, as, className: (0, import_utils3.cx)("ui-step__icon", className), "data-status": status, __css: css, ...rest } ); } ); StepIcon.displayName = "StepIcon"; StepIcon.__ui__ = "StepIcon"; var CheckIcon = (props) => { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "svg", { "aria-hidden": "true", fill: "currentColor", height: "1em", stroke: "currentColor", strokeWidth: "0", viewBox: "0 0 20 20", width: "1em", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "path", { clipRule: "evenodd", d: "M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z", fillRule: "evenodd" } ) } ); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { StepIcon, StepNumber, StepStatus }); //# sourceMappingURL=step-status.js.map