UNPKG

@payfit/unity-components

Version:

42 lines (41 loc) • 2.46 kB
import { MultiSelectContext as e } from "../Multiselect.context.js"; import { collectSelectableKeys as t } from "../utils/select-all.js"; import { MultiSelectSelectAllCheckbox as n } from "./MultiSelectSelectAllCheckbox.js"; import { MultiSelectSeparator as r } from "./MultiSelectSeparator.js"; import { useContext as i } from "react"; import { uyTv as a } from "@payfit/unity-themes"; import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime"; import { useTranslation as l } from "react-i18next"; import { ListStateContext as u } from "react-aria-components/ListBox"; import { AutocompleteStateContext as d, useFilter as f } from "react-aria-components/Autocomplete"; //#region src/core/components/multi-select/parts/MultiSelectSelectAllOption.tsx var p = a({ slots: { base: [ "uy:flex uy:w-full uy:items-center uy:gap-100 uy:px-150 uy:py-100", "uy:rounded-50 uy:cursor-pointer uy:outline-none", "uy:data-[hovered=true]:bg-surface-neutral-hover", "uy:data-[pressed=true]:bg-surface-neutral-pressed", "uy:data-[focus-visible=true]:outline uy:data-[focus-visible=true]:outline-2 uy:data-[focus-visible=true]:outline-solid uy:data-[focus-visible=true]:outline-utility-focus-ring uy:data-[focus-visible=true]:-outline-offset-2", "uy:data-[disabled=true]:cursor-not-allowed uy:data-[disabled=true]:text-content-neutral-disabled", "uy:typography-body-strong uy:text-content-neutral" ] } }); function m({ groupLabel: a, withSeparator: m = !1 }) { let { t: h } = l("unity"), g = i(d), _ = i(u), { isDisabled: v, isReadOnly: y, isLoading: b, searchOptions: x, getSelectionState: S, toggleSelection: C } = i(e), { contains: w } = f(x ?? { sensitivity: "base" }), T = _ ? t(_.collection, _.selectionManager, a) : /* @__PURE__ */ new Set(), E = g?.inputValue ?? "", D = new Set(Array.from(T).filter((e) => { if (!_ || !E) return !0; let t = _.collection.getItem(e); return t !== null && w(t.textValue ?? "", E); })), O = S?.(D) ?? { isSelected: !1, isIndeterminate: !1 }, k = v || y || b || D.size === 0, { base: A } = p(), j = a ?? h((e) => e.unity.component.multiSelect.selectAll.label); return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s(n, { className: A(), isDisabled: k, isIndeterminate: O.isIndeterminate, isSelected: O.isSelected, label: j, onChange: () => C?.(D) }), m && /* @__PURE__ */ s(r, {})] }); } m.displayName = "MultiSelectSelectAllOption"; //#endregion export { m as MultiSelectSelectAllOption };