@amaui/ui-react
Version:
UI for React
220 lines • 8.36 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
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", "Component", "className", "children"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import React from 'react';
import { is } from '@amaui/utils';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react';
import LineElement from '../Line';
import SurfaceElement from '../Surface';
import TypeElement from '../Type';
import { staticClassName } from '../utils';
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: 'amaui-TopAppBar'
});
const TopAppBar = /*#__PURE__*/React.forwardRef((props_, ref) => {
const theme = useAmauiTheme();
const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiTopAppBar?.props?.default), props_), [props_]);
const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]);
const Surface = React.useMemo(() => theme?.elements?.Surface || SurfaceElement, [theme]);
const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [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 = _objectWithoutProperties(props, _excluded);
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, 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 classNameTitle = classNames([staticClassName('TopAppBar', theme) && ['amaui-TopAppBar-title'], classes.title, classes[`title_version_${version}`], version === 'small' && !start.length && classes.title_no_start]);
const classNameTitleMedium = classNames([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 = is('simple', title_) ? /*#__PURE__*/React.createElement(Type, {
version: "t1",
className: classNameTitle
}, 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__*/React.createElement(Type, {
version: version === 'medium' ? 'h3' : 'h2',
className: classNameTitleMedium
}, 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
});
}
}
return /*#__PURE__*/React.createElement(Surface, _extends({
ref: ref,
color: color,
tonal: tonal,
gap: 0,
justify: "space-between",
Component: Line,
AdditionalProps: {
Component
},
className: classNames([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), /*#__PURE__*/React.createElement(Line, {
direction: "row",
align: "center",
justify: "space-between",
gap: 0,
className: classNames([staticClassName('TopAppBar', theme) && ['amaui-TopAppBar-wrapper'], classes.wrapper, classes[`version_small_size_${size}`]])
}, !!start.length && /*#__PURE__*/React.createElement(Line, {
direction: "row",
align: "center",
justify: "flex-start",
gap: 0,
className: classNames([staticClassName('TopAppBar', theme) && ['amaui-TopAppBar-aside', `amaui-TopAppBar-start`], classes.aside])
}, start), ['small', 'center'].includes(version) && title, !!end.length && /*#__PURE__*/React.createElement(Line, {
direction: "row",
align: "center",
justify: "flex-end",
gap: 0,
className: classNames([staticClassName('TopAppBar', theme) && ['amaui-TopAppBar-aside', `amaui-TopAppBar-end`], classes.aside])
}, end)), ['medium', 'large'].includes(version) && /*#__PURE__*/React.createElement(Line, {
justify: "flex-end",
gap: 0
}, title));
});
TopAppBar.displayName = 'amaui-TopAppBar';
export default TopAppBar;