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