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