UNPKG

@payfit/unity-components

Version:

157 lines (156 loc) • 5.77 kB
import { Button as e } from "../button/Button.js"; import { Text as t } from "../text/Text.js"; import { useContainerQueryLevel as n } from "../../hooks/use-container-query-level.js"; import { Code as r } from "../code/Code.js"; import { initConfig as i } from "./initConfig.js"; import { Collapsible as a } from "./parts/Collapsible.js"; import { forwardRef as o, useCallback as s, useRef as c } from "react"; import { uyTv as l } from "@payfit/unity-themes"; import { jsx as u, jsxs as d } from "react/jsx-runtime"; import { useTranslation as f } from "react-i18next"; import { Icon as p } from "@payfit/unity-icons"; import { Illustration as m } from "@payfit/unity-illustrations"; //#region src/core/components/error-state/ErrorState.tsx var h = l({ slots: { container: ["uy:@container uy:w-full uy:h-full uy:content-center uy:flex-1"], wrapper: [ "uy:border-solid uy:border-border-neutral uy:border uy:rounded-200 uy:p-300", "uy:@section:py-600 uy:@section:px-auto", "uy:@page:border-0 uy:@page:py-auto uy:@page:px-auto", "uy:@app:border-0 uy:@app:py-auto uy:@app:px-auto" ], base: ["uy:max-w-[704px] uy:flex uy:flex-col uy:items-center uy:justify-center uy:gap-150 uy:@section:gap-250 uy:w-full uy:justify-self-center"], content: ["uy:flex uy:flex-col uy:items-center uy:justify-center uy:gap-250"], illustration: [ "uy:@section:block", "uy:hidden", "uy:@page:w-[200px]", "uy:@section:w-[200px]", "uy:@app:w-[240px]" ], icon: ["uy:bg-surface-neutral-lowest uy:rounded-125 uy:p-100", "uy:@section:hidden"], informationContainer: ["uy:flex uy:flex-col uy:items-center uy:justify-center uy:gap-100 uy:@section:gap-150 uy:text-center uy"], information: [ "uy:hidden", "", "uy:@section:block" ], informationComponent: ["uy:block", "uy:@section:hidden"], h1: ["uy:hidden uy:@app:block"], h2: ["uy:hidden uy:@page:@max-app:block"], h3: ["uy:hidden uy:@section:@max-page:block"], h4: ["uy:block uy:@section:hidden"], description: ["uy:hidden uy:@section:block uy:@section:w-full"] } }), g = (e, t) => /* @__PURE__ */ d(a, { children: [/* @__PURE__ */ u("div", { className: "uy:mb-200", children: e.detailDescription ?? t?.detailDescription }), /* @__PURE__ */ u(r, { children: e.error.message })] }), _ = (t, n) => { let r = t.backButtonLabel ?? n?.backButtonLabel; return /* @__PURE__ */ u("div", { className: "uy:mt-200 uy:@section:block uy:hidden", children: /* @__PURE__ */ u(e, { onPress: t.onBackButtonPress ?? n?.onBackButtonPress, color: "primary", variant: "ghost", children: r }) }); }, v = (e, t) => e === "generic" ? t ? "known" : "unknown" : e, y = o((r, a) => { let { icon: o, illustration: l, onButtonPress: y, buttonLabel: b, mainTitle: x, mainDescription: S, mainDescriptionComponent: C, type: w, error: T, entityName: E, role: D = "status" } = r, { base: O, content: k, container: A, wrapper: j, illustration: M, icon: N, informationContainer: P, information: F, informationComponent: ee, description: I, h1: L, h2: R, h3: z, h4: B } = h(), { t: V } = f("unity"), H = i(V, { noPermissionEntityName: E }), U = c(null), { level: W } = n({ ref: U }), G = s((e) => { U.current = e, a && (typeof a == "function" ? a(e) : a.current = e); }, [a]), K = v(w, T), q = H.get(K), J = l ?? q?.illustration, Y = o ?? q?.icon, X = b ?? q?.buttonLabel, Z = x ?? q?.mainTitle, Q = S ?? q?.mainDescription, $ = C ?? q?.mainDescriptionComponent; return /* @__PURE__ */ u("div", { "data-dd-privacy": "allow", role: D, className: A(), ref: G, "data-container-level": W, children: /* @__PURE__ */ u("div", { className: j(), children: /* @__PURE__ */ d("div", { className: O(), children: [ /* @__PURE__ */ d("div", { className: k(), children: [ J && /* @__PURE__ */ u(m, { src: J, variant: "picture", alt: V((e) => e.unity.component.errorState.common.illustration.alt), className: M(), isDecorative: !0 }), Y && /* @__PURE__ */ u(p, { src: Y, size: 24, color: "content.neutral.low", alt: V((e) => e.unity.component.errorState.common.icon.alt), className: N() }), /* @__PURE__ */ d("div", { className: P(), children: [ /* @__PURE__ */ u(t, { asElement: "h1", variant: "h1", color: "content.neutral", className: L(), children: Z }), /* @__PURE__ */ u(t, { asElement: "h2", variant: "h2", color: "content.neutral", className: R(), children: Z }), /* @__PURE__ */ u(t, { asElement: "h3", variant: "h3", color: "content.neutral", className: z(), children: Z }), /* @__PURE__ */ u(t, { asElement: "h4", variant: "h4", color: "content.neutral", className: B(), children: Z }), /* @__PURE__ */ u(t, { asElement: "p", variant: "body", color: "content.neutral.low", className: F(), children: Q }), /* @__PURE__ */ u(t, { asElement: "p", variant: "body", color: "content.neutral.low", className: ee(), children: $ }) ] }) ] }), /* @__PURE__ */ u(e, { variant: W === "component" ? "ghost" : "primary", onPress: y, children: X }), K === "unknown" && _(r, q), K === "known" && /* @__PURE__ */ u("div", { className: I(), children: g(r, q) }) ] }) }) }); }); y.displayName = "ErrorState"; //#endregion export { y as ErrorState, h as errorState };