@oneplatformdev/ui 0.0.1-beta.18 → 0.0.1-beta.19
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 +59 -57
- package/package.json +1 -1
package/Combobox/Combobox.mjs
CHANGED
@@ -1,120 +1,122 @@
|
|
1
|
-
import { jsx as a, jsxs as
|
2
|
-
import n, { useRef as
|
1
|
+
import { jsx as a, jsxs as r } from "react/jsx-runtime";
|
2
|
+
import n, { useRef as _, useCallback as w, useEffect as x } from "react";
|
3
3
|
import { LoadingMask as B } from "../LoadingMask/LoadingMask.mjs";
|
4
|
-
import { Popover as F, PopoverTrigger as
|
5
|
-
import { Button as
|
4
|
+
import { Popover as F, PopoverTrigger as V, PopoverContent as X } from "../Popover/Popover.mjs";
|
5
|
+
import { Button as q } from "../Button/Button.mjs";
|
6
6
|
import "../Button/buttonVariants.mjs";
|
7
|
-
import { Command as
|
8
|
-
import { cn as
|
9
|
-
import { useDebounceCallback as
|
10
|
-
import { X as
|
11
|
-
const
|
7
|
+
import { Command as z, CommandInput as A, CommandList as H, CommandEmpty as J, CommandGroup as K, CommandItem as Q } from "../Command/Command.mjs";
|
8
|
+
import { cn as N } from "@oneplatformdev/utils";
|
9
|
+
import { useDebounceCallback as W } from "@oneplatformdev/hooks";
|
10
|
+
import { X as Y, ChevronsUpDown as Z, Check as $ } from "lucide-react";
|
11
|
+
const de = (S) => {
|
12
12
|
var y;
|
13
13
|
const {
|
14
14
|
value: o,
|
15
|
-
onChange:
|
16
|
-
placeholder:
|
15
|
+
onChange: k,
|
16
|
+
placeholder: D,
|
17
17
|
disabled: L,
|
18
18
|
searchLabel: O,
|
19
19
|
fetchOptions: P,
|
20
|
-
options:
|
20
|
+
options: t,
|
21
21
|
emptyLabel: j = "No options",
|
22
|
-
onMount:
|
23
|
-
} =
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
onMount: u
|
23
|
+
} = S, s = _(!1), [l, p] = n.useState(!1), [G, h] = n.useState(""), [f, c] = n.useState([]), [i, b] = n.useState(), [v, C] = n.useState(!1), M = w(async () => {
|
24
|
+
await g();
|
25
|
+
}, []), T = W(M, 1e3, { leading: !1, trailing: !0 });
|
26
|
+
x(() => {
|
27
|
+
t != null && t.length && c(t);
|
28
|
+
}, [t]);
|
29
|
+
const E = async () => {
|
28
30
|
l || (g(), h(""));
|
29
31
|
}, g = async (e) => {
|
30
32
|
C(!0);
|
31
33
|
try {
|
32
|
-
const
|
33
|
-
|
34
|
-
} catch (
|
35
|
-
console.error("Unexpected error while get option:",
|
34
|
+
const m = await P(e);
|
35
|
+
c(m);
|
36
|
+
} catch (m) {
|
37
|
+
console.error("Unexpected error while get option:", m);
|
36
38
|
} finally {
|
37
39
|
C(!1);
|
38
40
|
}
|
39
|
-
},
|
41
|
+
}, I = (e) => {
|
40
42
|
h(e), T(e);
|
41
|
-
},
|
42
|
-
|
43
|
-
},
|
44
|
-
|
45
|
-
},
|
46
|
-
if (!
|
47
|
-
|
43
|
+
}, d = (e) => {
|
44
|
+
k(e.value), b(e);
|
45
|
+
}, R = () => {
|
46
|
+
d({ value: "", label: "" }), b(void 0);
|
47
|
+
}, U = w(() => {
|
48
|
+
if (!u) {
|
49
|
+
s.current = !0;
|
48
50
|
return;
|
49
51
|
}
|
50
|
-
|
51
|
-
|
52
|
+
u({ setOptions: c }).finally(() => {
|
53
|
+
s.current = !0;
|
52
54
|
});
|
53
|
-
}, [
|
54
|
-
return
|
55
|
-
|
56
|
-
}), []), /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */
|
55
|
+
}, []);
|
56
|
+
return x(() => (U(), () => {
|
57
|
+
s.current = !1;
|
58
|
+
}), []), /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */ r(
|
57
59
|
F,
|
58
60
|
{
|
59
61
|
open: l,
|
60
62
|
onOpenChange: (e) => {
|
61
|
-
p(e), e &&
|
63
|
+
p(e), e && E();
|
62
64
|
},
|
63
65
|
children: [
|
64
|
-
/* @__PURE__ */ a(
|
65
|
-
|
66
|
+
/* @__PURE__ */ a(V, { asChild: !0, className: "border-border", children: /* @__PURE__ */ r(
|
67
|
+
q,
|
66
68
|
{
|
67
69
|
variant: "outline",
|
68
70
|
role: "combobox",
|
69
71
|
"aria-expanded": l,
|
70
|
-
className:
|
72
|
+
className: N(
|
71
73
|
"w-full justify-between font-normal text-sm border bg-input",
|
72
74
|
l ? "border-2 border-sidebar-accent" : "border-border"
|
73
75
|
),
|
74
76
|
disabled: L,
|
75
77
|
children: [
|
76
|
-
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((y = f.find((e) => e.value === o)) == null ? void 0 : y.label) || (
|
78
|
+
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((y = f.find((e) => e.value === o)) == null ? void 0 : y.label) || (i == null ? void 0 : i.label) : /* @__PURE__ */ a("span", { className: "text-gray-400", children: D }) }),
|
77
79
|
o ? /* @__PURE__ */ a(
|
78
|
-
|
80
|
+
Y,
|
79
81
|
{
|
80
82
|
className: "opacity-50 w-4 h-4 cursor-pointer hover:opacity-100",
|
81
83
|
onClick: (e) => {
|
82
|
-
e.stopPropagation(),
|
84
|
+
e.stopPropagation(), R();
|
83
85
|
}
|
84
86
|
}
|
85
|
-
) : /* @__PURE__ */ a(
|
87
|
+
) : /* @__PURE__ */ a(Z, { className: "opacity-50 w-4 h-4" })
|
86
88
|
]
|
87
89
|
}
|
88
90
|
) }),
|
89
91
|
/* @__PURE__ */ a(
|
90
|
-
|
92
|
+
X,
|
91
93
|
{
|
92
94
|
className: "w-[var(--radix-popper-anchor-width)] max-w-none p-0",
|
93
95
|
align: "start",
|
94
|
-
children: /* @__PURE__ */
|
96
|
+
children: /* @__PURE__ */ r(z, { shouldFilter: !1, children: [
|
95
97
|
/* @__PURE__ */ a(
|
96
|
-
|
98
|
+
A,
|
97
99
|
{
|
98
100
|
placeholder: O,
|
99
|
-
value:
|
100
|
-
onValueChange:
|
101
|
+
value: G,
|
102
|
+
onValueChange: I
|
101
103
|
}
|
102
104
|
),
|
103
|
-
/* @__PURE__ */
|
104
|
-
!v && /* @__PURE__ */ a(
|
105
|
-
/* @__PURE__ */ a(
|
106
|
-
|
105
|
+
/* @__PURE__ */ r(H, { children: [
|
106
|
+
!v && /* @__PURE__ */ a(J, { children: j }),
|
107
|
+
/* @__PURE__ */ a(K, { children: v ? /* @__PURE__ */ a("div", { className: "flex justify-center", children: /* @__PURE__ */ a(B, {}) }) : f.map((e) => /* @__PURE__ */ r(
|
108
|
+
Q,
|
107
109
|
{
|
108
110
|
value: e.value,
|
109
111
|
onSelect: () => {
|
110
|
-
o === e.value ?
|
112
|
+
o === e.value ? d({ value: "", label: "" }) : d(e), p(!1);
|
111
113
|
},
|
112
114
|
children: [
|
113
115
|
e.label,
|
114
116
|
/* @__PURE__ */ a(
|
115
|
-
|
117
|
+
$,
|
116
118
|
{
|
117
|
-
className:
|
119
|
+
className: N(
|
118
120
|
"ml-auto",
|
119
121
|
o === e.value ? "opacity-100" : "opacity-0"
|
120
122
|
)
|
@@ -133,5 +135,5 @@ const ie = (N) => {
|
|
133
135
|
) });
|
134
136
|
};
|
135
137
|
export {
|
136
|
-
|
138
|
+
de as Combobox
|
137
139
|
};
|