mcr-design-systems 1.0.18 → 1.0.19
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.
|
@@ -49,6 +49,10 @@ export interface PhoneInputProps extends Omit<React.InputHTMLAttributes<HTMLInpu
|
|
|
49
49
|
* Test identifier
|
|
50
50
|
*/
|
|
51
51
|
'data-testid'?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the dropdown is open (controlled)
|
|
54
|
+
*/
|
|
55
|
+
clearText?: boolean;
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
58
|
* A phone input component that combines a country selector dropdown with a phone number input field.
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as d, jsx as c } from "react/jsx-runtime";
|
|
2
2
|
import * as n from "react";
|
|
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
|
|
3
|
+
import Y from "../../node_modules/libphonenumber-js/examples.mobile.json.js";
|
|
4
|
+
import { cn as C } from "../../shared/utils/cn.js";
|
|
5
|
+
import { COUNTRIES_DATA as q } from "../../shared/flags/countries-data.js";
|
|
6
|
+
import { FLAG_POSITIONS as H } from "../../shared/flags/flag-positions.js";
|
|
7
|
+
import { FLAG_BASE64 as J } from "../../shared/flags/base64.js";
|
|
8
|
+
import { phoneInputVariants as K } from "./helper/variants.js";
|
|
9
|
+
import { Dropdown as X } from "../Dropdown/index.js";
|
|
10
10
|
import { Typography as v } from "../Typography/index.js";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { getExampleNumber as
|
|
14
|
-
import { AsYouType as
|
|
15
|
-
const
|
|
11
|
+
import P from "../Icon/Icon.js";
|
|
12
|
+
import Z from "./FagDefault.js";
|
|
13
|
+
import { getExampleNumber as ee } from "../../node_modules/libphonenumber-js/min/exports/getExampleNumber.js";
|
|
14
|
+
import { AsYouType as te } from "../../node_modules/libphonenumber-js/min/exports/AsYouType.js";
|
|
15
|
+
const D = ({
|
|
16
16
|
countryCode: o
|
|
17
17
|
}) => {
|
|
18
|
-
const t =
|
|
19
|
-
return /* @__PURE__ */
|
|
18
|
+
const t = H[o];
|
|
19
|
+
return /* @__PURE__ */ c("div", { className: "w-[30px] h-[20px] overflow-hidden rounded-xs", children: t === void 0 ? /* @__PURE__ */ c(Z, {}) : /* @__PURE__ */ c(
|
|
20
20
|
"div",
|
|
21
21
|
{
|
|
22
|
-
className:
|
|
22
|
+
className: C(),
|
|
23
23
|
style: {
|
|
24
|
-
backgroundImage: `url('${
|
|
24
|
+
backgroundImage: `url('${J}')`,
|
|
25
25
|
backgroundPosition: `${t.x}px ${t.y}px`,
|
|
26
26
|
backgroundSize: "512px 512px",
|
|
27
27
|
width: "32px",
|
|
@@ -30,11 +30,11 @@ const F = ({
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
) });
|
|
33
|
-
},
|
|
33
|
+
}, oe = (o) => {
|
|
34
34
|
try {
|
|
35
|
-
const t =
|
|
35
|
+
const t = ee(
|
|
36
36
|
o.toUpperCase(),
|
|
37
|
-
|
|
37
|
+
Y
|
|
38
38
|
);
|
|
39
39
|
if (t)
|
|
40
40
|
return t.formatNational();
|
|
@@ -44,153 +44,187 @@ const F = ({
|
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
return "Enter phone number";
|
|
47
|
-
},
|
|
47
|
+
}, F = (o, t) => {
|
|
48
48
|
if (!o || !o.trim()) return "";
|
|
49
49
|
try {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
let
|
|
53
|
-
for (const
|
|
54
|
-
|
|
55
|
-
return
|
|
50
|
+
const a = new te(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;
|
|
56
56
|
} catch {
|
|
57
57
|
return o.replace(/[^\d]/g, "") || "";
|
|
58
58
|
}
|
|
59
|
-
},
|
|
59
|
+
}, re = n.forwardRef(
|
|
60
60
|
({
|
|
61
61
|
onCountryChange: o,
|
|
62
62
|
value: t = "",
|
|
63
|
-
onValueChange:
|
|
64
|
-
placeholder:
|
|
65
|
-
countries:
|
|
66
|
-
showSearch:
|
|
63
|
+
onValueChange: a,
|
|
64
|
+
placeholder: l,
|
|
65
|
+
countries: s = q,
|
|
66
|
+
showSearch: h = !1,
|
|
67
67
|
searchPlaceholder: O = "Search countries",
|
|
68
|
-
className:
|
|
69
|
-
size:
|
|
70
|
-
"data-testid":
|
|
71
|
-
error:
|
|
68
|
+
className: T,
|
|
69
|
+
size: u = "md",
|
|
70
|
+
"data-testid": z,
|
|
71
|
+
error: R,
|
|
72
|
+
clearText: k,
|
|
72
73
|
// placeholder = 'Enter phone number',
|
|
73
74
|
...A
|
|
74
75
|
}, L) => {
|
|
75
|
-
const [y,
|
|
76
|
-
t ||
|
|
77
|
-
), [g,
|
|
78
|
-
|
|
76
|
+
const [y, M] = n.useState(!1), [_, w] = n.useState(!1), [i, $] = n.useState(
|
|
77
|
+
t || s[0]?.code || "us"
|
|
78
|
+
), [g, I] = n.useState(""), N = n.useRef(null), S = y, x = n.useCallback((e) => {
|
|
79
|
+
M(e), e || I("");
|
|
79
80
|
}, []), m = n.useMemo(
|
|
80
|
-
() =>
|
|
81
|
-
[
|
|
82
|
-
),
|
|
83
|
-
size:
|
|
84
|
-
opened:
|
|
85
|
-
inputFocused:
|
|
86
|
-
}),
|
|
81
|
+
() => s.find((e) => e.code === i) || s[0],
|
|
82
|
+
[s, i]
|
|
83
|
+
), B = n.useMemo(() => l || oe(i), [i, l]), b = K({
|
|
84
|
+
size: u,
|
|
85
|
+
opened: S,
|
|
86
|
+
inputFocused: _
|
|
87
|
+
}), E = n.useCallback(
|
|
87
88
|
(e) => {
|
|
88
|
-
if (o?.(e), x(!1),
|
|
89
|
-
const r =
|
|
89
|
+
if (o?.(e), x(!1), $(e.code), t && t.trim()) {
|
|
90
|
+
const r = F(
|
|
90
91
|
t,
|
|
91
92
|
e.code
|
|
92
93
|
);
|
|
93
|
-
|
|
94
|
+
a?.({
|
|
94
95
|
formatted: r,
|
|
95
96
|
raw: t,
|
|
96
97
|
country: e
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
},
|
|
100
|
-
[o, x, t,
|
|
101
|
-
),
|
|
101
|
+
[o, x, t, a]
|
|
102
|
+
), j = n.useMemo(() => s.filter(
|
|
102
103
|
(e) => e.name.toLowerCase().includes(g.toLowerCase()) || e.code.toLowerCase().includes(g.toLowerCase())
|
|
103
104
|
).map((e) => ({
|
|
104
105
|
label: e.name,
|
|
105
106
|
value: e.code,
|
|
106
|
-
icon: /* @__PURE__ */
|
|
107
|
+
icon: /* @__PURE__ */ c(D, { countryCode: e.code }),
|
|
107
108
|
startIconSize: "auto",
|
|
108
109
|
endIconSize: "auto",
|
|
109
|
-
endIcon: /* @__PURE__ */
|
|
110
|
+
endIcon: /* @__PURE__ */ d(v, { variants: "body", size: "sm", color: "fg-neutral-subtlest", children: [
|
|
110
111
|
"+",
|
|
111
112
|
e.dial_code
|
|
112
113
|
] })
|
|
113
|
-
})), [
|
|
114
|
+
})), [s, g]), U = k ? /* @__PURE__ */ c(
|
|
115
|
+
"div",
|
|
116
|
+
{
|
|
117
|
+
onMouseDown: (e) => {
|
|
118
|
+
e.preventDefault(), e.stopPropagation(), setTimeout(() => {
|
|
119
|
+
a && a({
|
|
120
|
+
formatted: "",
|
|
121
|
+
raw: "",
|
|
122
|
+
country: m
|
|
123
|
+
});
|
|
124
|
+
}, 0);
|
|
125
|
+
},
|
|
126
|
+
className: "inline-flex items-center justify-center",
|
|
127
|
+
role: "button",
|
|
128
|
+
tabIndex: 0,
|
|
129
|
+
"aria-label": "Clear text",
|
|
130
|
+
children: /* @__PURE__ */ c(
|
|
131
|
+
P,
|
|
132
|
+
{
|
|
133
|
+
name: "x-circle",
|
|
134
|
+
variant: "solid",
|
|
135
|
+
size: {
|
|
136
|
+
sm: 16,
|
|
137
|
+
md: 20,
|
|
138
|
+
lg: 24
|
|
139
|
+
}[u],
|
|
140
|
+
className: "cursor-pointer text-fg-neutral-subtle"
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
) : null, V = n.useCallback(
|
|
114
145
|
(e) => {
|
|
115
|
-
const r = e.target.value, p = t,
|
|
146
|
+
const r = e.target.value, p = t, G = r.length < p.length;
|
|
116
147
|
if (r.length > 20) {
|
|
117
148
|
e.preventDefault();
|
|
118
149
|
return;
|
|
119
150
|
}
|
|
120
151
|
if (/^[0-9\s\-()+ ]*$/.test(r) || r === "") {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
152
|
+
const f = r.replace(/[^\d]/g, ""), Q = p.replace(/[^\d]/g, "");
|
|
153
|
+
if (G && f === Q) {
|
|
154
|
+
a?.({
|
|
124
155
|
formatted: r,
|
|
125
156
|
raw: r.replace(/[^\d]/g, ""),
|
|
126
157
|
country: m
|
|
127
158
|
});
|
|
128
159
|
return;
|
|
129
160
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
formatted:
|
|
133
|
-
raw:
|
|
161
|
+
const W = f ? F(f, i) : "";
|
|
162
|
+
a?.({
|
|
163
|
+
formatted: W,
|
|
164
|
+
raw: f,
|
|
134
165
|
country: m
|
|
135
166
|
});
|
|
136
167
|
}
|
|
137
168
|
},
|
|
138
|
-
[m,
|
|
169
|
+
[m, a, i, t]
|
|
139
170
|
);
|
|
140
|
-
return /* @__PURE__ */
|
|
141
|
-
/* @__PURE__ */
|
|
142
|
-
|
|
171
|
+
return /* @__PURE__ */ d("div", { className: C("flex items-center", T), ref: N, children: [
|
|
172
|
+
/* @__PURE__ */ c(
|
|
173
|
+
X,
|
|
143
174
|
{
|
|
144
175
|
open: y,
|
|
145
176
|
onOpenChange: x,
|
|
146
|
-
items:
|
|
177
|
+
items: j,
|
|
147
178
|
value: i,
|
|
148
179
|
onValueChange: (e) => {
|
|
149
|
-
const r =
|
|
180
|
+
const r = s.find(
|
|
150
181
|
(p) => p.code === e
|
|
151
182
|
);
|
|
152
|
-
r &&
|
|
183
|
+
r && E(r);
|
|
153
184
|
},
|
|
154
185
|
align: "start",
|
|
155
186
|
"data-testid": "align-start-dropdown",
|
|
156
|
-
search:
|
|
187
|
+
search: h,
|
|
157
188
|
searchPlaceholder: O,
|
|
158
189
|
enableVirtualization: !0,
|
|
159
190
|
onSearchChange: (e) => {
|
|
160
|
-
|
|
191
|
+
I(e);
|
|
161
192
|
},
|
|
162
|
-
width:
|
|
163
|
-
children: /* @__PURE__ */
|
|
164
|
-
/* @__PURE__ */
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
-
/* @__PURE__ */
|
|
193
|
+
width: N.current?.clientWidth || "auto",
|
|
194
|
+
children: /* @__PURE__ */ d("div", { className: b.countryButton(), children: [
|
|
195
|
+
/* @__PURE__ */ c(D, { countryCode: i }),
|
|
196
|
+
/* @__PURE__ */ d("div", { className: "flex gap-xs-4", children: [
|
|
197
|
+
/* @__PURE__ */ d(v, { variants: "body", size: "md", children: [
|
|
167
198
|
"+",
|
|
168
199
|
m.dial_code
|
|
169
200
|
] }),
|
|
170
|
-
/* @__PURE__ */
|
|
201
|
+
/* @__PURE__ */ c(P, { name: S ? "chevron-up" : "chevron-down", size: 16 })
|
|
171
202
|
] })
|
|
172
203
|
] })
|
|
173
204
|
}
|
|
174
205
|
),
|
|
175
|
-
/* @__PURE__ */
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
206
|
+
/* @__PURE__ */ d("div", { className: b.inputContainer({ error: R, size: u }), children: [
|
|
207
|
+
/* @__PURE__ */ c(
|
|
208
|
+
"input",
|
|
209
|
+
{
|
|
210
|
+
...A,
|
|
211
|
+
ref: L,
|
|
212
|
+
className: C(b.input({ size: u })),
|
|
213
|
+
placeholder: B,
|
|
214
|
+
value: t,
|
|
215
|
+
onChange: V,
|
|
216
|
+
onFocus: () => w(!0),
|
|
217
|
+
onBlur: () => w(!1),
|
|
218
|
+
"data-testid": z
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
U
|
|
222
|
+
] })
|
|
189
223
|
] });
|
|
190
224
|
}
|
|
191
225
|
);
|
|
192
|
-
|
|
226
|
+
re.displayName = "PhoneInput";
|
|
193
227
|
export {
|
|
194
|
-
|
|
195
|
-
|
|
228
|
+
re as PhoneInput,
|
|
229
|
+
re as default
|
|
196
230
|
};
|
|
@@ -117,6 +117,7 @@ export declare const generateTailwindConfig: ({ brand, font, }: {
|
|
|
117
117
|
brand: Record<string | number, string>;
|
|
118
118
|
};
|
|
119
119
|
borderColor: Record<string, string>;
|
|
120
|
+
outline: Record<string, string>;
|
|
120
121
|
borderRadius: {
|
|
121
122
|
readonly none: "0rem";
|
|
122
123
|
readonly xs: "0.125rem";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { alphaColors as a, colorScales as
|
|
1
|
+
import { alphaColors as a, colorScales as g, baseColors as d } from "./primitives/colors.js";
|
|
2
2
|
import { typography as t } from "./primitives/typography.js";
|
|
3
|
-
import { zIndex as
|
|
3
|
+
import { zIndex as h, shadows as p, borderRadius as u, spacing as n } from "./primitives/layout.js";
|
|
4
4
|
import { semanticTokens as f } from "./semantic.js";
|
|
5
|
-
const i = /* @__PURE__ */ new Map(),
|
|
5
|
+
const i = /* @__PURE__ */ new Map(), x = () => ({
|
|
6
6
|
// Base colors
|
|
7
|
-
...
|
|
7
|
+
...d,
|
|
8
8
|
// Color scales
|
|
9
|
-
...
|
|
9
|
+
...g,
|
|
10
10
|
// Alpha colors
|
|
11
11
|
"white-alpha": a.white,
|
|
12
12
|
"black-alpha": a.black,
|
|
@@ -17,23 +17,23 @@ const i = /* @__PURE__ */ new Map(), u = () => ({
|
|
|
17
17
|
const e = `semantic-${o}`;
|
|
18
18
|
if (i.has(e))
|
|
19
19
|
return i.get(e);
|
|
20
|
-
const r =
|
|
20
|
+
const r = b(o);
|
|
21
21
|
return i.set(e, r), r;
|
|
22
|
-
},
|
|
22
|
+
}, b = (o) => {
|
|
23
23
|
const e = {};
|
|
24
24
|
try {
|
|
25
25
|
const r = f.light[o];
|
|
26
26
|
if (!r)
|
|
27
27
|
return console.warn(`No tokens found for category: ${o}`), e;
|
|
28
28
|
Object.keys(r).forEach((s) => {
|
|
29
|
-
const
|
|
30
|
-
e[s] = `var(${
|
|
29
|
+
const m = o === "border" ? `--color-border-${s}` : `--color-${o}-${s}`;
|
|
30
|
+
e[s] = `var(${m})`;
|
|
31
31
|
});
|
|
32
32
|
} catch (r) {
|
|
33
33
|
console.error(`Error generating semantic colors for ${o}:`, r);
|
|
34
34
|
}
|
|
35
35
|
return e;
|
|
36
|
-
},
|
|
36
|
+
}, l = () => c("border"), C = () => ({
|
|
37
37
|
sm: "640px",
|
|
38
38
|
// Small devices
|
|
39
39
|
md: "768px",
|
|
@@ -72,14 +72,15 @@ const i = /* @__PURE__ */ new Map(), u = () => ({
|
|
|
72
72
|
fontFamily: e || t.fontFamilies,
|
|
73
73
|
// Colors (optimized with caching)
|
|
74
74
|
colors: {
|
|
75
|
-
...
|
|
75
|
+
...x(),
|
|
76
76
|
brand: o
|
|
77
77
|
},
|
|
78
|
-
borderColor:
|
|
78
|
+
borderColor: l(),
|
|
79
|
+
outline: l(),
|
|
79
80
|
// Visual Effects
|
|
80
|
-
borderRadius:
|
|
81
|
-
boxShadow:
|
|
82
|
-
zIndex:
|
|
81
|
+
borderRadius: u,
|
|
82
|
+
boxShadow: p,
|
|
83
|
+
zIndex: h,
|
|
83
84
|
// Animation & Transitions
|
|
84
85
|
transitionTimingFunction: {
|
|
85
86
|
"bounce-gentle": "cubic-bezier(0.68, -0.55, 0.265, 1.55)"
|