@konstructio/ui 0.1.2-alpha.24 → 0.1.2-alpha.25

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,145 +1,137 @@
1
- import { jsxs as z, jsx as r } from "react/jsx-runtime";
2
- import { S as A } from "../../../../index-BtQfgaSF.js";
3
- import { d as H } from "../../../../debounce-BFejQm9P.js";
4
- import { forwardRef as V, useRef as y, useState as Z, useImperativeHandle as B, useCallback as G, useEffect as J } from "react";
5
- import { Loading as K } from "../../../Loading/Loading.js";
6
- import { cn as i } from "../../../../utils/index.js";
7
- import { useNavigationUlList as Q } from "../../hooks/useNavigationList.js";
8
- import { ListItem as L } from "../ListItem/ListItem.js";
9
- import { listVariants as R } from "./List.variants.js";
10
- import { DEFAULT_LIST_SIZE as W } from "../../constants/pagination.js";
11
- import { useDropdownContext as X } from "../../contexts/dropdown.hook.js";
12
- const ie = V(
1
+ import { jsxs as H, jsx as o } from "react/jsx-runtime";
2
+ import { S as V } from "../../../../index-BtQfgaSF.js";
3
+ import { d as Z } from "../../../../debounce-BFejQm9P.js";
4
+ import { forwardRef as B, useRef as w, useState as G, useImperativeHandle as J, useMemo as K, useEffect as M } from "react";
5
+ import { Loading as Q } from "../../../Loading/Loading.js";
6
+ import { cn as a } from "../../../../utils/index.js";
7
+ import { useNavigationUlList as R } from "../../hooks/useNavigationList.js";
8
+ import { ListItem as v } from "../ListItem/ListItem.js";
9
+ import { listVariants as W } from "./List.variants.js";
10
+ import { DEFAULT_LIST_SIZE as X } from "../../constants/pagination.js";
11
+ import { useDropdownContext as Y } from "../../contexts/dropdown.hook.js";
12
+ const ue = B(
13
13
  ({
14
14
  additionalOptions: k,
15
15
  className: C,
16
- inputRef: c,
17
- isLoading: N,
18
- itemClassName: f,
19
- name: F,
20
- searchable: x = !1,
21
- listItemSecondRowClassName: u,
16
+ inputRef: i,
17
+ isLoading: F,
18
+ itemClassName: l,
19
+ name: N,
20
+ searchable: b = !1,
21
+ listItemSecondRowClassName: c,
22
22
  wrapperInputRef: I,
23
- isInfiniteScrollEnabled: m,
24
- onFetchMoreOptions: n
25
- }, j) => {
26
- const a = y(null), p = y(null), [g, w] = Z(!1), {
27
- isOpen: E,
28
- searchTerm: l,
29
- canFilter: O,
30
- canContinueFetching: o,
31
- page: d,
32
- options: h,
23
+ isInfiniteScrollEnabled: u,
24
+ onFetchMoreOptions: f
25
+ }, O) => {
26
+ const s = w(null), m = w(null), [p, L] = G(!1), {
27
+ isOpen: T,
28
+ searchTerm: g,
29
+ canFilter: j,
30
+ canContinueFetching: n,
31
+ page: E,
32
+ options: x,
33
+ isTyping: y,
33
34
  setOptions: P,
34
35
  setPage: S,
35
- setCanContinueFetching: T
36
- } = X();
37
- B(j, () => a.current, [a]);
38
- const b = x && O ? h.filter((e) => {
39
- const t = l.toLowerCase();
36
+ setCanContinueFetching: D
37
+ } = Y();
38
+ J(O, () => s.current, [s]);
39
+ const d = b && j ? x.filter((e) => {
40
+ const t = g.toLowerCase();
40
41
  return (typeof e.label == "string" ? e.label.toLowerCase() : "").includes(t);
41
- }) : h;
42
- Q({
43
- ulRef: a,
42
+ }) : x;
43
+ R({
44
+ ulRef: s,
44
45
  wrapperInputRef: I,
45
- searchable: x,
46
- filteredOptions: b
46
+ searchable: b,
47
+ filteredOptions: d
47
48
  });
48
- const D = b.filter(
49
- (e, t, s) => t === s.findIndex((v) => v.value === e.value)
50
- ), U = b.length === 0, _ = G(
51
- H(async (e) => {
49
+ const U = d.filter(
50
+ (e, t, r) => t === r.findIndex((h) => h.value === e.value)
51
+ ), _ = d.length === 0, q = K(
52
+ () => Z(async (e) => {
52
53
  const [t] = e;
53
- if (t.isIntersecting)
54
+ if (t.isIntersecting && !p && f && n)
54
55
  try {
55
- if (n && !g && o) {
56
- w(!0);
57
- const s = d + 1, { data: v, hasMore: q } = await n({
58
- page: s,
59
- pageSize: W,
60
- termOfSearch: l
61
- });
62
- S(s), T(q), P([...h, ...v]);
63
- }
56
+ L(!0);
57
+ const r = E + 1, { data: h, hasMore: z } = await f({
58
+ page: r,
59
+ pageSize: X,
60
+ termOfSearch: g
61
+ });
62
+ S(r), D(z), P((A) => [...A, ...h]);
64
63
  } catch {
65
64
  console.error("Error fetching more options");
66
65
  } finally {
67
- w(!1);
66
+ L(!1);
68
67
  }
69
68
  }, 100),
70
- [d, n, l, o, g]
69
+ [p, f, g]
71
70
  );
72
- return J(() => {
73
- if (m && o && p.current) {
74
- const e = new IntersectionObserver(_, {
71
+ return M(() => {
72
+ if (u && n && m.current && !y) {
73
+ const e = new IntersectionObserver(q, {
75
74
  threshold: 0.1
76
75
  });
77
- return e.observe(p.current), () => e.disconnect();
76
+ return e.observe(m.current), () => e.disconnect();
78
77
  }
79
- }, [
80
- d,
81
- l,
82
- m,
83
- n,
84
- o,
85
- g
86
- ]), /* @__PURE__ */ z(
78
+ }, [u, n, p, y]), /* @__PURE__ */ H(
87
79
  "ul",
88
80
  {
89
- ref: a,
90
- title: F,
81
+ ref: s,
82
+ title: N,
91
83
  role: "listbox",
92
- className: i(R({ className: C })),
93
- "data-state": E ? "open" : "closed",
84
+ className: a(W({ className: C })),
85
+ "data-state": T ? "open" : "closed",
94
86
  children: [
95
- N ? /* @__PURE__ */ r(
96
- L,
87
+ F ? /* @__PURE__ */ o(
88
+ v,
97
89
  {
98
- className: i("select-none", f),
90
+ className: a("select-none", l),
99
91
  isClickable: !1,
100
- inputRef: c,
92
+ inputRef: i,
101
93
  value: "Loading...",
102
94
  label: "Loading...",
103
- listItemSecondRowClassName: u
95
+ listItemSecondRowClassName: c
104
96
  }
105
- ) : U ? /* @__PURE__ */ r(
106
- L,
97
+ ) : _ ? /* @__PURE__ */ o(
98
+ v,
107
99
  {
108
- className: i("select-none", f),
100
+ className: a("select-none", l),
109
101
  isClickable: !1,
110
- inputRef: c,
102
+ inputRef: i,
111
103
  value: "No options",
112
104
  label: "No options",
113
- listItemSecondRowClassName: u
105
+ listItemSecondRowClassName: c
114
106
  }
115
- ) : D.map((e) => /* @__PURE__ */ r(
116
- L,
107
+ ) : U.map((e) => /* @__PURE__ */ o(
108
+ v,
117
109
  {
118
- className: i("select-none", f),
110
+ className: a("select-none", l),
119
111
  isClickable: !0,
120
- inputRef: c,
121
- listItemSecondRowClassName: u,
112
+ inputRef: i,
113
+ listItemSecondRowClassName: c,
122
114
  ...e
123
115
  },
124
116
  e.value
125
117
  )),
126
- m && o && /* @__PURE__ */ r(
118
+ u && n && /* @__PURE__ */ o(
127
119
  "li",
128
120
  {
129
- ref: p,
121
+ ref: m,
130
122
  role: "option",
131
123
  "data-action": "true",
132
124
  className: "flex items-center justify-center py-3",
133
125
  onClick: (e) => e.stopPropagation(),
134
- children: /* @__PURE__ */ r(K, { className: "w-4 h-4 text-aurora-500 select-none" })
126
+ children: /* @__PURE__ */ o(Q, { className: "w-4 h-4 text-aurora-500 select-none" })
135
127
  }
136
128
  ),
137
- k?.map((e, t) => /* @__PURE__ */ r("li", { role: "option", "data-action": "true", children: /* @__PURE__ */ r(A, { className: "flex p-2 w-full h-full gap-1 items-center text-sm [&>svg]:w-3.5 [&>svg]:h-3.5 [&>svg]:shrink-0 cursor-pointer select-none hover:bg-gray-50 hover:dark:bg-slate-700 focus:outline-0", children: e }) }, t))
129
+ k?.map((e, t) => /* @__PURE__ */ o("li", { role: "option", "data-action": "true", children: /* @__PURE__ */ o(V, { className: "flex p-2 w-full h-full gap-1 items-center text-sm [&>svg]:w-3.5 [&>svg]:h-3.5 [&>svg]:shrink-0 cursor-pointer select-none hover:bg-gray-50 hover:dark:bg-slate-700 focus:outline-0", children: e }) }, t))
138
130
  ]
139
131
  }
140
132
  );
141
133
  }
142
134
  );
143
135
  export {
144
- ie as List
136
+ ue as List
145
137
  };
@@ -1,89 +1,93 @@
1
- import { jsx as l, jsxs as d } from "react/jsx-runtime";
2
- import { useRef as w, useCallback as o } from "react";
3
- import { Typography as C } from "../../../Typography/Typography.js";
4
- import { cn as i } from "../../../../utils/index.js";
5
- import { listItemVariants as L } from "./ListItem.variants.js";
6
- import { useDropdownContext as I } from "../../contexts/dropdown.hook.js";
7
- const K = ({
8
- isClickable: p,
9
- className: h,
10
- inputRef: b,
11
- listItemSecondRowClassName: x,
1
+ import { jsxs as g, jsx as l } from "react/jsx-runtime";
2
+ import { useRef as y, useCallback as m } from "react";
3
+ import { Typography as w } from "../../../Typography/Typography.js";
4
+ import { cn as f } from "../../../../utils/index.js";
5
+ import { listItemVariants as C } from "./ListItem.variants.js";
6
+ import { useDropdownContext as L } from "../../contexts/dropdown.hook.js";
7
+ function I(r, n) {
8
+ const o = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), c = new RegExp(`(${o})`, "gi");
9
+ return r.split(c).map((t, a) => t.toLowerCase() === n.toLowerCase() ? /* @__PURE__ */ l(
10
+ "mark",
11
+ {
12
+ className: "bg-transparent font-semibold text-slate-800 dark:text-slate-50",
13
+ children: t
14
+ },
15
+ a
16
+ ) : /* @__PURE__ */ l("span", { children: t }, a));
17
+ }
18
+ const $ = ({
19
+ isClickable: r,
20
+ className: n,
21
+ inputRef: o,
22
+ listItemSecondRowClassName: c,
12
23
  ...t
13
24
  }) => {
14
- const { searchTerm: a, highlightSearchEnabled: c, setValue: m, toggleOpen: f } = I(), g = w(null), n = o(
25
+ const { searchTerm: a, highlightSearchEnabled: d, setValue: h, toggleOpen: u } = L(), p = y(null), i = m(
15
26
  (e) => {
16
- m(e.value, b), f(!1);
27
+ h(e.value, o), u(!1);
17
28
  },
18
- [m, f]
19
- ), u = o(
20
- (e, r) => {
21
- e.key === "Enter" && (e.stopPropagation(), n(r));
29
+ [h, u]
30
+ ), x = m(
31
+ (e, s) => {
32
+ e.key === "Enter" && (e.stopPropagation(), i(s));
22
33
  },
23
- [n]
24
- ), k = o(
25
- (e, r) => {
34
+ [i]
35
+ ), b = m(
36
+ (e, s) => {
26
37
  if (typeof e != "string")
27
38
  return e;
28
- const y = c && a.length > 0 ? e.split(new RegExp(`(${a})`, "gi")).map((s) => s.toLowerCase() === a.toLowerCase() ? /* @__PURE__ */ l(
29
- "mark",
30
- {
31
- className: "bg-transparent font-semibold text-slate-800 dark:text-slate-50",
32
- children: s
33
- },
34
- s
35
- ) : s) : [e];
36
- return /* @__PURE__ */ d(
37
- C,
39
+ const k = d && a.length > 0 ? I(e, a) : [e];
40
+ return /* @__PURE__ */ g(
41
+ w,
38
42
  {
39
43
  variant: "body2",
40
44
  className: "text-zinc-700 dark:text-slate-50 font-medium",
41
45
  children: [
42
- y,
43
- r ? /* @__PURE__ */ l(
46
+ k,
47
+ s ? /* @__PURE__ */ l(
44
48
  "span",
45
49
  {
46
- className: i(
50
+ className: f(
47
51
  "block font-normal text-sm text-slate-800 dark:text-slate-50",
48
- x
52
+ c
49
53
  ),
50
- children: r
54
+ children: s
51
55
  }
52
56
  ) : null
53
57
  ]
54
58
  }
55
59
  );
56
60
  },
57
- [c, a]
61
+ [d, a]
58
62
  );
59
- return /* @__PURE__ */ d(
63
+ return /* @__PURE__ */ g(
60
64
  "li",
61
65
  {
62
- ref: g,
66
+ ref: p,
63
67
  role: "option",
64
68
  "data-action": "false",
65
- className: i(L({ className: h })),
69
+ className: f(C({ className: n })),
66
70
  tabIndex: 0,
67
71
  onClick: (e) => {
68
- p && (n(t), e.stopPropagation());
72
+ r && (i(t), e.stopPropagation());
69
73
  },
70
- onKeyDown: (e) => u(e, t),
74
+ onKeyDown: (e) => x(e, t),
71
75
  children: [
72
76
  t.leftIcon ? /* @__PURE__ */ l(
73
77
  "span",
74
78
  {
75
- className: i("w-4 h-4 flex justify-center", {
79
+ className: f("w-4 h-4 flex justify-center", {
76
80
  "items-center": !t.subLabel,
77
81
  "items-baseline -translate-y-2": !!t.subLabel
78
82
  }),
79
83
  children: t.leftIcon
80
84
  }
81
85
  ) : null,
82
- k(t.label, t.subLabel)
86
+ b(t.label, t.subLabel)
83
87
  ]
84
88
  }
85
89
  );
86
90
  };
87
91
  export {
88
- K as ListItem
92
+ $ as ListItem
89
93
  };
@@ -44,7 +44,6 @@ const fe = [
44
44
  isOpen: f,
45
45
  searchTerm: G,
46
46
  value: o,
47
- // canFilter,
48
47
  options: n,
49
48
  setValue: c,
50
49
  setSearchTerm: J,
@@ -64,7 +63,7 @@ const fe = [
64
63
  }, [x, n, c, o]);
65
64
  const S = (r) => {
66
65
  const p = r.target.value;
67
- K(!0), q?.(p), c(""), J(p || "");
66
+ K(!0), c(""), J(p ?? ""), q?.(p);
68
67
  const b = n.find(
69
68
  (X) => X.value.toLocaleLowerCase() === p.toLocaleLowerCase()
70
69
  );
@@ -8,6 +8,7 @@ const t = e({
8
8
  canContinueFetching: !0,
9
9
  page: 1,
10
10
  options: [],
11
+ isTyping: !1,
11
12
  setOptions() {
12
13
  throw new Error("setOptions function must be overridden");
13
14
  },
@@ -1,53 +1,58 @@
1
- import { jsx as w } from "react/jsx-runtime";
2
- import { useState as e, useRef as A, useCallback as u, useEffect as I } from "react";
3
- import { DropdownContext as O } from "./dropdown.context.js";
4
- import { useToggle as _ } from "../../../hooks/useToggle.js";
5
- const s = 1, N = ({
6
- children: p,
7
- value: m,
8
- name: c,
9
- highlightSearch: f = !1,
10
- options: r,
1
+ import { jsx as G } from "react/jsx-runtime";
2
+ import { useState as e, useRef as f, useCallback as p, useEffect as T } from "react";
3
+ import { DropdownContext as L } from "./dropdown.context.js";
4
+ import { useToggle as N } from "../../../hooks/useToggle.js";
5
+ const c = 1, O = 300, U = ({
6
+ children: d,
7
+ value: C,
8
+ name: i,
9
+ highlightSearch: E = !1,
10
+ options: n,
11
11
  onChange: a,
12
- onBlur: g
12
+ onBlur: u
13
13
  }) => {
14
- const [d, i] = e(r), C = A(f), [T, l] = _(!1), [E, F] = e(""), [v, P] = e(!0), [S, n] = e(!0), [b, o] = e(s), x = u(
15
- (t, h) => {
16
- h?.current && (h.current.value = t), n(!0), o(s), a?.({ target: { value: t, name: c ?? "" } }), g?.();
14
+ const [v, l] = e(n), F = f(E), [P, g] = N(!1), [D, I] = e(""), [S, b] = e(!0), [x, o] = e(!0), [A, s] = e(c), [_, h] = e(!1), t = f(void 0), w = p(
15
+ (r, m) => {
16
+ m?.current && (m.current.value = r), t.current && clearTimeout(t.current), h(!0), o(!0), s(c), a?.({ target: { value: r, name: i ?? "" } }), u?.(), t.current = setTimeout(() => {
17
+ h(!1);
18
+ }, O);
17
19
  },
18
- [a, c, g]
19
- ), D = u(
20
- (t) => {
21
- l(t), n(!0), o(s);
20
+ [a, i, u]
21
+ ), y = p(
22
+ (r) => {
23
+ g(r), o(!0), s(c);
22
24
  },
23
- [l]
25
+ [g]
24
26
  );
25
- return I(() => {
26
- i(r);
27
- }, [r.length]), /* @__PURE__ */ w(
28
- O.Provider,
27
+ return T(() => {
28
+ l(n);
29
+ }, [n.length]), T(() => () => {
30
+ t.current && clearTimeout(t.current);
31
+ }, []), /* @__PURE__ */ G(
32
+ L.Provider,
29
33
  {
30
34
  value: {
31
- highlightSearchEnabled: C.current,
32
- isOpen: T,
33
- searchTerm: E,
34
- value: m,
35
- canFilter: v,
36
- canContinueFetching: S,
37
- page: b,
38
- options: d,
39
- setOptions: i,
40
- setPage: o,
41
- setCanContinueFetching: n,
42
- setCanFilter: P,
43
- setSearchTerm: F,
44
- setValue: x,
45
- toggleOpen: D
35
+ highlightSearchEnabled: F.current,
36
+ isOpen: P,
37
+ searchTerm: D,
38
+ value: C,
39
+ canFilter: S,
40
+ canContinueFetching: x,
41
+ page: A,
42
+ options: v,
43
+ isTyping: _,
44
+ setOptions: l,
45
+ setPage: s,
46
+ setCanContinueFetching: o,
47
+ setCanFilter: b,
48
+ setSearchTerm: I,
49
+ setValue: w,
50
+ toggleOpen: y
46
51
  },
47
- children: p
52
+ children: d
48
53
  }
49
54
  );
50
55
  };
51
56
  export {
52
- N as DropdownProvider
57
+ U as DropdownProvider
53
58
  };
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.23",
5
+ "version": "0.1.2-alpha.24",
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.24",
5
+ "version": "0.1.2-alpha.25",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",