meticulous-ui 3.6.0 → 3.6.2

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,131 +1,132 @@
1
- import { jsxs as C, jsx as a } from "react/jsx-runtime";
2
- import { useState as $, useId as ie, useRef as v, useMemo as le, useEffect as h, useLayoutEffect as ae, useCallback as ue, createElement as de } from "react";
1
+ import { jsxs as v, jsx as d } from "react/jsx-runtime";
2
+ import { useState as S, useId as le, useRef as O, useMemo as ae, useEffect as b, useLayoutEffect as de, useCallback as ue, createElement as pe } from "react";
3
+ import r from "../../_virtual/index.js";
3
4
  import E from "../../colors/grey.js";
4
5
  import fe from "../MenuItem/MenuItem.js";
5
- import pe from "../../colors/colorMap.js";
6
- import { blue as me } from "../../colors/blue.js";
6
+ import me from "../../colors/colorMap.js";
7
+ import { blue as he } from "../../colors/blue.js";
7
8
  import j from "../Spinner/Spinner.js";
8
- import { DropdownWrapper as he, Box as be, PWrapper as we, ChevronDownWrapper as xe, OptionWrapper as ge, SearchContainer as Ie, SearchIcon as ke, SearchInput as Se, OptionsList as Ce, LoadMoreSentinel as $e, SpinnerWrapper as ve } from "./styles.js";
9
- const ye = (n) => {
10
- if (typeof n != "string") return n;
11
- if (n.endsWith("px")) return parseFloat(n);
12
- if (n.endsWith("rem")) {
13
- const O = parseFloat(n), s = parseFloat(getComputedStyle(document.documentElement).fontSize);
14
- return O * s;
9
+ import { DropdownWrapper as be, Box as ge, PWrapper as we, ChevronDownWrapper as xe, OptionWrapper as Ie, SearchContainer as ye, SearchIcon as Ce, SearchInput as ke, OptionsList as ve, LoadMoreSentinel as Se, SpinnerWrapper as Oe } from "./styles.js";
10
+ const $e = (o) => {
11
+ if (typeof o != "string") return o;
12
+ if (o.endsWith("px")) return parseFloat(o);
13
+ if (o.endsWith("rem")) {
14
+ const D = parseFloat(o), i = parseFloat(getComputedStyle(document.documentElement).fontSize);
15
+ return D * i;
15
16
  }
16
- return parseFloat(n);
17
- }, Pe = ({
18
- options: n,
19
- onChange: O,
20
- value: s,
21
- width: b = "32rem",
17
+ return parseFloat(o);
18
+ }, Ee = ({
19
+ options: o,
20
+ onChange: D,
21
+ value: i,
22
+ width: g = "32rem",
22
23
  menuHeight: F = "32rem",
23
24
  placeholder: K,
24
25
  theme: Q = "blue",
25
26
  isLoading: w,
26
27
  isDisabled: x,
27
- loaderColor: z,
28
- searchable: g = !1,
28
+ loaderColor: R,
29
+ searchable: I = !1,
29
30
  onLoadMore: u,
30
- hasMore: I = !1,
31
- isLoadingMore: d = !1,
32
- searchPh: R = "Search...",
31
+ hasMore: y = !1,
32
+ isLoadingMore: p = !1,
33
+ searchPh: W = "Search...",
33
34
  ...U
34
35
  }) => {
35
- const [r, f] = $(!1), [q, W] = $(!1), [N, T] = $("bottom"), [k, A] = $(""), [c, p] = $(-1), y = ie(), m = v(null), S = v(null), D = v(null), B = v(null), G = v(!0), J = () => !w && !x && f((e) => !e), P = (e) => {
36
- e !== s && (O(e), f(!1));
37
- }, i = le(() => {
38
- if (!g || !k.trim()) return n;
39
- const e = k.toLowerCase();
40
- return n.filter(({ label: t }) => t.toLowerCase().includes(e));
41
- }, [n, k, g]);
42
- h(() => {
43
- if (r) {
44
- const e = i.findIndex((t) => t.value === s);
45
- if (e !== -1 && !i[e].disabled)
46
- p(e);
36
+ const [n, f] = S(!1), [q, P] = S(!1), [N, G] = S("bottom"), [C, A] = S(""), [c, m] = S(-1), $ = le(), h = O(null), k = O(null), z = O(null), B = O(null), J = O(!0), X = () => !w && !x && f((e) => !e), H = (e) => {
37
+ e !== i && (D(e), f(!1));
38
+ }, l = ae(() => {
39
+ if (!I || !C.trim()) return o;
40
+ const e = C.toLowerCase();
41
+ return o.filter(({ label: t }) => t.toLowerCase().includes(e));
42
+ }, [o, C, I]);
43
+ b(() => {
44
+ if (n) {
45
+ const e = l.findIndex((t) => t.value === i);
46
+ if (e !== -1 && !l[e].disabled)
47
+ m(e);
47
48
  else {
48
- const t = i.findIndex((o) => !o.disabled);
49
- p(t);
49
+ const t = l.findIndex((s) => !s.disabled);
50
+ m(t);
50
51
  }
51
52
  } else
52
- A(""), p(-1);
53
- }, [r, k, i, s]), h(() => {
54
- if (r && c !== -1 && S.current) {
55
- const e = S.current.children[c];
53
+ A(""), m(-1);
54
+ }, [n, C, l, i]), b(() => {
55
+ if (n && c !== -1 && k.current) {
56
+ const e = k.current.children[c];
56
57
  e && e.scrollIntoView({
57
58
  block: "nearest",
58
59
  behavior: "auto"
59
60
  });
60
61
  }
61
- }, [c, r]), h(() => {
62
- r && g && D.current && D.current.focus();
63
- }, [r, g]), h(() => {
64
- r || (G.current = !0);
65
- }, [r]), h(() => {
62
+ }, [c, n]), b(() => {
63
+ n && I && z.current && z.current.focus();
64
+ }, [n, I]), b(() => {
65
+ n || (J.current = !0);
66
+ }, [n]), b(() => {
66
67
  const e = (t) => {
67
- m.current && !m.current.contains(t.target) && f(!1);
68
+ h.current && !h.current.contains(t.target) && f(!1);
68
69
  };
69
70
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
70
- }, []), ae(() => {
71
- if (r && S.current && m.current) {
72
- const e = m.current.getBoundingClientRect(), t = window.innerHeight, o = ye(F), l = t - e.bottom;
73
- T(
74
- l < o + 8 && e.top > l ? "top" : "bottom"
71
+ }, []), de(() => {
72
+ if (n && k.current && h.current) {
73
+ const e = h.current.getBoundingClientRect(), t = window.innerHeight, s = $e(F), a = t - e.bottom;
74
+ G(
75
+ a < s + 8 && e.top > a ? "top" : "bottom"
75
76
  );
76
77
  }
77
- }, [r, F]);
78
- const X = (e) => {
78
+ }, [n, F]);
79
+ const Y = (e) => {
79
80
  let t = e + 1;
80
- for (; t < i.length; ) {
81
- if (!i[t].disabled) return t;
81
+ for (; t < l.length; ) {
82
+ if (!l[t].disabled) return t;
82
83
  t++;
83
84
  }
84
85
  return e;
85
- }, Y = (e) => {
86
+ }, Z = (e) => {
86
87
  let t = e - 1;
87
88
  for (; t >= 0; ) {
88
- if (!i[t].disabled) return t;
89
+ if (!l[t].disabled) return t;
89
90
  t--;
90
91
  }
91
92
  return e;
92
- }, Z = (e) => {
93
+ }, _ = (e) => {
93
94
  if (!(w || x)) {
94
- if (!r) {
95
+ if (!n) {
95
96
  (e.key === " " || e.key === "Enter" || e.key === "ArrowDown" || e.key === "ArrowUp") && (e.preventDefault(), f(!0));
96
97
  return;
97
98
  }
98
99
  switch (e.key) {
99
100
  case "ArrowDown":
100
101
  e.preventDefault();
101
- const t = X(c);
102
- t === c && I && !d && u?.(), p(t);
102
+ const t = Y(c);
103
+ t === c && y && !p && u?.(), m(t);
103
104
  break;
104
105
  case "ArrowUp":
105
- e.preventDefault(), p((l) => Y(l));
106
+ e.preventDefault(), m((a) => Z(a));
106
107
  break;
107
108
  case "Enter":
108
109
  e.preventDefault();
109
- const o = i[c];
110
- o && !o.disabled && P(o.value);
110
+ const s = l[c];
111
+ s && !s.disabled && H(s.value);
111
112
  break;
112
113
  case "Escape":
113
114
  f(!1);
114
115
  break;
115
116
  }
116
117
  }
117
- }, H = ue(() => {
118
- I && !d && u && u();
119
- }, [I, d, u]);
120
- h(() => {
118
+ }, T = ue(() => {
119
+ y && !p && u && u();
120
+ }, [y, p, u]);
121
+ b(() => {
121
122
  const e = B.current;
122
- if (!e || !u || !I) return;
123
+ if (!e || !u || !y) return;
123
124
  const t = new IntersectionObserver(
124
- ([o]) => {
125
- o.isIntersecting && !d && H();
125
+ ([s]) => {
126
+ s.isIntersecting && !p && T();
126
127
  },
127
128
  {
128
- root: S.current,
129
+ root: k.current,
129
130
  // Observe relative to the scrollable container
130
131
  threshold: 0.1,
131
132
  rootMargin: "20px"
@@ -133,100 +134,138 @@ const ye = (n) => {
133
134
  }
134
135
  );
135
136
  return t.observe(e), () => t.disconnect();
136
- }, [H, u, I, d]);
137
+ }, [T, u, y, p]);
137
138
  const {
138
- m50: _,
139
- m100: L,
140
- m200: M,
141
- m500: ee
142
- } = pe[Q] ?? me, te = (e, t) => () => !e && p(t), V = (e) => `${y}-opt-${e}`, re = ({ value: e, label: t, disabled: o }, l) => /* @__PURE__ */ de(
139
+ m50: L,
140
+ m100: M,
141
+ m200: ee,
142
+ m500: te
143
+ } = me[Q] ?? he, re = (e, t) => () => !e && m(t), V = (e) => `${$}-opt-${e}`, ne = ({ value: e, label: t, disabled: s }, a) => /* @__PURE__ */ pe(
143
144
  fe,
144
145
  {
145
146
  value: e,
146
147
  label: t,
147
- isDisabled: o,
148
- onSelect: P,
149
- onMouseEnter: te(o, l),
150
- isSelected: e === s,
151
- isHighlighted: l === c,
148
+ isDisabled: s,
149
+ onSelect: H,
150
+ onMouseEnter: re(s, a),
151
+ isSelected: e === i,
152
+ isHighlighted: a === c,
152
153
  key: e,
153
- id: V(l),
154
- width: b,
155
- selectedColor: M,
156
- hoverColor: _,
157
- activeColor: L
154
+ id: V(a),
155
+ width: g,
156
+ selectedColor: ee,
157
+ hoverColor: L,
158
+ activeColor: M
158
159
  }
159
- ), ne = (e) => () => {
160
- W(e);
161
- }, oe = (e) => {
162
- W(!1), m.current?.contains(e.relatedTarget) || f(!1);
160
+ ), oe = (e) => () => {
161
+ P(e);
163
162
  }, se = (e) => {
163
+ P(!1), h.current?.contains(e.relatedTarget) || f(!1);
164
+ }, ie = (e) => {
164
165
  A(e.target.value);
165
166
  }, ce = (e) => {
166
167
  e.stopPropagation();
167
168
  };
168
- return /* @__PURE__ */ C(
169
- he,
169
+ return /* @__PURE__ */ v(
170
+ be,
170
171
  {
171
- ref: m,
172
- $width: b,
172
+ ref: h,
173
+ $width: g,
173
174
  ...U,
174
175
  tabIndex: x || w ? -1 : 0,
175
- onKeyDown: Z,
176
+ onKeyDown: _,
176
177
  $isLoading: w,
177
178
  $isDisabled: x,
178
179
  role: "combobox",
179
- "aria-expanded": r,
180
+ "aria-expanded": n,
180
181
  "aria-haspopup": "listbox",
181
- "aria-controls": y,
182
+ "aria-controls": $,
182
183
  "aria-disabled": x || void 0,
183
184
  "aria-activedescendant": c !== -1 ? V(c) : void 0,
184
- onFocus: ne(!0),
185
- onBlur: oe,
185
+ onFocus: oe(!0),
186
+ onBlur: se,
186
187
  children: [
187
- /* @__PURE__ */ C(
188
- be,
188
+ /* @__PURE__ */ v(
189
+ ge,
189
190
  {
190
- $width: b,
191
- onClick: J,
192
- $isOpen: r,
193
- $border: ee,
194
- $isFocused: q && !r,
191
+ $width: g,
192
+ onClick: X,
193
+ $isOpen: n,
194
+ $border: te,
195
+ $isFocused: q && !n,
195
196
  children: [
196
- /* @__PURE__ */ a(we, { $width: b, color: s ? E.m700 : E.m500, size: "1.92rem", children: s ? n.find(({ value: e }) => s === e)?.label : K }),
197
- /* @__PURE__ */ a(xe, { color: E.m500, size: 22, $isOpen: r, "aria-hidden": !0 })
197
+ /* @__PURE__ */ d(we, { $width: g, color: i ? E.m700 : E.m500, size: "1.92rem", children: i ? o.find(({ value: e }) => i === e)?.label : K }),
198
+ /* @__PURE__ */ d(xe, { color: E.m500, size: 22, $isOpen: n, "aria-hidden": !0 })
198
199
  ]
199
200
  }
200
201
  ),
201
- /* @__PURE__ */ C(ge, { $isOpen: r, $width: b, $height: F, $top: N === "top", children: [
202
- g && /* @__PURE__ */ C(Ie, { onClick: ce, children: [
203
- /* @__PURE__ */ a(ke, { size: 20, color: E.m600, "aria-hidden": !0 }),
204
- /* @__PURE__ */ a(
205
- Se,
202
+ /* @__PURE__ */ v(Ie, { $isOpen: n, $width: g, $height: F, $top: N === "top", children: [
203
+ I && /* @__PURE__ */ v(ye, { onClick: ce, children: [
204
+ /* @__PURE__ */ d(Ce, { size: 20, color: E.m600, "aria-hidden": !0 }),
205
+ /* @__PURE__ */ d(
206
+ ke,
206
207
  {
207
- ref: D,
208
- value: k,
209
- onChange: se,
210
- placeholder: R,
211
- "aria-label": R,
212
- "aria-controls": y,
208
+ ref: z,
209
+ value: C,
210
+ onChange: ie,
211
+ placeholder: W,
212
+ "aria-label": W,
213
+ "aria-controls": $,
213
214
  "aria-autocomplete": "list",
214
- "aria-expanded": r,
215
+ "aria-expanded": n,
215
216
  role: "combobox",
216
- tabIndex: r ? 0 : -1
217
+ tabIndex: n ? 0 : -1
217
218
  }
218
219
  )
219
220
  ] }),
220
- /* @__PURE__ */ C(Ce, { ref: S, role: "listbox", id: y, tabIndex: -1, children: [
221
- i.map(re),
222
- u && /* @__PURE__ */ a($e, { ref: B, children: d && /* @__PURE__ */ a(j, { size: "small", color: z }) })
221
+ /* @__PURE__ */ v(ve, { ref: k, role: "listbox", id: $, tabIndex: -1, children: [
222
+ l.map(ne),
223
+ u && /* @__PURE__ */ d(Se, { ref: B, children: p && /* @__PURE__ */ d(j, { size: "small", color: R }) })
223
224
  ] })
224
225
  ] }),
225
- w && /* @__PURE__ */ a(ve, { children: /* @__PURE__ */ a(j, { size: "small", color: z }) })
226
+ w && /* @__PURE__ */ d(Oe, { children: /* @__PURE__ */ d(j, { size: "small", color: R }) })
226
227
  ]
227
228
  }
228
229
  );
229
230
  };
231
+ Ee.propTypes = {
232
+ /** Array of option objects: `{ value, label, disabled? }` */
233
+ options: r.arrayOf(
234
+ r.shape({
235
+ value: r.any,
236
+ label: r.string,
237
+ disabled: r.bool
238
+ })
239
+ ),
240
+ /** Currently selected value (controlled) */
241
+ value: r.any,
242
+ /** Called with the selected value when an option is picked */
243
+ onChange: r.func,
244
+ /** CSS width of the dropdown trigger. Defaults to `'32rem'` */
245
+ width: r.string,
246
+ /** Maximum CSS height of the dropdown menu. Defaults to `'32rem'` */
247
+ menuHeight: r.string,
248
+ /** Placeholder text shown when no value is selected */
249
+ placeholder: r.string,
250
+ /** Color theme key. Defaults to `'blue'` */
251
+ theme: r.string,
252
+ /** Shows a spinner inside the trigger and disables interaction */
253
+ isLoading: r.bool,
254
+ /** Disables the dropdown */
255
+ isDisabled: r.bool,
256
+ /** Color key for the loading spinner */
257
+ loaderColor: r.string,
258
+ /** Adds a search input inside the dropdown menu */
259
+ searchable: r.bool,
260
+ /** Placeholder text for the search input. Defaults to `'Search...'` */
261
+ searchPh: r.string,
262
+ /** Called when the user scrolls to the bottom of the list (infinite scroll) */
263
+ onLoadMore: r.func,
264
+ /** Whether more options are available to load */
265
+ hasMore: r.bool,
266
+ /** Shows a spinner at the bottom while loading more options */
267
+ isLoadingMore: r.bool
268
+ };
230
269
  export {
231
- Pe as default
270
+ Ee as default
232
271
  };
@@ -1,67 +1,88 @@
1
- import { jsxs as $, jsx as n } from "react/jsx-runtime";
2
- import { useState as g, useRef as H } from "react";
3
- import P from "../../../colors/grey.js";
1
+ import { jsxs as $, jsx as s } from "react/jsx-runtime";
2
+ import { useState as C, useRef as P } from "react";
3
+ import r from "../../../_virtual/index.js";
4
+ import H from "../../../colors/grey.js";
4
5
  import j from "../../Typography/P/P.js";
5
6
  import z from "../../../colors/white.js";
6
- import { blue as m } from "../../../colors/blue.js";
7
- import { Wrapper as B, CbInput as C, Box as E } from "./styles.js";
8
- import { getColor as F } from "./helpers.js";
9
- const J = ({
10
- label: u,
11
- value: r,
12
- color: d = "blue",
13
- textColor: l = P.m700,
14
- disabled: s,
15
- onChange: o,
16
- tabIndex: p,
17
- innerShade: h,
18
- outerShade: k,
19
- ...y
7
+ import { blue as u } from "../../../colors/blue.js";
8
+ import { Wrapper as B, CbInput as E, Box as F } from "./styles.js";
9
+ import { getColor as I } from "./helpers.js";
10
+ const K = ({
11
+ label: d,
12
+ value: o,
13
+ color: m = "blue",
14
+ textColor: p = H.m700,
15
+ disabled: a,
16
+ onChange: t,
17
+ tabIndex: h,
18
+ innerShade: b,
19
+ outerShade: y,
20
+ ...g
20
21
  }) => {
21
- const [S, t] = g(!1), c = F(d), b = h ?? c?.m500 ?? m.m500, x = k ?? c?.m600 ?? m.m600, a = H(0), w = (e) => o(e.target.checked), D = (e) => {
22
+ const [k, n] = C(!1), c = I(m), S = b ?? c?.m500 ?? u.m500, x = y ?? c?.m600 ?? u.m600, i = P(0), w = (e) => t(e.target.checked), D = (e) => {
22
23
  if (e.key === "Enter" || e.key === " ") {
23
- const i = Date.now();
24
- if (i - a.current < 500) {
24
+ const f = Date.now();
25
+ if (f - i.current < 500) {
25
26
  e.preventDefault(), e.stopPropagation();
26
27
  return;
27
28
  }
28
- if (a.current = i, e.key === " ") {
29
- e.preventDefault(), o(!r);
29
+ if (i.current = f, e.key === " ") {
30
+ e.preventDefault(), t(!o);
30
31
  return;
31
32
  }
32
- o(!r), t(!1);
33
+ t(!o), n(!1);
33
34
  }
34
- e.key === "Escape" && t(!1);
35
- }, f = (e) => () => t(e);
36
- return /* @__PURE__ */ $(B, { as: "label", $disabled: s, ...y, children: [
37
- /* @__PURE__ */ n(
38
- C,
35
+ e.key === "Escape" && n(!1);
36
+ }, l = (e) => () => n(e);
37
+ return /* @__PURE__ */ $(B, { as: "label", $disabled: a, ...g, children: [
38
+ /* @__PURE__ */ s(
39
+ E,
39
40
  {
40
41
  type: "checkbox",
41
- checked: r,
42
+ checked: o,
42
43
  onChange: w,
43
44
  onKeyDown: D,
44
- onFocus: f(!0),
45
- onBlur: f(!1),
46
- disabled: s,
47
- tabIndex: p
45
+ onFocus: l(!0),
46
+ onBlur: l(!1),
47
+ disabled: a,
48
+ tabIndex: h
48
49
  }
49
50
  ),
50
- /* @__PURE__ */ n(
51
- E,
51
+ /* @__PURE__ */ s(
52
+ F,
52
53
  {
53
- $value: r,
54
- $focused: S,
54
+ $value: o,
55
+ $focused: k,
55
56
  size: 6,
56
57
  color: z,
57
- $innerShade: b,
58
+ $innerShade: S,
58
59
  $outerShade: x,
59
60
  "aria-hidden": "true"
60
61
  }
61
62
  ),
62
- /* @__PURE__ */ n(j, { color: l, size: "1.92rem", children: u })
63
+ /* @__PURE__ */ s(j, { color: p, size: "1.92rem", children: d })
63
64
  ] });
64
65
  };
66
+ K.propTypes = {
67
+ /** Text label rendered next to the checkbox */
68
+ label: r.string,
69
+ /** Controlled checked state */
70
+ value: r.bool,
71
+ /** Color theme key for the checkbox accent. Defaults to 'blue' */
72
+ color: r.string,
73
+ /** Color of the label text */
74
+ textColor: r.string,
75
+ /** Disables the checkbox */
76
+ disabled: r.bool,
77
+ /** Called with the new boolean value on change */
78
+ onChange: r.func,
79
+ /** Tab order index for the checkbox input */
80
+ tabIndex: r.number,
81
+ /** Override the inner fill color (checked state) */
82
+ innerShade: r.string,
83
+ /** Override the outer border/ring color (checked state) */
84
+ outerShade: r.string
85
+ };
65
86
  export {
66
- J as default
87
+ K as default
67
88
  };