mcr-design-systems 1.0.21 → 1.0.23

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
1
  import { jsx as e, jsxs as T } from "react/jsx-runtime";
2
2
  import * as R from "react";
3
3
  import { cn as i } from "../../shared/utils/cn.js";
4
- import { dataTestId as y } from "../../shared/utils/dataTestId.js";
5
- import x from "../Icon/Icon.js";
4
+ import { dataTestId as x } from "../../shared/utils/dataTestId.js";
5
+ import y from "../Icon/Icon.js";
6
6
  import { menuItemVariants as j } from "./helper/variants.js";
7
7
  import { Typography as S } from "../Typography/index.js";
8
8
  import { Tooltip as q } from "../Tooltip/index.js";
@@ -10,15 +10,15 @@ import { useTruncateTooltip as A } from "../../shared/hooks/useTruncateTooltip.j
10
10
  const D = R.forwardRef(
11
11
  ({
12
12
  label: m,
13
- disabled: z = !1,
14
- icon: c,
15
- endIcon: l,
16
- shortcut: o,
17
- selected: s = !1,
18
- showCheckmark: g = !1,
19
- className: d,
20
- "data-testid": n,
21
- onSelect: f,
13
+ disabled: g = !1,
14
+ icon: o,
15
+ endIcon: c,
16
+ shortcut: l,
17
+ selected: n = !1,
18
+ showCheckmark: z = !1,
19
+ className: f,
20
+ "data-testid": s,
21
+ onSelect: d,
22
22
  children: u,
23
23
  size: b,
24
24
  variant: k,
@@ -28,13 +28,13 @@ const D = R.forwardRef(
28
28
  endIconSize: E = "md",
29
29
  ...h
30
30
  }, N) => {
31
- const a = j({ size: b, variant: k, state: w, selected: s }), { textRef: I, isTruncated: M } = A(), v = (r, t) => r ? typeof r == "string" ? /* @__PURE__ */ e(x, { name: r, size: 16, className: t }) : typeof r == "function" ? /* @__PURE__ */ e("span", { className: t, children: r(s) }) : /* @__PURE__ */ e("span", { className: t, children: r }) : null;
31
+ const a = j({ size: b, variant: k, state: w, selected: n }), { textRef: I, isTruncated: M } = A(), v = (r, t) => r ? typeof r == "string" ? /* @__PURE__ */ e(y, { name: r, size: 16, className: t }) : typeof r == "function" ? /* @__PURE__ */ e("span", { className: t, children: r(n) }) : /* @__PURE__ */ e("span", { className: t, children: r }) : null;
32
32
  return u ? /* @__PURE__ */ e(
33
33
  "div",
34
34
  {
35
35
  ref: N,
36
- className: i(a.item(), d),
37
- onClick: f,
36
+ className: i(a.item(), f),
37
+ onClick: d,
38
38
  onMouseEnter: (r) => {
39
39
  r.preventDefault();
40
40
  },
@@ -44,7 +44,7 @@ const D = R.forwardRef(
44
44
  );
45
45
  t && document.activeElement === t && (r.currentTarget.blur(), t.focus());
46
46
  },
47
- ...n && y(n),
47
+ ...s && x(s),
48
48
  ...h,
49
49
  children: u
50
50
  }
@@ -54,37 +54,40 @@ const D = R.forwardRef(
54
54
  ref: N,
55
55
  className: i(
56
56
  a.item({
57
- disabled: z
57
+ disabled: g
58
58
  }),
59
- d
59
+ f
60
60
  ),
61
- onClick: f,
62
- ...n && y(n),
61
+ onClick: d,
62
+ ...s && x(s),
63
63
  ...h,
64
64
  children: [
65
- g && s && /* @__PURE__ */ e("div", { className: a.indicator(), children: /* @__PURE__ */ e(x, { name: "check", size: 12 }) }),
66
- c && /* @__PURE__ */ e(
65
+ z && n && /* @__PURE__ */ e("div", { className: a.indicator(), children: /* @__PURE__ */ e(y, { name: "check", size: 12 }) }),
66
+ o && /* @__PURE__ */ e(
67
67
  "span",
68
68
  {
69
69
  className: a.iconStart({
70
70
  size: C || "md"
71
71
  }),
72
- children: v(c)
72
+ children: v(o)
73
73
  }
74
74
  ),
75
75
  p ? /* @__PURE__ */ e("span", { className: a.label(), children: p }) : /* @__PURE__ */ e(q, { content: m, disabled: !M, showArrow: !1, children: /* @__PURE__ */ e(
76
76
  S,
77
77
  {
78
78
  ref: I,
79
- variants: "body",
79
+ variants: n ? "action-emphasize" : "body",
80
80
  size: "md",
81
- className: i(a.label(), "text-left"),
81
+ className: i(a.label(), "text-left", {
82
+ "text-fg-selected-rest": n,
83
+ "text-fg-neutral-main": !n
84
+ }),
82
85
  children: m
83
86
  }
84
87
  ) }),
85
88
  /* @__PURE__ */ T("div", { className: a.endContent(), children: [
86
- o && /* @__PURE__ */ e("span", { className: a.shortcut(), children: o }),
87
- l && /* @__PURE__ */ e("span", { className: a.iconEnd({ size: E || "md" }), children: v(l) })
89
+ l && /* @__PURE__ */ e("span", { className: a.shortcut(), children: l }),
90
+ c && /* @__PURE__ */ e("span", { className: a.iconEnd({ size: E || "md" }), children: v(c) })
88
91
  ] })
89
92
  ]
90
93
  }
@@ -1,27 +1,27 @@
1
- import { jsxs as m, jsx as c } from "react/jsx-runtime";
2
- import * as n from "react";
3
- import q from "../../node_modules/libphonenumber-js/examples.mobile.json.js";
4
- import { cn as w } from "../../shared/utils/cn.js";
5
- import { COUNTRIES_DATA as H } from "../../shared/flags/countries-data.js";
6
- import { FLAG_POSITIONS as J } from "../../shared/flags/flag-positions.js";
7
- import { FLAG_BASE64 as K } from "../../shared/flags/base64.js";
8
- import { phoneInputVariants as X } from "./helper/variants.js";
9
- import { Dropdown as Z } from "../Dropdown/index.js";
10
- import { Typography as P } from "../Typography/index.js";
11
- import D from "../Icon/Icon.js";
12
- import ee from "./FagDefault.js";
13
- import { getExampleNumber as te } from "../../node_modules/libphonenumber-js/min/exports/getExampleNumber.js";
14
- import { AsYouType as oe } from "../../node_modules/libphonenumber-js/min/exports/AsYouType.js";
15
- const F = ({
16
- countryCode: o
1
+ import { jsxs as g, jsx as i } from "react/jsx-runtime";
2
+ import * as a from "react";
3
+ import Z from "../../node_modules/libphonenumber-js/examples.mobile.json.js";
4
+ import { cn as v } from "../../shared/utils/cn.js";
5
+ import { COUNTRIES_DATA as ee } from "../../shared/flags/countries-data.js";
6
+ import { FLAG_POSITIONS as te } from "../../shared/flags/flag-positions.js";
7
+ import { FLAG_BASE64 as oe } from "../../shared/flags/base64.js";
8
+ import { phoneInputVariants as re } from "./helper/variants.js";
9
+ import { Dropdown as ne } from "../Dropdown/index.js";
10
+ import { Typography as z } from "../Typography/index.js";
11
+ import L from "../Icon/Icon.js";
12
+ import ae from "./FagDefault.js";
13
+ import { getExampleNumber as se } from "../../node_modules/libphonenumber-js/min/exports/getExampleNumber.js";
14
+ import { AsYouType as ie } from "../../node_modules/libphonenumber-js/min/exports/AsYouType.js";
15
+ const M = ({
16
+ countryCode: n
17
17
  }) => {
18
- const t = J[o];
19
- return /* @__PURE__ */ c("div", { className: "w-[30px] h-[20px] overflow-hidden rounded-xs", children: t === void 0 ? /* @__PURE__ */ c(ee, {}) : /* @__PURE__ */ c(
18
+ const t = te[n];
19
+ return /* @__PURE__ */ i("div", { className: "w-[30px] h-[20px] overflow-hidden rounded-xs", children: t === void 0 ? /* @__PURE__ */ i(ae, {}) : /* @__PURE__ */ i(
20
20
  "div",
21
21
  {
22
- className: w(),
22
+ className: v(),
23
23
  style: {
24
- backgroundImage: `url('${K}')`,
24
+ backgroundImage: `url('${oe}')`,
25
25
  backgroundPosition: `${t.x}px ${t.y}px`,
26
26
  backgroundSize: "512px 512px",
27
27
  width: "32px",
@@ -30,99 +30,99 @@ const F = ({
30
30
  }
31
31
  }
32
32
  ) });
33
- }, re = (o) => {
33
+ }, ce = (n) => {
34
34
  try {
35
- const t = te(
36
- o.toUpperCase(),
37
- q
35
+ const t = se(
36
+ n.toUpperCase(),
37
+ Z
38
38
  );
39
39
  if (t)
40
40
  return t.formatNational();
41
41
  } catch {
42
42
  console.warn(
43
- `Could not get example number for country code: ${o}`
43
+ `Could not get example number for country code: ${n}`
44
44
  );
45
45
  }
46
46
  return "Enter phone number";
47
- }, O = (o, t) => {
48
- if (!o || !o.trim()) return "";
47
+ }, A = (n, t) => {
48
+ if (!n || !n.trim()) return "";
49
49
  try {
50
- const a = new oe(t.toUpperCase()), l = o.replace(/[^\d]/g, "");
51
- if (!l) return "";
52
- let s = "";
53
- for (const h of l)
54
- s = a.input(h);
55
- return s || l;
50
+ const s = new ie(t.toUpperCase()), d = n.replace(/[^\d]/g, "");
51
+ if (!d) return "";
52
+ let r = "";
53
+ for (const S of d)
54
+ r = s.input(S);
55
+ return t.toLowerCase() === "us" && d.length === 3 && r.includes(")") && (r = r.replace(")", "")), r || d;
56
56
  } catch {
57
- return o.replace(/[^\d]/g, "") || "";
57
+ return n.replace(/[^\d]/g, "") || "";
58
58
  }
59
- }, ne = n.forwardRef(
59
+ }, le = a.forwardRef(
60
60
  ({
61
- onCountryChange: o,
61
+ onCountryChange: n,
62
62
  value: t = "",
63
- onValueChange: a,
64
- placeholder: l,
65
- countries: s = H,
66
- showSearch: h = !1,
67
- searchPlaceholder: T = "Search countries",
68
- className: z,
69
- size: p = "md",
70
- "data-testid": R,
71
- error: k,
72
- clearText: A,
73
- defaultCountryCode: y,
63
+ onValueChange: s,
64
+ placeholder: d,
65
+ countries: r = ee,
66
+ showSearch: S = !1,
67
+ searchPlaceholder: B = "Search countries",
68
+ className: _,
69
+ size: x = "md",
70
+ "data-testid": $,
71
+ error: E,
72
+ clearText: j,
73
+ defaultCountryCode: P,
74
74
  // placeholder = 'Enter phone number',
75
- ...L
76
- }, M) => {
77
- const [C, _] = n.useState(!1), [$, I] = n.useState(!1), [i, B] = n.useState(
78
- y || s[0]?.code || "us"
79
- ), [g, N] = n.useState(""), S = n.useRef(null), v = C, x = n.useCallback((e) => {
80
- _(e), e || N("");
81
- }, []), d = n.useMemo(
82
- () => s.find((e) => e.code === i) || s[0],
83
- [s, i]
75
+ ...U
76
+ }, V) => {
77
+ const [T, G] = a.useState(!1), [Q, D] = a.useState(!1), [l, W] = a.useState(
78
+ P || r[0]?.code || "us"
79
+ ), [y, F] = a.useState(""), R = a.useRef(null), k = T, I = a.useCallback((e) => {
80
+ G(e), e || F("");
81
+ }, []), p = a.useMemo(
82
+ () => r.find((e) => e.code === l) || r[0],
83
+ [r, l]
84
84
  );
85
- console.log(d, y);
86
- const E = n.useMemo(() => l || re(i), [i, l]), b = X({
87
- size: p,
88
- opened: v,
89
- inputFocused: $
90
- }), j = n.useCallback(
85
+ console.log(p, P);
86
+ const Y = a.useMemo(() => d || ce(l), [l, d]), N = re({
87
+ size: x,
88
+ opened: k,
89
+ inputFocused: Q
90
+ }), q = a.useCallback(
91
91
  (e) => {
92
- if (o?.(e), x(!1), B(e.code), t && t.trim()) {
93
- const r = O(
92
+ if (n?.(e), I(!1), W(e.code), t && t.trim()) {
93
+ const o = A(
94
94
  t,
95
95
  e.code
96
96
  );
97
- a?.({
98
- formatted: r,
97
+ s?.({
98
+ formatted: o,
99
99
  raw: t,
100
100
  country: e
101
101
  });
102
102
  }
103
103
  },
104
- [o, x, t, a]
105
- ), U = n.useMemo(() => s.filter(
106
- (e) => e.name.toLowerCase().includes(g.toLowerCase()) || e.code.toLowerCase().includes(g.toLowerCase())
104
+ [n, I, t, s]
105
+ ), H = a.useMemo(() => r.filter(
106
+ (e) => e.name.toLowerCase().includes(y.toLowerCase()) || e.code.toLowerCase().includes(y.toLowerCase())
107
107
  ).map((e) => ({
108
108
  label: e.name,
109
109
  value: e.code,
110
- icon: /* @__PURE__ */ c(F, { countryCode: e.code }),
110
+ icon: /* @__PURE__ */ i(M, { countryCode: e.code }),
111
111
  startIconSize: "auto",
112
112
  endIconSize: "auto",
113
- endIcon: /* @__PURE__ */ m(P, { variants: "body", size: "sm", color: "fg-neutral-subtlest", children: [
113
+ endIcon: /* @__PURE__ */ g(z, { variants: "body", size: "sm", color: "fg-neutral-subtlest", children: [
114
114
  "+",
115
115
  e.dial_code
116
116
  ] })
117
- })), [s, g]), V = A ? /* @__PURE__ */ c(
117
+ })), [r, y]), J = j ? /* @__PURE__ */ i(
118
118
  "div",
119
119
  {
120
120
  onMouseDown: (e) => {
121
121
  e.preventDefault(), e.stopPropagation(), setTimeout(() => {
122
- a && a({
122
+ s && s({
123
123
  formatted: "",
124
124
  raw: "",
125
- country: d
125
+ country: p
126
126
  });
127
127
  }, 0);
128
128
  },
@@ -130,8 +130,8 @@ const F = ({
130
130
  role: "button",
131
131
  tabIndex: 0,
132
132
  "aria-label": "Clear text",
133
- children: /* @__PURE__ */ c(
134
- D,
133
+ children: /* @__PURE__ */ i(
134
+ L,
135
135
  {
136
136
  name: "x-circle",
137
137
  variant: "solid",
@@ -139,95 +139,127 @@ const F = ({
139
139
  sm: 16,
140
140
  md: 20,
141
141
  lg: 24
142
- }[p],
142
+ }[x],
143
143
  className: "cursor-pointer text-fg-neutral-subtle"
144
144
  }
145
145
  )
146
146
  }
147
- ) : null, G = n.useCallback(
147
+ ) : null, K = a.useCallback(
148
148
  (e) => {
149
- const r = e.target.value, u = t, Q = r.length < u.length;
150
- if (r.length > 20) {
149
+ const o = e.target.value, b = t, C = e.target.selectionStart || 0, O = o.length < b.length;
150
+ if (o.length > 20) {
151
151
  e.preventDefault();
152
152
  return;
153
153
  }
154
- if (/^[0-9\s\-()+ ]*$/.test(r) || r === "") {
155
- const f = r.replace(/[^\d]/g, ""), W = u.replace(/[^\d]/g, "");
156
- if (Q && f === W) {
157
- a?.({
158
- formatted: r,
159
- raw: r.replace(/[^\d]/g, ""),
160
- country: d
161
- });
154
+ if (/^[0-9\s\-()+ ]*$/.test(o) || o === "") {
155
+ const h = o.replace(/[^\d]/g, ""), X = b.replace(/[^\d]/g, "");
156
+ if (O && h === X) {
157
+ s?.({
158
+ formatted: o,
159
+ raw: o.replace(/[^\d]/g, ""),
160
+ country: p
161
+ }), setTimeout(() => {
162
+ e.target && e.target.setSelectionRange(C, C);
163
+ }, 0);
162
164
  return;
163
165
  }
164
- const Y = f ? O(f, i) : "";
165
- a?.({
166
- formatted: Y,
167
- raw: f,
168
- country: d
169
- });
166
+ const u = h ? A(h, l) : "";
167
+ let m = C;
168
+ if (u !== o)
169
+ if (O) {
170
+ const w = o.slice(0, C).replace(/[^\d]/g, "").length;
171
+ let f = 0;
172
+ for (let c = 0; c < u.length; c++)
173
+ if (/\d/.test(u[c]) && (f++, f === w)) {
174
+ m = c + 1;
175
+ break;
176
+ }
177
+ m = Math.max(0, m);
178
+ } else {
179
+ const w = h.length;
180
+ let f = 0;
181
+ for (let c = 0; c < u.length; c++)
182
+ if (/\d/.test(u[c]) && (f++, f === w)) {
183
+ m = c + 1;
184
+ break;
185
+ }
186
+ f < w && (m = u.length);
187
+ }
188
+ s?.({
189
+ formatted: u,
190
+ raw: h,
191
+ country: p
192
+ }), setTimeout(() => {
193
+ e.target && e.target.setSelectionRange(m, m);
194
+ }, 0);
170
195
  }
171
196
  },
172
- [d, a, i, t]
197
+ [p, s, l, t]
173
198
  );
174
- return /* @__PURE__ */ m("div", { className: w("flex items-center", z), ref: S, children: [
175
- /* @__PURE__ */ c(
176
- Z,
199
+ return /* @__PURE__ */ g("div", { className: v("flex items-center", _), ref: R, children: [
200
+ /* @__PURE__ */ i(
201
+ ne,
177
202
  {
178
- open: C,
179
- onOpenChange: x,
180
- items: U,
181
- value: i,
203
+ open: T,
204
+ onOpenChange: I,
205
+ items: H,
206
+ value: l,
182
207
  onValueChange: (e) => {
183
- const r = s.find(
184
- (u) => u.code === e
208
+ const o = r.find(
209
+ (b) => b.code === e
185
210
  );
186
- r && j(r);
211
+ o && q(o);
187
212
  },
188
213
  align: "start",
189
214
  "data-testid": "align-start-dropdown",
190
- search: h,
191
- searchPlaceholder: T,
215
+ search: S,
216
+ searchPlaceholder: B,
192
217
  enableVirtualization: !0,
193
218
  onSearchChange: (e) => {
194
- N(e);
219
+ F(e);
195
220
  },
196
- width: S.current?.clientWidth || "auto",
197
- children: /* @__PURE__ */ m("div", { className: b.countryButton(), children: [
198
- /* @__PURE__ */ c(F, { countryCode: i }),
199
- /* @__PURE__ */ m("div", { className: "flex gap-xs-4", children: [
200
- /* @__PURE__ */ m(P, { variants: "body", size: "md", children: [
221
+ width: R.current?.clientWidth || "auto",
222
+ children: /* @__PURE__ */ g("div", { className: N.countryButton(), children: [
223
+ /* @__PURE__ */ i(M, { countryCode: l }),
224
+ /* @__PURE__ */ g("div", { className: "flex gap-xs-4", children: [
225
+ /* @__PURE__ */ g(z, { variants: "body", size: "md", color: "fg-neutral-main", children: [
201
226
  "+",
202
- d.dial_code
227
+ p.dial_code
203
228
  ] }),
204
- /* @__PURE__ */ c(D, { name: v ? "chevron-up" : "chevron-down", size: 16 })
229
+ /* @__PURE__ */ i(
230
+ L,
231
+ {
232
+ name: k ? "chevron-up" : "chevron-down",
233
+ size: 16,
234
+ className: "text-fg-neutral-main"
235
+ }
236
+ )
205
237
  ] })
206
238
  ] })
207
239
  }
208
240
  ),
209
- /* @__PURE__ */ m("div", { className: b.inputContainer({ error: k, size: p }), children: [
210
- /* @__PURE__ */ c(
241
+ /* @__PURE__ */ g("div", { className: N.inputContainer({ error: E, size: x }), children: [
242
+ /* @__PURE__ */ i(
211
243
  "input",
212
244
  {
213
- ...L,
214
- ref: M,
215
- className: w(b.input({ size: p })),
216
- placeholder: E,
245
+ ...U,
246
+ ref: V,
247
+ className: v(N.input({ size: x })),
248
+ placeholder: Y,
217
249
  value: t,
218
- onChange: G,
219
- onFocus: () => I(!0),
220
- onBlur: () => I(!1),
221
- "data-testid": R
250
+ onChange: K,
251
+ onFocus: () => D(!0),
252
+ onBlur: () => D(!1),
253
+ "data-testid": $
222
254
  }
223
255
  ),
224
- V
256
+ J
225
257
  ] })
226
258
  ] });
227
259
  }
228
260
  );
229
- ne.displayName = "PhoneInput";
261
+ le.displayName = "PhoneInput";
230
262
  export {
231
- ne as PhoneInput,
232
- ne as default
263
+ le as PhoneInput,
264
+ le as default
233
265
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcr-design-systems",
3
3
  "private": false,
4
- "version": "1.0.21",
4
+ "version": "1.0.23",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",