@payfit/unity-components
Version:
68 lines (67 loc) • 1.95 kB
JavaScript
import { forwardRef as e, useMemo as t, useState as n } from "react";
import { uyTv as r } from "@payfit/unity-themes";
import { mergeProps as i, useFocus as a, useFocusVisible as o, useHover as s, useObjectRef as c } from "react-aria";
import { useButton as l } from "react-aria/useButton";
import { jsx as u } from "react/jsx-runtime";
//#region src/components/actionable/Actionable.tsx
var d = r({
base: "uy:group",
variants: { isUnstyled: {
true: "",
false: [
"uy:cursor-pointer",
"uy:aria-disabled:cursor-not-allowed",
"uy:aria-disabled:text-content-neutral-disabled"
]
} },
defaultVariants: { isUnstyled: !1 }
}), f = e((e, r) => {
let { asElement: f = "div", isUnstyled: p = !1, className: m, children: h, ...g } = e;
r = c(r);
let { isFocusVisible: _ } = o(), { isHovered: v, hoverProps: y } = s({
onHoverStart: g.onHoverStart,
onHoverEnd: g.onHoverEnd,
onHoverChange: g.onHoverChange,
isDisabled: g.isDisabled
}), [b, x] = n(!1), { focusProps: S } = a({
onFocusChange: x,
isDisabled: g.isDisabled
}), { buttonProps: C, isPressed: w } = l({
...g,
isDisabled: g.isDisabled,
elementType: f
}, r), T = t(() => d({
isUnstyled: p,
className: m
}), [m, p]), E = f, D = (e) => {
if (g.isDisabled) {
e.preventDefault(), e.stopPropagation();
return;
}
let t = i(C, y, S);
t.onClick && t.onClick(e);
}, { onClick: O, ...k } = i(C, y, S);
return /* @__PURE__ */ u(E, {
...k,
onClick: D,
className: T,
...w && { "data-pressed": w },
...b && { "data-focused": b },
...v && { "data-hovered": v },
...g.isDisabled && { "data-disabled": g.isDisabled },
..._ && { "data-focus-visible": _ },
ref: r,
children: typeof h == "function" ? h({
isHovered: v,
isPressed: w,
isFocused: b,
isDisabled: !!g.isDisabled,
isFocusVisible: _,
isPending: !1,
defaultChildren: null
}) : h
});
});
f.displayName = "Actionable";
//#endregion
export { f as Actionable };