UNPKG

@payfit/unity-components

Version:

103 lines (102 loc) 2.86 kB
import { Icon as e } from "../icon/Icon.js"; import { Spinner as t } from "../spinner/Spinner.js"; import { isExternalUrl as n } from "../link/utils.js"; import { linkButtonFilled as r, linkButtonGhost as i, linkButtonOutlined as a } from "./LinkButton.variants.js"; import { forwardRef as o, useMemo as s } from "react"; import { useUnityTheme as c, uyMerge as l } from "@payfit/unity-themes"; import { jsx as u, jsxs as d } from "react/jsx-runtime"; import { Link as f } from "react-aria-components/Link"; //#region src/components/link-button/RawLinkButton.tsx var p = (n, r) => n ? /* @__PURE__ */ u(t, { size: "small", color: "inherit", label: "Loading..." }) : r ? /* @__PURE__ */ u(e, { src: r, size: 20, color: "inherit", role: "presentation", "data-unity-icon": "prefix" }) : null, m = o(({ variant: t, href: o, children: m, color: h = "primary", size: g = "default", isDisabled: _ = !1, isLoading: v = !1, prefixIcon: y, suffixIcon: b, truncateLabelLength: x, mode: S = "default", isExternal: C, ...w }, T) => { let E = C ?? n(o), { theme: D } = c(), O = s(() => { let e = { size: g, isDisabled: _, isLoading: v, mode: S }, n; switch (t) { case "primary": n = r({ ...e, color: h }); break; case "secondary": if (D === "rebrand") { let t = h === "inverted" ? "inverted.low" : "neutral"; n = r({ ...e, color: t }); } else n = a({ ...e, color: h }); break; case "ghost": n = i({ ...e, color: h }); break; case "outlined": n = a({ ...e, color: h }); break; } return l(n, "uy:no-underline", _ || v ? `${t === "primary" || t === "secondary" && D === "rebrand" ? "uy:data-[disabled]:bg-surface-neutral-disabled" : "uy:data-[disabled]:bg-transparent"} uy:data-[disabled]:text-content-neutral-disabled uy:data-[disabled]:cursor-not-allowed` : "", v ? "uy:data-[disabled]:cursor-progress" : ""); }, [ t, h, g, _, v, S, D ]), k = { ...v && { "data-loading": v } }; return /* @__PURE__ */ u(f, { "data-dd-privacy": "allow", ...w, href: o, ref: T, isDisabled: _ || v, className: O, target: E ? "_blank" : w.target, rel: E && !w.rel ? "noopener noreferrer" : w.rel, ...k, children: /* @__PURE__ */ d("span", { className: "uy:inline-flex uy:gap-50 uy:items-center", children: [ p(v, y), x && x > 0 ? /* @__PURE__ */ u("span", { style: { "--uy-button-label-truncation-length": `${x}ch` }, className: "uy:truncate uy:min-w-0 uy:w-(--uy-button-label-truncation-length)", children: m }) : m, b && /* @__PURE__ */ u(e, { src: b, size: 20, color: "inherit", role: "presentation", "data-unity-icon": "suffix" }) ] }) }); }); m.displayName = "RawLinkButton"; //#endregion export { m as RawLinkButton };