@oneplatformdev/ui 0.0.1-beta.14 → 0.0.1-beta.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,109 +1,120 @@
1
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";
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 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 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: y,
16
- placeholder: x,
17
- disabled: N,
18
- searchLabel: S,
19
- fetchOptions: L,
15
+ onChange: S,
16
+ placeholder: k,
17
+ disabled: L,
18
+ searchLabel: O,
19
+ fetchOptions: P,
20
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);
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 j = async () => {
27
- l || (v(), m(""));
28
- }, v = async (e) => {
29
- b(!0);
27
+ const M = async () => {
28
+ l || (g(), h(""));
29
+ }, g = async (e) => {
30
+ C(!0);
30
31
  try {
31
- const i = await L(e);
32
- h(i);
33
- } catch (i) {
34
- console.error("Unexpected error while get option:", i);
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
- b(!1);
37
+ C(!1);
37
38
  }
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,
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
- d(e), e && j();
61
+ p(e), e && M();
51
62
  },
52
63
  children: [
53
- /* @__PURE__ */ a(_, { asChild: !0, className: "border-border", children: /* @__PURE__ */ t(
54
- F,
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: g(
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: N,
74
+ disabled: L,
64
75
  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 }) }),
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
- z,
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(), T();
82
+ e.stopPropagation(), I();
72
83
  }
73
84
  }
74
- ) : /* @__PURE__ */ a(A, { className: "opacity-50 w-4 h-4" })
85
+ ) : /* @__PURE__ */ a(Y, { className: "opacity-50 w-4 h-4" })
75
86
  ]
76
87
  }
77
88
  ) }),
