UNPKG

@amaui/ui-react

Version:
144 lines (143 loc) 8.04 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const style_react_1 = require("@amaui/style-react"); const Divider_1 = __importDefault(require("../Divider")); const Line_1 = __importDefault(require("../Line")); const utils_1 = require("../utils"); const useStyle = (0, style_react_1.style)(theme => ({ root: {}, orientation_horizontal: { width: '100%', overflow: 'auto hidden', '& > *': { flex: '0 0 auto' } }, inactive: { pointerEvents: 'none', cursor: 'default' }, divider: { margin: '0', '&.amaui-Divider-root': { transition: theme.methods.transitions.make(['background', 'width', 'height']) } }, divider_active: { '&.amaui-Divider-root': { opacity: '1' } }, divider_orientation_horizontal: { '&.amaui-Divider-root': { minWidth: '14px' } }, divider_orientation_vertical: { alignSelf: 'flex-start', transform: 'translateX(-50%)', '&.amaui-Divider-root': { minHeight: 14, marginInlineStart: '20px' } }, divider_orientation_vertical_stepDirection_column: { alignSelf: 'center', '&.amaui-Divider-root': { margin: '0px' } }, divider_active_orientation_horizontal: { '&.amaui-Divider-root': { height: '2px' } }, divider_active_orientation_vertical: { '&.amaui-Divider-root': { width: '2px' } } }), { name: 'amaui-Stepper' }); const Stepper = react_1.default.forwardRef((props_, ref) => { const theme = (0, style_react_1.useAmauiTheme)(); const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.amauiStepper) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]); const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]); const Divider = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Divider) || Divider_1.default; }, [theme]); const { gap = 2, tonal = true, color = 'default', version = 'text', iconColor = 'inverted', iconColorActive = 'primary', dividerColor = 'inverted', dividerColorActive = 'primary', active = 0, completed, stepDirection = 'row', orientation = 'horizontal', dividerActive = true, individualDividers = props.stepDirection === 'column' && orientation !== 'vertical', free, DividerProps, Component = 'div', className, style, children } = props, other = __rest(props, ["gap", "tonal", "color", "version", "iconColor", "iconColorActive", "dividerColor", "dividerColorActive", "active", "completed", "stepDirection", "orientation", "dividerActive", "individualDividers", "free", "DividerProps", "Component", "className", "style", "children"]); const { classes } = useStyle(); const steps = react_1.default.Children.toArray(children); return ((0, jsx_runtime_1.jsx)(Line, Object.assign({ ref: ref, gap: gap, direction: orientation === 'horizontal' ? 'row' : 'column', justify: 'flex-start', align: orientation === 'vertical' ? 'flex-start' : 'center', Component: Component, className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('Stepper', theme) && [ 'amaui-Stepper-root' ], className, classes.root, classes[`orientation_${orientation}`] ]), style: style }, other, { children: steps.map((item, index) => { const active_ = active === index; const other_ = {}; if ((!active_ && !free)) other_.disabled = true; return react_1.default.cloneElement(item, { step: index + 1, tonal, color, version, activeStep: active, active: active_, iconColor: item.props.iconColor !== undefined ? item.props.iconColor : iconColor, iconColorActive: item.props.iconColorActive !== undefined ? item.props.iconColorActive : iconColorActive, dividerColor: item.props.dividerColor !== undefined ? item.props.dividerColor : dividerColor, dividerColorActive: item.props.dividerColorActive !== undefined ? item.props.dividerColorActive : dividerColorActive, orientation: item.props.orientation !== undefined ? item.props.orientation : orientation, stepDirection: item.props.stepDirection !== undefined ? item.props.stepDirection : stepDirection, completed: item.props.completed !== undefined ? item.props.completed : completed === null || completed === void 0 ? void 0 : completed[index], divider: item.props.divider !== undefined ? item.props.divider : individualDividers, className: (0, style_react_1.classNames)([ (!active_ && !free) && classes.inactive ]), style: Object.assign({}, item.props.style) }); }) .flatMap((item, index) => { const active_ = active >= index + 1; const values = [item]; if (!individualDividers && index !== children.length - 1) values.push((0, jsx_runtime_1.jsx)(Divider, Object.assign({ orientation: orientation, color: active_ ? dividerColorActive : dividerColor, flex: true }, DividerProps, { className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('Stepper', theme) && [ 'amaui-Stepper-divider', active_ && dividerActive && `amaui-Stepper-divider-active` ], DividerProps === null || DividerProps === void 0 ? void 0 : DividerProps.className, classes.divider, classes[`divider_orientation_${orientation}`], classes[`divider_orientation_${orientation}_stepDirection_${stepDirection}`], active_ && dividerActive && [ classes.divider_active, classes[`divider_active_orientation_${orientation}`] ] ]) }))); return values; }) .map((item, index) => (react_1.default.cloneElement(item, { key: index }))) }))); }); Stepper.displayName = 'amaui-Stepper'; exports.default = Stepper;