UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

63 lines (62 loc) 2.15 kB
"use client"; import { jsxs as s, jsx as n } from "react/jsx-runtime"; import * as b from "react"; import { Select as C, SelectTrigger as O, SelectValue as B, SelectContent as G, SelectSeparator as N, SelectGroup as j, SelectLabel as w, SelectItem as D } from "./select.js"; import { SelectScrollDownButton as F, SelectScrollUpButton as R } from "./select.js"; function U({ options: p, placeholder: d, children: m, label: g, className: h, labelKey: S, valueKey: o, descriptionKey: u, groupNameKey: a, isOptionDisabled: f, ...A }) { const i = (t) => { const c = S && o, e = String(c ? t[o] : t.value), r = c ? String(t[S]) : t.label, l = c && u ? String(t[u]) : null, x = c ? f?.(t) ?? !1 : t.disabled; return /* @__PURE__ */ n(D, { value: e, disabled: x, children: /* @__PURE__ */ s("span", { className: "flex flex-col", children: [ /* @__PURE__ */ n("span", { children: r }), l && /* @__PURE__ */ s("span", { className: "text-muted-foreground text-d-tertiary text-xs", children: [ "- ", l ] }) ] }) }, e); }; return /* @__PURE__ */ s(C, { ...A, label: g, className: h, children: [ m || /* @__PURE__ */ n(O, { className: "w-full", children: /* @__PURE__ */ n(B, { placeholder: d }) }), /* @__PURE__ */ n(G, { children: (() => { if (!p.some((e) => a ? String(e[a]) : e.groupName)) return p.map(i); const c = p.reduce( (e, r) => { const l = a ? String(r[a]) : r.groupName || "Altro"; return e[l] || (e[l] = []), e[l].push(r), e; }, {} ); return Object.entries(c).map(([e, r], l) => /* @__PURE__ */ s(b.Fragment, { children: [ l > 0 && /* @__PURE__ */ n(N, {}), /* @__PURE__ */ s(j, { children: [ /* @__PURE__ */ n(w, { children: e }), r.map(i) ] }) ] }, e)); })() }) ] }); } export { U as AppSelect, G as AppSelectContent, j as AppSelectGroup, D as AppSelectItem, w as AppSelectLabel, F as AppSelectScrollDownButton, R as AppSelectScrollUpButton, N as AppSelectSeparator, O as AppSelectTrigger, B as AppSelectValue };