@konstructio/ui 0.1.2-alpha.39 → 0.1.2-alpha.40

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,21 +1,34 @@
1
- import { jsx as o } from "react/jsx-runtime";
2
- import { forwardRef as l } from "react";
3
- import { MultiSelectDropdownProvider as c } from "./contexts/MultiSelectDropdown.provider.js";
4
- import { Wrapper as n } from "./components/Wrapper/Wrapper.js";
5
- const x = l(
6
- ({ options: t, multiselect: p, value: e, onChange: i, onBlur: f, name: r, ...m }, d) => /* @__PURE__ */ o(
7
- c,
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { forwardRef as n } from "react";
3
+ import { MultiSelectDropdownProvider as a } from "./contexts/MultiSelectDropdown.provider.js";
4
+ import { Wrapper as s } from "./components/Wrapper/Wrapper.js";
5
+ const u = n(
6
+ ({
7
+ options: t,
8
+ multiselect: e,
9
+ value: p,
10
+ onChange: i,
11
+ onBlur: l,
12
+ name: o,
13
+ isLoading: d,
14
+ noOptionsText: m,
15
+ ...f
16
+ }, c) => /* @__PURE__ */ r(
17
+ a,
8
18
  {
9
19
  defaultOptions: t,
10
- multiselect: p,
11
- value: e,
20
+ multiselect: e,
21
+ value: p,
12
22
  onChange: i,
13
- onBlur: f,
14
- name: r,
15
- children: /* @__PURE__ */ o(n, { ref: d, ...m, name: r })
23
+ onBlur: l,
24
+ name: o,
25
+ isLoading: d,
26
+ noOptionsText: m,
27
+ children: /* @__PURE__ */ r(s, { ref: c, ...f, name: o })
16
28
  }
17
29
  )
18
30
  );
31
+ u.displayName = "MultiSelectDropdown";
19
32
  export {
20
- x as MultiSelectDropdown
33
+ u as MultiSelectDropdown
21
34
  };
@@ -1,27 +1,32 @@
1
- import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
- import { cn as m } from "../../../../utils/index.js";
3
- import { wrapperVariants as i } from "./Item.variants.js";
4
- import { useMultiSelectDropdown as s } from "../../contexts/MultiSelectDropdown.hook.js";
5
- import { Typography as c } from "../../../Typography/Typography.js";
6
- import { Tag as p } from "../../../Tag/Tag.js";
7
- const x = ({ option: r, theme: a, isSelected: o }) => {
8
- const { onSelectOption: e } = s();
9
- return /* @__PURE__ */ l(
1
+ import { jsxs as m, jsx as t } from "react/jsx-runtime";
2
+ import { cn as i } from "../../../../utils/index.js";
3
+ import { wrapperVariants as s } from "./Item.variants.js";
4
+ import { useMultiSelectDropdown as c } from "../../contexts/MultiSelectDropdown.hook.js";
5
+ import { Typography as p } from "../../../Typography/Typography.js";
6
+ import { Tag as n } from "../../../Tag/Tag.js";
7
+ const u = ({
8
+ option: r,
9
+ theme: e,
10
+ isSelected: a,
11
+ className: o
12
+ }) => {
13
+ const { onSelectOption: l } = c();
14
+ return /* @__PURE__ */ m(
10
15
  "li",
11
16
  {
12
17
  role: "option",
13
- "data-theme": a,
14
- className: m(i({ isSelected: o })),
15
- onClick: () => e(r),
18
+ "data-theme": e,
19
+ className: i(s({ isSelected: a }), o),
20
+ onClick: () => l(r),
16
21
  children: [
17
- /* @__PURE__ */ t(c, { variant: "body2", className: "text-slate-800", children: r.label }),
18
- /* @__PURE__ */ t(
19
- p,
22
+ /* @__PURE__ */ t(p, { variant: "body2", className: "text-slate-800", children: r.label }),
23
+ r.tagLabel && /* @__PURE__ */ t(
24
+ n,
20
25
  {
21
26
  id: r.id,
22
27
  label: r.tagLabel,
23
28
  color: r.tagColor,
24
- isSelected: o
29
+ isSelected: a
25
30
  }
26
31
  )
27
32
  ]
@@ -29,5 +34,5 @@ const x = ({ option: r, theme: a, isSelected: o }) => {
29
34
  );
30
35
  };
31
36
  export {
32
- x as Item
37
+ u as Item
33
38
  };
@@ -1,28 +1,36 @@
1
1
  import { jsx as e } from "react/jsx-runtime";
2
- import { cn as s } from "../../../../utils/index.js";
3
- import { Item as a } from "../Item/Item.js";
2
+ import { cn as m } from "../../../../utils/index.js";
3
+ import { Item as i } from "../Item/Item.js";
4
4
  import { wrapperVariants as p } from "./List.variants.js";
5
- import { useMultiSelectDropdown as l } from "../../contexts/MultiSelectDropdown.hook.js";
6
- import { Typography as c } from "../../../Typography/Typography.js";
7
- const y = ({ theme: o }) => {
8
- const { options: r, selectedOptions: i } = l();
9
- return /* @__PURE__ */ e("ul", { role: "listbox", "data-theme": o, className: s(p()), children: r.length > 0 ? r.map((t) => /* @__PURE__ */ e(
10
- a,
5
+ import { useMultiSelectDropdown as c } from "../../contexts/MultiSelectDropdown.hook.js";
6
+ import { Typography as d } from "../../../Typography/Typography.js";
7
+ const y = ({ theme: s }) => {
8
+ const { options: o, selectedOptions: n, isLoading: r, noOptionsText: a } = c();
9
+ return /* @__PURE__ */ e("ul", { role: "listbox", "data-theme": s, className: m(p()), children: r ? /* @__PURE__ */ e(
10
+ i,
11
+ {
12
+ option: { id: "loading", label: "Loading..." },
13
+ className: "select-none pointer-events-none",
14
+ isSelected: !1
15
+ },
16
+ "loading"
17
+ ) : o.length > 0 ? o.map((t) => /* @__PURE__ */ e(
18
+ i,
11
19
  {
12
20
  option: t,
13
- isSelected: i.some(
14
- (m) => m.id === t.id
21
+ isSelected: n.some(
22
+ (l) => l.id === t.id
15
23
  )
16
24
  },
17
25
  t.id
18
- )) : /* @__PURE__ */ e(
19
- c,
26
+ )) : /* @__PURE__ */ e("li", { className: "select-none", children: /* @__PURE__ */ e(
27
+ d,
20
28
  {
21
29
  variant: "body2",
22
30
  className: "text-zinc-800 dark:text-slate-50 italic px-2 py-2",
23
- children: "No options"
31
+ children: a ?? "No options"
24
32
  }
25
- ) });
33
+ ) }) });
26
34
  };
27
35
  export {
28
36
  y as List
@@ -2,22 +2,30 @@ import "../Item/Item.js";
2
2
  import { List as v } from "../List/List.js";
3
3
  import { jsxs as m, jsx as e } from "react/jsx-runtime";
4
4
  import * as c from "react";
5
- import { forwardRef as N, useId as b, useImperativeHandle as C } from "react";
6
- import { Tag as O } from "../../../Tag/Tag.js";
7
- import { cn as a } from "../../../../utils/index.js";
8
- import { useMultiSelectDropdown as R } from "../../hooks/useMultiSelectDropdown.js";
9
- import { labelVariants as S, multiSelectDropdownVariants as k, wrapperVariants as D } from "../../MultiSelectDropdown.variants.js";
10
- import { C as M } from "../../../../chevron-up-CRyLc5Ml.js";
11
- import { useMultiSelectDropdown as y } from "../../contexts/MultiSelectDropdown.hook.js";
12
- const I = (r) => /* @__PURE__ */ c.createElement("svg", { width: 9, height: 9, viewBox: "0 0 9 9", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...r }, /* @__PURE__ */ c.createElement("path", { d: "M8.16667 0.8225L7.34417 0L4.08333 3.26083L0.8225 0L0 0.8225L3.26083 4.08333L0 7.34417L0.8225 8.16667L4.08333 4.90583L7.34417 8.16667L8.16667 7.34417L4.90583 4.08333L8.16667 0.8225Z", fill: "#364153" })), Z = N(
5
+ import { forwardRef as b, useId as S, useImperativeHandle as C } from "react";
6
+ import { S as O } from "../../../../loader-juvMSJ9L.js";
7
+ import { cn as t } from "../../../../utils/index.js";
8
+ import { useMultiSelectDropdown as k } from "../../hooks/useMultiSelectDropdown.js";
9
+ import { labelVariants as D, multiSelectDropdownVariants as M, wrapperVariants as R } from "../../MultiSelectDropdown.variants.js";
10
+ import { C as y } from "../../../../chevron-up-CRyLc5Ml.js";
11
+ import { useMultiSelectDropdown as I } from "../../contexts/MultiSelectDropdown.hook.js";
12
+ import { Tag as V } from "../../../Tag/Tag.js";
13
+ const j = (r) => /* @__PURE__ */ c.createElement("svg", { width: 9, height: 9, viewBox: "0 0 9 9", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...r }, /* @__PURE__ */ c.createElement("path", { d: "M8.16667 0.8225L7.34417 0L4.08333 3.26083L0.8225 0L0 0.8225L3.26083 4.08333L0 7.34417L0.8225 8.16667L4.08333 4.90583L7.34417 8.16667L8.16667 7.34417L4.90583 4.08333L8.16667 0.8225Z", fill: "#364153" })), E = b(
13
14
  ({ label: r, labelClassName: p, name: l, placeholder: d = "", theme: h, wrapperClassName: f }, u) => {
14
- const i = b(), { selectedOptions: n, isOpen: o, onOpen: w, onRemoveOption: L, inputRef: s } = y(), { wrapperRef: g, handleOpen: x } = R();
15
- return C(u, () => s.current, [s]), /* @__PURE__ */ m(
15
+ const o = S(), {
16
+ selectedOptions: n,
17
+ isOpen: s,
18
+ onOpen: w,
19
+ onRemoveOption: L,
20
+ inputRef: i,
21
+ isLoading: g
22
+ } = I(), { wrapperRef: x, handleOpen: N } = k();
23
+ return C(u, () => i.current, [i]), /* @__PURE__ */ m(
16
24
  "div",
17
25
  {
18
- ref: g,
19
- className: a(
20
- D({
26
+ ref: x,
27
+ className: t(
28
+ R({
21
29
  className: f
22
30
  })
23
31
  ),
@@ -26,9 +34,9 @@ const I = (r) => /* @__PURE__ */ c.createElement("svg", { width: 9, height: 9, v
26
34
  r ? /* @__PURE__ */ e(
27
35
  "label",
28
36
  {
29
- htmlFor: l ?? i,
30
- className: a(
31
- S({
37
+ htmlFor: l ?? o,
38
+ className: t(
39
+ D({
32
40
  className: p
33
41
  })
34
42
  ),
@@ -39,36 +47,36 @@ const I = (r) => /* @__PURE__ */ c.createElement("svg", { width: 9, height: 9, v
39
47
  /* @__PURE__ */ m(
40
48
  "div",
41
49
  {
42
- id: l ?? i,
43
- className: a(k()),
50
+ id: l ?? o,
51
+ className: t(M()),
44
52
  role: "combobox",
45
- onClick: x,
46
- "aria-expanded": o,
53
+ onClick: N,
54
+ "aria-expanded": s,
47
55
  children: [
48
- n.length === 0 ? /* @__PURE__ */ e("span", { className: "text-base text-inherit select-none", children: d }) : /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-2", children: n.map((t) => /* @__PURE__ */ e(
49
- O,
56
+ n.length === 0 ? /* @__PURE__ */ e("span", { className: "text-base text-inherit select-none", children: d }) : /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-2", children: n.map((a) => /* @__PURE__ */ e(
57
+ V,
50
58
  {
51
- id: t.id,
52
- label: t.tagLabel,
53
- color: t.tagColor || "gray-800",
59
+ id: a.id,
60
+ label: a.tagLabel || a.label || "",
61
+ color: a.tagColor || "gray-800",
54
62
  className: "select-none gap-2",
55
63
  rightIcon: /* @__PURE__ */ e(
56
- I,
64
+ j,
57
65
  {
58
66
  className: "w-2 h-2",
59
- onClick: () => L(t)
67
+ onClick: () => L(a)
60
68
  }
61
69
  ),
62
- "data-value": t.label
70
+ "data-value": a.label
63
71
  },
64
- t.id
72
+ a.id
65
73
  )) }),
66
- /* @__PURE__ */ e(
67
- M,
74
+ g ? /* @__PURE__ */ e(O, { className: "w-4 h-4 text-slate-400 animate-spin shrink-0" }) : /* @__PURE__ */ e(
75
+ y,
68
76
  {
69
- className: a(
77
+ className: t(
70
78
  "w-4 h-4 text-inherit transition-all duration-50 shrink-0",
71
- o ? "rotate-0" : "rotate-180"
79
+ s ? "rotate-0" : "rotate-180"
72
80
  )
73
81
  }
74
82
  )
@@ -78,19 +86,20 @@ const I = (r) => /* @__PURE__ */ c.createElement("svg", { width: 9, height: 9, v
78
86
  /* @__PURE__ */ e(
79
87
  "input",
80
88
  {
81
- ref: s,
89
+ ref: i,
82
90
  type: "text",
83
91
  name: l,
84
92
  className: "hidden",
85
93
  readOnly: !0
86
94
  }
87
95
  ),
88
- o ? /* @__PURE__ */ e(v, {}) : null
96
+ s ? /* @__PURE__ */ e(v, {}) : null
89
97
  ]
90
98
  }
91
99
  );
92
100
  }
93
101
  );
102
+ E.displayName = "MultiSelectDropdownWrapper";
94
103
  export {
95
- Z as Wrapper
104
+ E as Wrapper
96
105
  };
@@ -1,5 +1,5 @@
1
- import { createContext as t } from "react";
2
- const n = {
1
+ import { createContext as n } from "react";
2
+ const t = {
3
3
  options: [],
4
4
  selectedOptions: [],
5
5
  isOpen: !1,
@@ -12,8 +12,10 @@ const n = {
12
12
  },
13
13
  onOpen() {
14
14
  throw new Error("Function not implemented.");
15
- }
16
- }, o = t(n);
15
+ },
16
+ isLoading: !1,
17
+ noOptionsText: void 0
18
+ }, e = n(t);
17
19
  export {
18
- o as MultiSelectDropdownContext
20
+ e as MultiSelectDropdownContext
19
21
  };
@@ -1,119 +1,138 @@
1
- import { jsx as P } from "react/jsx-runtime";
2
- import { useRef as V, useState as R, useEffect as b, useCallback as p } from "react";
3
- import { MultiSelectDropdownContext as k } from "./MultiSelectDropdown.context.js";
4
- import { useToggle as y } from "../../../hooks/useToggle.js";
5
- const T = ({
1
+ import { jsx as V } from "react/jsx-runtime";
2
+ import { useRef as k, useState as R, useEffect as g, useCallback as S } from "react";
3
+ import { MultiSelectDropdownContext as C } from "./MultiSelectDropdown.context.js";
4
+ import { useToggle as E } from "../../../hooks/useToggle.js";
5
+ const q = ({
6
6
  children: x,
7
- defaultOptions: o = [],
8
- multiselect: c = !0,
9
- value: a,
10
- onChange: f,
11
- onBlur: S,
12
- name: I
7
+ defaultOptions: r = [],
8
+ multiselect: i = !0,
9
+ value: f,
10
+ onChange: m,
11
+ onBlur: u,
12
+ name: h,
13
+ isLoading: b,
14
+ noOptionsText: j
13
15
  }) => {
14
- const m = V(null), [u, h] = y(!1), [g, O] = R(o), [i, v] = R([]), r = a !== void 0;
15
- b(() => {
16
- if (r) {
17
- const t = a || [];
18
- v(t);
19
- const n = new Set(t.map((s) => s.id));
20
- O(
21
- c ? o.filter((s) => !n.has(s.id)) : o.map((s) => ({
16
+ const d = k(null), [w, I] = E(!1), [y, p] = R(r), [c, v] = R([]), o = f !== void 0;
17
+ g(() => {
18
+ if (!o) {
19
+ const n = new Set(
20
+ c.map((e) => e.id)
21
+ );
22
+ p(
23
+ i ? r.filter((e) => !n.has(e.id)) : r.map((e) => ({
24
+ ...e,
25
+ isSelected: n.has(e.id)
26
+ }))
27
+ );
28
+ }
29
+ }, [r, i, o, c]), g(() => {
30
+ if (o) {
31
+ const n = f || [];
32
+ v(n);
33
+ const e = new Set(n.map((s) => s.id));
34
+ p(
35
+ i ? r.filter((s) => !e.has(s.id)) : r.map((s) => ({
22
36
  ...s,
23
- isSelected: n.has(s.id)
37
+ isSelected: e.has(s.id)
24
38
  }))
25
39
  );
26
40
  }
27
- }, [a, r, o, c]);
28
- const d = p(
29
- (t) => {
30
- const n = t.map(({ id: e, value: w, label: M }) => ({
31
- id: e,
32
- value: w ?? M
33
- })), s = JSON.stringify(n);
34
- m.current && (m.current.value = s), f && f({
41
+ }, [f, o, r, i]);
42
+ const l = S(
43
+ (n) => {
44
+ const e = n.map(({ id: t, value: O, label: P }) => ({
45
+ id: t,
46
+ value: O ?? P
47
+ })), s = JSON.stringify(e);
48
+ d.current && (d.current.value = s), m && m({
35
49
  target: {
36
- value: t,
37
- name: I ?? ""
50
+ value: n,
51
+ name: h ?? ""
38
52
  }
39
53
  });
40
54
  },
41
- [f, I]
42
- ), l = p(
43
- (t) => {
44
- const n = u;
45
- h(t), n && t === !1 && S && S();
55
+ [m, h]
56
+ ), a = S(
57
+ (n) => {
58
+ const e = w;
59
+ I(n), e && n === !1 && u && d.current && u({
60
+ target: d.current,
61
+ type: "blur"
62
+ });
46
63
  },
47
- [u, h, S]
48
- ), j = p(
49
- (t) => {
50
- if (r) {
51
- const e = [
52
- ...c ? i : [],
53
- t
64
+ [w, I, u, d]
65
+ ), D = S(
66
+ (n) => {
67
+ if (o) {
68
+ const t = [
69
+ ...i ? c : [],
70
+ n
54
71
  ];
55
- d(e), l(!1);
72
+ l(t), a(!1);
56
73
  return;
57
74
  }
58
- const n = [
59
- ...c ? i : [],
60
- t
75
+ const e = [
76
+ ...i ? c : [],
77
+ n
61
78
  ];
62
- v(n);
63
- const s = n.map((e) => e.id);
64
- O(() => c ? o.filter(
65
- (e) => !s.includes(e.id)
66
- ) : o.map((e) => ({
67
- ...e,
68
- isSelected: s.includes(e.id)
69
- }))), d(n), l(!1);
79
+ v(e);
80
+ const s = e.map((t) => t.id);
81
+ p(() => i ? r.filter(
82
+ (t) => !s.includes(t.id)
83
+ ) : r.map((t) => ({
84
+ ...t,
85
+ isSelected: s.includes(t.id)
86
+ }))), l(e), a(!1);
70
87
  },
71
88
  [
72
- o,
73
- d,
74
- c,
75
- i,
89
+ r,
76
90
  l,
77
- r
91
+ i,
92
+ c,
93
+ a,
94
+ o
78
95
  ]
79
- ), D = p(
80
- (t) => {
81
- if (r) {
82
- const e = i.filter(
83
- (w) => w.id !== t.id
96
+ ), M = S(
97
+ (n) => {
98
+ if (o) {
99
+ const t = c.filter(
100
+ (O) => O.id !== n.id
84
101
  );
85
- d(e);
102
+ l(t);
86
103
  return;
87
104
  }
88
- const n = i.filter(
89
- (e) => e.id !== t.id
105
+ const e = c.filter(
106
+ (t) => t.id !== n.id
90
107
  );
91
- v(n);
92
- const s = n.map((e) => e.id);
93
- O(
94
- () => o.filter(
95
- (e) => !s.includes(e.id)
108
+ v(e);
109
+ const s = e.map((t) => t.id);
110
+ p(
111
+ () => r.filter(
112
+ (t) => !s.includes(t.id)
96
113
  )
97
- ), d(n);
114
+ ), l(e);
98
115
  },
99
- [o, d, i, r]
116
+ [r, l, c, o]
100
117
  );
101
- return /* @__PURE__ */ P(
102
- k.Provider,
118
+ return /* @__PURE__ */ V(
119
+ C.Provider,
103
120
  {
104
121
  value: {
105
- options: g,
106
- selectedOptions: i,
107
- isOpen: u,
108
- inputRef: m,
109
- onSelectOption: j,
110
- onRemoveOption: D,
111
- onOpen: l
122
+ options: y,
123
+ selectedOptions: c,
124
+ isOpen: w,
125
+ inputRef: d,
126
+ onSelectOption: D,
127
+ onRemoveOption: M,
128
+ onOpen: a,
129
+ isLoading: b,
130
+ noOptionsText: j
112
131
  },
113
132
  children: x
114
133
  }
115
134
  );
116
135
  };
117
136
  export {
118
- T as MultiSelectDropdownProvider
137
+ q as MultiSelectDropdownProvider
119
138
  };
package/dist/index.d.ts CHANGED
@@ -378,7 +378,7 @@ export declare const MultiSelectDropdown: FC<MultiSelectDropdownProps>;
378
378
  declare type MultiSelectDropdownOption = {
379
379
  id: string | number;
380
380
  label: string;
381
- tagLabel: string;
381
+ tagLabel?: string;
382
382
  tagColor?: TagProps['color'];
383
383
  value?: string;
384
384
  };
@@ -393,7 +393,9 @@ declare interface MultiSelectDropdownProps extends VariantProps<typeof multiSele
393
393
  multiselect?: boolean;
394
394
  value?: MultiSelectDropdownOption[];
395
395
  onChange?: OnChangeFn_2;
396
- onBlur?: VoidFunction;
396
+ onBlur?: OnBlurFn;
397
+ isLoading?: boolean;
398
+ noOptionsText?: string;
397
399
  }
398
400
 
399
401
  declare const multiSelectDropdownVariants: (props?: ClassProp | undefined) => string;
@@ -486,6 +488,11 @@ declare interface NumberInputProps extends VariantProps<typeof numberInputVarian
486
488
 
487
489
  declare const numberInputVariants: (props?: ClassProp | undefined) => string;
488
490
 
491
+ declare type OnBlurFn = (event: {
492
+ target: HTMLInputElement | null;
493
+ type?: string;
494
+ }) => void;
495
+
489
496
  declare type OnChangeFn = (params: {
490
497
  target: {
491
498
  value: string;
package/dist/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.1.2-alpha.38",
5
+ "version": "0.1.2-alpha.39",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.1.2-alpha.39",
5
+ "version": "0.1.2-alpha.40",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",