UNPKG

@amaui/ui-react

Version:
153 lines (152 loc) 8.41 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 Surface_1 = __importDefault(require("../Surface")); 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: { '&:last-of-type': { '& $divider': { display: 'none' } } }, orientation_vertical: { minHeight: '77px' }, orientation_horizontal: { minWidth: '114px' }, icon: { display: 'inline-block', width: '12px', height: '12px', borderRadius: theme.methods.shape.radius.value(40, 'px') }, aside_orientation_vertical: { padding: `${theme.methods.space.value(0.5, 'px')} ${theme.methods.space.value(3, 'px')}` }, aside_orientation_horizontal: { padding: `${theme.methods.space.value(3, 'px')} ${theme.methods.space.value(0.5, 'px')}` }, iconWrapper: { lineHeight: '0' }, iconWrapper_orientation_vertical: { marginBlock: '8px' }, iconWrapper_orientation_horizontal: { marginInline: '8px' }, divider: { '&.amaui-Divider-root': { margin: '0px' } }, divider_orientation_vertical: { '&.amaui-Divider-root': { width: '2px' } }, divider_orientation_horizontal: { '&.amaui-Divider-root': { height: '2px' } } }), { name: 'amaui-TimelineItem' }); const TimelineItem = 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.amauiTimelineItem) === 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 Surface = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Surface) || Surface_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 { orientation = 'vertical', start, end, DividerProps: DividerProps_ = !props.Divider ? { tonal: 'secondary', color: 'neutral' } : undefined, IconProps = !props.Icon ? { tonal: 'secondary', color: 'neutral', version: 'filled' } : undefined, Icon, Divider: Divider_, Component = 'li', className, children } = props, other = __rest(props, ["orientation", "start", "end", "DividerProps", "IconProps", "Icon", "Divider", "Component", "className", "children"]); const { classes } = useStyle(); const direction = orientation === 'vertical' ? 'row' : 'column'; const lineDirection = orientation === 'vertical' ? 'column' : 'row'; const DividerProps = Object.assign({}, DividerProps_); if (!Divider_) { DividerProps.orientation = orientation; } return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ ref: ref, gap: 0, align: 'unset', justify: 'unset', direction: direction, Component: Component, className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-root' ], className, classes.root, classes[`orientation_${orientation}`] ]) }, other, { children: [start && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-aside', 'amaui-TimelineItem-item', 'amaui-TimelineItem-start' ], classes.aside, classes.item, classes.start, classes[`aside_orientation_${orientation}`] ]) }, { children: start }))), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0, direction: lineDirection, align: 'center', justify: 'flex-start', className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-item', 'amaui-TimelineItem-middle' ], classes.item, classes.middle ]) }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-icon-wrapper' ], classes.iconWrapper, classes[`iconWrapper_orientation_${orientation}`] ]) }, { children: Icon ? Icon : ((0, jsx_runtime_1.jsx)(Surface, Object.assign({}, IconProps, { tonal: true, className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-icon' ], IconProps === null || IconProps === void 0 ? void 0 : IconProps.className, classes.icon ]) }))) })), Divider_ ? Divider_ : ((0, jsx_runtime_1.jsx)(Divider, Object.assign({}, DividerProps, { className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-divider' ], DividerProps === null || DividerProps === void 0 ? void 0 : DividerProps.className, classes.divider, classes[`divider_orientation_${orientation}`] ]), flex: true })))] })), (end || children) && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('TimelineItem', theme) && [ 'amaui-TimelineItem-aside', 'amaui-TimelineItem-item', 'amaui-TimelineItem-end' ], classes.aside, classes.item, classes.end, classes[`aside_orientation_${orientation}`] ]) }, { children: end || children })))] }))); }); TimelineItem.displayName = 'amaui-TimelineItem'; exports.default = TimelineItem;