UNPKG

@onesy/ui-react

Version:
297 lines 9.85 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["tonal", "color", "version", "size", "center", "title", "start", "end", "position", "WrapperProps", "Component", "className", "children"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { c as _c } from "react/compiler-runtime"; import React from 'react'; import { is } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import LineElement from '../Line'; import SurfaceElement from '../Surface'; import TypeElement from '../Type'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(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: 'onesy-TopAppBar' }); const TopAppBar = props_ => { const $ = _c(24); const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyTopAppBar?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const Surface = theme?.elements?.Surface || SurfaceElement; const Type = theme?.elements?.Type || TypeElement; const { tonal: t0, color: t1, version: t2, size: t3, center: t4, title: title_, start: start_, end: end_, position, WrapperProps, Component: t5, className, children: children_ } = props, other = _objectWithoutProperties(props, _excluded); const tonal = t0 === undefined ? true : t0; const color = t1 === undefined ? "primary" : t1; const version = t2 === undefined ? "small" : t2; const size = t3 === undefined ? "regular" : t3; const center = t4 === undefined ? true : t4; const Component = t5 === undefined ? "div" : t5; const { classes } = useStyle(); const start = React.Children.toArray(start_).map((item, index) => /*#__PURE__*/React.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.Children.toArray(end_).map((item_0, index_0) => /*#__PURE__*/React.cloneElement(item_0, { key: index_0, tonal: item_0.props.tonal !== undefined ? item_0.props.tonal : tonal, color: item_0.props.color !== undefined ? item_0.props.color : color, version: item_0.props.version !== undefined ? item_0.props.version : "filled", elevation: item_0.props.elevation !== undefined ? item_0.props.elevation : false })); const classNameTitle = classNames([staticClassName("TopAppBar", theme) && ["onesy-TopAppBar-title"], classes.title, classes[`title_version_${version}`], version === "small" && !start.length && classes.title_no_start]); const classNameTitleMedium = classNames([staticClassName("TopAppBar", theme) && ["onesy-TopAppBar-title", "onesy-TopAppBar-title-medium"], classes.title, classes[`title_version_${version}`]]); let title; if (title_) { if (["small", "center"].includes(version)) { title = is("simple", title_) ? /*#__PURE__*/_jsx(Type, { version: "t1", className: classNameTitle, children: title_ }) : title_ && /*#__PURE__*/React.cloneElement(title_, { tonal: title_.props.tonal !== undefined ? title_.props.tonal : tonal, color: title_.props.color !== undefined ? title_.props.color : "inherit", className: classNameTitle }); } else { title = is("simple", title_) ? /*#__PURE__*/_jsx(Type, { version: version === "medium" ? "h3" : "h2", className: classNameTitleMedium, children: title_ }) : title_ && /*#__PURE__*/React.cloneElement(title_, { tonal: title_.props.tonal !== undefined ? title_.props.tonal : tonal, color: title_.props.color !== undefined ? title_.props.color : "inherit", className: classNameTitleMedium }); } } const t6 = classNames([staticClassName("TopAppBar", theme) && ["onesy-TopAppBar-root", `onesy-TopAppBar-version-${version}`, `onesy-TopAppBar-size-${size}`], className, classes.root, position && classes[`position_${position}`], center && classes[`center${["absolute", "fixed"].includes(position) ? "_absolute" : ""}`]]); const t7 = "row"; const t8 = "center"; const t9 = "space-between"; const t10 = 0; const t11 = classNames([staticClassName("TopAppBar", theme) && ["onesy-TopAppBar-wrapper"], WrapperProps?.className, classes.wrapper, classes[`version_small_size_${size}`]]); let t12; if ($[0] !== Line || $[1] !== classes.aside || $[2] !== start || $[3] !== theme) { t12 = !!start.length && /*#__PURE__*/_jsx(Line, { direction: "row", align: "center", justify: "flex-start", gap: 0, className: classNames([staticClassName("TopAppBar", theme) && ["onesy-TopAppBar-aside", "onesy-TopAppBar-start"], classes.aside]), children: start }); $[0] = Line; $[1] = classes.aside; $[2] = start; $[3] = theme; $[4] = t12; } else { t12 = $[4]; } let t13; if ($[5] !== title || $[6] !== version) { t13 = ["small", "center"].includes(version) && title; $[5] = title; $[6] = version; $[7] = t13; } else { t13 = $[7]; } let t14; if ($[8] !== Line || $[9] !== classes.aside || $[10] !== end || $[11] !== theme) { t14 = !!end.length && /*#__PURE__*/_jsx(Line, { direction: "row", align: "center", justify: "flex-end", gap: 0, className: classNames([staticClassName("TopAppBar", theme) && ["onesy-TopAppBar-aside", "onesy-TopAppBar-end"], classes.aside]), children: end }); $[8] = Line; $[9] = classes.aside; $[10] = end; $[11] = theme; $[12] = t14; } else { t14 = $[12]; } let t15; if ($[13] !== Line || $[14] !== WrapperProps || $[15] !== t11 || $[16] !== t12 || $[17] !== t13 || $[18] !== t14) { t15 = /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({ direction: t7, align: t8, justify: t9, gap: t10 }, WrapperProps), {}, { className: t11, children: [t12, t13, t14] })); $[13] = Line; $[14] = WrapperProps; $[15] = t11; $[16] = t12; $[17] = t13; $[18] = t14; $[19] = t15; } else { t15 = $[19]; } let t16; if ($[20] !== Line || $[21] !== title || $[22] !== version) { t16 = ["medium", "large"].includes(version) && /*#__PURE__*/_jsx(Line, { justify: "flex-end", gap: 0, children: title }); $[20] = Line; $[21] = title; $[22] = version; $[23] = t16; } else { t16 = $[23]; } return /*#__PURE__*/_jsxs(Surface, _objectSpread(_objectSpread({ color: color, tonal: tonal, gap: 0, justify: "space-between", Component: Line, AdditionalProps: { Component }, className: t6 }, other), {}, { children: [t15, t16] })); }; TopAppBar.displayName = 'onesy-TopAppBar'; export default TopAppBar;