UNPKG

@payfit/unity-components

Version:

85 lines (84 loc) • 3.85 kB
import { SelectListContextProvider as e } from "./SelectList.context.js"; import { VIRTUALIZATION_CONFIG as t } from "./constants.js"; import { useControlledSelection as n } from "./hooks/useControlledSelection.js"; import { useSelectedFirstSorting as r } from "./hooks/useSelectedFirstSorting.js"; import { SelectedItemsSection as i } from "./parts/SelectedItemsSection.js"; import { SelectListEmptyState as a } from "./parts/SelectListEmptyState.js"; import { SelectListSearchInput as o } from "./parts/SelectListSearchInput.js"; import { forwardRef as s, useMemo as c } from "react"; import { uyTv as l } from "@payfit/unity-themes"; import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime"; import { Separator as p } from "react-aria-components/Separator"; import { Collection as m, ListBox as h } from "react-aria-components/ListBox"; import { Autocomplete as g, useFilter as _ } from "react-aria-components/Autocomplete"; import { Virtualizer as v } from "react-aria-components/Virtualizer"; //#region src/core/components/select-list/SelectList.tsx var y = l({ slots: { wrapper: "uy:bg-surface-neutral uy:p-100 uy:overscroll-contain", base: "uy:flex uy:w-full uy:gap-100 uy:h-500 uy:border uy:border-solid uy:rounded-75 uy:py-100 uy:border-border-form-enabled uy:bg-surface-form-enabled uy:px-150 uy:typography-body uy:focus-within:outline-none uy:focus-within:ring-2 uy:focus-within:ring-utility-focus-ring uy:focus-within:ring-offset-2 uy:active:border-border-form-active", inputContainer: "uy:sticky uy:top-0 uy:bg-surface-neutral", separator: "uy:h-[1px] uy:border-border-neutral uy:w-full uy:mt-100", list: "uy:overflow-y-auto uy:mt-100 uy:max-h-[300px]", selectedListBox: "uy:bg-surface-neutral uy:border-b uy:border-border-neutral uy:py-100 uy:data-[empty=true]:border-0 uy:data-[is-last=true]:border-0 uy:data-[is-last=true]:py-0" } }); function b({ items: s, children: l, value: b, onChange: x, className: S, wrapperClassName: C, showSearch: w, searchPlaceholder: T, searchAutoFocus: E = !1, sortSelectedFirst: D = !1, selectedSectionLabel: O = "Selected", selectionMode: k = "multiple", indicatorPosition: A = "start", ...j }, M) { let { contains: N } = _({ sensitivity: "base" }), { wrapper: P, inputContainer: F, list: I, separator: L, selectedListBox: R } = y(), [z, B] = n(b, x), V = c(() => w === void 0 ? (Array.isArray(s) ? s.length : Array.from(s).length) >= 10 : w, [s, w]), H = r(s, z, D), U = c(() => H.remainingItems ? !H.remainingItems[Symbol.iterator]().next().done : !1, [H.remainingItems]), W = /* @__PURE__ */ d(i, { items: H.selectedItems, selectedKeys: z, onSelectionChange: B, selectionMode: k, selectionBehavior: j.selectionBehavior, label: O, className: R(), "data-is-last": !U, children: l }), G = /* @__PURE__ */ d(h, { ...j, selectionMode: k, autoFocus: V && E ? !1 : j.autoFocus, className: I({ className: S }), items: H.remainingItems, selectedKeys: z, onSelectionChange: B, renderEmptyState: a, children: /* @__PURE__ */ d(m, { items: H.remainingItems, children: l }) }); return /* @__PURE__ */ d(e, { value: { selectionMode: k, indicatorPosition: A }, children: /* @__PURE__ */ d("div", { ref: M, className: P({ className: C }), children: V ? /* @__PURE__ */ f(g, { filter: N, children: [ /* @__PURE__ */ f("div", { className: F(), "data-dd-privacy": "mask", children: [/* @__PURE__ */ d(o, { placeholder: T, autoFocus: E }), /* @__PURE__ */ d(p, { className: L() })] }), W, U && /* @__PURE__ */ d(v, { ...t, children: G }) ] }) : /* @__PURE__ */ f(u, { children: [W, U && /* @__PURE__ */ d(v, { ...t, children: G })] }) }) }); } var x = s(b); x.displayName = "SelectList"; //#endregion export { x as SelectList };