@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.
@@ -1,109 +1,122 @@
1
- import { jsx as a, jsxs as t } from "react/jsx-runtime";
2
- import n, { useEffect as E } from "react";
3
- import { LoadingMask as I } from "../LoadingMask/LoadingMask.mjs";
4
- import { Popover as U, PopoverTrigger as _, PopoverContent as B } from "../Popover/Popover.mjs";
5
- import { Button as F } from "../Button/Button.mjs";
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 G, CommandInput as M, CommandList as R, CommandEmpty as V, CommandGroup as W, CommandItem as X } from "../Command/Command.mjs";
8
- import { cn as g } from "@oneplatformdev/utils";
9
- import { useDebounceCallback as q } from "@oneplatformdev/hooks";
10
- import { X as z, ChevronsUpDown as A, Check as H } from "lucide-react";
11
- const te = (w) => {
12
- var C;
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: y,
16
- placeholder: x,
17
- disabled: N,
18
- searchLabel: S,
19
- fetchOptions: L,
20
- options: r,
21
- emptyLabel: O = "No options"
22
- } = w, [l, d] = n.useState(!1), [P, m] = n.useState(""), [p, h] = n.useState([]), [s, u] = n.useState(), [f, b] = n.useState(!1);
23
- E(() => {
24
- r != null && r.length && h(r);
25
- }, [r]);
26
- const j = async () => {
27
- l || (v(), m(""));
28
- }, v = async (e) => {
29
- b(!0);
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 i = await L(e);
32
- h(i);
33
- } catch (i) {
34
- console.error("Unexpected error while get option:", i);
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
- b(!1);
39
+ C(!1);
37
40
  }
38
- }, k = q(v, 1e3), D = (e) => {
39
- m(e), k(e);
40
- }, c = (e) => {
41
- y(e.value), u(e);
42
- }, T = () => {
43
- c({ value: "", label: "" }), u(void 0);
44
- };
45
- return /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */ t(
46
- U,
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
- d(e), e && j();
63
+ p(e), e && E();
51
64
  },
52
65
  children: [
53
- /* @__PURE__ */ a(_, { asChild: !0, className: "border-border", children: /* @__PURE__ */ t(
54
- F,
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: g(
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: N,
76
+ disabled: L,
64
77
  children: [
65
- /* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((C = p.find((e) => e.value === o)) == null ? void 0 : C.label) || (s == null ? void 0 : s.label) : /* @__PURE__ */ a("span", { className: "text-gray-400", children: x }) }),
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
- z,
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(), T();
84
+ e.stopPropagation(), R();
72
85
  }
73
86
  }
74
- ) : /* @__PURE__ */ a(A, { className: "opacity-50 w-4 h-4" })
87
+ ) : /* @__PURE__ */ a(Z, { className: "opacity-50 w-4 h-4" })
75
88
  ]
76
89
  }
77
90
  ) }),
78
91
  /* @__PURE__ */ a(
79
- B,
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__ */ t(G, { shouldFilter: !1, children: [
96
+ children: /* @__PURE__ */ r(z, { shouldFilter: !1, children: [
84
97
  /* @__PURE__ */ a(
85
- M,
98
+ A,
86
99
  {
87
- placeholder: S,
88
- value: P,
89
- onValueChange: D
100
+ placeholder: O,
101
+ value: G,
102
+ onValueChange: I
90
103
  }
91
104
  ),
92
- /* @__PURE__ */ t(R, { children: [
93
- !f && /* @__PURE__ */ a(V, { children: O }),
94
- /* @__PURE__ */ a(W, { children: f ? /* @__PURE__ */ a("div", { className: "flex justify-center", children: /* @__PURE__ */ a(I, {}) }) : p.map((e) => /* @__PURE__ */ t(
95
- X,
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 ? c({ value: "", label: "" }) : c(e), d(!1);
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
- H,
117
+ $,
105
118
  {
106
- className: g(
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
- te as Combobox
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneplatformdev/ui",
3
- "version": "0.0.1-beta.17",
3
+ "version": "0.0.1-beta.19",
4
4
  "description": "UI React Components.",
5
5
  "author": "One Platform Development Team",
6
6
  "keywords": [