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.
- package/dist/components/MenuItem/index.js +29 -26
- package/dist/components/PhoneInput/index.js +161 -129
- package/package.json +1 -1
|
@@ -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
|
|
5
|
-
import
|
|
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:
|
|
14
|
-
icon:
|
|
15
|
-
endIcon:
|
|
16
|
-
shortcut:
|
|
17
|
-
selected:
|
|
18
|
-
showCheckmark:
|
|
19
|
-
className:
|
|
20
|
-
"data-testid":
|
|
21
|
-
onSelect:
|
|
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:
|
|
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(),
|
|
37
|
-
onClick:
|
|
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
|
-
...
|
|
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:
|
|
57
|
+
disabled: g
|
|
58
58
|
}),
|
|
59
|
-
|
|
59
|
+
f
|
|
60
60
|
),
|
|
61
|
-
onClick:
|
|
62
|
-
...
|
|
61
|
+
onClick: d,
|
|
62
|
+
...s && x(s),
|
|
63
63
|
...h,
|
|
64
64
|
children: [
|
|
65
|
-
|
|
66
|
-
|
|
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(
|
|
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
|
-
|
|
87
|
-
|
|
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
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import { cn as
|
|
5
|
-
import { COUNTRIES_DATA as
|
|
6
|
-
import { FLAG_POSITIONS as
|
|
7
|
-
import { FLAG_BASE64 as
|
|
8
|
-
import { phoneInputVariants as
|
|
9
|
-
import { Dropdown as
|
|
10
|
-
import { Typography as
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { getExampleNumber as
|
|
14
|
-
import { AsYouType as
|
|
15
|
-
const
|
|
16
|
-
countryCode:
|
|
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 =
|
|
19
|
-
return /* @__PURE__ */
|
|
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:
|
|
22
|
+
className: v(),
|
|
23
23
|
style: {
|
|
24
|
-
backgroundImage: `url('${
|
|
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
|
-
},
|
|
33
|
+
}, ce = (n) => {
|
|
34
34
|
try {
|
|
35
|
-
const t =
|
|
36
|
-
|
|
37
|
-
|
|
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: ${
|
|
43
|
+
`Could not get example number for country code: ${n}`
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
return "Enter phone number";
|
|
47
|
-
},
|
|
48
|
-
if (!
|
|
47
|
+
}, A = (n, t) => {
|
|
48
|
+
if (!n || !n.trim()) return "";
|
|
49
49
|
try {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
let
|
|
53
|
-
for (const
|
|
54
|
-
|
|
55
|
-
return
|
|
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
|
|
57
|
+
return n.replace(/[^\d]/g, "") || "";
|
|
58
58
|
}
|
|
59
|
-
},
|
|
59
|
+
}, le = a.forwardRef(
|
|
60
60
|
({
|
|
61
|
-
onCountryChange:
|
|
61
|
+
onCountryChange: n,
|
|
62
62
|
value: t = "",
|
|
63
|
-
onValueChange:
|
|
64
|
-
placeholder:
|
|
65
|
-
countries:
|
|
66
|
-
showSearch:
|
|
67
|
-
searchPlaceholder:
|
|
68
|
-
className:
|
|
69
|
-
size:
|
|
70
|
-
"data-testid":
|
|
71
|
-
error:
|
|
72
|
-
clearText:
|
|
73
|
-
defaultCountryCode:
|
|
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
|
-
...
|
|
76
|
-
},
|
|
77
|
-
const [
|
|
78
|
-
|
|
79
|
-
), [
|
|
80
|
-
|
|
81
|
-
}, []),
|
|
82
|
-
() =>
|
|
83
|
-
[
|
|
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(
|
|
86
|
-
const
|
|
87
|
-
size:
|
|
88
|
-
opened:
|
|
89
|
-
inputFocused:
|
|
90
|
-
}),
|
|
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 (
|
|
93
|
-
const
|
|
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
|
-
|
|
98
|
-
formatted:
|
|
97
|
+
s?.({
|
|
98
|
+
formatted: o,
|
|
99
99
|
raw: t,
|
|
100
100
|
country: e
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
|
-
[
|
|
105
|
-
),
|
|
106
|
-
(e) => e.name.toLowerCase().includes(
|
|
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__ */
|
|
110
|
+
icon: /* @__PURE__ */ i(M, { countryCode: e.code }),
|
|
111
111
|
startIconSize: "auto",
|
|
112
112
|
endIconSize: "auto",
|
|
113
|
-
endIcon: /* @__PURE__ */
|
|
113
|
+
endIcon: /* @__PURE__ */ g(z, { variants: "body", size: "sm", color: "fg-neutral-subtlest", children: [
|
|
114
114
|
"+",
|
|
115
115
|
e.dial_code
|
|
116
116
|
] })
|
|
117
|
-
})), [
|
|
117
|
+
})), [r, y]), J = j ? /* @__PURE__ */ i(
|
|
118
118
|
"div",
|
|
119
119
|
{
|
|
120
120
|
onMouseDown: (e) => {
|
|
121
121
|
e.preventDefault(), e.stopPropagation(), setTimeout(() => {
|
|
122
|
-
|
|
122
|
+
s && s({
|
|
123
123
|
formatted: "",
|
|
124
124
|
raw: "",
|
|
125
|
-
country:
|
|
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__ */
|
|
134
|
-
|
|
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
|
-
}[
|
|
142
|
+
}[x],
|
|
143
143
|
className: "cursor-pointer text-fg-neutral-subtle"
|
|
144
144
|
}
|
|
145
145
|
)
|
|
146
146
|
}
|
|
147
|
-
) : null,
|
|
147
|
+
) : null, K = a.useCallback(
|
|
148
148
|
(e) => {
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
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(
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
formatted:
|
|
159
|
-
raw:
|
|
160
|
-
country:
|
|
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
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
[
|
|
197
|
+
[p, s, l, t]
|
|
173
198
|
);
|
|
174
|
-
return /* @__PURE__ */
|
|
175
|
-
/* @__PURE__ */
|
|
176
|
-
|
|
199
|
+
return /* @__PURE__ */ g("div", { className: v("flex items-center", _), ref: R, children: [
|
|
200
|
+
/* @__PURE__ */ i(
|
|
201
|
+
ne,
|
|
177
202
|
{
|
|
178
|
-
open:
|
|
179
|
-
onOpenChange:
|
|
180
|
-
items:
|
|
181
|
-
value:
|
|
203
|
+
open: T,
|
|
204
|
+
onOpenChange: I,
|
|
205
|
+
items: H,
|
|
206
|
+
value: l,
|
|
182
207
|
onValueChange: (e) => {
|
|
183
|
-
const
|
|
184
|
-
(
|
|
208
|
+
const o = r.find(
|
|
209
|
+
(b) => b.code === e
|
|
185
210
|
);
|
|
186
|
-
|
|
211
|
+
o && q(o);
|
|
187
212
|
},
|
|
188
213
|
align: "start",
|
|
189
214
|
"data-testid": "align-start-dropdown",
|
|
190
|
-
search:
|
|
191
|
-
searchPlaceholder:
|
|
215
|
+
search: S,
|
|
216
|
+
searchPlaceholder: B,
|
|
192
217
|
enableVirtualization: !0,
|
|
193
218
|
onSearchChange: (e) => {
|
|
194
|
-
|
|
219
|
+
F(e);
|
|
195
220
|
},
|
|
196
|
-
width:
|
|
197
|
-
children: /* @__PURE__ */
|
|
198
|
-
/* @__PURE__ */
|
|
199
|
-
/* @__PURE__ */
|
|
200
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
227
|
+
p.dial_code
|
|
203
228
|
] }),
|
|
204
|
-
/* @__PURE__ */
|
|
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__ */
|
|
210
|
-
/* @__PURE__ */
|
|
241
|
+
/* @__PURE__ */ g("div", { className: N.inputContainer({ error: E, size: x }), children: [
|
|
242
|
+
/* @__PURE__ */ i(
|
|
211
243
|
"input",
|
|
212
244
|
{
|
|
213
|
-
...
|
|
214
|
-
ref:
|
|
215
|
-
className:
|
|
216
|
-
placeholder:
|
|
245
|
+
...U,
|
|
246
|
+
ref: V,
|
|
247
|
+
className: v(N.input({ size: x })),
|
|
248
|
+
placeholder: Y,
|
|
217
249
|
value: t,
|
|
218
|
-
onChange:
|
|
219
|
-
onFocus: () =>
|
|
220
|
-
onBlur: () =>
|
|
221
|
-
"data-testid":
|
|
250
|
+
onChange: K,
|
|
251
|
+
onFocus: () => D(!0),
|
|
252
|
+
onBlur: () => D(!1),
|
|
253
|
+
"data-testid": $
|
|
222
254
|
}
|
|
223
255
|
),
|
|
224
|
-
|
|
256
|
+
J
|
|
225
257
|
] })
|
|
226
258
|
] });
|
|
227
259
|
}
|
|
228
260
|
);
|
|
229
|
-
|
|
261
|
+
le.displayName = "PhoneInput";
|
|
230
262
|
export {
|
|
231
|
-
|
|
232
|
-
|
|
263
|
+
le as PhoneInput,
|
|
264
|
+
le as default
|
|
233
265
|
};
|