UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

86 lines (85 loc) 2.88 kB
"use client"; import React from 'react'; import clsx from 'clsx'; import Context from "../../shared/Context.js"; import { processChildren, extendPropsWithContext } from "../../shared/component-helper.js"; import { applySpacing } from "../space/SpacingUtils.js"; import Anchor from "../anchor/Anchor.js"; import Skeleton from "../skeleton/Skeleton.js"; import { H1, P } from "../../elements/index.js"; import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const defaultProps = { statusCode: '404' }; export default function GlobalError(localProps) { const context = React.useContext(Context); const translation = context.getTranslation(localProps).GlobalError; const allProps = extendPropsWithContext(localProps, defaultProps, context === null || context === void 0 ? void 0 : context.GlobalError, translation, translation[localProps.statusCode || defaultProps.statusCode], { skeleton: context === null || context === void 0 ? void 0 : context.skeleton }); const { statusCode, skeleton, center, className, title, help, errorMessageCode, links, text, ...attributes } = allProps; const textParams = { children: text }; const params = applySpacing(attributes, { className: clsx(`dnb-global-error dnb-global-error--${statusCode}`, className, center && 'dnb-global-error--center') }); const additionalContent = processChildren(allProps); return _jsx(Skeleton, { ...attributes, ...params, show: skeleton, element: "section", children: _jsxs("div", { className: "dnb-global-error__inner", children: [_jsxs("div", { className: "dnb-global-error__inner__content", children: [_jsx(H1, { size: "x-large", top: true, bottom: true, children: title }), _jsx(P, { bottom: true, ...textParams }), errorMessageCode && _jsx(P, { bottom: true, className: "dnb-global-error__status", children: String(errorMessageCode).replace('%statusCode', statusCode) }), help && (links === null || links === void 0 ? void 0 : links.length) > 0 && _jsx(P, { top: "medium", bottom: true, children: help }), help && (links === null || links === void 0 ? void 0 : links.length) > 0 && _jsx(P, { bottom: "large", className: "dnb-global-error__links", children: links.map(({ text, url }) => { return _jsx(Anchor, { href: url, children: text }, text); }) })] }), additionalContent] }) }); } withComponentMarkers(GlobalError, { _supportsSpacingProps: true }); //# sourceMappingURL=GlobalError.js.map