mcr-design-systems 1.0.212 → 1.0.214

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.
@@ -4,7 +4,7 @@ const s = e({
4
4
  variants: {
5
5
  shape: {
6
6
  circle: "rounded-full",
7
- square: "rounded-md"
7
+ square: "rounded-lg"
8
8
  },
9
9
  type: {
10
10
  initials: "font-semibold uppercase text-fg-brand-rest bg-bg-brand-subtle-rest",
@@ -32,6 +32,8 @@ export interface AvatarProps extends React.HTMLAttributes<HTMLDivElement>, Varia
32
32
  containerClassName?: string;
33
33
  outerClassName?: string;
34
34
  showHelperTextIcon?: boolean;
35
+ shouldShowPlaceholderIconUpload?: boolean;
36
+ shouldShowDropdownForOptions?: boolean;
35
37
  }
36
38
  declare const Avatar: React.FC<AvatarProps>;
37
39
  export default Avatar;
@@ -1,12 +1,12 @@
1
- import { jsxs as N, jsx as t, Fragment as he } from "react/jsx-runtime";
2
- import { useState as p, useRef as F, useEffect as M } from "react";
3
- import { avatar as fe, presenceBadge as pe } from "./helper/variants.js";
4
- import _ from "../Icon/Icon.js";
5
- import { cn as s } from "../../shared/utils/cn.js";
6
- import ue from "../Loading/index.js";
7
- import { Dropdown as de } from "../Dropdown/index.js";
8
- import $ from "../TextField/HelperText.js";
9
- const I = {
1
+ import { jsxs as N, jsx as t, Fragment as pe } from "react/jsx-runtime";
2
+ import { useState as p, useRef as $, useEffect as F } from "react";
3
+ import { avatar as ue, presenceBadge as xe } from "./helper/variants.js";
4
+ import B from "../Icon/Icon.js";
5
+ import { cn as o } from "../../shared/utils/cn.js";
6
+ import de from "../Loading/index.js";
7
+ import { Dropdown as we } from "../Dropdown/index.js";
8
+ import G from "../TextField/HelperText.js";
9
+ const j = {
10
10
  10: "text-[4.55px]",
11
11
  12: "text-[5.45px]",
12
12
  14: "text-[6.36px]",
@@ -25,123 +25,125 @@ const I = {
25
25
  88: "text-[40px]",
26
26
  128: "text-[58.18px]",
27
27
  160: "text-[72.73px]"
28
- }, xe = 2 * 1024 * 1024, B = ["image/jpeg", "image/jpg", "image/png", "image/webp"], G = "avatar-cache-v1", je = ({
28
+ }, ge = 2 * 1024 * 1024, T = ["image/jpeg", "image/jpg", "image/png", "image/webp"], W = "avatar-cache-v1", Ce = ({
29
29
  src: n = "",
30
30
  size: l = 48,
31
- shape: T = "circle",
32
- showPresence: W = !1,
33
- presenceStatus: D = "available",
34
- alt: H = "",
35
- className: J,
36
- firstName: j,
31
+ shape: H = "circle",
32
+ showPresence: J = !1,
33
+ presenceStatus: Z = "available",
34
+ alt: D = "",
35
+ className: V,
36
+ firstName: I,
37
37
  lastName: R,
38
- onUpload: U,
39
- onRemove: C,
40
- isLoading: x = !1,
41
- isCanEdit: Z = !0,
38
+ onUpload: C,
39
+ onRemove: L,
40
+ isLoading: d = !1,
41
+ isCanEdit: X = !0,
42
42
  disableCache: w = !1,
43
- icon: L,
44
- bordered: V = !1,
45
- overlap: X = !1,
46
- overlapPrefix: S = "",
47
- helperText: k,
48
- errors: i,
49
- maxFileSize: Y = xe,
50
- allowedFileTypes: q = B,
51
- innerClass: K = "",
52
- containerClassName: Q = "",
43
+ icon: U,
44
+ bordered: Y = !1,
45
+ overlap: q = !1,
46
+ overlapPrefix: k = "",
47
+ helperText: S,
48
+ errors: m,
49
+ maxFileSize: K = ge,
50
+ allowedFileTypes: Q = T,
51
+ innerClass: z = "",
52
+ containerClassName: ee = "",
53
53
  outerClassName: O = "",
54
- showHelperTextIcon: z = !0,
54
+ showHelperTextIcon: te = !0,
55
+ shouldShowPlaceholderIconUpload: A = !0,
56
+ shouldShowDropdownForOptions: P = !0,
55
57
  ...g
56
58
  }) => {
57
- const [ee, m] = p(!1), [v, u] = p(""), [a, c] = p(n || ""), [d, b] = p(""), [A, E] = p(!1), h = F(null), te = F(null), re = async (e) => {
59
+ const [re, s] = p(!1), [v, u] = p(""), [a, i] = p(n || ""), [x, b] = p(""), [M, E] = p(!1), f = $(null), ae = $(null), ne = async (e) => {
58
60
  try {
59
- const r = await caches.open(G);
61
+ const r = await caches.open(W);
60
62
  if (!await r.match(e)) {
61
- const f = await fetch(e, {
63
+ const h = await fetch(e, {
62
64
  mode: "cors",
63
65
  method: "GET",
64
66
  headers: { "Access-Control-Allow-Origin": "*" }
65
67
  });
66
- if (!f.ok)
67
- throw new Error(`Failed to fetch image: ${f.status}`);
68
- await r.put(e, f.clone());
68
+ if (!h.ok)
69
+ throw new Error(`Failed to fetch image: ${h.status}`);
70
+ await r.put(e, h.clone());
69
71
  }
70
72
  } catch {
71
73
  }
72
74
  };
73
- s();
74
- const ae = async (e) => {
75
+ o();
76
+ const le = async (e) => {
75
77
  if (w) return null;
76
78
  try {
77
- const o = await (await caches.open(G)).match(e);
78
- if (o) {
79
- const f = await o.blob();
80
- return URL.createObjectURL(f);
79
+ const c = await (await caches.open(W)).match(e);
80
+ if (c) {
81
+ const h = await c.blob();
82
+ return URL.createObjectURL(h);
81
83
  }
82
84
  return null;
83
85
  } catch {
84
86
  return null;
85
87
  }
86
88
  };
87
- M(() => {
89
+ F(() => {
88
90
  let e = null;
89
- return n && !w ? (re(n), ae(n).then((r) => {
90
- r ? (b(r), c(r), e = r) : c(n);
91
- })) : c(n || ""), () => {
91
+ return n && !w ? (ne(n), le(n).then((r) => {
92
+ r ? (b(r), i(r), e = r) : i(n);
93
+ })) : i(n || ""), () => {
92
94
  e && URL.revokeObjectURL(e);
93
95
  };
94
- }, [n, w]), M(() => {
96
+ }, [n, w]), F(() => {
95
97
  if (!a) {
96
98
  E(!1);
97
99
  return;
98
100
  }
99
101
  const e = new window.Image();
100
102
  return e.src = a, e.onload = () => E(!1), e.onerror = () => {
101
- E(!0), d && a !== d && c(d);
103
+ E(!0), x && a !== x && i(x);
102
104
  }, () => {
103
105
  a.startsWith("blob:") && URL.revokeObjectURL(a);
104
106
  };
105
- }, [a, d]);
106
- const ne = () => S || (L ? /* @__PURE__ */ t(
107
+ }, [a, x]);
108
+ const ce = () => k || (U ? /* @__PURE__ */ t(
107
109
  "span",
108
110
  {
109
- className: `flex h-full w-full items-center justify-center ${I[l ?? 48]}`,
110
- children: L
111
+ className: `flex h-full w-full items-center justify-center ${j[l ?? 48]}`,
112
+ children: U
111
113
  }
112
- ) : j || R ? `${j?.[0] || ""}${R?.[0] || ""}`.toUpperCase() : n ? n[0]?.toUpperCase() : ""), le = async (e) => {
114
+ ) : I || R ? `${I?.[0] || ""}${R?.[0] || ""}`.toUpperCase() : n ? n[0]?.toUpperCase() : ""), se = async (e) => {
113
115
  const r = e.target.files?.[0];
114
116
  if (!r) return;
115
- if (!q.includes(r.type)) {
117
+ if (!Q.includes(r.type)) {
116
118
  u(
117
- i?.imageFileTypeError || "Please select a valid image file (JPG, JPEG, PNG, or WEBP)"
119
+ m?.imageFileTypeError || "Please select a valid image file (JPG, JPEG, PNG, or WEBP)"
118
120
  );
119
121
  return;
120
122
  }
121
- if (r.size > Y) {
123
+ if (r.size > K) {
122
124
  u(
123
- i?.imageUploadLimitError || "Image is too large, must be no larger than 2 MB."
125
+ m?.imageUploadLimitError || "Image is too large, must be no larger than 2 MB."
124
126
  );
125
127
  return;
126
128
  }
127
129
  u("");
128
- let o = null;
130
+ let c = null;
129
131
  try {
130
- o = URL.createObjectURL(r), c(o), await U?.(r);
132
+ c = URL.createObjectURL(r), i(c), await C?.(r);
131
133
  } finally {
132
- h.current && (h.current.value = ""), m(!1), o && URL.revokeObjectURL(o);
134
+ f.current && (f.current.value = ""), s(!1), c && URL.revokeObjectURL(c);
133
135
  }
134
- }, oe = async () => {
136
+ }, ie = async () => {
135
137
  try {
136
- await C?.(), c(""), b("");
138
+ await L?.(), i(""), b("");
137
139
  } finally {
138
- m(!1), u("");
140
+ s(!1), u("");
139
141
  }
140
- }, ce = (e) => {
141
- e === "change-photo" ? h.current?.click() : e === "remove-photo" && oe().then(() => {
142
- c(""), b("");
143
- }), m(!1);
144
- }, y = Z && (U || C) && l >= 24, se = ne(), ie = l && l >= 24 && l <= 64, { id: me } = "data-testid" in g ? g : { id: "avatar" }, P = {
142
+ }, oe = (e) => {
143
+ e === "change-photo" ? f.current?.click() : e === "remove-photo" && ie().then(() => {
144
+ i(""), b("");
145
+ }), s(!1);
146
+ }, y = X && (C || L) && l >= 24, me = ce(), fe = l && l >= 24 && l <= 64, { id: he } = "data-testid" in g ? g : { id: "avatar" }, _ = {
145
147
  10: "h-[0.625rem] w-[0.625rem]",
146
148
  // 10px
147
149
  12: "h-[0.75rem] w-[0.75rem]",
@@ -179,21 +181,21 @@ const I = {
179
181
  160: "h-[10rem] w-[10rem]"
180
182
  // 160px
181
183
  };
182
- return /* @__PURE__ */ N("div", { "data-testid": me, className: "relative block w-fit", children: [
184
+ return /* @__PURE__ */ N("div", { "data-testid": he, className: "relative block w-fit", children: [
183
185
  /* @__PURE__ */ t(
184
186
  "div",
185
187
  {
186
- className: s(
188
+ className: o(
187
189
  "w-fit overflow-hidden",
188
- P[l ?? 48],
189
- Q
190
+ _[l ?? 48],
191
+ ee
190
192
  ),
191
193
  children: /* @__PURE__ */ N(
192
- de,
194
+ we,
193
195
  {
194
196
  selected: !0,
195
- onValueChange: ce,
196
- open: ee,
197
+ onValueChange: oe,
198
+ open: re,
197
199
  items: [
198
200
  {
199
201
  label: "Change photo",
@@ -207,58 +209,68 @@ const I = {
207
209
  }
208
210
  ],
209
211
  align: "start",
210
- onOpenChange: y && !x ? (e) => m(e) : void 0,
212
+ onOpenChange: (e) => {
213
+ if (!e)
214
+ return s(!1);
215
+ y && !d && P || !P && a ? s(e) : (f.current?.click(), s(!1));
216
+ },
211
217
  children: [
212
218
  /* @__PURE__ */ N(
213
219
  "div",
214
220
  {
215
- className: s(
216
- fe({
217
- shape: T,
221
+ className: o(
222
+ ue({
223
+ shape: H,
218
224
  // type: previewSrc && !isImageError ? 'image' : 'initials',
219
- className: s(P[l ?? 48], J),
220
- bordered: a && !A ? !0 : V,
221
- overlap: X
225
+ className: o(_[l ?? 48], V),
226
+ bordered: a && !M ? !0 : Y,
227
+ overlap: q
222
228
  }),
223
229
  O
224
230
  ),
225
231
  ...g,
226
232
  children: [
227
- a && !A ? /* @__PURE__ */ t(
233
+ a && !M ? /* @__PURE__ */ t(
228
234
  "img",
229
235
  {
230
236
  src: a,
231
- alt: H,
232
- className: s("object-cover", K)
237
+ alt: D,
238
+ className: o("object-cover", z)
233
239
  }
234
240
  ) : /* @__PURE__ */ t(
235
241
  "div",
236
242
  {
237
- className: `flex h-full w-full items-center justify-center ${I[l ?? 48]}`,
243
+ className: `flex h-full w-full items-center justify-center ${j[l ?? 48]}`,
238
244
  children: /* @__PURE__ */ t(
239
245
  "div",
240
246
  {
241
- className: s(
242
- `${I[l ?? 48]} leading-none`,
247
+ className: o(
248
+ `${j[l ?? 48]} leading-none`,
243
249
  O
244
250
  ),
245
- children: se
251
+ children: me
246
252
  }
247
253
  )
248
254
  }
249
255
  ),
250
- y && !x && /* @__PURE__ */ t(
256
+ y && !d && /* @__PURE__ */ t(
251
257
  "div",
252
258
  {
253
- ref: te,
254
- className: "absolute bottom-0 flex w-full cursor-pointer items-center justify-center bg-black-alpha-4",
259
+ ref: ae,
260
+ className: o(
261
+ "absolute bottom-0 flex w-full cursor-pointer items-center justify-center",
262
+ {
263
+ "bg-black-alpha-4": A
264
+ }
265
+ ),
255
266
  style: {
256
267
  color: "white",
257
- height: ie ? "100%" : "24px"
268
+ height: fe ? "100%" : "24px"
258
269
  },
259
- onClick: () => a ? m(!0) : h.current?.click(),
260
- children: /* @__PURE__ */ t(
261
- _,
270
+ onClick: () => {
271
+ },
272
+ children: A && /* @__PURE__ */ t(
273
+ B,
262
274
  {
263
275
  name: "camera-01",
264
276
  size: 16,
@@ -270,15 +282,15 @@ const I = {
270
282
  /* @__PURE__ */ t(
271
283
  "input",
272
284
  {
273
- ref: h,
285
+ ref: f,
274
286
  type: "file",
275
- accept: B.join(","),
287
+ accept: T.join(","),
276
288
  className: "hidden",
277
- onChange: le
289
+ onChange: se
278
290
  }
279
291
  ),
280
- x && /* @__PURE__ */ t("div", { className: "absolute bottom-0 inset-0 flex items-center justify-center bg-black-alpha-4", children: /* @__PURE__ */ t(
281
- ue,
292
+ d && /* @__PURE__ */ t("div", { className: "absolute bottom-0 inset-0 flex items-center justify-center bg-black-alpha-4", children: /* @__PURE__ */ t(
293
+ de,
282
294
  {
283
295
  thickness: 2,
284
296
  width: 14,
@@ -288,21 +300,21 @@ const I = {
288
300
  ]
289
301
  }
290
302
  ),
291
- W && !y && /* @__PURE__ */ t("span", { className: pe({ status: D }), children: /* @__PURE__ */ t("svg", { className: "h-2 w-2", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ t("circle", { cx: "10", cy: "10", r: "10" }) }) })
303
+ J && !y && /* @__PURE__ */ t("span", { className: xe({ status: Z }), children: /* @__PURE__ */ t("svg", { className: "h-2 w-2", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ t("circle", { cx: "10", cy: "10", r: "10" }) }) })
292
304
  ]
293
305
  }
294
306
  )
295
307
  }
296
308
  ),
297
- v || i?.externalUploadError ? /* @__PURE__ */ t("div", { className: "mt-1 flex items-center gap-1", children: /* @__PURE__ */ t(
298
- $,
309
+ v || m?.externalUploadError ? /* @__PURE__ */ t("div", { className: "mt-1 flex items-center gap-1", children: /* @__PURE__ */ t(
310
+ G,
299
311
  {
300
- text: v || i?.externalUploadError,
312
+ text: v || m?.externalUploadError,
301
313
  error: !0,
302
314
  haveIcon: !0,
303
315
  iconsSize: 16,
304
316
  iconsCustom: /* @__PURE__ */ t(
305
- _,
317
+ B,
306
318
  {
307
319
  name: "alert-octagon",
308
320
  className: "text-fg-accent-error",
@@ -311,16 +323,16 @@ const I = {
311
323
  }
312
324
  )
313
325
  }
314
- ) }) : /* @__PURE__ */ t(he, { children: k ? /* @__PURE__ */ t(
315
- $,
326
+ ) }) : /* @__PURE__ */ t(pe, { children: S ? /* @__PURE__ */ t(
327
+ G,
316
328
  {
317
- text: k,
318
- error: !!v || !!i?.externalUploadError,
319
- haveIcon: z
329
+ text: S,
330
+ error: !!v || !!m?.externalUploadError,
331
+ haveIcon: te
320
332
  }
321
333
  ) : null })
322
334
  ] });
323
335
  };
324
336
  export {
325
- je as default
337
+ Ce as default
326
338
  };