@onesy/ui-react
Version:
UI for React
305 lines (304 loc) • 11.7 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _compilerRuntime = require("react/compiler-runtime");
var _react = _interopRequireDefault(require("react"));
var _utils = require("@onesy/utils");
var _styleReact = require("@onesy/style-react");
var _Line = _interopRequireDefault(require("../Line"));
var _Surface = _interopRequireDefault(require("../Surface"));
var _Type = _interopRequireDefault(require("../Type"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
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) { (0, _defineProperty2.default)(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; }
const useStyle = (0, _styleReact.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: 'onesy-TopAppBar'
});
const TopAppBar = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3;
const $ = (0, _compilerRuntime.c)(24);
const theme = (0, _styleReact.useOnesyTheme)();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesyTopAppBar) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
const Surface = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Surface) || _Surface.default;
const Type = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Type) || _Type.default;
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 = (0, _objectWithoutProperties2.default)(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.default.Children.toArray(start_).map((item, index) => /*#__PURE__*/_react.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.default.Children.toArray(end_).map((item_0, index_0) => /*#__PURE__*/_react.default.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 = (0, _styleReact.classNames)([(0, _utils2.staticClassName)("TopAppBar", theme) && ["onesy-TopAppBar-title"], classes.title, classes[`title_version_${version}`], version === "small" && !start.length && classes.title_no_start]);
const classNameTitleMedium = (0, _styleReact.classNames)([(0, _utils2.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 = (0, _utils.is)("simple", title_) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: "t1",
className: classNameTitle,
children: title_
}) : title_ && /*#__PURE__*/_react.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.is)("simple", title_) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
version: version === "medium" ? "h3" : "h2",
className: classNameTitleMedium,
children: title_
}) : title_ && /*#__PURE__*/_react.default.cloneElement(title_, {
tonal: title_.props.tonal !== undefined ? title_.props.tonal : tonal,
color: title_.props.color !== undefined ? title_.props.color : "inherit",
className: classNameTitleMedium
});
}
}
const t6 = (0, _styleReact.classNames)([(0, _utils2.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 = (0, _styleReact.classNames)([(0, _utils2.staticClassName)("TopAppBar", theme) && ["onesy-TopAppBar-wrapper"], WrapperProps === null || WrapperProps === void 0 ? void 0 : 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__*/(0, _jsxRuntime.jsx)(Line, {
direction: "row",
align: "center",
justify: "flex-start",
gap: 0,
className: (0, _styleReact.classNames)([(0, _utils2.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__*/(0, _jsxRuntime.jsx)(Line, {
direction: "row",
align: "center",
justify: "flex-end",
gap: 0,
className: (0, _styleReact.classNames)([(0, _utils2.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__*/(0, _jsxRuntime.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__*/(0, _jsxRuntime.jsx)(Line, {
justify: "flex-end",
gap: 0,
children: title
});
$[20] = Line;
$[21] = title;
$[22] = version;
$[23] = t16;
} else {
t16 = $[23];
}
return /*#__PURE__*/(0, _jsxRuntime.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';
var _default = exports.default = TopAppBar;