UNPKG

@amaui/ui-react

Version:
201 lines (200 loc) 10.2 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 utils_1 = require("@amaui/utils"); const style_react_1 = require("@amaui/style-react"); const Line_1 = __importDefault(require("../Line")); const Surface_1 = __importDefault(require("../Surface")); const Type_1 = __importDefault(require("../Type")); const utils_2 = require("../utils"); const useStyle = (0, style_react_1.style)(theme => ({ root: { zIndex: theme.z_index.app_bar, width: '100%', paddingInline: theme.methods.space.value(0.5, 'px') }, wrapper: { width: '100%' }, // Size version_small_size_small: { height: '56px' }, version_small_size_regular: { height: '64px' }, version_small_size_large: { height: '72px' }, version_center_size_small: { height: '56px' }, version_center_size_regular: { height: '64px' }, version_center_size_large: { height: '72px' }, version_medium_size_small: { height: '104px' }, version_medium_size_regular: { height: '112px' }, version_medium_size_large: { height: '120px' }, version_large_size_small: { height: '144px' }, version_large_size_regular: { height: '152px' }, version_large_size_large: { height: '160px' }, aside: { flex: '0 0 auto', width: 'auto' }, title: { flex: '1 1 auto', textAlign: 'start', marginInline: '4px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title_version_small: { marginInline: '4px' }, title_version_center: { textAlign: 'center', marginInline: '4px' }, title_version_medium: { marginInline: '12px', marginBottom: '20px', width: 'calc(100% - 24px)' }, title_version_large: { textAlign: 'start', marginInline: '12px', marginBottom: '28px', width: 'calc(100% - 24px)' }, title_no_start: { marginInlineStart: '12px' }, position_relative: { position: 'relative' }, position_absolute: { position: 'absolute' }, position_static: { position: 'static' }, position_fixed: { position: 'fixed' }, position_sticky: { position: 'sticky', top: '8px' }, position_unset: { position: 'unset' }, center: { margin: '8px auto' }, center_absolute: { top: '8px', left: '50%', transform: 'translateX(-50%)' } }), { name: 'amaui-TopAppBar' }); const TopAppBar = 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.amauiTopAppBar) === 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 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 { tonal = true, color = 'primary', version = 'small', size = 'regular', center = true, title: title_, start: start_, end: end_, position, Component = 'div', className, children: children_ } = props, other = __rest(props, ["tonal", "color", "version", "size", "center", "title", "start", "end", "position", "Component", "className", "children"]); const { classes } = useStyle(); const start = react_1.default.Children .toArray(start_) .map((item, index) => react_1.default.cloneElement(item, { key: index, tonal: item.props.tonal !== undefined ? item.props.tonal : tonal, color: item.props.color !== undefined ? item.props.color : color, version: item.props.version !== undefined ? item.props.version : 'filled', elevation: item.props.elevation !== undefined ? item.props.elevation : false })); const end = react_1.default.Children .toArray(end_) .map((item, index) => react_1.default.cloneElement(item, { key: index, tonal: item.props.tonal !== undefined ? item.props.tonal : tonal, color: item.props.color !== undefined ? item.props.color : color, version: item.props.version !== undefined ? item.props.version : 'filled', elevation: item.props.elevation !== undefined ? item.props.elevation : false })); const classNameTitle = (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('TopAppBar', theme) && [ 'amaui-TopAppBar-title' ], classes.title, classes[`title_version_${version}`], version === 'small' && !start.length && classes.title_no_start ]); const classNameTitleMedium = (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('TopAppBar', theme) && [ 'amaui-TopAppBar-title', 'amaui-TopAppBar-title-medium' ], classes.title, classes[`title_version_${version}`] ]); let title; if (title_) { if (['small', 'center'].includes(version)) { title = (0, utils_1.is)('simple', title_) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 't1', className: classNameTitle }, { children: title_ }))) : (title_ && react_1.default.cloneElement(title_, { tonal: title_.props.tonal !== undefined ? title_.props.tonal : tonal, color: title_.props.color !== undefined ? title_.props.color : 'inherit', className: classNameTitle })); } else { title = (0, utils_1.is)('simple', title_) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: version === 'medium' ? 'h3' : 'h2', className: classNameTitleMedium }, { children: title_ }))) : (title_ && react_1.default.cloneElement(title_, { tonal: title_.props.tonal !== undefined ? title_.props.tonal : tonal, color: title_.props.color !== undefined ? title_.props.color : 'inherit', className: classNameTitleMedium })); } } return ((0, jsx_runtime_1.jsxs)(Surface, Object.assign({ ref: ref, color: color, tonal: tonal, gap: 0, justify: 'space-between', Component: Line, AdditionalProps: { Component }, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('TopAppBar', theme) && [ 'amaui-TopAppBar-root', `amaui-TopAppBar-version-${version}`, `amaui-TopAppBar-size-${size}` ], className, classes.root, position && classes[`position_${position}`], center && classes[`center${['absolute', 'fixed'].includes(position) ? '_absolute' : ''}`] ]) }, other, { children: [(0, jsx_runtime_1.jsxs)(Line, Object.assign({ direction: 'row', align: 'center', justify: 'space-between', gap: 0, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('TopAppBar', theme) && [ 'amaui-TopAppBar-wrapper' ], classes.wrapper, classes[`version_small_size_${size}`] ]) }, { children: [!!start.length && ((0, jsx_runtime_1.jsx)(Line, Object.assign({ direction: 'row', align: 'center', justify: 'flex-start', gap: 0, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('TopAppBar', theme) && [ 'amaui-TopAppBar-aside', `amaui-TopAppBar-start` ], classes.aside ]) }, { children: start }))), ['small', 'center'].includes(version) && title, !!end.length && ((0, jsx_runtime_1.jsx)(Line, Object.assign({ direction: 'row', align: 'center', justify: 'flex-end', gap: 0, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('TopAppBar', theme) && [ 'amaui-TopAppBar-aside', `amaui-TopAppBar-end` ], classes.aside ]) }, { children: end })))] })), ['medium', 'large'].includes(version) && ((0, jsx_runtime_1.jsx)(Line, Object.assign({ justify: 'flex-end', gap: 0 }, { children: title })))] }))); }); TopAppBar.displayName = 'amaui-TopAppBar'; exports.default = TopAppBar;