@amaui/ui-react
Version:
UI for React
71 lines (70 loc) • 6.47 kB
JavaScript
"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 react_router_dom_1 = require("react-router-dom");
const utils_1 = require("@amaui/utils");
const style_react_1 = require("@amaui/style-react");
const IconMaterialArrowBackW100_1 = __importDefault(require("@amaui/icons-material-rounded-react/IconMaterialArrowBackW100"));
const IconMaterialArrowForwardW100_1 = __importDefault(require("@amaui/icons-material-rounded-react/IconMaterialArrowForwardW100"));
const IconButton_1 = __importDefault(require("../IconButton"));
const Line_1 = __importDefault(require("../Line"));
const Tooltip_1 = __importDefault(require("../Tooltip"));
const Type_1 = __importDefault(require("../Type"));
const utils_2 = require("../utils");
const useStyle = (0, style_react_1.style)(theme => ({
root: {
position: 'relative',
height: '100%',
maxWidth: '1024px',
padding: theme.methods.space.value(3, 'px'),
'& .amaui-overflow-y': {
height: '0px',
flex: '1 1 auto',
overflowX: 'hidden',
overflowY: 'auto'
}
},
name: {
maxWidth: '440px'
}
}), { name: 'amaui-Page' });
const Page = 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.amauiPage) === 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 IconButton = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.IconButton) || IconButton_1.default; }, [theme]);
const Tooltip = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Tooltip) || Tooltip_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 { back, forward, noHeader, name, IconBack = IconMaterialArrowBackW100_1.default, IconForward = IconMaterialArrowForwardW100_1.default, Component = Line, className, children } = props, other = __rest(props, ["back", "forward", "noHeader", "name", "IconBack", "IconForward", "Component", "className", "children"]);
const { classes } = useStyle();
const navigate = (0, utils_1.isEnvironment)('browser') && (0, react_router_dom_1.useNavigate)();
const IconButtonProps = {
color: 'inherit'
};
const navigation = (back || forward) && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ direction: 'row', align: 'center', justify: 'space-between', fullWidth: true }, { children: [back ? ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: ((back === null || back === void 0 ? void 0 : back.name) !== undefined ? back.name : back === null || back === void 0 ? void 0 : back.label) || 'Back' }, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ onClick: () => navigate(back === null || back === void 0 ? void 0 : back.to) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconBack, {}) })) }))) : (0, jsx_runtime_1.jsx)("span", {}), forward ? ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: ((forward === null || forward === void 0 ? void 0 : forward.name) !== undefined ? forward.name : forward === null || forward === void 0 ? void 0 : forward.label) || 'Forward' }, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ onClick: () => navigate(forward === null || forward === void 0 ? void 0 : forward.to) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconForward, {}) })) }))) : (0, jsx_runtime_1.jsx)("span", {})] })));
const header = !noHeader && (navigation || name) && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 2, direction: 'column', fullWidth: true }, { children: [navigation, (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 0, direction: 'row', align: 'center', justify: 'center', fullWidth: true }, { children: (0, utils_1.is)('string', name) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 't1', color: 'inherit', align: 'center', className: classes.name }, { children: name }))) : name }))] })));
return ((0, jsx_runtime_1.jsxs)(Component, Object.assign({ ref: ref, gap: 4, direction: 'column', justify: 'unset', align: 'unset', fullWidth: true, flex: true, className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('Page', theme) && [
'amaui-Page-root'
],
className,
classes.root
]) }, other, { children: [header, (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 0, direction: 'column', justify: 'unset', align: 'unset', fullWidth: true, flex: true }, { children: children }))] })));
});
Page.displayName = 'amaui-Page';
exports.default = Page;