UNPKG

@amaui/ui-react

Version:
189 lines (188 loc) 8.38 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 Type_1 = __importDefault(require("../Type")); const Surface_1 = __importDefault(require("../Surface")); const utils_1 = require("../utils"); const useStyle = (0, style_react_1.style)(theme => ({ root: { // Reset margin: '0', border: 'none', display: 'flex', flexShrink: '0', opacity: theme.palette.visual_contrast.default.opacity.divider, transition: theme.methods.transitions.make('background') }, divider_tonal: { opacity: '1' }, orientation_vertical: { margin: '0 8px', height: '100%', width: '1px' }, orientation_vertical_middle: { margin: `16px 8px`, height: `calc(100% - 32px)` }, // Orientation orientation_horizontal: { margin: '8px 0', height: '1px', width: '100%' }, orientation_horizontal_middle: { margin: `8px 16px`, width: `calc(100% - 32px)` }, rootWithChildren: { display: 'flex', opacity: '1', color: theme.palette.text.default.primary, background: 'transparent', // Reset height: 'unset', width: 'unset', margin: '0', border: 'none' }, // Orientation rootWithChildren_orientation_horizontal: { flexDirection: 'row', alignItems: 'center', width: '100%' }, rootWithChildren_orientation_horizontal_middle: { margin: `0 16px`, width: `calc(100% - 32px)` }, rootWithChildren_orientation_vertical: { flexDirection: 'column', alignItems: 'center', height: '100%' }, rootWithChildren_orientation_vertical_middle: { margin: `16px 0`, height: `calc(100% - 32px)` }, // flex flex_orientation_horizontal: { flex: '1 1 auto', width: 'auto' }, flex_orientation_vertical: { flex: '1 1 auto' }, text: { flex: '0 0 auto' }, // Orientation text_horizontal: { margin: `0 16px`, }, text_vertical: { margin: `16px 0`, }, divider: { flex: '0 1 100%', opacity: theme.palette.visual_contrast.default.opacity.divider }, // Orientation divider_orientation_horizontal: { height: '1px' }, divider_orientation_vertical: { width: '1px' }, orientation_horizontal_padding: { marginInline: '16px', width: 'calc(100% - 32px)' }, orientation_vertical_padding: { marginBlock: '16px', height: 'calc(100% - 32px)' }, color_inherit: { opacity: theme.palette.visual_contrast.default.opacity.divider, color: 'inherit', background: 'currentColor' }, inset: { marginLeft: `72px`, width: `calc(100% - 72px)` } }), { name: 'amaui-Divider' }); const Divider = 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.amauiDivider) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]); const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_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 { tonal = true, color = 'inverted', inset, middle, padding, opacity = theme.palette.visual_contrast.default.opacity.divider, alignment = 'center', orientation = 'horizontal', flex, Component: Component_ = 'hr', className, style, children } = props, other = __rest(props, ["tonal", "color", "inset", "middle", "padding", "opacity", "alignment", "orientation", "flex", "Component", "className", "style", "children"]); const { classes } = useStyle(); const styles = { root: {}, divider: {}, start: {}, end: {} }; let Component = Component_; if (children && Component === 'hr') Component = 'div'; if (alignment === 'start') styles.start.flexBasis = '15%'; if (alignment === 'end') styles.end.flexBasis = '15%'; return ((0, jsx_runtime_1.jsx)(Surface, Object.assign({ ref: ref, version: 'filled', tonal: tonal, color: color, Component: Component, className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('Divider', theme) && [ 'amaui-Divider-root' ], className, classes[children ? 'rootWithChildren' : 'root'], classes[`${children ? 'rootWithChildren_' : ''}orientation_${orientation}`], flex && classes[`flex_orientation_${orientation}`], inset && classes.inset, middle && classes[`${children ? `rootWithChildren_` : ''}orientation_${orientation}_middle`], padding && classes[`orientation_${orientation}_padding`], color === 'inherit' && classes.color_inherit, tonal && classes.divider_tonal ]), style: Object.assign(Object.assign({}, style), styles.root) }, other, { children: children && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Surface, { version: 'filled', tonal: tonal, color: color, className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('Divider', theme) && [ 'amaui-Divider-divider' ], classes.divider, classes[`divider_orientation_${orientation}`], tonal && classes.divider_tonal ]), style: Object.assign(Object.assign({}, styles.divider), styles.start) }), (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b2', className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('Divider', theme) && [ 'amaui-Divider-text' ], classes.text, classes[`text_${orientation}`] ]) }, { children: children })), (0, jsx_runtime_1.jsx)(Surface, { version: 'filled', tonal: tonal, color: color, className: (0, style_react_1.classNames)([ (0, utils_1.staticClassName)('Divider', theme) && [ 'amaui-Divider-divider' ], classes.divider, classes[`divider_orientation_${orientation}`], tonal && classes.divider_tonal ]), style: Object.assign(Object.assign({}, styles.divider), styles.end) })] }) }))); }); Divider.displayName = 'amaui-Divider'; exports.default = Divider;