@studiolxd/brand 43.0.0 → 44.1.0

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,18 +1,19 @@
1
1
  'use client';
2
2
  import './avatar-upload.css';
3
- import { Icon as e } from "./icon.js";
4
- import { VisuallyHidden as t } from "./visually-hidden.js";
5
- import { n } from "./_shared/form-size.js";
6
- import { Button as r } from "./button.js";
7
- import { Avatar as i } from "./avatar.js";
3
+ import { n as e } from "./_shared/brandmessagescontext.js";
4
+ import { Icon as t } from "./icon.js";
5
+ import { VisuallyHidden as n } from "./visually-hidden.js";
6
+ import { n as r } from "./_shared/form-size.js";
7
+ import { Button as i } from "./button.js";
8
+ import { Avatar as a } from "./avatar.js";
8
9
  import { ErrorText as ee } from "./error-text.js";
9
- import { n as te, t as a } from "./_shared/validate.js";
10
- import { t as ne } from "./_shared/env.js";
11
- import { t as re } from "./_shared/imagecropdialog.js";
12
- import { useCallback as ie, useEffect as o, useId as s, useRef as c, useState as l } from "react";
10
+ import { i as te, n as ne, r as o, t as re } from "./_shared/validate.js";
11
+ import { t as ie } from "./_shared/env.js";
12
+ import { t as ae } from "./_shared/imagecropdialog.js";
13
+ import { useCallback as oe, useEffect as s, useId as se, useRef as c, useState as l } from "react";
13
14
  import { jsx as u, jsxs as d } from "react/jsx-runtime";
14
15
  //#region src/stories/molecules/AvatarUpload/AvatarUpload.tsx
