UNPKG

@payfit/unity-components

Version:

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