@payfit/unity-components
Version:
72 lines (71 loc) • 3.38 kB
JavaScript
import { VIRTUALIZATION_CONFIG as e } from "./constants.js";
import { useControlledSelection as t } from "./hooks/useControlledSelection.js";
import { useSelectedFirstSorting as n } from "./hooks/useSelectedFirstSorting.js";
import { SelectedItemsSection as r } from "./parts/SelectedItemsSection.js";
import { SelectListEmptyState as i } from "./parts/SelectListEmptyState.js";
import { SelectListSearchInput as a } from "./parts/SelectListSearchInput.js";
import { forwardRef as o, useMemo as s } from "react";
import { uyTv as c } from "@payfit/unity-themes";
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
import { Separator as f } from "react-aria-components/Separator";
import { Collection as p, ListBox as m } from "react-aria-components/ListBox";
import { Autocomplete as h, useFilter as g } from "react-aria-components/Autocomplete";
import { Virtualizer as _ } from "react-aria-components/Virtualizer";
//#region src/components/select-list/SelectList.tsx
var v = c({ 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:bg-border-neutral uy:w-full uy:mt-100",
list: "uy:overflow-y-auto uy:mt-100 uy: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 y({ items: o, children: c, value: y, onChange: b, className: x, showSearch: S = !1, sortSelectedFirst: C = !1, selectedSectionLabel: w = "Selected", ...T }, E) {
let { contains: D } = g({ sensitivity: "base" }), { wrapper: O, inputContainer: k, list: A, separator: j, selectedListBox: M } = v(), [N, P] = t(y, b), F = s(() => (Array.isArray(o) ? o.length : Array.from(o).length) >= 10 || S, [o, S]), I = n(o, N, C), L = s(() => I.remainingItems ? !I.remainingItems[Symbol.iterator]().next().done : !1, [I.remainingItems]), R = /* @__PURE__ */ u(r, {
items: I.selectedItems,
selectedKeys: N,
onSelectionChange: P,
selectionMode: T.selectionMode,
selectionBehavior: T.selectionBehavior,
label: w,
className: M(),
"data-is-last": !L
}), z = /* @__PURE__ */ u(m, {
...T,
className: A({ className: x }),
items: I.remainingItems,
selectedKeys: N,
onSelectionChange: P,
renderEmptyState: i,
children: /* @__PURE__ */ u(p, {
items: I.remainingItems,
children: c
})
});
return /* @__PURE__ */ u("div", {
ref: E,
className: O(),
children: F ? /* @__PURE__ */ d(h, {
filter: D,
children: [
/* @__PURE__ */ d("div", {
className: k(),
"data-dd-privacy": "mask",
children: [/* @__PURE__ */ u(a, {}), /* @__PURE__ */ u(f, { className: j() })]
}),
R,
L && /* @__PURE__ */ u(_, {
...e,
children: z
})
]
}) : /* @__PURE__ */ d(l, { children: [R, L && /* @__PURE__ */ u(_, {
...e,
children: z
})] })
});
}
var b = o(y);
b.displayName = "SelectList";
//#endregion
export { b as SelectList };