15
- var ae = {
16
+ var ce = {
16
17
  sm: "2xl",
17
18
  md: "3xl",
18
19
  lg: "4xl"
@@ -21,92 +22,94 @@ var ae = {
21
22
  md: "lg",
22
23
  lg: "xl"
23
24
  };
24
- function p(e) {
25
- return e.split(",").map((e) => e.trim()).filter(Boolean).map((e) => e.startsWith(".") ? e.slice(1) : e.split("/")[1] ?? e).map((e) => e.toUpperCase()).join(", ");
25
+ function le(e, t) {
26
+ return o(e.split(",").map((e) => e.trim()).filter(Boolean).map((e) => e.startsWith(".") ? e.slice(1) : e.split("/")[1] ?? e).map((e) => e.toUpperCase()), t);
26
27
  }
27
- function m({ src: m, name: oe, alt: h, shape: g = "circle", size: se, accept: _ = "image/jpeg,image/png,image/webp", maxSize: v, outputMimeType: y = "image/jpeg", outputSize: b, disabled: x = !1, busy: S = !1, errorMessage: ce, onChange: le, onSelect: C, onError: w, buttonLabel: T = "Subir", buttonAccessibleLabel: ue, hintLabel: de, formatsLabel: fe, maxSizeHint: pe = (e) => `máx. ${e}`, invalidTypeError: E = (e) => `Formato no admitido. Se aceptan ${e}.`, tooLargeError: D = (e) => `El archivo pesa demasiado. El máximo es ${e}.`, dropActiveMessage: me = "Suelta la imagen sobre el avatar para subirla", dropHintLabel: O = "…o arrastra la imagen hasta el avatar", cropTitle: he = "Recortar imagen", cropDescription: k, cropCancelLabel: A = "Cancelar", cropConfirmLabel: j = "Guardar", cropCloseLabel: M = "Cerrar", cropLoadingLabel: N, cropErrorMessage: P, className: F }) {
28
- let I = n(se), L = c(null), R = c(null), [z, B] = l(null), [V, H] = l(!1), [ge, U] = l(!1), [_e, W] = l(null), G = s(), K = `${G}-hint`, q = `${G}-error`, J = fe ?? p(_), Y = de ?? [J, v === void 0 ? null : pe(a(v))].filter(Boolean).join(" · "), X = _e ?? ce, Z = x || S, Q = ue ?? T;
29
- ne() && !Q.toLowerCase().includes(T.toLowerCase()) && console.warn(`[AvatarUpload] El nombre accesible del botón ("${Q}") no contiene su texto visible ("${T}"). WCAG 2.5.3 (Label in Name) lo exige: quien navega por voz dice lo que ve, y con estos textos no encontraría el control.`), o(() => {
30
- R.current = z;
31
- }, [z]), o(() => () => {
32
- R.current && URL.revokeObjectURL(R.current.url);
33
- }, []), o(() => {
34
- if (Z) return;
28
+ function p({ src: o, name: p, alt: m, shape: h = "circle", size: ue, accept: g = "image/jpeg,image/png,image/webp", maxSize: _, outputMimeType: de = "image/jpeg", outputSize: v, disabled: fe = !1, busy: y = !1, errorMessage: b, onChange: pe, onSelect: x, onError: S, subject: me, buttonLabel: he, buttonAccessibleLabel: ge, hintLabel: _e, formatsLabel: ve, locale: C = re, maxSizeHint: ye, invalidTypeError: w, tooLargeError: T, dropActiveMessage: be, dropHintLabel: xe, cropTitle: Se, cropDescription: Ce, cropCancelLabel: E, cropConfirmLabel: D, cropCloseLabel: O, cropLoadingLabel: k, cropErrorMessage: A, className: we }) {
29
+ let j = e("avatarUpload"), M = r(ue), N = c(null), P = c(null), [F, I] = l(null), [L, R] = l(!1), [z, B] = l(!1), [Te, V] = l(null), H = se(), U = `${H}-hint`, W = `${H}-error`, G = j("subject", me), K = ve ?? le(g, C), q = _e ?? [K, _ === void 0 ? null : j("maxSize", ye)(ne(_, C))].filter(Boolean).join(" · "), J = Te ?? b, Y = fe || y, X = j("button", he), Z = ge ?? j("buttonFor")(G);
30
+ ie() && !Z.toLowerCase().includes(X.toLowerCase()) && console.warn(`[AvatarUpload] El nombre accesible del botón ("${Z}") no contiene su texto visible ("${X}"). WCAG 2.5.3 (Label in Name) lo exige: quien navega por voz dice lo que ve, y con estos textos no encontraría el control.`), s(() => {
31
+ P.current = F;
32
+ }, [F]), s(() => () => {
33
+ P.current && URL.revokeObjectURL(P.current.url);
34
+ }, []), s(() => {
35
+ if (Y) return;
35
36
  let e = 0, t = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files"), n = (n) => {
36
- t(n) && (e += 1, H(!0));
37
+ t(n) && (e += 1, R(!0));
37
38
  }, r = () => {
38
- e = Math.max(0, e - 1), e === 0 && H(!1);
39
+ e = Math.max(0, e - 1), e === 0 && R(!1);
39
40
  }, i = () => {
40
- e = 0, H(!1);
41
+ e = 0, R(!1);
41
42
  };
42
43
  return window.addEventListener("dragenter", n), window.addEventListener("dragleave", r), window.addEventListener("drop", i), window.addEventListener("dragend", i), () => {
43
- window.removeEventListener("dragenter", n), window.removeEventListener("dragleave", r), window.removeEventListener("drop", i), window.removeEventListener("dragend", i), H(!1);
44
+ window.removeEventListener("dragenter", n), window.removeEventListener("dragleave", r), window.removeEventListener("drop", i), window.removeEventListener("dragend", i), R(!1);
44
45
  };
45
- }, [Z]);
46
- let $ = ie((e) => {
47
- let t = te(e, _, v, D, E(J));
46
+ }, [Y]);
47
+ let Q = oe((e) => {
48
+ let t = te(e, g, _, j("tooLarge", T), j("invalidType", w)(K), C);
48
49
  if (t) {
49
- W(t), w?.(t);
50
+ V(t), S?.(t);
50
51
  return;
51
52
  }
52
- W(null), C?.(e), B({
53
+ V(null), x?.(e), I({
53
54
  url: URL.createObjectURL(e),
54
55
  file: e
55
56
  });
56
57
  }, [
58
+ g,
57
59
  _,
58
- v,
59
- D,
60
- E,
61
- J,
60
+ j,
61
+ T,
62
62
  w,
63
- C
64
- ]), ve = () => {
65
- z && URL.revokeObjectURL(z.url), B(null);
66
- }, ye = async (e) => {
67
- z && await le(e, z.file);
68
- };
63
+ K,
64
+ C,
65
+ S,
66
+ x
67
+ ]), Ee = () => {
68
+ F && URL.revokeObjectURL(F.url), I(null);
69
+ }, De = async (e) => {
70
+ F && await pe(e, F.file);
71
+ }, $ = xe ?? j("dropHint")(G);
69
72
  return /* @__PURE__ */ d("div", {
70
73
  className: [
71
74
  "avatar-upload",
72
- g === "square" ? "avatar-upload--square" : "",
73
- V ? "avatar-upload--armed" : "",
74
- ge ? "avatar-upload--over" : "",
75
- Z ? "avatar-upload--inert" : "",
76
- F ?? ""
75
+ h === "square" ? "avatar-upload--square" : "",
76
+ L ? "avatar-upload--armed" : "",
77
+ z ? "avatar-upload--over" : "",
78
+ Y ? "avatar-upload--inert" : "",
79
+ we ?? ""
77
80
  ].filter(Boolean).join(" "),
78
81
  children: [
79
82
  /* @__PURE__ */ d("div", {
80
83
  className: "avatar-upload__target",
81
84
  onClick: () => {
82
- Z || L.current?.click();
85
+ Y || N.current?.click();
83
86
  },
84
87
  onDragEnter: (e) => {
85
- e.preventDefault(), Z || U(!0);
88
+ e.preventDefault(), Y || B(!0);
86
89
  },
87
90
  onDragOver: (e) => {
88
- e.preventDefault(), !Z && (e.dataTransfer.dropEffect = "copy", U(!0));
91
+ e.preventDefault(), !Y && (e.dataTransfer.dropEffect = "copy", B(!0));
89
92
  },
90
93
  onDragLeave: (e) => {
91
- e.currentTarget.contains(e.relatedTarget) || U(!1);
94
+ e.currentTarget.contains(e.relatedTarget) || B(!1);
92
95
  },
93
96
  onDrop: (e) => {
94
- if (e.preventDefault(), U(!1), H(!1), Z) return;
97
+ if (e.preventDefault(), B(!1), R(!1), Y) return;
95
98
  let t = e.dataTransfer.files?.[0];
96
- t && $(t);
99
+ t && Q(t);
97
100
  },
98
- children: [/* @__PURE__ */ u(i, {
99
- src: m ?? void 0,
100
- name: oe,
101
- ...h === void 0 ? {} : { alt: h },
102
- shape: g,
103
- size: ae[I]
101
+ children: [/* @__PURE__ */ u(a, {
102
+ src: o ?? void 0,
103
+ name: p,
104
+ ...m === void 0 ? {} : { alt: m },
105
+ shape: h,
106
+ size: ce[M]
104
107
  }), /* @__PURE__ */ u("span", {
105
108
  className: "avatar-upload__overlay",
106
109
  "aria-hidden": "true",
107
- children: /* @__PURE__ */ u(e, {
110
+ children: /* @__PURE__ */ u(t, {
108
111
  name: "upload",
109
- size: f[I]
112
+ size: f[M]
110
113
  })
111
114
  })]
112
115
  }),
@@ -114,63 +117,63 @@ function m({ src: m, name: oe, alt: h, shape: g = "circle", size: se, accept: _
114
117
  className: "avatar-upload__body",
115
118
  children: [
116
119
  /* @__PURE__ */ u("input", {
117
- ref: L,
120
+ ref: N,
118
121
  type: "file",
119
122
  className: "avatar-upload__input",
120
- accept: _,
123
+ accept: g,
121
124
  tabIndex: -1,
122
125
  "aria-hidden": "true",
123
- disabled: Z,
126
+ disabled: Y,
124
127
  onChange: (e) => {
125
128
  let t = e.target.files?.[0];
126
- t && $(t), e.target.value = "";
129
+ t && Q(t), e.target.value = "";
127
130
  }
128
131
  }),
129
- /* @__PURE__ */ u(r, {
132
+ /* @__PURE__ */ u(i, {
130
133
  variant: "outline",
131
- size: I,
132
- disabled: Z,
133
- onClick: () => L.current?.click(),
134
- ...Q === T ? {} : { "aria-label": Q },
135
- "aria-describedby": [Y ? K : null, X ? q : null].filter(Boolean).join(" ") || void 0,
136
- children: T
134
+ size: M,
135
+ disabled: Y,
136
+ onClick: () => N.current?.click(),
137
+ ...Z === X ? {} : { "aria-label": Z },
138
+ "aria-describedby": [q ? U : null, J ? W : null].filter(Boolean).join(" ") || void 0,
139
+ children: X
137
140
  }),
138
- Y && /* @__PURE__ */ u(t, {
139
- id: K,
140
- children: Y
141
+ q && /* @__PURE__ */ u(n, {
142
+ id: U,
143
+ children: q
141
144
  }),
142
- O && /* @__PURE__ */ u("span", {
145
+ $ && /* @__PURE__ */ u("span", {
143
146
  className: "avatar-upload__hint",
144
- children: O
147
+ children: $
145
148
  }),
146
- X && /* @__PURE__ */ u(ee, {
147
- id: q,
148
- children: X
149
+ J && /* @__PURE__ */ u(ee, {
150
+ id: W,
151
+ children: J
149
152
  })
150
153
  ]
151
154
  }),
152
- /* @__PURE__ */ u(t, {
155
+ /* @__PURE__ */ u(n, {
153
156
  role: "status",
154
- children: V ? me : ""
157
+ children: L ? be ?? j("dropActive")(G) : ""
155
158
  }),
156
- /* @__PURE__ */ u(re, {
157
- sourceUrl: z?.url ?? null,
158
- title: he,
159
- description: k,
160
- circularCrop: g === "circle",
161
- outputMimeType: y,
162
- ...b === void 0 ? {} : { outputSize: b },
163
- busy: S,
164
- cancelLabel: A,
165
- confirmLabel: j,
166
- closeLabel: M,
167
- ...N === void 0 ? {} : { loadingLabel: N },
168
- ...P === void 0 ? {} : { errorMessage: P },
169
- onConfirm: ye,
170
- onClose: ve
159
+ /* @__PURE__ */ u(ae, {
160
+ sourceUrl: F?.url ?? null,
161
+ title: Se,
162
+ description: Ce,
163
+ circularCrop: h === "circle",
164
+ outputMimeType: de,
165
+ ...v === void 0 ? {} : { outputSize: v },
166
+ busy: y,
167
+ cancelLabel: E ?? j("cropCancel"),
168
+ confirmLabel: D ?? j("cropConfirm"),
169
+ ...O === void 0 ? {} : { closeLabel: O },
170
+ ...k === void 0 ? {} : { loadingLabel: k },
171
+ ...A === void 0 ? {} : { errorMessage: A },
172
+ onConfirm: De,
173
+ onClose: Ee
171
174
  })
172
175
  ]
173
176
  });
174
177
  }
175
178
  //#endregion
176
- export { m as AvatarUpload };
179
+ export { p as AvatarUpload };