@overdoser/react-toolkit 0.16.0 → 0.18.0

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,125 +1,123 @@
1
- import { jsxs as S, jsx as i } from "react/jsx-runtime";
2
- import { forwardRef as T, useState as U, useRef as V, useEffect as q, useCallback as M } from "react";
3
- import f from "clsx";
4
- import r from "./NumberInput.module.scss.js";
5
- const g = (n) => {
1
+ import { jsxs as B, jsx as s } from "react/jsx-runtime";
2
+ import { forwardRef as q, useState as z, useRef as L, useEffect as G, useCallback as S } from "react";
3
+ import m from "clsx";
4
+ import l from "./NumberInput.module.scss.js";
5
+ const x = (n) => {
6
6
  if (n.trim() === "") return null;
7
- const p = Number(n);
8
- return Number.isNaN(p) ? null : p;
9
- }, z = T(
7
+ const h = Number(n);
8
+ return Number.isNaN(h) ? null : h;
9
+ }, H = q(
10
10
  ({
11
11
  value: n,
12
- defaultValue: p,
13
- onChange: b,
14
- min: o,
15
- max: s,
16
- step: x = 1,
17
- precision: k,
18
- inputSize: j = "md",
19
- error: D = !1,
20
- hideControls: B = !1,
21
- disabled: l,
12
+ defaultValue: h,
13
+ onChange: v,
14
+ min: u,
15
+ max: a,
16
+ step: D = 1,
17
+ precision: N,
18
+ inputSize: R = "md",
19
+ error: C = !1,
20
+ hideControls: A = !1,
21
+ disabled: i,
22
+ readOnly: f,
22
23
  classes: d,
23
- className: L,
24
- style: R,
25
- onKeyDown: A,
26
- onBlur: F,
27
- ...C
28
- }, K) => {
29
- const u = n !== void 0, I = (u ? n : p) ?? null, [v, m] = U(I != null ? String(I) : ""), N = V(!1), a = u ? n ?? null : g(v);
30
- q(() => {
31
- u && !N.current && m(n != null ? String(n) : "");
32
- }, [u, n]);
33
- const y = M(
24
+ className: F,
25
+ style: K,
26
+ onKeyDown: W,
27
+ onBlur: E,
28
+ ...I
29
+ }, P) => {
30
+ const c = n !== void 0, j = (c ? n : h) ?? null, [g, p] = z(j != null ? String(j) : ""), w = L(!1), b = L(!1), r = c ? n ?? null : x(g);
31
+ G(() => {
32
+ c && (!w.current || b.current) && p(n != null ? String(n) : ""), b.current = !1;
33
+ }, [c, n]);
34
+ const M = S(
34
35
  (t) => {
35
36
  let e = t;
36
- if (o != null && (e = Math.max(o, e)), s != null && (e = Math.min(s, e)), k != null) {
37
- const c = 10 ** k;
38
- e = Math.round(e * c) / c;
37
+ if (u != null && (e = Math.max(u, e)), a != null && (e = Math.min(a, e)), N != null) {
38
+ const o = 10 ** N;
39
+ e = Math.round(e * o) / o;
39
40
  }
40
41
  return e;
41
42
  },
42
- [o, s, k]
43
- ), w = M(
43
+ [u, a, N]
44
+ ), y = S(
44
45
  (t) => {
45
- u || m(t != null ? String(t) : ""), b?.(t);
46
+ c ? b.current = !0 : p(t != null ? String(t) : ""), v?.(t);
46
47
  },
47
- [u, b]
48
- ), h = M(
48
+ [c, v]
49
+ ), k = S(
49
50
  (t) => {
50
- if (l) return;
51
- w(y((a ?? o ?? 0) + t * x));
51
+ if (i || f) return;
52
+ y(M((r ?? u ?? 0) + t * D));
52
53
  },
53
- [l, a, o, x, y, w]
54
- ), W = s != null && a != null && a >= s, E = o != null && a != null && a <= o, P = (t) => {
55
- A?.(t), !t.defaultPrevented && (t.key === "ArrowUp" ? (t.preventDefault(), h(1)) : t.key === "ArrowDown" && (t.preventDefault(), h(-1)));
54
+ [i, f, r, u, D, M, y]
55
+ ), T = a != null && r != null && r >= a, U = u != null && r != null && r <= u, V = (t) => {
56
+ W?.(t), !t.defaultPrevented && (t.key === "ArrowUp" ? (t.preventDefault(), k(1)) : t.key === "ArrowDown" && (t.preventDefault(), k(-1)));
56
57
  };
57
- return /* @__PURE__ */ S(
58
+ return /* @__PURE__ */ B(
58
59
  "div",
59
60
  {
60
- className: f(
61
- r.root,
62
- r[j],
63
- D && r.error,
64
- l && r.disabled,
61
+ className: m(
62
+ l.root,
63
+ l[R],
64
+ C && l.error,
65
+ i && l.disabled,
65
66
  d?.root,
66
- L
67
+ F
67
68
  ),
68
- style: R,
69
- "data-disabled": l || void 0,
69
+ style: K,
70
+ "data-disabled": i || void 0,
70
71
  children: [
71
- /* @__PURE__ */ i(
72
+ /* @__PURE__ */ s(
72
73
  "input",
73
74
  {
74
- ref: K,
75
+ ref: P,
75
76
  type: "text",
76
77
  inputMode: "decimal",
77
- className: f(r.input, d?.input),
78
- value: v,
79
- disabled: l,
80
- "aria-invalid": D || void 0,
78
+ className: m(l.input, d?.input),
79
+ value: g,
80
+ disabled: i,
81
+ readOnly: f,
82
+ "aria-invalid": C || void 0,
81
83
  onChange: (t) => {
82
- m(t.target.value), b?.(g(t.target.value));
84
+ b.current = !1, p(t.target.value), v?.(x(t.target.value));
83
85
  },
84
- onKeyDown: P,
86
+ onKeyDown: V,
85
87
  onFocus: (t) => {
86
- N.current = !0, C.onFocus?.(t);
88
+ w.current = !0, I.onFocus?.(t);
87
89
  },
88
90
  onBlur: (t) => {
89
- N.current = !1;
90
- const e = g(v);
91
- if (e != null) {
92
- const c = y(e);
93
- c !== e ? w(c) : m(String(c));
94
- }
95
- F?.(t);
91
+ w.current = !1;
92
+ const e = x(g), o = e != null ? M(e) : null;
93
+ o !== e && y(o), c ? p(r != null ? String(r) : "") : o != null && o === e && p(String(o)), E?.(t);
96
94
  },
97
- ...C
95
+ ...I
98
96
  }
99
97
  ),
100
- !B && /* @__PURE__ */ S("div", { className: f(r.controls, d?.controls), children: [
101
- /* @__PURE__ */ i(
98
+ !A && /* @__PURE__ */ B("div", { className: m(l.controls, d?.controls), children: [
99
+ /* @__PURE__ */ s(
102
100
  "button",
103
101
  {
104
102
  type: "button",
105
103
  tabIndex: -1,
106
- className: f(r.increment, d?.increment),
107
- onClick: () => h(1),
108
- disabled: l || W,
104
+ className: m(l.increment, d?.increment),
105
+ onClick: () => k(1),
106
+ disabled: i || f || T,
109
107
  "aria-label": "Increment",
110
- children: /* @__PURE__ */ i("svg", { viewBox: "0 0 10 6", "aria-hidden": "true", children: /* @__PURE__ */ i("path", { d: "M1 5l4-4 4 4", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
108
+ children: /* @__PURE__ */ s("svg", { viewBox: "0 0 10 6", "aria-hidden": "true", children: /* @__PURE__ */ s("path", { d: "M1 5l4-4 4 4", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
111
109
  }
112
110
  ),
113
- /* @__PURE__ */ i(
111
+ /* @__PURE__ */ s(
114
112
  "button",
115
113
  {
116
114
  type: "button",
117
115
  tabIndex: -1,
118
- className: f(r.decrement, d?.decrement),
119
- onClick: () => h(-1),
120
- disabled: l || E,
116
+ className: m(l.decrement, d?.decrement),
117
+ onClick: () => k(-1),
118
+ disabled: i || f || U,
121
119
  "aria-label": "Decrement",
122
- children: /* @__PURE__ */ i("svg", { viewBox: "0 0 10 6", "aria-hidden": "true", children: /* @__PURE__ */ i("path", { d: "M1 1l4 4 4-4", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
120
+ children: /* @__PURE__ */ s("svg", { viewBox: "0 0 10 6", "aria-hidden": "true", children: /* @__PURE__ */ s("path", { d: "M1 1l4 4 4-4", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
123
121
  }
124
122
  )
125
123
  ] })
@@ -128,7 +126,7 @@ const g = (n) => {
128
126
  );
129
127
  }
130
128
  );
131
- z.displayName = "NumberInput";
129
+ H.displayName = "NumberInput";
132
130
  export {
133
- z as NumberInput
131
+ H as NumberInput
134
132
  };
@@ -86,6 +86,11 @@ export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'onCh
86
86
  * - **Searchable**: set `searchable`. Custom dropdown with text filter.
87
87
  * - **Multi**: set `multiple`. Chip-based multi-select with text filter.
88
88
  *
89
+ * In the searchable and multi modes `name` / `form` go to a hidden native
90
+ * `<select>` (so the value is submitted with `FormData`), `aria-*` / `data-*`
91
+ * go to the visible control, `required` becomes `aria-required`, and
92
+ * `onFocus` / `onBlur` fire when focus enters / leaves the whole widget.
93
+ *
89
94
  * @example Native: <Select options={[{ value: 'a', label: 'A' }]} onValueChange={setValue} />
90
95
  * @example Searchable: <Select searchable options={users} value={id} onValueChange={setId} />
91
96
  * @example Multi: <Select multiple options={tags} value={selected} onValuesChange={setSelected} />