@onesy/ui-react
Version:
UI for React
73 lines • 3.64 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 = ["name", "to", "link", "renderButton", "fullHeight", "start", "end", "buttonText", "ButtonProps", "TypeProps", "className"];
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 { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import SectionElement from '../Section';
import TypeElement from '../Type';
import ButtonElement from '../Button';
import { staticClassName } from '../utils';
const useStyle = styleMethod(theme => ({
root: {},
fullHeight: {
height: '100vh'
}
}), {
name: 'onesy-NotFound'
});
const NotFound = /*#__PURE__*/React.forwardRef((props_, ref) => {
const theme = useOnesyTheme();
const l = theme.l;
const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyNotFound?.props?.default), props_), [props_]);
const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]);
const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]);
const Button = React.useMemo(() => theme?.elements?.Button || ButtonElement, [theme]);
const {
name = l('Page not found'),
to = '/',
link = '',
renderButton,
fullHeight,
start,
end,
buttonText = l('Back'),
ButtonProps,
TypeProps,
className
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const navigate = isEnvironment('browser') && useNavigate();
const onTo = React.useCallback(() => {
if (link) window.open(link, 'blank');else navigate(to);
}, [to, link]);
return /*#__PURE__*/React.createElement(Section, _extends({
ref: ref,
flex: true,
fullWidth: true,
align: "center",
justify: "center",
className: classNames([staticClassName('NotFound', theme) && [`onesy-NotFound-root`], className, classes.root, fullHeight && classes.fullHeight])
}, other), start, /*#__PURE__*/React.createElement(Type, _extends({
version: "h3",
align: "center"
}, TypeProps, {
className: classNames([staticClassName('NotFound', theme) && [`onesy-NotFound-type`], TypeProps?.className])
}), name), is('function', renderButton) ? renderButton({}) : /*#__PURE__*/React.createElement(Button, _extends({
color: "default",
version: "outlined",
size: "small",
onClick: onTo
}, ButtonProps, {
className: classNames([staticClassName('NotFound', theme) && [`onesy-NotFound-button`], ButtonProps?.className, classes.button])
}), buttonText), end);
});
NotFound.displayName = 'onesy-NotFound';
export default NotFound;