@payfit/unity-components
Version:
91 lines (90 loc) • 2.24 kB
JavaScript
import { Icon as e } from "../icon/Icon.js";
import { Spinner as t } from "../spinner/Spinner.js";
import { buttonFilled as n, buttonGhost as r, buttonOutlined as i } from "./Button.variants.js";
import { forwardRef as a, useMemo as o } from "react";
import { useUnityTheme as s, uyMerge as c } from "@payfit/unity-themes";
import { jsx as l, jsxs as u } from "react/jsx-runtime";
import { Button as d } from "react-aria-components/Button";
//#region src/components/button/Button.tsx
var f = (n, r) => n ? /* @__PURE__ */ l(t, {
size: "small",
color: "inherit",
label: "Loading..."
}) : r ? /* @__PURE__ */ l(e, {
src: r,
size: 20,
color: "inherit",
role: "presentation",
"data-unity-icon": "prefix"
}) : null, p = a(({ variant: t, children: a, color: p = "primary", size: m = "default", isDisabled: h = !1, isLoading: g = !1, prefixIcon: _, suffixIcon: v, truncateLabelLength: y, ...b }, x) => {
let { theme: S } = s(), C = o(() => {
let e = {
size: m,
isDisabled: h,
isLoading: g
};
switch (t) {
case "primary": return c(n({
...e,
color: p
}));
case "secondary":
if (S === "rebrand") {
let t = p === "inverted" ? "inverted.low" : "neutral";
return c(n({
...e,
color: t
}));
}
return c(i({
...e,
color: p
}));
case "ghost": return c(r({
...e,
color: p
}));
case "outlined": return c(i({
...e,
color: p
}));
}
}, [
t,
p,
m,
h,
g,
S
]), w = { ...g && { "data-loading": g } };
return /* @__PURE__ */ l(d, {
"data-dd-privacy": "allow",
...b,
ref: x,
isDisabled: h || g,
isPending: g,
className: C,
...w,
children: /* @__PURE__ */ u("span", {
className: "uy:inline-flex uy:gap-50 uy:items-center",
children: [
f(g, _),
y && y > 0 ? /* @__PURE__ */ l("span", {
style: { "--uy-button-label-truncation-length": `${y}ch` },
className: "uy:truncate uy:min-w-0 uy:w-(--uy-button-label-truncation-length)",
children: a
}) : a,
v && /* @__PURE__ */ l(e, {
src: v,
size: 20,
color: "inherit",
role: "presentation",
"data-unity-icon": "suffix"
})
]
})
});
});
p.displayName = "Button";
//#endregion
export { p as Button };