@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
94 lines (93 loc) • 4.41 kB
JavaScript
"use client";
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
const _excluded = ["status", "statusCode", "skeleton", "center", "className", "title", "help", "code", "errorMessageCode", "links", "text"];
import "core-js/modules/es.string.replace.js";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import React from 'react';
import classnames from 'classnames';
import Context from '../../shared/Context';
import { processChildren, extendPropsWithContext } from '../../shared/component-helper';
import { createSpacingClasses } from '../space/SpacingHelper';
import Anchor from '../anchor/Anchor';
import Skeleton from '../skeleton/Skeleton';
import { H1, P, Code } from '../../elements';
const defaultProps = {
status: '404',
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.status || localProps.statusCode || defaultProps.statusCode], {
skeleton: context === null || context === void 0 ? void 0 : context.skeleton
});
const {
status,
statusCode,
skeleton,
center,
className,
title,
help,
code,
errorMessageCode,
links,
text
} = allProps,
attributes = _objectWithoutProperties(allProps, _excluded);
const statusToUse = status !== defaultProps.status ? status : statusCode;
const textParams = {};
if (typeof text === 'string') {
textParams.dangerouslySetInnerHTML = {
__html: text
};
} else {
textParams.children = text;
}
const spacingClasses = createSpacingClasses(attributes);
const params = _objectSpread({
className: classnames(`dnb-global-error dnb-global-error--${statusToUse}`, createSpacingClasses(attributes), className, spacingClasses, center && 'dnb-global-error--center')
}, attributes);
const additionalContent = processChildren(allProps);
const userProvidedCodeValue = Object.prototype.hasOwnProperty.call(localProps, 'code');
return React.createElement(Skeleton, _extends({}, params, {
show: skeleton,
element: "section"
}), React.createElement("div", {
className: "dnb-global-error__inner"
}, React.createElement("div", {
className: "dnb-global-error__inner__content"
}, React.createElement(H1, {
size: "x-large",
top: true,
bottom: true
}, title), React.createElement(P, _extends({
bottom: true
}, textParams)), userProvidedCodeValue && code && React.createElement(P, {
bottom: true,
className: "dnb-global-error__status"
}, code, " ", statusToUse && React.createElement(Code, null, statusToUse)), !userProvidedCodeValue && errorMessageCode && React.createElement(P, {
bottom: true,
className: "dnb-global-error__status"
}, String(errorMessageCode).replace('%statusCode', statusToUse)), help && (links === null || links === void 0 ? void 0 : links.length) && React.createElement(P, {
top: "medium",
bottom: true
}, help), help && (links === null || links === void 0 ? void 0 : links.length) && React.createElement(P, {
bottom: "large",
className: "dnb-global-error__links"
}, links.map(_ref => {
let {
text,
url
} = _ref;
return React.createElement(Anchor, {
key: text,
href: url
}, text);
}))), additionalContent));
}
GlobalError._supportsSpacingProps = true;
//# sourceMappingURL=GlobalError.js.map