@oneplatformdev/ui 0.0.1-beta.17 → 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 +76 -63
- package/Combobox/Combobox.types.d.ts +7 -0
- package/package.json +1 -1
package/Combobox/Combobox.mjs
CHANGED
@@ -1,109 +1,122 @@
|
|
1
|
-
import { jsx as a, jsxs as
|
2
|
-
import n, { useEffect 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 _, useCallback as w, useEffect as x } 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
|
12
|
-
var
|
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
|
+
var y;
|
13
13
|
const {
|
14
14
|
value: o,
|
15
|
-
onChange:
|
16
|
-
placeholder:
|
17
|
-
disabled:
|
18
|
-
searchLabel:
|
19
|
-
fetchOptions:
|
20
|
-
options:
|
21
|
-
emptyLabel:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}, [
|
26
|
-
|
27
|
-
|
28
|
-
},
|
29
|
-
|
15
|
+
onChange: k,
|
16
|
+
placeholder: D,
|
17
|
+
disabled: L,
|
18
|
+
searchLabel: O,
|
19
|
+
fetchOptions: P,
|
20
|
+
options: t,
|
21
|
+
emptyLabel: j = "No options",
|
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 () => {
|
30
|
+
l || (g(), h(""));
|
31
|
+
}, g = async (e) => {
|
32
|
+
C(!0);
|
30
33
|
try {
|
31
|
-
const
|
32
|
-
|
33
|
-
} catch (
|
34
|
-
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);
|
35
38
|
} finally {
|
36
|
-
|
39
|
+
C(!1);
|
37
40
|
}
|
38
|
-
},
|
39
|
-
|
40
|
-
},
|
41
|
-
|
42
|
-
},
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
|
41
|
+
}, I = (e) => {
|
42
|
+
h(e), T(e);
|
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;
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
u({ setOptions: c }).finally(() => {
|
53
|
+
s.current = !0;
|
54
|
+
});
|
55
|
+
}, []);
|
56
|
+
return x(() => (U(), () => {
|
57
|
+
s.current = !1;
|
58
|
+
}), []), /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */ r(
|
59
|
+
F,
|
47
60
|
{
|
48
61
|
open: l,
|
49
62
|
onOpenChange: (e) => {
|
50
|
-
|
63
|
+
p(e), e && E();
|
51
64
|
},
|
52
65
|
children: [
|
53
|
-
/* @__PURE__ */ a(
|
54
|
-
|
66
|
+
/* @__PURE__ */ a(V, { asChild: !0, className: "border-border", children: /* @__PURE__ */ r(
|
67
|
+
q,
|
55
68
|
{
|
56
69
|
variant: "outline",
|
57
70
|
role: "combobox",
|
58
71
|
"aria-expanded": l,
|
59
|
-
className:
|
72
|
+
className: N(
|
60
73
|
"w-full justify-between font-normal text-sm border bg-input",
|
61
74
|
l ? "border-2 border-sidebar-accent" : "border-border"
|
62
75
|
),
|
63
|
-
disabled:
|
76
|
+
disabled: L,
|
64
77
|
children: [
|
65
|
-
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((
|
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 }) }),
|
66
79
|
o ? /* @__PURE__ */ a(
|
67
|
-
|
80
|
+
Y,
|
68
81
|
{
|
69
82
|
className: "opacity-50 w-4 h-4 cursor-pointer hover:opacity-100",
|
70
83
|
onClick: (e) => {
|
71
|
-
e.stopPropagation(),
|
84
|
+
e.stopPropagation(), R();
|
72
85
|
}
|
73
86
|
}
|
74
|
-
) : /* @__PURE__ */ a(
|
87
|
+
) : /* @__PURE__ */ a(Z, { className: "opacity-50 w-4 h-4" })
|
75
88
|
]
|
76
89
|
}
|
77
90
|
) }),
|
78
91
|
/* @__PURE__ */ a(
|
79
|
-
|
92
|
+
X,
|
80
93
|
{
|
81
94
|
className: "w-[var(--radix-popper-anchor-width)] max-w-none p-0",
|
82
95
|
align: "start",
|
83
|
-
children: /* @__PURE__ */
|
96
|
+
children: /* @__PURE__ */ r(z, { shouldFilter: !1, children: [
|
84
97
|
/* @__PURE__ */ a(
|
85
|
-
|
98
|
+
A,
|
86
99
|
{
|
87
|
-
placeholder:
|
88
|
-
value:
|
89
|
-
onValueChange:
|
100
|
+
placeholder: O,
|
101
|
+
value: G,
|
102
|
+
onValueChange: I
|
90
103
|
}
|
91
104
|
),
|
92
|
-
/* @__PURE__ */
|
93
|
-
!
|
94
|
-
/* @__PURE__ */ a(
|
95
|
-
|
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,
|
96
109
|
{
|
97
110
|
value: e.value,
|
98
111
|
onSelect: () => {
|
99
|
-
o === e.value ?
|
112
|
+
o === e.value ? d({ value: "", label: "" }) : d(e), p(!1);
|
100
113
|
},
|
101
114
|
children: [
|
102
115
|
e.label,
|
103
116
|
/* @__PURE__ */ a(
|
104
|
-
|
117
|
+
$,
|
105
118
|
{
|
106
|
-
className:
|
119
|
+
className: N(
|
107
120
|
"ml-auto",
|
108
121
|
o === e.value ? "opacity-100" : "opacity-0"
|
109
122
|
)
|
@@ -122,5 +135,5 @@ const te = (w) => {
|
|
122
135
|
) });
|
123
136
|
};
|
124
137
|
export {
|
125
|
-
|
138
|
+
de as Combobox
|
126
139
|
};
|
@@ -1,7 +1,12 @@
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
2
|
+
|
1
3
|
export interface ComboboxOption {
|
2
4
|
value: string;
|
3
5
|
label: string;
|
4
6
|
}
|
7
|
+
export interface ComboboxPropsOnMountParams {
|
8
|
+
setOptions: Dispatch<SetStateAction<ComboboxOption[]>>;
|
9
|
+
}
|
5
10
|
export interface ComboboxProps {
|
6
11
|
value: string;
|
7
12
|
onChange: (value: string) => void;
|
@@ -12,4 +17,6 @@ export interface ComboboxProps {
|
|
12
17
|
options?: ComboboxOption[];
|
13
18
|
/** CommandEmpty label*/
|
14
19
|
emptyLabel?: string;
|
20
|
+
/** Callback for load data on start component */
|
21
|
+
onMount?: (params: ComboboxPropsOnMountParams) => Promise<ComboboxOption[]>;
|
15
22
|
}
|