@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,194 +1,197 @@
1
1
  'use client';
2
2
  import './file-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 { t as r } from "./_shared/progressbar.js";
7
- import { n as i, t as a } from "./_shared/validate.js";
8
- import { forwardRef as o, useCallback as s, useEffect as c, useId as ee, useRef as l, useState as u } from "react";
9
- import { jsx as d, jsxs as f } from "react/jsx-runtime";
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 { t as i } from "./_shared/progressbar.js";
8
+ import { i as a, n as o, t as s } from "./_shared/validate.js";
9
+ import { forwardRef as c, useCallback as l, useEffect as u, useId as d, useRef as f, useState as p } from "react";
10
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
10
11
  //#region src/stories/atoms/FileUpload/FileUpload.tsx
11
- var p = /* @__PURE__ */ new WeakMap();
12
- function te(e) {
12
+ var g = /* @__PURE__ */ new WeakMap();
13
+ function ee(e) {
13
14
  if (!e.type.startsWith("image/")) return;
14
- let t = p.get(e);
15
- return t || (t = URL.createObjectURL(e), p.set(e, t)), t;
15
+ let t = g.get(e);
16
+ return t || (t = URL.createObjectURL(e), g.set(e, t)), t;
16
17
  }
17
- function m(e) {
18
- let t = p.get(e);
19
- t && (URL.revokeObjectURL(t), p.delete(e));
18
+ function _(e) {
19
+ let t = g.get(e);
20
+ t && (URL.revokeObjectURL(t), g.delete(e));
20
21
  }
21
- function h(e, t) {
22
+ function v(e, t) {
22
23
  typeof e == "function" ? e(t) : e && (e.current = t);
23
24
  }
24
- var g = o(function({ multiple: o = !1, accept: p, maxSize: g, maxFiles: _, value: v, defaultValue: y = [], onChange: b, progress: x, disabled: S = !1, error: C = !1, id: w, name: T, describedBy: E, ariaLabel: D, "aria-describedby": O, "aria-label": k, required: ne, onBlur: re, className: ie, dropzoneLabel: A = "Arrastra archivos aquí", dropzoneActiveLabel: ae = "Suelta los archivos aquí", dropzoneHintLabel: j = "o haz clic para seleccionar", maxSizeHint: oe = (e) => `máx. ${e}`, maxFilesHint: se = (e) => `hasta ${e} archivos`, filesLabel: ce = "Archivos seleccionados", progressLabel: le = "Progreso de subida", removeFileLabel: M = (e) => `Eliminar ${e}`, tooLargeError: N = (e) => `Archivo demasiado grande (máx. ${e})`, invalidTypeError: P = "Tipo de archivo no permitido", size: F }, I) {
25
- let L = n(F), R = L === "sm" ? "sm" : L === "lg" ? "lg" : "md", z = v !== void 0, [B, V] = u(y), [H, U] = u(/* @__PURE__ */ new Map()), [W, G] = u(!1), K = l(/* @__PURE__ */ new Set()), q = l(null), ue = ee(), J = w ?? `file-upload-${ue}`, Y = z ? v : B;
26
- c(() => {
27
- Y.forEach((e) => K.current.add(e));
28
- }, [Y]), c(() => {
29
- let e = K.current;
25
+ var y = c(function({ multiple: c = !1, accept: g, maxSize: y, maxFiles: b, value: x, defaultValue: S = [], onChange: C, progress: w, disabled: T = !1, error: E = !1, id: D, name: te, describedBy: ne, ariaLabel: re, "aria-describedby": ie, "aria-label": ae, required: oe, onBlur: se, className: ce, locale: O = s, dropzoneLabel: le, dropzoneActiveLabel: ue, dropzoneHintLabel: de, maxSizeHint: fe, maxFilesHint: pe, filesLabel: me, progressLabel: he, removeFileLabel: k, tooLargeError: A, invalidTypeError: j, size: M }, N) {
26
+ let P = e("fileUpload"), F = r(M), I = F === "sm" ? "sm" : F === "lg" ? "lg" : "md", L = x !== void 0, [R, z] = p(S), [B, V] = p(/* @__PURE__ */ new Map()), [H, U] = p(!1), W = f(/* @__PURE__ */ new Set()), G = f(null), ge = d(), K = D ?? `file-upload-${ge}`, q = L ? x : R;
27
+ u(() => {
28
+ q.forEach((e) => W.current.add(e));
29
+ }, [q]), u(() => {
30
+ let e = W.current;
30
31
  return () => {
31
- e.forEach(m);
32
+ e.forEach(_);
32
33
  };
33
34
  }, []);
34
- let X = s((e) => {
35
- if (S) return;
36
- let t = Array.from(e), n = z ? v ?? [] : B, r = new Map(H), a = [...n];
35
+ let J = l((e) => {
36
+ if (T) return;
37
+ let t = Array.from(e), n = L ? x ?? [] : R, r = new Map(B), i = [...n];
37
38
  for (let e of t) {
38
- if (_ !== void 0 && a.filter((e) => !r.has(e)).length >= _) break;
39
- let t = i(e, p, g, N, P);
40
- t && r.set(e, t), a.push(e);
39
+ if (b !== void 0 && i.filter((e) => !r.has(e)).length >= b) break;
40
+ let t = a(e, g, y, P("tooLarge", A), P("invalidType", j), O);
41
+ t && r.set(e, t), i.push(e);
41
42
  }
42
- U(r), z || V(a), b?.(a.filter((e) => !r.has(e)));
43
+ V(r), L || z(i), C?.(i.filter((e) => !r.has(e)));
43
44
  }, [
44
- S,
45
- p,
45
+ T,
46
46
  g,
47
- _,
48
- z,
49
- v,
50
- B,
51
- H,
47
+ y,
52
48
  b,
53
- N,
54
- P
55
- ]), de = s((e) => {
56
- let t = (z ? v ?? [] : B).filter((t) => t !== e), n = new Map(H);
57
- n.delete(e), m(e), U(n), z || V(t), b?.(t.filter((e) => !n.has(e))), q.current && (q.current.value = "");
49
+ L,
50
+ x,
51
+ R,
52
+ B,
53
+ C,
54
+ P,
55
+ A,
56
+ j,
57
+ O
58
+ ]), _e = l((e) => {
59
+ let t = (L ? x ?? [] : R).filter((t) => t !== e), n = new Map(B);
60
+ n.delete(e), _(e), V(n), L || z(t), C?.(t.filter((e) => !n.has(e))), G.current && (G.current.value = "");
58
61
  }, [
59
- z,
60
- v,
62
+ L,
63
+ x,
64
+ R,
61
65
  B,
62
- H,
63
- b
64
- ]), fe = (e) => {
65
- e.target.files && X(e.target.files);
66
- }, pe = (e) => {
67
- e.preventDefault(), S || G(!0);
68
- }, me = (e) => {
69
- e.preventDefault(), G(!1);
70
- }, he = (e) => {
71
- e.preventDefault(), G(!1), !S && e.dataTransfer.files && X(e.dataTransfer.files);
72
- }, Z = () => {
73
- S || q.current?.click();
74
- }, ge = [
66
+ C
67
+ ]), ve = (e) => {
68
+ e.target.files && J(e.target.files);
69
+ }, ye = (e) => {
70
+ e.preventDefault(), T || U(!0);
71
+ }, be = (e) => {
72
+ e.preventDefault(), U(!1);
73
+ }, Y = (e) => {
74
+ e.preventDefault(), U(!1), !T && e.dataTransfer.files && J(e.dataTransfer.files);
75
+ }, xe = () => {
76
+ T || G.current?.click();
77
+ }, Se = [
75
78
  "file-upload",
76
- L === "md" ? "" : `file-upload--${L}`,
77
- W ? "file-upload--dragging" : "",
78
- C ? "file-upload--error" : "",
79
- S ? "file-upload--disabled" : "",
80
- Y.length > 0 ? "file-upload--has-files" : "",
81
- ie ?? ""
82
- ].filter(Boolean).join(" "), Q = `${J}-hint`, _e = [E ?? O, Q].filter(Boolean).join(" "), $ = [];
83
- return p && $.push(p), g && $.push(oe(a(g))), o && _ && $.push(se(_)), /* @__PURE__ */ f("div", {
84
- className: ge,
79
+ F === "md" ? "" : `file-upload--${F}`,
80
+ H ? "file-upload--dragging" : "",
81
+ E ? "file-upload--error" : "",
82
+ T ? "file-upload--disabled" : "",
83
+ q.length > 0 ? "file-upload--has-files" : "",
84
+ ce ?? ""
85
+ ].filter(Boolean).join(" "), X = `${K}-hint`, Ce = [ne ?? ie, X].filter(Boolean).join(" "), Z = P("dropzone", le), Q = P("dropzoneHint", de), $ = [];
86
+ return g && $.push(g), y && $.push(P("maxSize", fe)(o(y, O))), c && b && $.push(P("maxFiles", pe)(b)), /* @__PURE__ */ h("div", {
87
+ className: Se,
85
88
  children: [
86
- /* @__PURE__ */ d(t, { children: /* @__PURE__ */ d("input", {
89
+ /* @__PURE__ */ m(n, { children: /* @__PURE__ */ m("input", {
87
90
  ref: (e) => {
88
- q.current = e, h(I, e);
91
+ G.current = e, v(N, e);
89
92
  },
90
93
  type: "file",
91
- id: J,
92
- name: T,
93
- multiple: o,
94
- accept: p,
95
- disabled: S,
96
- required: ne,
97
- "aria-label": D ?? k,
98
- "aria-describedby": _e,
99
- "aria-invalid": C || void 0,
100
- onChange: fe,
101
- onBlur: re
94
+ id: K,
95
+ name: te,
96
+ multiple: c,
97
+ accept: g,
98
+ disabled: T,
99
+ required: oe,
100
+ "aria-label": re ?? ae,
101
+ "aria-describedby": Ce,
102
+ "aria-invalid": E || void 0,
103
+ onChange: ve,
104
+ onBlur: se
102
105
  }) }),
103
- /* @__PURE__ */ f("div", {
106
+ /* @__PURE__ */ h("div", {
104
107
  className: "file-upload__dropzone",
105
- onClick: Z,
106
- onDragOver: pe,
107
- onDragLeave: me,
108
- onDrop: he,
108
+ onClick: xe,
109
+ onDragOver: ye,
110
+ onDragLeave: be,
111
+ onDrop: Y,
109
112
  "aria-hidden": "true",
110
113
  children: [
111
- /* @__PURE__ */ d(e, {
114
+ /* @__PURE__ */ m(t, {
112
115
  name: "upload",
113
- size: R,
116
+ size: I,
114
117
  className: "file-upload__icon"
115
118
  }),
116
- /* @__PURE__ */ d("span", {
119
+ /* @__PURE__ */ m("span", {
117
120
  className: "file-upload__text",
118
- children: W ? ae : A
121
+ children: H ? P("dropzoneActive", ue) : Z
119
122
  }),
120
- /* @__PURE__ */ d("span", {
123
+ /* @__PURE__ */ m("span", {
121
124
  className: "file-upload__text file-upload__text--secondary",
122
- children: j
125
+ children: Q
123
126
  }),
124
- $.length > 0 && /* @__PURE__ */ d("span", {
127
+ $.length > 0 && /* @__PURE__ */ m("span", {
125
128
  className: "file-upload__subtext",
126
129
  children: $.join(" · ")
127
130
  })
128
131
  ]
129
132
  }),
130
- /* @__PURE__ */ d(t, {
131
- id: Q,
133
+ /* @__PURE__ */ m(n, {
134
+ id: X,
132
135
  children: [
133
- A,
134
- j,
136
+ Z,
137
+ Q,
135
138
  ...$
136
139
  ].join(". ")
137
140
  }),
138
- Y.length > 0 && /* @__PURE__ */ d("ul", {
141
+ q.length > 0 && /* @__PURE__ */ m("ul", {
139
142
  className: "file-upload__list",
140
- "aria-label": ce,
141
- children: Y.map((t, n) => {
142
- let r = H.get(t), i = te(t);
143
- return /* @__PURE__ */ f("li", {
143
+ "aria-label": P("files", me),
144
+ children: q.map((e, n) => {
145
+ let r = B.get(e), i = ee(e);
146
+ return /* @__PURE__ */ h("li", {
144
147
  className: `file-upload__item${r ? " file-upload__item--error" : ""}`,
145
148
  children: [
146
- /* @__PURE__ */ d("div", {
149
+ /* @__PURE__ */ m("div", {
147
150
  className: "file-upload__item-thumb",
148
151
  "aria-hidden": "true",
149
- children: i ? /* @__PURE__ */ d("img", {
152
+ children: i ? /* @__PURE__ */ m("img", {
150
153
  src: i,
151
154
  alt: ""
152
- }) : /* @__PURE__ */ d(e, {
155
+ }) : /* @__PURE__ */ m(t, {
153
156
  name: "file-text",
154
157
  size: "sm"
155
158
  })
156
159
  }),
157
- /* @__PURE__ */ f("div", {
160
+ /* @__PURE__ */ h("div", {
158
161
  className: "file-upload__item-info",
159
162
  children: [
160
- /* @__PURE__ */ d("span", {
163
+ /* @__PURE__ */ m("span", {
161
164
  className: "file-upload__item-name",
162
- children: t.name
165
+ children: e.name
163
166
  }),
164
- /* @__PURE__ */ d("span", {
167
+ /* @__PURE__ */ m("span", {
165
168
  className: "file-upload__item-size",
166
- children: a(t.size)
169
+ children: o(e.size, O)
167
170
  }),
168
- r && /* @__PURE__ */ d("span", {
171
+ r && /* @__PURE__ */ m("span", {
169
172
  className: "file-upload__item-error-msg",
170
173
  role: "alert",
171
174
  children: r
172
175
  })
173
176
  ]
174
177
  }),
175
- /* @__PURE__ */ d("button", {
178
+ /* @__PURE__ */ m("button", {
176
179
  className: "file-upload__item-remove",
177
180
  type: "button",
178
- onClick: () => de(t),
179
- "aria-label": M(t.name),
180
- children: /* @__PURE__ */ d(e, {
181
+ onClick: () => _e(e),
182
+ "aria-label": P("removeFile", k)(e.name),
183
+ children: /* @__PURE__ */ m(t, {
181
184
  name: "close",
182
185
  size: "sm"
183
186
  })
184
187
  })
185
188
  ]
186
- }, `${t.name}-${t.size}-${n}`);
189
+ }, `${e.name}-${e.size}-${n}`);
187
190
  })
188
191
  }),
189
- x !== void 0 && /* @__PURE__ */ d(r, {
190
- value: x,
191
- label: le,
192
+ w !== void 0 && /* @__PURE__ */ m(i, {
193
+ value: w,
194
+ label: P("progress", he),
192
195
  size: "sm",
193
196
  className: "file-upload__progress"
194
197
  })
@@ -196,4 +199,4 @@ var g = o(function({ multiple: o = !1, accept: p, maxSize: g, maxFiles: _, value
196
199
  });
197
200
  });
198
201
  //#endregion
199
- export { g as FileUpload };
202
+ export { y as FileUpload };