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 l, jsx as s } from "react/jsx-runtime";
1
+ import { jsxs as d, jsx as c } from "react/jsx-runtime";
2
2
  import * as n from "react";
3
- import G from "../../node_modules/libphonenumber-js/examples.mobile.json.js";
4
- import { cn as b } from "../../shared/utils/cn.js";
5
- import { COUNTRIES_DATA as Q } from "../../shared/flags/countries-data.js";
6
- import { FLAG_POSITIONS as W } from "../../shared/flags/flag-positions.js";
7
- import { FLAG_BASE64 as Y } from "../../shared/flags/base64.js";
8
- import { phoneInputVariants as q } from "./helper/variants.js";
9
- import { Dropdown as H } from "../Dropdown/index.js";
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 J from "../Icon/Icon.js";
12
- import K from "./FagDefault.js";
13
- import { getExampleNumber as X } from "../../node_modules/libphonenumber-js/min/exports/getExampleNumber.js";
14
- import { AsYouType as Z } from "../../node_modules/libphonenumber-js/min/exports/AsYouType.js";
15
- const F = ({
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 = W[o];
19
- return /* @__PURE__ */ s("div", { className: "w-[30px] h-[20px] overflow-hidden rounded-xs", children: t === void 0 ? /* @__PURE__ */ s(K, {}) : /* @__PURE__ */ s(
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: b(),
22
+ className: C(),
23
23
  style: {
24
- backgroundImage: `url('${Y}')`,
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
- }, ee = (o) => {
33
+ }, oe = (o) => {
34
34
  try {
35
- const t = X(
35
+ const t = ee(
36
36
  o.toUpperCase(),
37
- G
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
- }, P = (o, t) => {
47
+ }, F = (o, t) => {
48
48
  if (!o || !o.trim()) return "";
49
49
  try {
50
- const c = new Z(t.toUpperCase()), d = o.replace(/[^\d]/g, "");
51
- if (!d) return "";
52
- let a = "";
53
- for (const f of d)
54
- a = c.input(f);
55
- return a || d;
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
- }, te = n.forwardRef(
59
+ }, re = n.forwardRef(
60
60
  ({
61
61
  onCountryChange: o,
62
62
  value: t = "",
63
- onValueChange: c,
64
- placeholder: d,
65
- countries: a = Q,
66
- showSearch: f = !1,
63
+ onValueChange: a,
64
+ placeholder: l,
65
+ countries: s = q,
66
+ showSearch: h = !1,
67
67
  searchPlaceholder: O = "Search countries",
68
- className: D,
69
- size: h = "md",
70
- "data-testid": R,
71
- error: k,
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, z] = n.useState(!1), [T, w] = n.useState(!1), [i, V] = n.useState(
76
- t || a[0]?.code || "us"
77
- ), [g, S] = n.useState(""), I = n.useRef(null), N = y, x = n.useCallback((e) => {
78
- z(e), e || S("");
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
- () => a.find((e) => e.code === i) || a[0],
81
- [a, i]
82
- ), _ = n.useMemo(() => d || ee(i), [i, d]), C = q({
83
- size: h,
84
- opened: N,
85
- inputFocused: T
86
- }), $ = n.useCallback(
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), V(e.code), t && t.trim()) {
89
- const r = P(
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
- c?.({
94
+ a?.({
94
95
  formatted: r,
95
96
  raw: t,
96
97
  country: e
97
98
  });
98
99
  }
99
100
  },
100
- [o, x, t, c]
101
- ), E = n.useMemo(() => a.filter(
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__ */ s(F, { countryCode: e.code }),
107
+ icon: /* @__PURE__ */ c(D, { countryCode: e.code }),
107
108
  startIconSize: "auto",
108
109
  endIconSize: "auto",
109
- endIcon: /* @__PURE__ */ l(v, { variants: "body", size: "sm", color: "fg-neutral-subtle", children: [
110
+ endIcon: /* @__PURE__ */ d(v, { variants: "body", size: "sm", color: "fg-neutral-subtlest", children: [
110
111
  "+",
111
112
  e.dial_code
112
113
  ] })
113
- })), [a, g]), B = n.useCallback(
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, M = r.length < p.length;
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 u = r.replace(/[^\d]/g, ""), U = p.replace(/[^\d]/g, "");
122
- if (M && u === U) {
123
- c?.({
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 j = u ? P(u, i) : "";
131
- c?.({
132
- formatted: j,
133
- raw: u,
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, c, i, t]
169
+ [m, a, i, t]
139
170
  );
140
- return /* @__PURE__ */ l("div", { className: b("flex items-center", D), ref: I, children: [
141
- /* @__PURE__ */ s(
142
- H,
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: E,
177
+ items: j,
147
178
  value: i,
148
179
  onValueChange: (e) => {
149
- const r = a.find(
180
+ const r = s.find(
150
181
  (p) => p.code === e
151
182
  );
152
- r && $(r);
183
+ r && E(r);
153
184
  },
154
185
  align: "start",
155
186
  "data-testid": "align-start-dropdown",
156
- search: f,
187
+ search: h,
157
188
  searchPlaceholder: O,
158
189
  enableVirtualization: !0,
159
190
  onSearchChange: (e) => {
160
- S(e);
191
+ I(e);
161
192
  },
162
- width: I.current?.clientWidth || "auto",
163
- children: /* @__PURE__ */ l("div", { className: C.countryButton(), children: [
164
- /* @__PURE__ */ s(F, { countryCode: i }),
165
- /* @__PURE__ */ l("div", { className: "flex gap-xs-4", children: [
166
- /* @__PURE__ */ l(v, { variants: "body", size: "md", children: [
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__ */ s(J, { name: N ? "chevron-up" : "chevron-down", size: 16 })
201
+ /* @__PURE__ */ c(P, { name: S ? "chevron-up" : "chevron-down", size: 16 })
171
202
  ] })
172
203
  ] })
173
204
  }
174
205
  ),
175
- /* @__PURE__ */ s("div", { className: C.inputContainer({ error: k, size: h }), children: /* @__PURE__ */ s(
176
- "input",
177
- {
178
- ...A,
179
- ref: L,
180
- className: b(C.input({ size: h })),
181
- placeholder: _,
182
- value: t,
183
- onChange: B,
184
- onFocus: () => w(!0),
185
- onBlur: () => w(!1),
186
- "data-testid": R
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
- te.displayName = "PhoneInput";
226
+ re.displayName = "PhoneInput";
193
227
  export {
194
- te as PhoneInput,
195
- te as default
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 m, baseColors as g } from "./primitives/colors.js";
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 d, shadows as h, borderRadius as p, spacing as n } from "./primitives/layout.js";
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(), u = () => ({
5
+ const i = /* @__PURE__ */ new Map(), x = () => ({
6
6
  // Base colors
7
- ...g,
7
+ ...d,
8
8
  // Color scales
9
- ...m,
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 = x(o);
20
+ const r = b(o);
21
21
  return i.set(e, r), r;
22
- }, x = (o) => {
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 l = o === "border" ? `--color-border-${s}` : `--color-${o}-${s}`;
30
- e[s] = `var(${l})`;
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
- }, b = () => c("border"), C = () => ({
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
- ...u(),
75
+ ...x(),
76
76
  brand: o
77
77
  },
78
- borderColor: b(),
78
+ borderColor: l(),
79
+ outline: l(),
79
80
  // Visual Effects
80
- borderRadius: p,
81
- boxShadow: h,
82
- zIndex: d,
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)"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcr-design-systems",
3
3
  "private": false,
4
- "version": "1.0.18",
4
+ "version": "1.0.19",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",