UNPKG

@onesy/ui-react

Version:
125 lines 4.99 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["back", "forward", "noHeader", "name", "IconBack", "IconForward", "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 React from 'react'; import { useNavigate } from 'react-router-dom'; import { is, isEnvironment } from '@onesy/utils'; import { style as styleMethod, classNames, useOnesyTheme } from '@onesy/style-react'; import IconMaterialArrowBack from '@onesy/icons-material-rounded-react/IconMaterialArrowBackW100'; import IconMaterialArrowForward from '@onesy/icons-material-rounded-react/IconMaterialArrowForwardW100'; import IconButtonElement from '../IconButton'; import LineElement from '../Line'; import TooltipElement from '../Tooltip'; import TypeElement from '../Type'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: { position: 'relative', height: '100%', maxWidth: '1024px', padding: theme.methods.space.value(3, 'px'), '& .onesy-overflow-y': { height: '0px', flex: '1 1 auto', overflowX: 'hidden', overflowY: 'auto' } }, name: { maxWidth: '440px' } }), { name: 'onesy' }); const Page = props_ => { const theme = useOnesyTheme(); const l = theme.l; const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyPage?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const IconButton = theme?.elements?.IconButton || IconButtonElement; const Tooltip = theme?.elements?.Tooltip || TooltipElement; const Type = theme?.elements?.Type || TypeElement; const { back, forward, noHeader, name, IconBack = IconMaterialArrowBack, IconForward = IconMaterialArrowForward, Component = Line, className, children } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const navigate = isEnvironment('browser') && useNavigate(); const IconButtonProps = { color: 'inherit' }; const navigation = (back || forward) && /*#__PURE__*/_jsxs(Line, { direction: "row", align: "center", justify: "space-between", fullWidth: true, children: [back ? /*#__PURE__*/_jsx(Tooltip, { name: (back?.name !== undefined ? back.name : back?.label) || l('Back'), children: /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({ onClick: () => navigate(back?.to) }, IconButtonProps), {}, { children: /*#__PURE__*/_jsx(IconBack, {}) })) }) : /*#__PURE__*/_jsx("span", {}), forward ? /*#__PURE__*/_jsx(Tooltip, { name: (forward?.name !== undefined ? forward.name : forward?.label) || l('Forward'), children: /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({ onClick: () => navigate(forward?.to) }, IconButtonProps), {}, { children: /*#__PURE__*/_jsx(IconForward, {}) })) }) : /*#__PURE__*/_jsx("span", {})] }); const header = !noHeader && (navigation || name) && /*#__PURE__*/_jsxs(Line, { gap: 2, direction: "column", fullWidth: true, children: [navigation, /*#__PURE__*/_jsx(Line, { gap: 0, direction: "row", align: "center", justify: "center", fullWidth: true, children: is('string', name) ? /*#__PURE__*/_jsx(Type, { version: "t1", color: "inherit", align: "center", className: classes.name, children: name }) : name })] }); return /*#__PURE__*/_jsxs(Component, _objectSpread(_objectSpread({ gap: 4, direction: "column", justify: "unset", align: "unset", fullWidth: true, flex: true, className: classNames([staticClassName('Page', theme) && ['onesy-Page-root'], className, classes.root]) }, other), {}, { children: [header, /*#__PURE__*/_jsx(Line, { gap: 0, direction: "column", justify: "unset", align: "unset", fullWidth: true, flex: true, children: children })] })); }; Page.displayName = 'onesy-Page'; export default Page;