UNPKG

@amaui/ui-react

Version:
71 lines 3.72 kB
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", "ButtonProps", "TypeProps", "className"]; 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 { useNavigate } from 'react-router-dom'; import { is, isEnvironment } from '@amaui/utils'; import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/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: 'amaui-NotFound' }); const NotFound = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useAmauiTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiNotFound?.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 = 'Page not found 🫠', to = '/', link = '', renderButton, fullHeight, start, end, 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) && [`amaui-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) && [`amaui-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) && [`amaui-NotFound-button`], ButtonProps?.className, classes.button]) }), "Back"), end); }); NotFound.displayName = 'amaui-NotFound'; export default NotFound;