@payfit/unity-components
Version:
88 lines (87 loc) • 3.04 kB
JavaScript
import { Search as e } from "../search/Search.js";
import { SelectButton as t } from "./parts/SelectButton.js";
import { forwardRef as n, useMemo as r, useState as i } from "react";
import { uyTv as a } from "@payfit/unity-themes";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
import { useIntl as c } from "react-intl";
import { Separator as l } from "react-aria-components/Separator";
import { Autocomplete as u, useFilter as d } from "react-aria-components/Autocomplete";
import { ListLayout as f, Virtualizer as p } from "react-aria-components/Virtualizer";
import { ListBox as m, Popover as h, Select as g } from "react-aria-components/Select";
//#region src/core/components/select/Select.tsx
var _ = a({ slots: {
base: "uy:flex uy:flex-col uy:gap-100 uy:w-full",
popover: "uy:rounded-100 uy:sm:rounded-75 uy:border uy:border-solid uy:border-border-neutral uy:w-[var(--trigger-width)] uy:bg-surface-neutral uy:shadow-300",
listbox: "uy:overflow-y-auto uy:max-h-[296px] uy:pt-100 uy:pb-100"
} }), v = ({ children: n, items: a, placeholder: v, isDisabled: y, isInvalid: b, isReadOnly: x, value: S, defaultValue: C, onChange: w, isSearchable: T = !1, searchAutoFocus: E, onBlur: D, placement: O, searchInputAriaLabel: k, renderEmptyState: A, renderValue: j, ...M }, N) => {
let P = c(), [F, I] = i(!1), { contains: L } = d({ sensitivity: "base" }), { base: R, popover: z, listbox: B } = _(), V = S !== void 0 || w !== void 0 ? {
value: S,
onChange: w
} : { defaultValue: C }, H = r(() => {
if (A !== void 0) return typeof A == "function" ? A : () => A;
}, [A]);
return /* @__PURE__ */ s(g, {
onOpenChange: I,
...M,
ref: N,
className: R(),
placeholder: y ? void 0 : v,
isDisabled: y || x,
isInvalid: b,
onBlur: D,
...V,
children: [/* @__PURE__ */ o(t, {
isDisabled: y,
isInvalid: b,
isReadOnly: x,
isOpen: F,
renderValue: j
}), /* @__PURE__ */ o(h, {
offset: 1,
containerPadding: 8,
className: z(),
placement: O,
children: T ? /* @__PURE__ */ s(u, {
filter: L,
children: [
/* @__PURE__ */ o("div", {
className: "uy:m-100",
children: /* @__PURE__ */ o(e, {
autoFocus: E,
label: k ?? P.formatMessage({
id: "unity:component:select:search:label",
defaultMessage: "Search options"
}),
"data-dd-privacy": "mask"
})
}),
/* @__PURE__ */ o(l, { className: "uy:mx-100 uy:border-t uy:border-border-neutral uy:border-solid" }),
/* @__PURE__ */ o(p, {
layout: f,
layoutOptions: { padding: 8 },
children: /* @__PURE__ */ o(m, {
items: a,
className: B(),
renderEmptyState: H,
children: n
})
})
]
}) : /* @__PURE__ */ o(p, {
layout: f,
layoutOptions: { padding: 8 },
children: /* @__PURE__ */ o(m, {
items: a,
className: B(),
renderEmptyState: H,
children: n
})
})
})]
});
}, y = n(function(e, t) {
return v(e, t);
});
y.displayName = "Select";
//#endregion
export { y as Select };