mcr-design-systems 1.0.21 → 1.0.22

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 m, jsx as i } from "react/jsx-runtime";
2
+ import * as r from "react";
3
+ import K from "../../node_modules/libphonenumber-js/examples.mobile.json.js";
4
+ import { cn as I } from "../../shared/utils/cn.js";
5
+ import { COUNTRIES_DATA as X } from "../../shared/flags/countries-data.js";
6
+ import { FLAG_POSITIONS as Z } from "../../shared/flags/flag-positions.js";
7
+ import { FLAG_BASE64 as ee } from "../../shared/flags/base64.js";
8
+ import { phoneInputVariants as te } from "./helper/variants.js";
9
+ import { Dropdown as oe } from "../Dropdown/index.js";
10
+ import { Typography as R } from "../Typography/index.js";
11
+ import M from "../Icon/Icon.js";
12
+ import ne from "./FagDefault.js";
13
+ import { getExampleNumber as re } from "../../node_modules/libphonenumber-js/min/exports/getExampleNumber.js";
14
+ import { AsYouType as ae } from "../../node_modules/libphonenumber-js/min/exports/AsYouType.js";
15
+ const O = ({
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 = Z[n];
19
+ return /* @__PURE__ */ i("div", { className: "w-[30px] h-[20px] overflow-hidden rounded-xs", children: t === void 0 ? /* @__PURE__ */ i(ne, {}) : /* @__PURE__ */ i(
20
20
  "div",
21
21
  {
22
- className: w(),
22
+ className: I(),
23
23
  style: {
24
- backgroundImage: `url('${K}')`,
24
+ backgroundImage: `url('${ee}')`,
25
25
  backgroundPosition: `${t.x}px ${t.y}px`,
26
26
  backgroundSize: "512px 512px",
27
27
  width: "32px",
@@ -30,91 +30,91 @@ const F = ({
30
30
  }
31
31
  }
32
32
  ) });
33
- }, re = (o) => {
33
+ }, se = (n) => {
34
34
  try {
35
- const t = te(
36
- o.toUpperCase(),
37
- q
35
+ const t = re(
36
+ n.toUpperCase(),
37
+ K
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
+ }, z = (n, t) => {
48
+ if (!n || !n.trim()) return "";
49
49
  try {
50
- const a = new oe(t.toUpperCase()), l = o.replace(/[^\d]/g, "");
50
+ const a = new ae(t.toUpperCase()), l = n.replace(/[^\d]/g, "");
51
51
  if (!l) return "";
52
52
  let s = "";
53
- for (const h of l)
54
- s = a.input(h);
53
+ for (const b of l)
54
+ s = a.input(b);
55
55
  return s || l;
56
56
  } catch {
57
- return o.replace(/[^\d]/g, "") || "";
57
+ return n.replace(/[^\d]/g, "") || "";
58
58
  }
59
- }, ne = n.forwardRef(
59
+ }, ie = r.forwardRef(
60
60
  ({
61
- onCountryChange: o,
61
+ onCountryChange: n,
62
62
  value: t = "",
63
63
  onValueChange: a,
64
64
  placeholder: l,
65
- countries: s = H,
66
- showSearch: h = !1,
67
- searchPlaceholder: T = "Search countries",
68
- className: z,
65
+ countries: s = X,
66
+ showSearch: b = !1,
67
+ searchPlaceholder: k = "Search countries",
68
+ className: A,
69
69
  size: p = "md",
70
- "data-testid": R,
71
- error: k,
72
- clearText: A,
73
- defaultCountryCode: y,
70
+ "data-testid": L,
71
+ error: _,
72
+ clearText: $,
73
+ defaultCountryCode: N,
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
+ ...B
76
+ }, E) => {
77
+ const [v, j] = r.useState(!1), [U, P] = r.useState(!1), [c, V] = r.useState(
78
+ N || s[0]?.code || "us"
79
+ ), [C, T] = r.useState(""), D = r.useRef(null), F = v, w = r.useCallback((e) => {
80
+ j(e), e || T("");
81
+ }, []), d = r.useMemo(
82
+ () => s.find((e) => e.code === c) || s[0],
83
+ [s, c]
84
84
  );
85
- console.log(d, y);
86
- const E = n.useMemo(() => l || re(i), [i, l]), b = X({
85
+ console.log(d, N);
86
+ const G = r.useMemo(() => l || se(c), [c, l]), S = te({
87
87
  size: p,
88
- opened: v,
89
- inputFocused: $
90
- }), j = n.useCallback(
88
+ opened: F,
89
+ inputFocused: U
90
+ }), Q = r.useCallback(
91
91
  (e) => {
92
- if (o?.(e), x(!1), B(e.code), t && t.trim()) {
93
- const r = O(
92
+ if (n?.(e), w(!1), V(e.code), t && t.trim()) {
93
+ const o = z(
94
94
  t,
95
95
  e.code
96
96
  );
97
97
  a?.({
98
- formatted: r,
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, w, t, a]
105
+ ), W = r.useMemo(() => s.filter(
106
+ (e) => e.name.toLowerCase().includes(C.toLowerCase()) || e.code.toLowerCase().includes(C.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(O, { 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__ */ m(R, { 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
+ })), [s, C]), Y = $ ? /* @__PURE__ */ i(
118
118
  "div",
119
119
  {
120
120
  onMouseDown: (e) => {
@@ -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
+ M,
135
135
  {
136
136
  name: "x-circle",
137
137
  variant: "solid",
@@ -144,90 +144,102 @@ const F = ({
144
144
  }
145
145
  )
146
146
  }
147
- ) : null, G = n.useCallback(
147
+ ) : null, q = r.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, f = t, u = e.target.selectionStart || 0, y = o.length < f.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) {
154
+ if (/^[0-9\s\-()+ ]*$/.test(o) || o === "") {
155
+ const h = o.replace(/[^\d]/g, ""), H = f.replace(/[^\d]/g, "");
156
+ if (y && h === H) {
157
157
  a?.({
158
- formatted: r,
159
- raw: r.replace(/[^\d]/g, ""),
158
+ formatted: o,
159
+ raw: o.replace(/[^\d]/g, ""),
160
160
  country: d
161
- });
161
+ }), setTimeout(() => {
162
+ e.target && e.target.setSelectionRange(u, u);
163
+ }, 0);
162
164
  return;
163
165
  }
164
- const Y = f ? O(f, i) : "";
166
+ const g = h ? z(h, c) : "";
167
+ let x = u;
168
+ if (!y && g.length > o.length) {
169
+ const J = g.length - o.length;
170
+ x = Math.min(
171
+ u + J,
172
+ g.length
173
+ );
174
+ } else y && (x = Math.max(0, u));
165
175
  a?.({
166
- formatted: Y,
167
- raw: f,
176
+ formatted: g,
177
+ raw: h,
168
178
  country: d
169
- });
179
+ }), setTimeout(() => {
180
+ e.target && e.target.setSelectionRange(x, x);
181
+ }, 0);
170
182
  }
171
183
  },
172
- [d, a, i, t]
184
+ [d, a, c, t]
173
185
  );
174
- return /* @__PURE__ */ m("div", { className: w("flex items-center", z), ref: S, children: [
175
- /* @__PURE__ */ c(
176
- Z,
186
+ return /* @__PURE__ */ m("div", { className: I("flex items-center", A), ref: D, children: [
187
+ /* @__PURE__ */ i(
188
+ oe,
177
189
  {
178
- open: C,
179
- onOpenChange: x,
180
- items: U,
181
- value: i,
190
+ open: v,
191
+ onOpenChange: w,
192
+ items: W,
193
+ value: c,
182
194
  onValueChange: (e) => {
183
- const r = s.find(
184
- (u) => u.code === e
195
+ const o = s.find(
196
+ (f) => f.code === e
185
197
  );
186
- r && j(r);
198
+ o && Q(o);
187
199
  },
188
200
  align: "start",
189
201
  "data-testid": "align-start-dropdown",
190
- search: h,
191
- searchPlaceholder: T,
202
+ search: b,
203
+ searchPlaceholder: k,
192
204
  enableVirtualization: !0,
193
205
  onSearchChange: (e) => {
194
- N(e);
206
+ T(e);
195
207
  },
196
- width: S.current?.clientWidth || "auto",
197
- children: /* @__PURE__ */ m("div", { className: b.countryButton(), children: [
198
- /* @__PURE__ */ c(F, { countryCode: i }),
208
+ width: D.current?.clientWidth || "auto",
209
+ children: /* @__PURE__ */ m("div", { className: S.countryButton(), children: [
210
+ /* @__PURE__ */ i(O, { countryCode: c }),
199
211
  /* @__PURE__ */ m("div", { className: "flex gap-xs-4", children: [
200
- /* @__PURE__ */ m(P, { variants: "body", size: "md", children: [
212
+ /* @__PURE__ */ m(R, { variants: "body", size: "md", color: "fg-neutral-main", children: [
201
213
  "+",
202
214
  d.dial_code
203
215
  ] }),
204
- /* @__PURE__ */ c(D, { name: v ? "chevron-up" : "chevron-down", size: 16 })
216
+ /* @__PURE__ */ i(M, { name: F ? "chevron-up" : "chevron-down", size: 16, className: "text-fg-neutral-main" })
205
217
  ] })
206
218
  ] })
207
219
  }
208
220
  ),
209
- /* @__PURE__ */ m("div", { className: b.inputContainer({ error: k, size: p }), children: [
210
- /* @__PURE__ */ c(
221
+ /* @__PURE__ */ m("div", { className: S.inputContainer({ error: _, size: p }), children: [
222
+ /* @__PURE__ */ i(
211
223
  "input",
212
224
  {
213
- ...L,
214
- ref: M,
215
- className: w(b.input({ size: p })),
216
- placeholder: E,
225
+ ...B,
226
+ ref: E,
227
+ className: I(S.input({ size: p })),
228
+ placeholder: G,
217
229
  value: t,
218
- onChange: G,
219
- onFocus: () => I(!0),
220
- onBlur: () => I(!1),
221
- "data-testid": R
230
+ onChange: q,
231
+ onFocus: () => P(!0),
232
+ onBlur: () => P(!1),
233
+ "data-testid": L
222
234
  }
223
235
  ),
224
- V
236
+ Y
225
237
  ] })
226
238
  ] });
227
239
  }
228
240
  );
229
- ne.displayName = "PhoneInput";
241
+ ie.displayName = "PhoneInput";
230
242
  export {
231
- ne as PhoneInput,
232
- ne as default
243
+ ie as PhoneInput,
244
+ ie as default
233
245
  };
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.22",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",