UNPKG

@payfit/unity-components

Version:

103 lines (102 loc) • 3.37 kB
import { Spinner as e } from "../../spinner/Spinner.js"; import { SegmentedButtonGroupContext as t } from "../SegmentedButtonGroups.context.js"; import { forwardRef as n, useContext as r, useRef as i } from "react"; import { useFocusRing as a } from "react-aria/useFocusRing"; import { uyTv as o } from "@payfit/unity-themes"; import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime"; import { useTranslation as u } from "react-i18next"; import { Icon as d } from "@payfit/unity-icons"; import { mergeProps as f } from "react-aria/mergeProps"; import { useRadio as p } from "react-aria/useRadioGroup"; import { VisuallyHidden as m } from "react-aria/VisuallyHidden"; //#region src/core/components/segmented-button-group/parts/ToggleButton.tsx var h = o({ slots: { base: ["uy:group uy:rounded-50 uy:pt-50 uy:pb-50 uy:pr-150 uy:flex uy:gap-25 uy:h-400", "uy:active:gb-surface-neutral-pressed"], wrapper: ["uy:flex uy:gap-50 uy:items-center uy:typography-action", "uy:active:text-content-neutral-pressed"] }, variants: { isSelected: { true: { base: "uy:bg-surface-neutral-enabled uy:shadow-raising" } }, isLoading: { true: { base: "uy:bg-surface-neutral-disabled uy:cursor-not-allowed", wrapper: "uy:text-content-inverted-disabled" } }, isFocusVisible: { true: { base: "uy:outline-none uy:ring-2 uy:ring-ring uy:ring-offset-2 uy:ring-utility-focus-ring" } }, hasPrefixIcon: { true: "", false: "" } }, compoundVariants: [ { isLoading: !1, isSelected: !1, className: { base: "uy:hover:bg-surface-neutral-hover", wrapper: "uy:text-content-neutral-enabled uy:group-hover:text-content-neutral-hover" } }, { isLoading: !0, hasPrefixIcon: !1, className: { base: "uy:pl-150 uy:cursor-not-allowed" } }, { isLoading: !0, hasPrefixIcon: !0, className: { base: "uy:pl-150 uy:cursor-not-allowed" } }, { isLoading: !1, hasPrefixIcon: !1, className: { base: "uy:pl-150 uy:cursor-pointer" } }, { isLoading: !1, hasPrefixIcon: !0, className: { base: "uy:pl-50 uy:cursor-pointer" } } ], defaultVariants: { isSelected: !1, isLoading: !1, hasPrefixIcon: !1 } }), g = ({ t, children: n, isLoading: r, prefixIcon: i, isSelected: a }) => r ? /* @__PURE__ */ c(e, { label: t((e) => e.unity.component.common.loading.label), color: "inherit", size: "small" }) : /* @__PURE__ */ l(s, { children: [i ? /* @__PURE__ */ c(d, { src: a ? `${i}Filled` : `${i}Outlined`, color: a ? "content.neutral" : "content.neutral.low", role: "presentation" }) : null, n] }), _ = n((e, n) => { let { children: o, value: s, prefixIcon: d, isLoading: _ } = e, { state: v } = r(t), y = i(null), { inputProps: b } = p(e, v, y), { focusProps: x, isFocusVisible: S } = a(), { t: C } = u("unity"), w = v.selectedValue === s, { base: T, wrapper: E } = h({ isSelected: w, hasPrefixIcon: !!d, isLoading: _, isFocusVisible: S }); return /* @__PURE__ */ l("label", { ref: n, className: T(), "aria-disabled": _, children: [/* @__PURE__ */ c(m, { children: /* @__PURE__ */ c("input", { ...f(b, x), ref: y, disabled: _ }) }), /* @__PURE__ */ c("span", { className: E(), children: g({ t: C, children: o, isLoading: _, isSelected: w, prefixIcon: d }) })] }); }); _.displayName = "ToggleButton"; //#endregion export { _ as ToggleButton };