@konstructio/ui 0.0.12-alpha.15 → 0.0.12-alpha.16

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,8 +1,8 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { forwardRef as i } from "react";
3
- import { DropdownProvider as t } from "./contexts/dropdown.provider.js";
4
- import { Wrapper as d } from "./components/Wrapper.js";
5
- const c = i(({ onChange: o, value: p, ...m }, f) => /* @__PURE__ */ r(t, { onChange: o, value: p, children: /* @__PURE__ */ r(d, { ref: f, ...m }) }));
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { forwardRef as t } from "react";
3
+ import { DropdownProvider as d } from "./contexts/dropdown.provider.js";
4
+ import { Wrapper as e } from "./components/Wrapper.js";
5
+ const x = t(({ onChange: p, value: m, name: r, ...f }, i) => /* @__PURE__ */ o(d, { onChange: p, value: m, name: r, children: /* @__PURE__ */ o(e, { name: r, ref: i, ...f }) }));
6
6
  export {
7
- c as Dropdown
7
+ x as Dropdown
8
8
  };
@@ -1,13 +1,13 @@
1
1
  import { jsxs as f, jsx as o } from "react/jsx-runtime";
2
2
  import { useRef as p, useCallback as s } from "react";
3
- import { cn as d } from "../../../../utils/index.js";
4
- import { listItemVariants as u } from "./ListItem.variants.js";
3
+ import { cn as u } from "../../../../utils/index.js";
4
+ import { listItemVariants as d } from "./ListItem.variants.js";
5
5
  import { Typography as h } from "../../../Typography/Typography.js";
6
6
  import { useDropdownContext as x } from "../../contexts/dropdown.hook.js";
