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. */ 'use strict'; var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var react = require('@carbon/react'); var React = require('react'); var Error403SVG = require('./assets/Error403SVG.js'); var Error404SVG = require('./assets/Error404SVG.js'); var ErrorGenericSVG = require('./assets/ErrorGenericSVG.js'); var index = require('../../_virtual/index.js'); var cx = require('classnames'); var devtools = require('../../global/js/utils/devtools.js'); var settings = require('../../settings.js'); var _span; // The block part of our conventional BEM class names (blockClass__E--M). const blockClass = `${settings.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. */ exports.FullPageError = /*#__PURE__*/React.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.createElement(Error403SVG.Error403SVG, { className: `${blockClass}__svg ${blockClass}__403` }) }, 404: { svg: /*#__PURE__*/React.createElement(Error404SVG.Error404SVG, { className: `${blockClass}__svg ${blockClass}__404` }) }, custom: { svg: /*#__PURE__*/React.createElement(ErrorGenericSVG.ErrorGenericSVG, { className: `${blockClass}__svg ${blockClass}__custom` }) } }; return /*#__PURE__*/React.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, { className: cx(blockClass, className), ref: ref, role: "main" }, devtools.getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("div", { className: `${blockClass}__container` }, /*#__PURE__*/React.createElement(react.Grid, { className: `${blockClass}__grid` }, /*#__PURE__*/React.createElement(react.Column, { sm: 4, md: 3, lg: 6, className: `${blockClass}__column` }, /*#__PURE__*/React.createElement("h1", { className: `${blockClass}__title` }, /*#__PURE__*/React.createElement("span", { className: `${blockClass}__label` }, _span || (_span = /*#__PURE__*/React.createElement("span", { "aria-hidden": "true" }, "\u21B3 ")), label), /*#__PURE__*/React.createElement("span", null, title)), /*#__PURE__*/React.createElement("p", { className: `${blockClass}__description` }, description), /*#__PURE__*/React.createElement("div", { className: `${blockClass}__body` }, children)), /*#__PURE__*/React.createElement(react.Column, { sm: 4, md: 5, lg: 10 }, /*#__PURE__*/React.createElement("div", { className: `${blockClass}__svg-container` }, errorData[kind].svg))))); }); // Return a placeholder if not released and not enabled by feature flag exports.FullPageError = settings.pkg.checkComponentEnabled(exports.FullPageError, componentName); // The display name of the component, used by React. Note that displayName // is used in preference to relying on function.name. exports.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. exports.FullPageError.propTypes = { /** * Provide the contents of the FullPageError. */ children: index.default.node, /** * Provide an optional class to be applied to the containing node. */ className: index.default.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: index.default.string.isRequired, /** * The kind of error page to be displayed, default is custom */ kind: index.default.oneOf(['custom', '403', '404']), /** * String that will describe the error that occurred */ label: index.default.string.isRequired, /** * This will be for the main title of the FullPageError component */ title: index.default.string.isRequired };