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