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