UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

133 lines (124 loc) 4.59 kB
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import { Grid, Column } from '@carbon/react'; import React__default from 'react'; import { Error403SVG } from './assets/Error403SVG.js'; import { Error404SVG } from './assets/Error404SVG.js'; import { ErrorGenericSVG } from './assets/ErrorGenericSVG.js'; import PropTypes from '../../_virtual/index.js'; import cx from 'classnames'; import { getDevtoolsProps } from '../../global/js/utils/devtools.js'; import { pkg } from '../../settings.js'; var _span; // The block part of our conventional BEM class names (blockClass__E--M). const blockClass = `${pkg.prefix}--full-page-error`; const componentName = 'FullPageError'; // Default values for props const defaults = { kind: 'custom' }; /** * Display a full-page error when the requested page is unavailable to the user. * This is typically caused by issues with the requested URL or access permissions. */ let FullPageError = /*#__PURE__*/React__default.forwardRef((_ref, ref) => { let { // The component props, in alphabetical order (for consistency). children, className, description, label, kind = defaults.kind, title, // Collect any other property values passed in. ...rest } = _ref; const errorData = { 403: { svg: /*#__PURE__*/React__default.createElement(Error403SVG, { className: `${blockClass}__svg ${blockClass}__403` }) }, 404: { svg: /*#__PURE__*/React__default.createElement(Error404SVG, { className: `${blockClass}__svg ${blockClass}__404` }) }, custom: { svg: /*#__PURE__*/React__default.createElement(ErrorGenericSVG, { className: `${blockClass}__svg ${blockClass}__custom` }) } }; return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, { className: cx(blockClass, className), ref: ref, role: "main" }, getDevtoolsProps(componentName)), /*#__PURE__*/React__default.createElement("div", { className: `${blockClass}__container` }, /*#__PURE__*/React__default.createElement(Grid, { className: `${blockClass}__grid` }, /*#__PURE__*/React__default.createElement(Column, { sm: 4, md: 3, lg: 6, className: `${blockClass}__column` }, /*#__PURE__*/React__default.createElement("h1", { className: `${blockClass}__title` }, /*#__PURE__*/React__default.createElement("span", { className: `${blockClass}__label` }, _span || (_span = /*#__PURE__*/React__default.createElement("span", { "aria-hidden": "true" }, "\u21B3 ")), label), /*#__PURE__*/React__default.createElement("span", null, title)), /*#__PURE__*/React__default.createElement("p", { className: `${blockClass}__description` }, description), /*#__PURE__*/React__default.createElement("div", { className: `${blockClass}__body` }, children)), /*#__PURE__*/React__default.createElement(Column, { sm: 4, md: 5, lg: 10 }, /*#__PURE__*/React__default.createElement("div", { className: `${blockClass}__svg-container` }, errorData[kind].svg))))); }); // Return a placeholder if not released and not enabled by feature flag FullPageError = pkg.checkComponentEnabled(FullPageError, componentName); // The display name of the component, used by React. Note that displayName // is used in preference to relying on function.name. FullPageError.displayName = componentName; // The types and DocGen commentary for the component props, // in alphabetical order (for consistency). // See https://www.npmjs.com/package/prop-types#usage. FullPageError.propTypes = { /** * Provide the contents of the FullPageError. */ children: PropTypes.node, /** * Provide an optional class to be applied to the containing node. */ className: PropTypes.string, /** * String that will provide the description for the error code. <br/> * This is optional for 403 and 404 kinds, and passing this would override their default descriptions. */ description: PropTypes.string.isRequired, /** * The kind of error page to be displayed, default is custom */ kind: PropTypes.oneOf(['custom', '403', '404']), /** * String that will describe the error that occurred */ label: PropTypes.string.isRequired, /** * This will be for the main title of the FullPageError component */ title: PropTypes.string.isRequired }; export { FullPageError };