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