UNPKG

@carbon/ibm-products

Version:
90 lines (88 loc) 3.89 kB
/** * Copyright IBM Corp. 2020, 2026 * * 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 { __toESM } from "../../_virtual/_rolldown/runtime.js"; import { require_classnames } from "../../node_modules/classnames/index.js"; import { pkg } from "../../settings.js"; import { getDevtoolsProps } from "../../global/js/utils/devtools.js"; import { Error403SVG } from "./assets/Error403SVG.js"; import { Error404SVG } from "./assets/Error404SVG.js"; import { ErrorGenericSVG } from "./assets/ErrorGenericSVG.js"; import React from "react"; import PropTypes from "prop-types"; import { Column, Grid } from "@carbon/react"; //#region src/components/FullPageError/FullPageError.tsx /** * Copyright IBM Corp. 2024, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ var import_classnames = /* @__PURE__ */ __toESM(require_classnames()); const blockClass = `${pkg.prefix}--full-page-error`; const componentName = "FullPageError"; 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. */ const FullPageError = React.forwardRef(({ children, className, description, label, kind = defaults.kind, title, ...rest }, ref) => { const errorData = { 403: { svg: /* @__PURE__ */ React.createElement(Error403SVG, { className: `${blockClass}__svg ${blockClass}__403` }) }, 404: { svg: /* @__PURE__ */ React.createElement(Error404SVG, { className: `${blockClass}__svg ${blockClass}__404` }) }, custom: { svg: /* @__PURE__ */ React.createElement(ErrorGenericSVG, { className: `${blockClass}__svg ${blockClass}__custom` }) } }; return /* @__PURE__ */ React.createElement("div", { ...rest, className: (0, import_classnames.default)(blockClass, className), ref, role: "main", ...getDevtoolsProps(componentName) }, /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__container` }, /* @__PURE__ */ React.createElement(Grid, { className: `${blockClass}__grid` }, /* @__PURE__ */ React.createElement(Column, { sm: 4, md: 3, lg: 6, className: `${blockClass}__column` }, /* @__PURE__ */ React.createElement("h1", { className: `${blockClass}__title` }, /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__label` }, /* @__PURE__ */ React.createElement("span", { "aria-hidden": "true" }, "↳ "), 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(Column, { sm: 4, md: 5, lg: 10 }, /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__svg-container` }, errorData[kind].svg))))); }); FullPageError.displayName = componentName; 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 }; //#endregion export { FullPageError };