@oneplatformdev/ui 0.0.1-beta.52 → 0.0.1-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Combobox/Combobox.mjs +38 -38
- package/Combobox/Combobox.types.d.ts +1 -0
- package/package.json +1 -1
package/Combobox/Combobox.mjs
CHANGED
@@ -1,81 +1,81 @@
|
|
1
|
-
import { jsx as a, jsxs as
|
1
|
+
import { jsx as a, jsxs as t, Fragment as R } from "react/jsx-runtime";
|
2
2
|
import l, { useRef as U, useEffect as _, useCallback as s, useLayoutEffect as A } from "react";
|
3
3
|
import { LoadingMask as V } from "../LoadingMask/LoadingMask.mjs";
|
4
4
|
import { Popover as X, PopoverTrigger as q, PopoverContent as z } from "../Popover/Popover.mjs";
|
5
5
|
import { Button as H } from "../Button/Button.mjs";
|
6
6
|
import "../Button/buttonVariants.mjs";
|
7
7
|
import { Command as J, CommandInput as K, CommandList as Q, CommandGroup as W, CommandEmpty as k, CommandItem as Y } from "../Command/Command.mjs";
|
8
|
-
import { cn as
|
8
|
+
import { cn as v } from "@oneplatformdev/utils";
|
9
9
|
import { useDebounceCallback as Z } from "@oneplatformdev/hooks";
|
10
10
|
import { X as $, ChevronsUpDown as ee, Check as ae } from "lucide-react";
|
11
11
|
const pe = (O) => {
|
12
12
|
var L;
|
13
13
|
const {
|
14
|
-
value:
|
14
|
+
value: o,
|
15
15
|
onChange: P,
|
16
16
|
placeholder: j,
|
17
17
|
disabled: D,
|
18
18
|
searchLabel: T = "Type to search...",
|
19
19
|
fetchOptions: B,
|
20
20
|
options: n,
|
21
|
-
emptyLabel:
|
21
|
+
emptyLabel: y = "No options",
|
22
22
|
emptyAction: c,
|
23
|
-
onMount:
|
24
|
-
} = O,
|
23
|
+
onMount: C
|
24
|
+
} = O, u = U(!1), [i, x] = l.useState(!1), [d, w] = l.useState(""), [m, p] = l.useState([]), [h, N] = l.useState(), [f, r] = l.useState(!1);
|
25
25
|
_(() => {
|
26
|
-
n != null && n.length &&
|
26
|
+
n != null && n.length && p(n);
|
27
27
|
}, [n]);
|
28
28
|
const E = async () => {
|
29
29
|
i || (S(), w(""));
|
30
30
|
}, S = s(async (e) => {
|
31
31
|
r(!0);
|
32
32
|
try {
|
33
|
-
const
|
34
|
-
|
35
|
-
} catch (
|
36
|
-
console.error("Unexpected error while get option:",
|
33
|
+
const g = await B(e);
|
34
|
+
p(g);
|
35
|
+
} catch (g) {
|
36
|
+
console.error("Unexpected error while get option:", g);
|
37
37
|
} finally {
|
38
38
|
r(!1);
|
39
39
|
}
|
40
40
|
}, []), M = Z(S, 1e3, { leading: !1, trailing: !0 }), F = s((e) => {
|
41
41
|
r(!0), w(e), M(e);
|
42
|
-
}, []),
|
42
|
+
}, []), b = s((e) => {
|
43
43
|
P(e.value), N(e), r(!1);
|
44
44
|
}, []), G = s(() => {
|
45
|
-
|
45
|
+
b({ value: "", label: "" }), N(void 0), r(!1);
|
46
46
|
}, []), I = s(() => {
|
47
|
-
if (!
|
48
|
-
|
47
|
+
if (!C) {
|
48
|
+
u.current = !0;
|
49
49
|
return;
|
50
50
|
}
|
51
|
-
|
52
|
-
|
51
|
+
C({ setOptions: p, search: d || "" }).finally(() => {
|
52
|
+
u.current = !0;
|
53
53
|
});
|
54
54
|
}, []);
|
55
55
|
return A(() => (I(), () => {
|
56
|
-
|
57
|
-
}), []), /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */
|
56
|
+
u.current = !1;
|
57
|
+
}), []), /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */ t(
|
58
58
|
X,
|
59
59
|
{
|
60
60
|
open: i,
|
61
61
|
onOpenChange: (e) => {
|
62
|
-
|
62
|
+
x(e), e && E();
|
63
63
|
},
|
64
64
|
children: [
|
65
|
-
/* @__PURE__ */ a(q, { asChild: !0, className: "border-input", children: /* @__PURE__ */
|
65
|
+
/* @__PURE__ */ a(q, { asChild: !0, className: "border-input", children: /* @__PURE__ */ t(
|
66
66
|
H,
|
67
67
|
{
|
68
68
|
variant: "outline",
|
69
69
|
role: "combobox",
|
70
70
|
"aria-expanded": i,
|
71
|
-
className:
|
71
|
+
className: v(
|
72
72
|
"w-full justify-between font-normal text-sm border bg-transparent",
|
73
73
|
i ? "border-2 border-sidebar-accent" : "border-border"
|
74
74
|
),
|
75
75
|
disabled: D,
|
76
76
|
children: [
|
77
|
-
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children:
|
78
|
-
|
77
|
+
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((L = m.find((e) => e.value === o)) == null ? void 0 : L.label) || (h == null ? void 0 : h.label) : /* @__PURE__ */ a("span", { className: "text-gray-400", children: j }) }),
|
78
|
+
o ? /* @__PURE__ */ a(
|
79
79
|
$,
|
80
80
|
{
|
81
81
|
className: "opacity-50 w-4 h-4 cursor-pointer hover:opacity-100",
|
@@ -92,42 +92,42 @@ const pe = (O) => {
|
|
92
92
|
{
|
93
93
|
className: "w-[var(--radix-popper-anchor-width)] max-w-none p-0",
|
94
94
|
align: "start",
|
95
|
-
children: /* @__PURE__ */
|
95
|
+
children: /* @__PURE__ */ t(J, { shouldFilter: !1, children: [
|
96
96
|
/* @__PURE__ */ a(
|
97
97
|
K,
|
98
98
|
{
|
99
99
|
placeholder: T,
|
100
|
-
value:
|
100
|
+
value: d,
|
101
101
|
onValueChange: F
|
102
102
|
}
|
103
103
|
),
|
104
|
-
/* @__PURE__ */ a(Q, { children: /* @__PURE__ */
|
104
|
+
/* @__PURE__ */ a(Q, { children: /* @__PURE__ */ t(
|
105
105
|
W,
|
106
106
|
{
|
107
|
-
className:
|
108
|
-
!
|
107
|
+
className: v(
|
108
|
+
!m.length && "p-0 shadow-none"
|
109
109
|
),
|
110
110
|
children: [
|
111
|
-
|
112
|
-
!
|
113
|
-
/* @__PURE__ */ a("span", { children:
|
114
|
-
typeof c == "function" ? c({ setOptions:
|
115
|
-
] })
|
116
|
-
!
|
111
|
+
f && /* @__PURE__ */ a("div", { className: "flex justify-center", children: /* @__PURE__ */ a(V, {}) }),
|
112
|
+
!f && !!d && /* @__PURE__ */ a(R, { children: c ? /* @__PURE__ */ t(k, { className: "flex flex-col gap-3 py-5 px-3 items-center", children: [
|
113
|
+
/* @__PURE__ */ a("span", { children: y }),
|
114
|
+
typeof c == "function" ? c({ setOptions: p, search: d || "" }) : c
|
115
|
+
] }) : /* @__PURE__ */ a(k, { children: y }) }),
|
116
|
+
!f && !!m.length && m.map((e) => /* @__PURE__ */ t(
|
117
117
|
Y,
|
118
118
|
{
|
119
119
|
value: e.value,
|
120
120
|
onSelect: () => {
|
121
|
-
|
121
|
+
o === e.value ? b({ value: "", label: "" }) : b(e), x(!1);
|
122
122
|
},
|
123
123
|
children: [
|
124
124
|
e.label,
|
125
125
|
/* @__PURE__ */ a(
|
126
126
|
ae,
|
127
127
|
{
|
128
|
-
className:
|
128
|
+
className: v(
|
129
129
|
"ml-auto",
|
130
|
-
|
130
|
+
o === e.value ? "opacity-100" : "opacity-0"
|
131
131
|
)
|
132
132
|
}
|
133
133
|
)
|