7
7
  const g = ({ theme: a, ...e }) => {
8
8
  const { setValue: n, toggleOpen: r } = x(), c = p(null), l = s(
9
9
  (t) => {
10
- n(t), r(!1);
10
+ n(t.value), r(!1);
11
11
  },
12
12
  [n, r]
13
13
  ), i = s(
@@ -21,7 +21,7 @@ const g = ({ theme: a, ...e }) => {
21
21
  {
22
22
  ref: c,
23
23
  role: "option",
24
- className: d(u({ theme: a })),
24
+ className: u(d({ theme: a })),
25
25
  tabIndex: 0,
26
26
  onClick: () => l(e),
27
27
  onKeyDown: (t) => i(t, e),
@@ -1,97 +1,99 @@
1
- import { jsxs as c, jsx as t } from "react/jsx-runtime";
2
- import { forwardRef as A, useId as H, useRef as y, useImperativeHandle as U, useEffect as d } from "react";
3
- import { cn as p } from "../../../utils/index.js";
4
- import { labelVariants as V, dropdownVariants as W } from "../Dropdown.variants.js";
5
- import { useDropdown as B } from "../hooks/useDropdown.js";
6
- import { List as G } from "./List/List.js";
7
- import { Typography as R } from "../../Typography/Typography.js";
8
- import { Loading as J } from "../../Loading/Loading.js";
9
- import { C as K } from "../../../chevron-up-DgLBQCKD.js";
10
- import { useDropdownContext as M } from "../contexts/dropdown.hook.js";
11
- import { useTheme as P } from "../../../contexts/theme.hook.js";
12
- const oe = A(
1
+ import { jsxs as m, jsx as t } from "react/jsx-runtime";
2
+ import { forwardRef as H, useId as M, useRef as R, useImperativeHandle as U, useMemo as W, useEffect as p } from "react";
3
+ import { cn as u } from "../../../utils/index.js";
4
+ import { labelVariants as B, dropdownVariants as G } from "../Dropdown.variants.js";
5
+ import { useDropdown as J } from "../hooks/useDropdown.js";
6
+ import { List as K } from "./List/List.js";
7
+ import { Typography as O } from "../../Typography/Typography.js";
8
+ import { Loading as P } from "../../Loading/Loading.js";
9
+ import { C as Q } from "../../../chevron-up-DgLBQCKD.js";
10
+ import { useDropdownContext as S } from "../contexts/dropdown.hook.js";
11
+ import { useTheme as X } from "../../../contexts/theme.hook.js";
12
+ const ae = H(
13
13
  ({
14
- theme: O,
15
- label: u,
16
- labelClassName: z,
17
- placeholder: T,
18
- name: o,
19
- options: a,
20
- required: h,
21
- defaultValue: m,
22
- isLoading: j
23
- }, E) => {
24
- const x = H(), r = y(null), b = y(null), { wrapperRef: n, wrapperInputRef: w, handleOpen: L, handleOpenIfClosed: k } = B({ ulRef: b }), { isOpen: N, toggleOpen: v, value: e, setValue: g } = M(), { theme: D } = P(), f = O ?? D, l = o ? `${x}-${o}` : x;
25
- U(E, () => r.current, [r]), d(() => {
26
- r.current && (r.current.value = e ? e.value : "");
27
- }, [e]), d(() => {
28
- if (m && !e) {
29
- const s = a && a.find((i) => i.value === m);
30
- s && g(s);
14
+ theme: z,
15
+ label: h,
16
+ labelClassName: T,
17
+ placeholder: j,
18
+ name: l,
19
+ options: n,
20
+ required: x,
21
+ defaultValue: f,
22
+ isLoading: E
23
+ }, L) => {
24
+ const v = M(), s = R(null), b = R(null), { wrapperRef: a, wrapperInputRef: w, handleOpen: k, handleOpenIfClosed: D } = J({ ulRef: b }), { isOpen: N, toggleOpen: g, value: r, setValue: C } = S(), { theme: F } = X(), d = z ?? F, c = l ? `${v}-${l}` : v;
25
+ U(L, () => s.current, [s]);
26
+ const e = W(() => n.find(({ value: o }) => o === r), [n, r]);
27
+ p(() => {
28
+ s.current && (s.current.value = r ? e == null ? void 0 : e.value : "");
29
+ }, [e, r]), p(() => {
30
+ if (f && !r) {
31
+ const o = n && n.find((i) => i.value === f);
32
+ o && C(o.value);
31
33
  }
32
- }, [m, a, g, e]), d(() => {
34
+ }, [f, n, C, r]), p(() => {
33
35
  var i;
34
- const s = new AbortController();
35
- return (i = n.current) == null || i.addEventListener("focusout", ($) => {
36
- var I;
37
- const C = $.relatedTarget;
38
- (!C || !((I = n.current) != null && I.contains(C))) && v(!1);
36
+ const o = new AbortController();
37
+ return (i = a.current) == null || i.addEventListener("focusout", (A) => {
38
+ var y;
39
+ const I = A.relatedTarget;
40
+ (!I || !((y = a.current) != null && y.contains(I))) && g(!1);
39
41
  }), () => {
40
- s.abort();
42
+ o.abort();
41
43
  };
42
- }, [v, n]);
43
- const F = () => e != null && e.leftIcon ? /* @__PURE__ */ t("span", { className: "w-4 h-4 flex justify-center items-center", children: e.leftIcon }) : null;
44
- return /* @__PURE__ */ c("div", { ref: n, className: "flex flex-col w-full relative", children: [
45
- u ? /* @__PURE__ */ c(
44
+ }, [g, a]);
45
+ const $ = () => e != null && e.leftIcon ? /* @__PURE__ */ t("span", { className: "w-4 h-4 flex justify-center items-center", children: e.leftIcon }) : null;
46
+ return /* @__PURE__ */ m("div", { ref: a, className: "flex flex-col w-full relative", children: [
47
+ h ? /* @__PURE__ */ m(
46
48
  "label",
47
49
  {
48
- id: l,
49
- className: p(
50
- V({ theme: f }),
51
- z
50
+ id: c,
51
+ className: u(
52
+ B({ theme: d }),
53
+ T
52
54
  ),
53
- htmlFor: l,
54
- onClick: k,
55
+ htmlFor: c,
56
+ onClick: D,
55
57
  children: [
56
- u,
57
- h ? /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" }) : null
58
+ h,
59
+ x ? /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" }) : null
58
60
  ]
59
61
  }
60
62
  ) : null,
61
- /* @__PURE__ */ c(
63
+ /* @__PURE__ */ m(
62
64
  "div",
63
65
  {
64
66
  ref: w,
65
- id: l,
66
- className: p(W({ theme: f })),
67
+ id: c,
68
+ className: u(G({ theme: d })),
67
69
  role: "combobox",
68
- onClick: L,
70
+ onClick: k,
69
71
  "aria-expanded": N,
70
72
  tabIndex: 0,
71
- "aria-labelledby": l,
73
+ "aria-labelledby": c,
72
74
  children: [
73
- /* @__PURE__ */ t("span", { className: "text-base text-inherit", children: e ? /* @__PURE__ */ c(
74
- R,
75
+ /* @__PURE__ */ t("span", { className: "text-base text-inherit", children: r ? /* @__PURE__ */ m(
76
+ O,
75
77
  {
76
78
  variant: "body2",
77
79
  className: "flex gap-3 items-center text-zinc-700",
78
80
  children: [
79
- F(),
80
- e.label
81
+ $(),
82
+ e == null ? void 0 : e.label
81
83
  ]
82
84
  }
83
85
  ) : /* @__PURE__ */ t(
84
- R,
86
+ O,
85
87
  {
86
88
  variant: "body2",
87
89
  className: "flex gap-3 items-center text-zinc-700",
88
- children: T
90
+ children: j
89
91
  }
90
92
  ) }),
91
- j ? /* @__PURE__ */ t(J, { className: "w-4 h-4 text-zinc-500" }) : /* @__PURE__ */ t(
92
- K,
93
+ E ? /* @__PURE__ */ t(P, { className: "w-4 h-4 text-zinc-500" }) : /* @__PURE__ */ t(
94
+ Q,
93
95
  {
94
- className: p(
96
+ className: u(
95
97
  "w-4 h-4 text-zinc-500 transition-all duration-50",
96
98
  N ? "rotate-0" : "rotate-180"
97
99
  )
@@ -103,28 +105,28 @@ const oe = A(
103
105
  /* @__PURE__ */ t(
104
106
  "input",
105
107
  {
106
- ref: r,
108
+ ref: s,
107
109
  type: "text",
108
- name: o,
110
+ name: l,
109
111
  className: "hidden",
110
112
  "aria-hidden": "true",
111
- required: h
113
+ required: x
112
114
  }
113
115
  ),
114
116
  /* @__PURE__ */ t(
115
- G,
117
+ K,
116
118
  {
117
119
  ref: b,
118
- name: o,
119
- wrapperRef: n,
120
+ name: l,
121
+ wrapperRef: a,
120
122
  wrapperInputRef: w,
121
- options: a,
122
- theme: f
123
+ options: n,
124
+ theme: d
123
125
  }
124
126
  )
125
127
  ] });
126
128
  }
127
129
  );
128
130
  export {
129
- oe as Wrapper
131
+ ae as Wrapper
130
132
  };
@@ -1,22 +1,22 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import { useCallback as i } from "react";
3
- import { DropdownContext as u } from "./dropdown.context.js";
4
- import { useToggle as d } from "../../../hooks/useToggle.js";
5
- const x = ({ children: o, onChange: r, value: t }) => {
6
- const [e, l] = d(!1), p = i(
7
- (s) => {
8
- r == null || r({ target: { value: s } });
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { useCallback as u } from "react";
3
+ import { DropdownContext as d } from "./dropdown.context.js";
4
+ import { useToggle as f } from "../../../hooks/useToggle.js";
5
+ const w = ({ children: t, onChange: r, value: e, name: o }) => {
6
+ const [l, p] = f(!1), s = u(
7
+ (m) => {
8
+ r == null || r({ target: { value: m, name: o ?? "" } });
9
9
  },
10
- [r]
10
+ [r, o]
11
11
  );
12
- return /* @__PURE__ */ m(
13
- u.Provider,
12
+ return /* @__PURE__ */ i(
13
+ d.Provider,
14
14
  {
15
- value: { value: t, isOpen: e, setValue: p, toggleOpen: l },
16
- children: o
15
+ value: { value: e, isOpen: l, setValue: s, toggleOpen: p },
16
+ children: t
17
17
  }
18
18
  );
19
19
  };
20
20
  export {
21
- x as DropdownProvider
21
+ w as DropdownProvider
22
22
  };
package/dist/index.d.ts CHANGED
@@ -142,15 +142,16 @@ export declare const Divider: FunctionComponent<HTMLAttributes<HTMLDivElement>>;
142
142
  export declare const Dropdown: FC<DropdownProps>;
143
143
 
144
144
  declare interface DropdownProps extends VariantProps<typeof dropdownVariants>, Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {
145
- onChange?: ({ target: { value } }: {
145
+ onChange?: ({ target: { value, name }, }: {
146
146
  target: {
147
- value: Option_3;
147
+ value: string;
148
+ name: string;
148
149
  };
149
150
  }) => void;
150
151
  label?: string;
151
152
  options: Option_3[];
152
153
  labelClassName?: string;
153
- value?: Option_3;
154
+ value?: string;
154
155
  isLoading?: boolean;
155
156
  }
156
157
 
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.0.12-alpha.14",
5
+ "version": "0.0.12-alpha.15",
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.0.12-alpha.15",
5
+ "version": "0.0.12-alpha.16",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",