UNPKG

@payfit/unity-components

Version:

69 lines (68 loc) 2.01 kB
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, useHover as o, useObjectRef as s } from "react-aria"; import { useFocusRing as c } from "react-aria/useFocusRing"; 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 = s(r); let { isFocusVisible: _, focusProps: v } = c(), { isHovered: y, hoverProps: b } = o({ onHoverStart: g.onHoverStart, onHoverEnd: g.onHoverEnd, onHoverChange: g.onHoverChange, isDisabled: g.isDisabled }), [x, S] = n(!1), { focusProps: C } = a({ onFocusChange: S, isDisabled: g.isDisabled }), { buttonProps: w, isPressed: T } = l({ ...g, isDisabled: g.isDisabled, elementType: f }, r), E = t(() => d({ isUnstyled: p, className: m }), [m, p]), D = f, O = (e) => { if (g.isDisabled) { e.preventDefault(), e.stopPropagation(); return; } let t = i(w, b, C, v); t.onClick && t.onClick(e); }, { onClick: k, ...A } = i(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 }, ..._ && { "data-focus-visible": _ }, ref: r, 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 };