@payfit/unity-components
Version:
101 lines (100 loc) • 2.54 kB
JavaScript
import { Icon as e } from "../icon/Icon.js";
import t from "../../hooks/use-id.js";
import { Spinner as n } from "../spinner/Spinner.js";
import { Tooltip as r } from "../tooltip/Tooltip.js";
import { iconButtonFilled as i, iconButtonGhost as a, iconButtonOutlined as o } from "./IconButton.variants.js";
import { forwardRef as s, useMemo as c } from "react";
import { cn as l, useUnityTheme as u, uyMerge as d } from "@payfit/unity-themes";
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
import { Button as h } from "react-aria-components/Button";
import { Link as g } from "react-aria-components/Link";
//#region src/components/icon-button/IconButton.tsx
var _ = s(({ as: s = "button", variant: _, color: v = "primary", icon: y, iconRole: b, label: x, isDisabled: S = !1, isLoading: C = !1, onClick: w, onPress: T, className: E, ...D }, O) => {
let k = t(), { theme: A } = u(), j = `icon-button-label-${k}`, M = S || C, N = c(() => {
let e = {
isDisabled: S,
isLoading: C
};
switch (_) {
case "primary": return d(i({
...e,
color: v
}));
case "secondary":
if (A === "rebrand") {
let t = v === "inverted" ? "inverted.low" : "neutral";
return d(i({
...e,
color: t
}));
}
return d(o({
...e,
color: v
}));
case "ghost": return d(a({
...e,
color: v
}));
case "outlined": return d(o({
...e,
color: v
}));
}
}, [
_,
v,
S,
C,
A
]), P = { ...C && { "data-loading": C } }, F = /* @__PURE__ */ m(f, { children: [C ? /* @__PURE__ */ p(n, {
size: "small",
label: "Loading",
color: "inherit"
}) : /* @__PURE__ */ p(e, {
role: b,
src: y,
size: 20,
color: "inherit",
"aria-labelledby": j
}), /* @__PURE__ */ p("span", {
id: j,
className: "uy:sr-only",
children: x
})] });
return s === "link" ? /* @__PURE__ */ p(r, {
title: x,
children: /* @__PURE__ */ p(g, {
ref: O,
"data-dd-privacy": "allow",
...D,
...w && { onClick: w },
className: l(N, E),
onPress: T,
isDisabled: M,
"aria-label": x,
"aria-disabled": M ? !0 : void 0,
"aria-busy": C || void 0,
...P,
children: F
})
}) : /* @__PURE__ */ p(r, {
title: x,
children: /* @__PURE__ */ p(h, {
ref: O,
"data-dd-privacy": "allow",
...D,
className: l(N, E),
onPress: T ?? w,
isDisabled: M,
isPending: C,
"aria-label": x,
"aria-disabled": M ? !0 : void 0,
...P,
children: F
})
});
});
_.displayName = "IconButton";
//#endregion
export { _ as IconButton };