78
89
  /* @__PURE__ */ a(
79
- B,
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(G, { shouldFilter: !1, children: [
94
+ children: /* @__PURE__ */ t(X, { shouldFilter: !1, children: [
84
95
  /* @__PURE__ */ a(
85
- M,
96
+ q,
86
97
  {
87
- placeholder: S,
88
- value: P,
89
- onValueChange: D
98
+ placeholder: O,
99
+ value: D,
100
+ onValueChange: E
90
101
  }
91
102
  ),
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,
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 ? c({ value: "", label: "" }) : c(e), d(!1);
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
- H,
115
+ Z,
105
116
  {
106
- className: g(
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
- te as Combobox
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
  }
@@ -1,106 +1,102 @@
1
- import { jsxs as r, jsx as o } from "react/jsx-runtime";
2
- import { forwardRef as L, useState as y, useEffect as M } from "react";
3
- import { useDropzone as U } from "react-dropzone";
4
- import { Card as j } from "../Card/Card.mjs";
5
- import { File as O, X } from "lucide-react";
6
- import { cn as f } from "@oneplatformdev/utils";
7
- import { F as Y, D as q } from "../FilePreview-Dhtv8F4u.js";
8
- import { isFile as v, extractName as G } from "./DropzoneUtils.mjs";
9
- const H = L(
1
+ import { jsxs as t, jsx as o } from "react/jsx-runtime";
2
+ import { forwardRef as L, useState as g } from "react";
3
+ import { useDropzone as M } from "react-dropzone";
4
+ import { Card as U } from "../Card/Card.mjs";
5
+ import { File as j, X as O } from "lucide-react";
6
+ import { cn as m } from "@oneplatformdev/utils";
7
+ import { F as X, D as Y } from "../DropzoneFilePreview-Dhtv8F4u.js";
8
+ import { isFile as v, extractName as q } from "./DropzoneUtils.mjs";
9
+ const G = L(
10
10
  ({
11
- acceptTypes: w = q,
12
- maxSizeMB: b,
13
- maxFiles: h = 1,
14
- onErrors: g,
15
- hideErrors: F = !1,
11
+ acceptTypes: y = Y,
12
+ maxSizeMB: w,
13
+ maxFiles: a = 1,
14
+ onErrors: x,
15
+ hideErrors: b = !1,
16
16
  disabled: p = !1,
17
17
  classNames: l,
18
- value: m = [],
18
+ value: u = [],
19
19
  onChangeValue: s,
20
- className: u,
20
+ className: F,
21
21
  labelDropzonePrompt: z = "Drop files here or click to select",
22
- labelOrClickToSelect: J = "Click to select files",
22
+ labelOrClickToSelect: H = "Click to select files",
23
23
  labelSelectedFiles: D = "Selected Files",
24
24
  labelUploadErrors: I = "Upload Errors",
25
25
  labelFileTooLarge: k = "File is too large",
26
- labelInvalidFileType: E = "Invalid file type",
27
- ...S
26
+ labelInvalidFileType: S = "Invalid file type",
27
+ ...E
28
28
  }, P) => {
29
- const [c, a] = y(m), [d, N] = y([]);
30
- M(() => {
31
- a(m);
32
- }, [m]);
33
- const W = (e, i) => {
34
- N(i), g && g(i);
35
- const t = [...c, ...e].slice(0, h);
36
- a(t), s == null || s(t);
29
+ const [c, h] = g(u), [d, N] = g([]), W = (e, i) => {
30
+ N(i), x && x(i);
31
+ const r = [...c, ...e].slice(0, a);
32
+ h(r), s == null || s(r);
37
33
  }, T = (e, i) => {
38
34
  if (p) return;
39
35
  e.stopPropagation();
40
- const t = c.filter((n, x) => x !== i);
41
- a(t), s == null || s(t);
42
- }, { getRootProps: _, getInputProps: A, isDragActive: B } = U({
36
+ const r = c.filter((n, f) => f !== i);
37
+ h(r), s == null || s(r);
38
+ }, { getRootProps: _, getInputProps: A, isDragActive: B } = M({
43
39
  onDrop: W,
44
- accept: w.reduce((e, i) => (e[i] = [], e), {}),
45
- maxSize: b * 1024 * 1024,
46
- maxFiles: h,
40
+ accept: y.reduce((e, i) => (e[i] = [], e), {}),
41
+ maxSize: w * 1024 * 1024,
42
+ maxFiles: a,
47
43
  disabled: p
48
44
  });
49
- return /* @__PURE__ */ r(
50
- j,
45
+ return /* @__PURE__ */ t(
46
+ U,
51
47
  {
52
48
  ..._(),
53
- ...S,
54
- className: f(
49
+ ...E,
50
+ className: m(
55
51
  "border-dashed border-2 p-6 text-center flex flex-col items-center justify-center",
56
52
  p && "bg-gray-300 pointer-events-none",
57
53
  d.length > 0 ? "border-red-500" : "border-gray-300",
58
54
  B && "bg-gray-100",
59
- u
55
+ F
60
56
  ),
61
57
  ref: P,
62
58
  children: [
63
59
  /* @__PURE__ */ o("input", { ...A() }),
64
- c.length === 0 && d.length === 0 && /* @__PURE__ */ r(
60
+ c.length === 0 && d.length === 0 && /* @__PURE__ */ t(
65
61
  "div",
66
62
  {
67
- className: f(
63
+ className: m(
68
64
  "flex flex-col items-center gap-1",
69
65
  l == null ? void 0 : l.idleWrapper
70
66
  ),
71
67
  children: [
72
- /* @__PURE__ */ o(O, { className: "w-8 h-8 text-gray-500" }),
73
- !p && /* @__PURE__ */ o("span", { className: "font-semibold text-gray-600", children: z })
68
+ /* @__PURE__ */ o(j, { className: "w-8 h-8 text-gray-500" }),
69
+ !p && /* @__PURE__ */ o("pre", { className: "font-semibold text-gray-600", children: z })
74
70
  ]
75
71
  }
76
72
  ),
77
- c.length > 0 && /* @__PURE__ */ r("div", { className: f("w-full mt-2", l == null ? void 0 : l.previewWrapper), children: [
78
- /* @__PURE__ */ r("span", { className: "font-semibold text-gray-600", children: [
73
+ c.length > 0 && /* @__PURE__ */ t("div", { className: m("w-full mt-2", l == null ? void 0 : l.previewWrapper), children: [
74
+ /* @__PURE__ */ t("pre", { className: "font-semibold text-gray-600", children: [
79
75
  D,
80
76
  ":"
81
77
  ] }),
82
78
  /* @__PURE__ */ o("ul", { className: "mt-2 text-sm text-gray-500 flex flex-wrap gap-4 items-start justify-center", children: c.map((e, i) => {
83
- const t = v(e) ? e.name : G(e), n = v(e) ? (e.size / (1024 * 1024)).toFixed(2) + " MB" : "";
84
- return /* @__PURE__ */ r(
79
+ const r = v(e) ? e.name : q(e), n = v(e) ? (e.size / (1024 * 1024)).toFixed(2) + " MB" : "";
80
+ return /* @__PURE__ */ t(
85
81
  "li",
86
82
  {
87
83
  className: "flex flex-col items-center gap-2 relative",
88
84
  children: [
89
- /* @__PURE__ */ r("div", { className: "relative", children: [
90
- /* @__PURE__ */ o(Y, { item: e, styles: l }),
85
+ /* @__PURE__ */ t("div", { className: "relative", children: [
86
+ /* @__PURE__ */ o(X, { item: e, styles: l }),
91
87
  /* @__PURE__ */ o("div", { className: "absolute top-0 right-0 cursor-pointer bg-gray-300 rounded-sm", children: /* @__PURE__ */ o(
92
- X,
88
+ O,
93
89
  {
94
90
  size: 16,
95
91
  strokeWidth: 1,
96
92
  color: "black",
97
- onClick: (x) => T(x, i)
93
+ onClick: (f) => T(f, i)
98
94
  }
99
95
  ) })
100
96
  ] }),
101
- /* @__PURE__ */ r("span", { className: "inline-flex flex-col items-center", children: [
102
- /* @__PURE__ */ o("span", { className: "max-w-[80px] text-ellipsis overflow-hidden whitespace-nowrap", children: t }),
103
- n && /* @__PURE__ */ r("span", { children: [
97
+ /* @__PURE__ */ t("span", { className: "inline-flex flex-col items-center", children: [
98
+ /* @__PURE__ */ o("span", { className: "max-w-[80px] text-ellipsis overflow-hidden whitespace-nowrap", children: r }),
99
+ n && /* @__PURE__ */ t("span", { children: [
104
100
  "(",
105
101
  n,
106
102
  ")"
@@ -112,20 +108,20 @@ const H = L(
112
108
  );
113
109
  }) })
114
110
  ] }),
115
- d.length > 0 && /* @__PURE__ */ r("div", { className: f("w-full mt-4", l == null ? void 0 : l.errorWrapper), children: [
116
- /* @__PURE__ */ r("span", { className: "font-semibold text-red-500", children: [
111
+ d.length > 0 && /* @__PURE__ */ t("div", { className: m("w-full mt-4", l == null ? void 0 : l.errorWrapper), children: [
112
+ /* @__PURE__ */ t("span", { className: "font-semibold text-red-500", children: [
117
113
  I,
118
114
  ":"
119
115
  ] }),
120
- /* @__PURE__ */ o("ul", { className: "mt-2 text-sm text-red-500 list-disc list-inside", children: d.map((e, i) => /* @__PURE__ */ r("li", { children: [
116
+ /* @__PURE__ */ o("ul", { className: "mt-2 text-sm text-red-500 list-disc list-inside", children: d.map((e, i) => /* @__PURE__ */ t("li", { children: [
121
117
  e.file.name,
122
118
  " (",
123
119
  (e.file.size / (1024 * 1024)).toFixed(2),
124
120
  " MB)",
125
- !F && /* @__PURE__ */ o("ul", { className: "ml-4 list-disc list-inside", children: e.errors.map((t, n) => /* @__PURE__ */ r("li", { children: [
126
- t.code === "file-too-large" && k,
127
- t.code === "file-invalid-type" && E,
128
- t.code !== "file-too-large" && t.code !== "file-invalid-type" && t.message
121
+ !b && /* @__PURE__ */ o("ul", { className: "ml-4 list-disc list-inside", children: e.errors.map((r, n) => /* @__PURE__ */ t("li", { children: [
122
+ r.code === "file-too-large" && k,
123
+ r.code === "file-invalid-type" && S,
124
+ r.code !== "file-too-large" && r.code !== "file-invalid-type" && r.message
129
125
  ] }, n)) })
130
126
  ] }, i)) })
131
127
  ] })
@@ -134,7 +130,7 @@ const H = L(
134
130
  );
135
131
  }
136
132
  );
137
- H.displayName = "Dropzone";
133
+ G.displayName = "Dropzone";
138
134
  export {
139
- H as Dropzone
135
+ G as Dropzone
140
136
  };
@@ -1,7 +1,7 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
3
  import "lucide-react";
4
- import { F } from "../FilePreview-Dhtv8F4u.js";
4
+ import { F } from "../DropzoneFilePreview-Dhtv8F4u.js";
5
5
  import "./DropzoneUtils.mjs";
6
6
  import "@oneplatformdev/utils";
7
7
  export {
@@ -1,5 +1,5 @@
1
1
  import { Dropzone as r } from "./Dropzone.mjs";
2
- import { D as T, a as _ } from "../FilePreview-Dhtv8F4u.js";
2
+ import { D as T, a as _ } from "../DropzoneFilePreview-Dhtv8F4u.js";
3
3
  export {
4
4
  T as DEFAULT_FILE_TYPES,
5
5
  _ as DEFAULT_IMAGES_TYPES,
@@ -1,22 +1,21 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { FormControl as p } from "../Form/Form.mjs";
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { FormControl as a } from "../Form/Form.mjs";
3
3
  import { FormRenderControl as l } from "../Form/FormRenderControl.mjs";
4
- import { Dropzone as s } from "../Dropzone/Dropzone.mjs";
5
- const h = (e) => {
6
- const { form: n, label: m, name: t, ...a } = e;
7
- return /* @__PURE__ */ r(
4
+ import { Dropzone as f } from "../Dropzone/Dropzone.mjs";
5
+ const h = (n) => {
6
+ const { form: e, label: m, name: t, ...p } = n;
7
+ return /* @__PURE__ */ o(
8
8
  l,
9
9
  {
10
- form: n,
10
+ form: e,
11
11
  label: m,
12
12
  name: t,
13
- render: ({ field: o }) => /* @__PURE__ */ r(p, { children: /* @__PURE__ */ r(
14
- s,
13
+ render: ({ field: r }) => /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(
14
+ f,
15
15
  {
16
- ...a,
17
- ...o,
18
- value: o.value,
19
- onChangeValue: o.onChange
16
+ ...p,
17
+ ...r,
18
+ onChangeValue: r.onChange
20
19
  }
21
20
  ) })
22
21
  }
@@ -3,5 +3,5 @@ import { FormRenderControlExtendProps } from '../Form';
3
3
  import { UseFormReturn } from 'react-hook-form';
4
4
  import { FieldValues } from 'react-hook-form/dist/types/fields';
5
5
 
6
- export interface FormSelectProps<Data extends FieldValues, Form extends UseFormReturn<Data>, ExtendOptionData> extends FormRenderControlExtendProps<Data, Form>, SelectProps<ExtendOptionData> {
6
+ export interface FormSelectProps<Data extends FieldValues, Form extends UseFormReturn<Data>, ExtendOptionData> extends FormRenderControlExtendProps<Data, Form>, Omit<SelectProps<ExtendOptionData>, 'onChange'> {
7
7
  }
package/index.mjs CHANGED
@@ -78,7 +78,7 @@ import { ToggleGroup as cn, ToggleGroupItem as Mn } from "./ToggleGroup/ToggleGr
78
78
  import { TooltipContent as An, TooltipProvider as In, TooltipRoot as wn, TooltipTrigger as hn } from "./Tooltip/TooltipRoot.mjs";
79
79
  import { Tooltip as Fn } from "./Tooltip/Tooltip.mjs";
80
80
  import { Dropzone as Bn } from "./Dropzone/Dropzone.mjs";
81
- import { D as Rn, a as kn } from "./FilePreview-Dhtv8F4u.js";
81
+ import { D as Rn, a as kn } from "./DropzoneFilePreview-Dhtv8F4u.js";
82
82
  import { FormDropzone as Nn } from "./FormDropzone/FormDropzone.mjs";
83
83
  export {
84
84
  e as Accordion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneplatformdev/ui",
3
- "version": "0.0.1-beta.14",
3
+ "version": "0.0.1-beta.18",
4
4
  "description": "UI React Components.",
5
5
  "author": "One Platform Development Team",
6
6
  "keywords": [