UNPKG

@payfit/unity-components

Version:

95 lines (94 loc) 2.41 kB
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, uyMerge as u } from "@payfit/unity-themes"; import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime"; import { Button as m } from "react-aria-components/Button"; import { Link as h } from "react-aria-components/Link"; //#region src/components/icon-button/IconButton.tsx var g = s(({ as: s = "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-${t()}`, k = x || S, A = c(() => { let e = { isDisabled: x, isLoading: S }; switch (g) { case "primary": return u(i({ ...e, color: _ })); case "secondary": { let t = _ === "inverted" ? "inverted.low" : "neutral"; return u(i({ ...e, color: t })); } case "ghost": return u(a({ ...e, color: _ })); case "outlined": return u(o({ ...e, color: _ })); } }, [ g, _, x, S ]), j = { ...S && { "data-loading": S } }, M = /* @__PURE__ */ p(d, { children: [S ? /* @__PURE__ */ f(n, { size: "small", label: "Loading", color: "inherit" }) : /* @__PURE__ */ f(e, { role: y, src: v, size: 20, color: "inherit", "aria-labelledby": O }), /* @__PURE__ */ f("span", { id: O, className: "uy:sr-only", children: b })] }); return s === "link" ? /* @__PURE__ */ f(r, { title: b, children: /* @__PURE__ */ f(h, { ref: D, "data-dd-privacy": "allow", ...E, ...C && { onClick: C }, className: l(A, T), onPress: w, isDisabled: k, "aria-label": b, "aria-disabled": k ? !0 : void 0, "aria-busy": S || void 0, ...j, children: M }) }) : /* @__PURE__ */ f(r, { title: b, children: /* @__PURE__ */ f(m, { ref: D, "data-dd-privacy": "allow", ...E, className: l(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 };