@sps-woodland/file-upload 7.17.13 → 7.19.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,9 +1,9 @@
1
1
  import * as e from "react";
2
- import { Metadata as ue, I18nContext as me, cl as I, Spinner as he, Icon as ve } from "@sps-woodland/core";
3
- import { parseFileSize as we, code as m } from "@spscommerce/utils";
4
- import { SpsButton as B } from "@spscommerce/ds-react";
5
- import { ButtonKind as V, SpsIcon as W } from "@spscommerce/ds-shared";
6
- const L = {
2
+ import { Metadata as _e, I18nContext as ue, cl as A, Spinner as me, Icon as he } from "@sps-woodland/core";
3
+ import { parseFileSize as ve, code as u } from "@spscommerce/utils";
4
+ import { SpsButton as M } from "@spscommerce/ds-react";
5
+ import { ButtonKind as I, SpsIcon as B } from "@spscommerce/ds-shared";
6
+ const V = {
7
7
  "7Z": ["application/x-7z-compressed"],
8
8
  AAC: ["audio/aac"],
9
9
  ABW: ["application/x-abiword"],
@@ -79,196 +79,196 @@ const L = {
79
79
  XUL: ["application/vnd.mozilla.xul+xml"],
80
80
  ZIP: ["application/zip"]
81
81
  };
82
- function ge(i, o, a) {
83
- return o in i ? Object.defineProperty(i, o, {
82
+ function we(o, l, a) {
83
+ return l in o ? Object.defineProperty(o, l, {
84
84
  value: a,
85
85
  enumerable: !0,
86
86
  configurable: !0,
87
87
  writable: !0
88
- }) : i[o] = a, i;
88
+ }) : o[l] = a, o;
89
89
  }
90
- function z(i, o) {
91
- var a = Object.keys(i);
90
+ function W(o, l) {
91
+ var a = Object.keys(o);
92
92
  if (Object.getOwnPropertySymbols) {
93
- var l = Object.getOwnPropertySymbols(i);
94
- o && (l = l.filter(function(n) {
95
- return Object.getOwnPropertyDescriptor(i, n).enumerable;
96
- })), a.push.apply(a, l);
93
+ var i = Object.getOwnPropertySymbols(o);
94
+ l && (i = i.filter(function(n) {
95
+ return Object.getOwnPropertyDescriptor(o, n).enumerable;
96
+ })), a.push.apply(a, i);
97
97
  }
98
98
  return a;
99
99
  }
100
- function R(i) {
101
- for (var o = 1; o < arguments.length; o++) {
102
- var a = arguments[o] != null ? arguments[o] : {};
103
- o % 2 ? z(Object(a), !0).forEach(function(l) {
104
- ge(i, l, a[l]);
105
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(a)) : z(Object(a)).forEach(function(l) {
106
- Object.defineProperty(i, l, Object.getOwnPropertyDescriptor(a, l));
100
+ function L(o) {
101
+ for (var l = 1; l < arguments.length; l++) {
102
+ var a = arguments[l] != null ? arguments[l] : {};
103
+ l % 2 ? W(Object(a), !0).forEach(function(i) {
104
+ we(o, i, a[i]);
105
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(o, Object.getOwnPropertyDescriptors(a)) : W(Object(a)).forEach(function(i) {
106
+ Object.defineProperty(o, i, Object.getOwnPropertyDescriptor(a, i));
107
107
  });
108
108
  }
109
- return i;
109
+ return o;
110
110
  }
111
- var Fe = (i, o, a) => {
112
- for (var l of Object.keys(i)) {
111
+ var ge = (o, l, a) => {
112
+ for (var i of Object.keys(o)) {
113
113
  var n;
114
- if (i[l] !== ((n = o[l]) !== null && n !== void 0 ? n : a[l]))
114
+ if (o[i] !== ((n = l[i]) !== null && n !== void 0 ? n : a[i]))
115
115
  return !1;
116
116
  }
117
117
  return !0;
118
- }, U = (i) => (o) => {
119
- var a = i.defaultClassName, l = R(R({}, i.defaultVariants), o);
120
- for (var n in l) {
121
- var v, w = (v = l[n]) !== null && v !== void 0 ? v : i.defaultVariants[n];
122
- if (w != null) {
123
- var p = w;
118
+ }, E = (o) => (l) => {
119
+ var a = o.defaultClassName, i = L(L({}, o.defaultVariants), l);
120
+ for (var n in i) {
121
+ var h, v = (h = i[n]) !== null && h !== void 0 ? h : o.defaultVariants[n];
122
+ if (v != null) {
123
+ var p = v;
124
124
  typeof p == "boolean" && (p = p === !0 ? "true" : "false");
125
- var c = i.variantClassNames[n][p];
126
- c && (a += " " + c);
125
+ var d = o.variantClassNames[n][p];
126
+ d && (a += " " + d);
127
127
  }
128
128
  }
129
- for (var [F, C] of i.compoundVariants)
130
- Fe(F, l, i.defaultVariants) && (a += " " + C);
129
+ for (var [g, U] of o.compoundVariants)
130
+ ge(g, i, o.defaultVariants) && (a += " " + U);
131
131
  return a;
132
- }, xe = "rh07jwm", k = "rh07jwn", ye = "rh07jwl", Se = U({ defaultClassName: "rh07jw0", variantClassNames: { active: { true: "rh07jw1", false: "rh07jw2" }, mini: { true: "rh07jw3", false: "rh07jw4" }, error: { true: "rh07jw5", false: "rh07jw6" }, shown: { true: "rh07jw7", false: "rh07jw8" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0 }, compoundVariants: [] }), be = "rh07jwq", Ee = U({ defaultClassName: "rh07jw9", variantClassNames: { constrainContentWidth: { true: "rh07jwa", false: "rh07jwb" } }, defaultVariants: { constrainContentWidth: !1 }, compoundVariants: [] }), Ue = "rh07jwp", Ce = "rh07jwr", je = U({ defaultClassName: "rh07jwd", variantClassNames: { mini: { true: "rh07jwe", false: "rh07jwf" }, error: { true: "rh07jwg", false: "rh07jwh" } }, defaultVariants: { mini: !1, error: !1 }, compoundVariants: [] }), X = "rh07jwc", Oe = "rh07jwo", De = U({ defaultClassName: "rh07jwi", variantClassNames: { mini: { true: "rh07jwj", false: "rh07jwk" } }, defaultVariants: { mini: !1 }, compoundVariants: [] });
133
- function G({
134
- constrainContentWidth: i,
135
- description: o,
132
+ }, Fe = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwm", z = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwn", xe = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwl", ye = E({ defaultClassName: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw0", variantClassNames: { active: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw1", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw2" }, mini: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw3", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw4" }, error: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw5", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw6" }, shown: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw7", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw8" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0 }, compoundVariants: [] }), Se = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwq", be = E({ defaultClassName: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw9", variantClassNames: { constrainContentWidth: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwa", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwb" } }, defaultVariants: { constrainContentWidth: !1 }, compoundVariants: [] }), Ee = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwp", Ue = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwr", Ce = E({ defaultClassName: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwd", variantClassNames: { mini: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwe", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwf" }, error: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwg", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwh" } }, defaultVariants: { mini: !1, error: !1 }, compoundVariants: [] }), R = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwc", je = "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwo", Oe = E({ defaultClassName: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwi", variantClassNames: { mini: { true: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwj", false: "pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwk" } }, defaultVariants: { mini: !1 }, compoundVariants: [] });
133
+ function X({
134
+ constrainContentWidth: o,
135
+ description: l,
136
136
  multiple: a = !1,
137
- dismissable: l,
137
+ dismissable: i,
138
138
  processing: n,
139
- mini: v,
140
- downloadLabel: w,
139
+ mini: h,
140
+ downloadLabel: v,
141
141
  acceptExtensions: p,
142
- maxSize: c,
143
- customRequirement: F,
144
- onSelection: C,
145
- onDismiss: N,
146
- download: T,
147
- shown: x,
148
- className: K,
149
- children: Te,
150
- ...Z
142
+ maxSize: d,
143
+ customRequirement: g,
144
+ onSelection: U,
145
+ onDismiss: k,
146
+ download: D,
147
+ shown: F,
148
+ className: G,
149
+ children: De,
150
+ ...K
151
151
  }) {
152
- const y = e.useRef(/* @__PURE__ */ new Set()), [q, P] = e.useState(x), [Pe, H] = e.useState([]), [J, _] = e.useState(""), [A, Y] = e.useState(), [Q, S] = e.useState(!1), [g, b] = e.useState(!1), [j, M] = e.useState([]), [$, ee] = e.useState(""), { t: h } = e.useContext(me), O = h(a ? "design-system:fileUpload.instructions_plural" : "design-system:fileUpload.instructions").split("|"), te = o || (a ? "Files" : "File"), d = e.useRef(null);
152
+ const x = e.useRef(/* @__PURE__ */ new Set()), [Z, N] = e.useState(F), [Ne, q] = e.useState([]), [H, J] = e.useState(""), [T, Y] = e.useState(), [Q, y] = e.useState(!1), [w, S] = e.useState(!1), [C, P] = e.useState([]), [$, ee] = e.useState(""), { t: m } = e.useContext(ue), j = m(a ? "design-system:fileUpload.instructions_plural" : "design-system:fileUpload.instructions").split("|"), te = l || (a ? "Files" : "File"), c = e.useRef(null);
153
153
  e.useEffect(() => {
154
- x && P(x);
155
- }, [x]), e.useEffect(() => {
156
- c && ae(c);
157
- }, [c]), e.useEffect(() => {
158
- p && le(p);
154
+ F && N(F);
155
+ }, [F]), e.useEffect(() => {
156
+ d && ae(d);
157
+ }, [d]), e.useEffect(() => {
158
+ p && ie(p);
159
159
  }, [p]);
160
- function ie() {
161
- l && (P(!1), N && N());
160
+ function oe() {
161
+ i && (N(!1), k && k());
162
162
  }
163
163
  function ae(t) {
164
164
  try {
165
- Y(we(t));
165
+ Y(ve(t));
166
166
  } catch {
167
167
  throw new Error(`Could not parse "${t}" as a file size.`);
168
168
  }
169
169
  }
170
- function le(t) {
171
- const f = (Array.isArray(t) ? t : t.trim().split(/\s?,\s?/)).map((u) => u.replace(/^\./, "")), r = f.map((u) => `.${u}`.toLowerCase());
170
+ function ie(t) {
171
+ const f = (Array.isArray(t) ? t : t.trim().split(/\s?,\s?/)).map((_) => _.replace(/^\./, "")), r = f.map((_) => `.${_}`.toLowerCase());
172
172
  ee(
173
- r.map((u, E) => E > 0 && E === r.length - 1 ? `or ${u}` : u).join(r.length > 2 ? ", " : " ")
174
- ), y.current.clear();
175
- for (const u of f) {
176
- const E = Object.keys(L).includes(u.toUpperCase()) ? L[u.toUpperCase()] : [];
177
- for (const fe of E)
178
- y.current.add(fe);
173
+ r.map((_, b) => b > 0 && b === r.length - 1 ? `or ${_}` : _).join(r.length > 2 ? ", " : " ")
174
+ ), x.current.clear();
175
+ for (const _ of f) {
176
+ const b = Object.keys(V).includes(_.toUpperCase()) ? V[_.toUpperCase()] : [];
177
+ for (const fe of b)
178
+ x.current.add(fe);
179
179
  }
180
- _(r.concat(Array.from(y.current)).join(","));
180
+ J(r.concat(Array.from(x.current)).join(","));
181
181
  }
182
- function D(t) {
183
- M([]);
182
+ function O(t) {
183
+ P([]);
184
184
  let s = [];
185
185
  const f = Array.from(t);
186
186
  for (const r of f)
187
- r === null ? s.push("Not a file") : (p && !y.current.has(r.type) && s.push(r.name), c && A && r.size > A && s.indexOf(r.name) === -1 && s.push(r.name));
188
- s.length ? (b(!0), d.current && d.current.value && (d.current.value = "")) : (H(f), C(f)), M(s);
187
+ r === null ? s.push("Not a file") : (p && !x.current.has(r.type) && s.push(r.name), d && T && r.size > T && s.indexOf(r.name) === -1 && s.push(r.name));
188
+ s.length ? (S(!0), c.current && c.current.value && (c.current.value = "")) : (q(f), U(f)), P(s);
189
189
  }
190
- function oe(t) {
191
- t.preventDefault(), b(!1), d.current && d.current.click();
190
+ function le(t) {
191
+ t.preventDefault(), S(!1), c.current && c.current.click();
192
192
  }
193
193
  function ne() {
194
- T && T();
194
+ D && D();
195
195
  }
196
196
  function se(t) {
197
- t.stopPropagation(), D(t.target.files || []), d.current && d.current.value && (d.current.value = "");
197
+ t.stopPropagation(), O(t.target.files || []), c.current && c.current.value && (c.current.value = "");
198
198
  }
199
199
  function re(t) {
200
- t.preventDefault(), t.stopPropagation(), S(!0), b(!1);
200
+ t.preventDefault(), t.stopPropagation(), y(!0), S(!1);
201
201
  }
202
202
  function pe(t) {
203
- t.preventDefault(), S(!0), b(!1);
204
- }
205
- function ce(t) {
206
- t.preventDefault(), S(!1);
203
+ t.preventDefault(), y(!0), S(!1);
207
204
  }
208
205
  function de(t) {
209
- t.preventDefault(), t.stopPropagation(), S(!1), t.dataTransfer.items ? D(
206
+ t.preventDefault(), y(!1);
207
+ }
208
+ function ce(t) {
209
+ t.preventDefault(), t.stopPropagation(), y(!1), t.dataTransfer.items ? O(
210
210
  Array.from(t.dataTransfer.items).map(
211
211
  (s) => s.getAsFile()
212
212
  )
213
- ) : D(t.dataTransfer.files);
213
+ ) : O(t.dataTransfer.files);
214
214
  }
215
215
  return /* @__PURE__ */ e.createElement(
216
216
  "div",
217
217
  {
218
- onDrop: de,
218
+ onDrop: ce,
219
219
  onDragOver: re,
220
- onDragLeave: ce,
220
+ onDragLeave: de,
221
221
  onDragEnter: pe,
222
- className: I(Se({ active: Q, mini: v, error: g, shown: q }), K),
223
- ...Z
222
+ className: A(ye({ active: Q, mini: h, error: w, shown: Z }), G),
223
+ ...K
224
224
  },
225
- /* @__PURE__ */ e.createElement("div", { className: I(Ee({ constrainContentWidth: i })) }, n ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(he, { size: "md", "aria-hidden": "true" }), /* @__PURE__ */ e.createElement("div", { className: X }, h("design-system:fileUpload.processing"))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
226
- ve,
225
+ /* @__PURE__ */ e.createElement("div", { className: A(be({ constrainContentWidth: o })) }, n ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(me, { size: "md", "aria-hidden": "true" }), /* @__PURE__ */ e.createElement("div", { className: R }, m("design-system:fileUpload.processing"))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
226
+ he,
227
227
  {
228
- className: je({ mini: v, error: g }),
229
- icon: g ? "exclamation-circle" : "upload-cloud",
228
+ className: Ce({ mini: h, error: w }),
229
+ icon: w ? "exclamation-circle" : "upload-cloud",
230
230
  "aria-hidden": "true"
231
231
  }
232
- ), /* @__PURE__ */ e.createElement("div", { className: De({ mini: v }) }, g ? /* @__PURE__ */ e.createElement("div", null, h(
233
- j.length > 1 ? "design-system:fileUpload.cancelled_plural" : "design-system:fileUpload.cancelled"
234
- )) : /* @__PURE__ */ e.createElement("div", null, h("design-system:fileUpload.title", { description: te }))), g ? /* @__PURE__ */ e.createElement("div", { className: ye }, new Set(
235
- j.map((t, s) => {
232
+ ), /* @__PURE__ */ e.createElement("div", { className: Oe({ mini: h }) }, w ? /* @__PURE__ */ e.createElement("div", null, m(
233
+ C.length > 1 ? "design-system:fileUpload.cancelled_plural" : "design-system:fileUpload.cancelled"
234
+ )) : /* @__PURE__ */ e.createElement("div", null, m("design-system:fileUpload.title", { description: te }))), w ? /* @__PURE__ */ e.createElement("div", { className: xe }, new Set(
235
+ C.map((t, s) => {
236
236
  const f = Math.floor(t.length / 2);
237
- return /* @__PURE__ */ e.createElement("div", { className: xe, key: t }, /* @__PURE__ */ e.createElement("span", { className: k }, t.substr(0, f)), /* @__PURE__ */ e.createElement("div", { className: k }, /* @__PURE__ */ e.createElement("span", null, t.substr(f))), s < j.length - 1 ? "," : "");
237
+ return /* @__PURE__ */ e.createElement("div", { className: Fe, key: t }, /* @__PURE__ */ e.createElement("span", { className: z }, t.substr(0, f)), /* @__PURE__ */ e.createElement("div", { className: z }, /* @__PURE__ */ e.createElement("span", null, t.substr(f))), s < C.length - 1 ? "," : "");
238
238
  })
239
- )) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", { className: X }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("span", null, O[0]), /* @__PURE__ */ e.createElement("a", { href: "", onClick: oe }, O[1]), /* @__PURE__ */ e.createElement("span", null, O[2]))), /* @__PURE__ */ e.createElement("div", { className: Oe }, p ? /* @__PURE__ */ e.createElement("span", null, "(", " ", h("design-system:fileUpload.acceptedTypes", {
239
+ )) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", { className: R }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("span", null, j[0]), /* @__PURE__ */ e.createElement("a", { href: "", onClick: le }, j[1]), /* @__PURE__ */ e.createElement("span", null, j[2]))), /* @__PURE__ */ e.createElement("div", { className: je }, p ? /* @__PURE__ */ e.createElement("span", null, "(", " ", m("design-system:fileUpload.acceptedTypes", {
240
240
  fileTypes: $
241
- }), " ", ")") : "", c ? /* @__PURE__ */ e.createElement("span", null, "( ", h("design-system:fileUpload.maximumSize", { size: c }), " )") : "", F ? /* @__PURE__ */ e.createElement("span", null, " ", F, " ") : ""), w && /* @__PURE__ */ e.createElement("div", { className: Ue }, /* @__PURE__ */ e.createElement(
242
- B,
241
+ }), " ", ")") : "", d ? /* @__PURE__ */ e.createElement("span", null, "( ", m("design-system:fileUpload.maximumSize", { size: d }), " )") : "", g ? /* @__PURE__ */ e.createElement("span", null, " ", g, " ") : ""), v && /* @__PURE__ */ e.createElement("div", { className: Ee }, /* @__PURE__ */ e.createElement(
242
+ M,
243
243
  {
244
- kind: V.LINK,
245
- icon: W.DOWNLOAD_CLOUD,
244
+ kind: I.LINK,
245
+ icon: B.DOWNLOAD_CLOUD,
246
246
  onClick: ne
247
247
  },
248
- w
248
+ v
249
249
  )))),
250
- l && !n && /* @__PURE__ */ e.createElement("div", { className: be }, /* @__PURE__ */ e.createElement(
251
- B,
250
+ i && !n && /* @__PURE__ */ e.createElement("div", { className: Se }, /* @__PURE__ */ e.createElement(
251
+ M,
252
252
  {
253
- kind: V.ICON,
254
- icon: W.X,
255
- title: h("design-system:fileUpload.close"),
256
- onClick: ie
253
+ kind: I.ICON,
254
+ icon: B.X,
255
+ title: m("design-system:fileUpload.close"),
256
+ onClick: oe
257
257
  }
258
258
  )),
259
- /* @__PURE__ */ e.createElement("form", { className: Ce }, /* @__PURE__ */ e.createElement(
259
+ /* @__PURE__ */ e.createElement("form", { className: Ue }, /* @__PURE__ */ e.createElement(
260
260
  "input",
261
261
  {
262
- ref: d,
262
+ ref: c,
263
263
  type: "file",
264
- accept: J || "*/*",
264
+ accept: H || "*/*",
265
265
  multiple: a || void 0,
266
266
  onChange: se
267
267
  }
268
268
  ))
269
269
  );
270
270
  }
271
- ue.set(G, {
271
+ _e.set(X, {
272
272
  name: "FileUpload",
273
273
  props: {
274
274
  constrainContentWidth: { type: "boolean" },
@@ -285,8 +285,8 @@ ue.set(G, {
285
285
  download: { type: "() => void" }
286
286
  }
287
287
  });
288
- const Ne = {
289
- components: [G],
288
+ const ke = {
289
+ components: [X],
290
290
  examples: {
291
291
  basic: {
292
292
  label: "Basic File Upload",
@@ -294,7 +294,7 @@ const Ne = {
294
294
  examples: {
295
295
  basic: {
296
296
  description: "Single file upload",
297
- react: m`
297
+ react: u`
298
298
  import { FileUpload } from "@sps-woodland/file-upload";
299
299
 
300
300
  function Component() {
@@ -310,7 +310,7 @@ const Ne = {
310
310
  },
311
311
  multiple: {
312
312
  description: "Multiple file upload",
313
- react: m`
313
+ react: u`
314
314
  import { FileUpload } from "@sps-woodland/file-upload";
315
315
 
316
316
  function Component() {
@@ -332,7 +332,7 @@ const Ne = {
332
332
  examples: {
333
333
  maxSize: {
334
334
  description: "Maximum size",
335
- react: m`
335
+ react: u`
336
336
  import { FileUpload } from "@sps-woodland/file-upload";
337
337
 
338
338
  function Component() {
@@ -348,7 +348,7 @@ const Ne = {
348
348
  },
349
349
  fileWhitelist: {
350
350
  description: "File type whitelist",
351
- react: m`
351
+ react: u`
352
352
  import { FileUpload } from "@sps-woodland/file-upload";
353
353
 
354
354
  function Component() {
@@ -369,7 +369,7 @@ const Ne = {
369
369
  },
370
370
  bothRestrictions: {
371
371
  description: "Both restrictions",
372
- react: m`
372
+ react: u`
373
373
  import { FileUpload } from "@sps-woodland/file-upload";
374
374
 
375
375
  function Component() {
@@ -396,7 +396,7 @@ const Ne = {
396
396
  description: "With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can show it again programmatically if you need to.",
397
397
  examples: {
398
398
  basic: {
399
- react: m`
399
+ react: u`
400
400
  import { FileUpload } from "@sps-woodland/file-upload";
401
401
 
402
402
  function Component() {
@@ -434,7 +434,7 @@ const Ne = {
434
434
  description: "You can optionally provide a button to download a file. Typically this will be a template for whatever the user is expected to upload. They can then fill out the template, save it, and upload it.",
435
435
  examples: {
436
436
  basic: {
437
- react: m`
437
+ react: u`
438
438
  import { FileUpload } from "@sps-woodland/file-upload";
439
439
 
440
440
  function Component() {
@@ -465,7 +465,7 @@ const Ne = {
465
465
  description: "When the file upload component is to be placed in a small container, it should be marked as a mini file upload so that everything fits.",
466
466
  examples: {
467
467
  basic: {
468
- react: m`
468
+ react: u`
469
469
  import { FileUpload } from "@sps-woodland/file-upload";
470
470
 
471
471
  function Component() {
@@ -490,7 +490,7 @@ const Ne = {
490
490
  description: "If this prop is provided, the content will be restricted to 50% of the overall width of the component. Consult your product designer if you're not sure whether to use this variant.",
491
491
  examples: {
492
492
  basic: {
493
- react: m`
493
+ react: u`
494
494
  import { FileUpload } from "@sps-woodland/file-upload";
495
495
 
496
496
  function Component() {
@@ -511,10 +511,10 @@ const Ne = {
511
511
  }
512
512
  }
513
513
  }
514
- }, Ve = {
515
- "File Upload": Ne
514
+ }, Ie = {
515
+ "File Upload": ke
516
516
  };
517
517
  export {
518
- G as FileUpload,
519
- Ve as MANIFEST
518
+ X as FileUpload,
519
+ Ie as MANIFEST
520
520
  };
@@ -0,0 +1,155 @@
1
+ (function(n,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("@sps-woodland/core"),require("@spscommerce/utils"),require("@spscommerce/ds-react"),require("@spscommerce/ds-shared")):typeof define=="function"&&define.amd?define(["exports","react","@sps-woodland/core","@spscommerce/utils","@spscommerce/ds-react","@spscommerce/ds-shared"],g):(n=typeof globalThis<"u"?globalThis:n||self,g(n.FileUpload={},n.React,n.core,n.utils,n.dsReact,n.dsShared))})(this,function(n,g,w,d,M,y){"use strict";function q(t){if(t&&t.__esModule)return t;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const i=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(l,a,i.get?i:{enumerable:!0,get:()=>t[a]})}}return l.default=t,Object.freeze(l)}const e=q(g),A={"7Z":["application/x-7z-compressed"],AAC:["audio/aac"],ABW:["application/x-abiword"],ARC:["application/octet-stream"],AVI:["video/x-msvideo"],AZW:["application/vnd.amazon.ebook"],BIN:["application/octet-stream"],BMP:["image/bmp"],BZ:["application/x-bzip"],BZ2:["application/x-bzip2"],CER:["application/pkix-cert","application/x-x509-ca-cert"],CSH:["application/x-csh"],CSS:["text/css"],CSV:["text/csv,application/vnd.ms-excel"],DOC:["application/msword"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],EOT:["application/vnd.ms-fontobject"],EPUB:["application/epub+zip"],ES:["application/ecmascript"],FLV:["video/x-flv"],GIF:["image/gif"],GZ:["application/x-gzip"],HTM:["text/html"],HTML:["text/html"],ICO:["image/x-icon"],ICS:["text/calendar"],JAR:["application/java-archive"],JPEG:["image/jpeg"],JPG:["image/jpeg"],JS:["application/javascript"],JSON:["application/json"],M3U:["audio/x-mpequrl"],MID:["audio/midi"],MIDI:["audio/midi"],MOV:["video/quicktime"],MP3:["audio/mpeg3"],MP4:["video/mp4"],MPEG:["video/mpeg"],MPKG:["application/vnd.apple.installer+xml"],ODP:["application/vnd.oasis.opendocument.presentation"],ODS:["application/vnd.oasis.opendocument.spreadsheet"],ODT:["application/vnd.oasis.opendocument.text"],OGA:["audio/ogg"],OGV:["video/ogg"],OGX:["application/ogg"],OTF:["font/otf"],PNG:["image/png"],PDF:["application/pdf"],PPT:["application/vnd.ms-powerpoint"],PPTX:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],RAR:["application/x-rar-compressed"],RTF:["application/rtf"],SH:["application/x-sh"],SVG:["image/svg+xml"],SWF:["application/x-shockwave-flash"],TAR:["application/x-tar"],TIF:["image/tiff"],TIFF:["image/tiff"],TS:["application/typescript"],TTF:["font/ttf"],TXT:["text/plain"],VSD:["application/vnd.visio"],WAV:["audio/wav"],WEBA:["audio/webm"],WEBM:["video/webm"],WEBP:["image/webp"],WOFF:["font/woff"],WOFF2:["font/woff2"],XHTML:["application/xhtml+xml"],XLS:["application/vnd.ms-excel"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]},je="";function K(t,l,a){return l in t?Object.defineProperty(t,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[l]=a,t}function I(t,l){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);l&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),a.push.apply(a,i)}return a}function B(t){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?I(Object(a),!0).forEach(function(i){K(t,i,a[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):I(Object(a)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(a,i))})}return t}var Z=(t,l,a)=>{for(var i of Object.keys(t)){var s;if(t[i]!==((s=l[i])!==null&&s!==void 0?s:a[i]))return!1}return!0},S=t=>l=>{var a=t.defaultClassName,i=B(B({},t.defaultVariants),l);for(var s in i){var v,F=(v=i[s])!==null&&v!==void 0?v:t.defaultVariants[s];if(F!=null){var c=F;typeof c=="boolean"&&(c=c===!0?"true":"false");var f=t.variantClassNames[s][c];f&&(a+=" "+f)}}for(var[b,D]of t.compoundVariants)Z(b,i,t.defaultVariants)&&(a+=" "+D);return a},H="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwm",V="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwn",J="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwl",Y=S({defaultClassName:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw0",variantClassNames:{active:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw1",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw2"},mini:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw3",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw4"},error:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw5",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw6"},shown:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw7",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw8"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0},compoundVariants:[]}),Q="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwq",$=S({defaultClassName:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw9",variantClassNames:{constrainContentWidth:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwa",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwb"}},defaultVariants:{constrainContentWidth:!1},compoundVariants:[]}),ee="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwp",te="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwr",oe=S({defaultClassName:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwd",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwe",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwf"},error:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwg",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwh"}},defaultVariants:{mini:!1,error:!1},compoundVariants:[]}),W="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwc",ae="pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwo",ie=S({defaultClassName:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwi",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwj",false:"pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwk"}},defaultVariants:{mini:!1},compoundVariants:[]});function k({constrainContentWidth:t,description:l,multiple:a=!1,dismissable:i,processing:s,mini:v,downloadLabel:F,acceptExtensions:c,maxSize:f,customRequirement:b,onSelection:D,onDismiss:z,download:L,shown:E,className:ne,children:ke,...se}){const U=e.useRef(new Set),[re,R]=e.useState(E),[De,pe]=e.useState([]),[de,ce]=e.useState(""),[X,fe]=e.useState(),[ue,C]=e.useState(!1),[x,j]=e.useState(!1),[T,G]=e.useState([]),[_e,me]=e.useState(""),{t:h}=e.useContext(w.I18nContext),N=h(a?"design-system:fileUpload.instructions_plural":"design-system:fileUpload.instructions").split("|"),he=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{E&&R(E)},[E]),e.useEffect(()=>{f&&we(f)},[f]),e.useEffect(()=>{c&&ge(c)},[c]);function ve(){i&&(R(!1),z&&z())}function we(o){try{fe(d.parseFileSize(o))}catch{throw new Error(`Could not parse "${o}" as a file size.`)}}function ge(o){const _=(Array.isArray(o)?o:o.trim().split(/\s?,\s?/)).map(m=>m.replace(/^\./,"")),p=_.map(m=>`.${m}`.toLowerCase());me(p.map((m,O)=>O>0&&O===p.length-1?`or ${m}`:m).join(p.length>2?", ":" ")),U.current.clear();for(const m of _){const O=Object.keys(A).includes(m.toUpperCase())?A[m.toUpperCase()]:[];for(const Ce of O)U.current.add(Ce)}ce(p.concat(Array.from(U.current)).join(","))}function P(o){G([]);let r=[];const _=Array.from(o);for(const p of _)p===null?r.push("Not a file"):(c&&!U.current.has(p.type)&&r.push(p.name),f&&X&&p.size>X&&r.indexOf(p.name)===-1&&r.push(p.name));r.length?(j(!0),u.current&&u.current.value&&(u.current.value="")):(pe(_),D(_)),G(r)}function Fe(o){o.preventDefault(),j(!1),u.current&&u.current.click()}function xe(){L&&L()}function ye(o){o.stopPropagation(),P(o.target.files||[]),u.current&&u.current.value&&(u.current.value="")}function Se(o){o.preventDefault(),o.stopPropagation(),C(!0),j(!1)}function be(o){o.preventDefault(),C(!0),j(!1)}function Ee(o){o.preventDefault(),C(!1)}function Ue(o){o.preventDefault(),o.stopPropagation(),C(!1),o.dataTransfer.items?P(Array.from(o.dataTransfer.items).map(r=>r.getAsFile())):P(o.dataTransfer.files)}return e.createElement("div",{onDrop:Ue,onDragOver:Se,onDragLeave:Ee,onDragEnter:be,className:w.cl(Y({active:ue,mini:v,error:x,shown:re}),ne),...se},e.createElement("div",{className:w.cl($({constrainContentWidth:t}))},s?e.createElement("div",null,e.createElement(w.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:W},h("design-system:fileUpload.processing"))):e.createElement("div",null,e.createElement(w.Icon,{className:oe({mini:v,error:x}),icon:x?"exclamation-circle":"upload-cloud","aria-hidden":"true"}),e.createElement("div",{className:ie({mini:v})},x?e.createElement("div",null,h(T.length>1?"design-system:fileUpload.cancelled_plural":"design-system:fileUpload.cancelled")):e.createElement("div",null,h("design-system:fileUpload.title",{description:he}))),x?e.createElement("div",{className:J},new Set(T.map((o,r)=>{const _=Math.floor(o.length/2);return e.createElement("div",{className:H,key:o},e.createElement("span",{className:V},o.substr(0,_)),e.createElement("div",{className:V},e.createElement("span",null,o.substr(_))),r<T.length-1?",":"")}))):e.createElement("span",null),e.createElement("div",{className:W},e.createElement("div",null,e.createElement("span",null,N[0]),e.createElement("a",{href:"",onClick:Fe},N[1]),e.createElement("span",null,N[2]))),e.createElement("div",{className:ae},c?e.createElement("span",null,"("," ",h("design-system:fileUpload.acceptedTypes",{fileTypes:_e})," ",")"):"",f?e.createElement("span",null,"( ",h("design-system:fileUpload.maximumSize",{size:f})," )"):"",b?e.createElement("span",null," ",b," "):""),F&&e.createElement("div",{className:ee},e.createElement(M.SpsButton,{kind:y.ButtonKind.LINK,icon:y.SpsIcon.DOWNLOAD_CLOUD,onClick:xe},F)))),i&&!s&&e.createElement("div",{className:Q},e.createElement(M.SpsButton,{kind:y.ButtonKind.ICON,icon:y.SpsIcon.X,title:h("design-system:fileUpload.close"),onClick:ve})),e.createElement("form",{className:te},e.createElement("input",{ref:u,type:"file",accept:de||"*/*",multiple:a||void 0,onChange:ye})))}w.Metadata.set(k,{name:"FileUpload",props:{constrainContentWidth:{type:"boolean"},description:{type:"string"},multiple:{type:"boolean"},dismissable:{type:"boolean"},mini:{type:"boolean"},downloadLabel:{type:"string"},acceptExtensions:{type:"string[] | string"},maxSize:{type:"string"},customRequirement:{type:"string"},onSelection:{type:"(files: File[]) => void",required:!0},dismissal:{type:"() => void"},download:{type:"() => void"}}});const le={"File Upload":{components:[k],examples:{basic:{label:"Basic File Upload",description:"Simply allow the user to drag-and-drop or select a single file or multiple files at once.",examples:{basic:{description:"Single file upload",react:d.code`
2
+ import { FileUpload } from "@sps-woodland/file-upload";
3
+
4
+ function Component() {
5
+ function selectFile(file) {
6
+ console.log(file);
7
+ }
8
+
9
+ return (
10
+ <FileUpload onSelection={selectFile} />
11
+ )
12
+ }
13
+ `},multiple:{description:"Multiple file upload",react:d.code`
14
+ import { FileUpload } from "@sps-woodland/file-upload";
15
+
16
+ function Component() {
17
+ function selectFile(file) {
18
+ console.log(file);
19
+ }
20
+
21
+ return (
22
+ <FileUpload onSelection={selectFile} multiple />
23
+ )
24
+ }
25
+ `}}},restrictions:{label:"Restrictions",description:"You can place restrictions on what files will be accepted with an extension whitelist and/or a maximum size.",examples:{maxSize:{description:"Maximum size",react:d.code`
26
+ import { FileUpload } from "@sps-woodland/file-upload";
27
+
28
+ function Component() {
29
+ function selectFile(file) {
30
+ console.log(file);
31
+ }
32
+
33
+ return (
34
+ <FileUpload onSelection={selectFile} maxSize="100KB" />
35
+ )
36
+ }
37
+ `},fileWhitelist:{description:"File type whitelist",react:d.code`
38
+ import { FileUpload } from "@sps-woodland/file-upload";
39
+
40
+ function Component() {
41
+ function selectFile(file) {
42
+ console.log(file);
43
+ }
44
+
45
+ return (
46
+ <FileUpload
47
+ description="Spreadsheets"
48
+ onSelection={selectFile}
49
+ acceptExtensions="XLS, xlsx, .csv"
50
+ multiple
51
+ />
52
+ )
53
+ }
54
+ `},bothRestrictions:{description:"Both restrictions",react:d.code`
55
+ import { FileUpload } from "@sps-woodland/file-upload";
56
+
57
+ function Component() {
58
+ function selectFile(file) {
59
+ console.log(file);
60
+ }
61
+
62
+ return (
63
+ <FileUpload
64
+ description="Spreadsheets"
65
+ onSelection={selectFile}
66
+ acceptExtensions="XLS, xlsx, .csv"
67
+ maxSize="100KB"
68
+ multiple
69
+ />
70
+ )
71
+ }
72
+ `}}},dismissable:{label:"Dismissable",description:"With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can show it again programmatically if you need to.",examples:{basic:{react:d.code`
73
+ import { FileUpload } from "@sps-woodland/file-upload";
74
+
75
+ function Component() {
76
+ const [showFileUpload, setShowFileUpload] = React.useState(true);
77
+ function handleDismissal() {
78
+ setShowFileUpload(false);
79
+ }
80
+
81
+ function selectFile(file) {
82
+ console.log(file);
83
+ }
84
+
85
+ return (
86
+ <>
87
+ <FileUpload
88
+ onSelection={selectFile}
89
+ dismissable
90
+ onDismiss={handleDismissal}
91
+ shown={showFileUpload}
92
+ />
93
+ {!showFileUpload && (
94
+ <SpsButton onClick={() => setShowFileUpload(true)}>
95
+ Reset
96
+ </SpsButton>
97
+ )}
98
+ </>
99
+ )
100
+ }
101
+ `}}},download:{label:"Download Button",description:"You can optionally provide a button to download a file. Typically this will be a template for whatever the user is expected to upload. They can then fill out the template, save it, and upload it.",examples:{basic:{react:d.code`
102
+ import { FileUpload } from "@sps-woodland/file-upload";
103
+
104
+ function Component() {
105
+ function selectFile(file) {
106
+ console.log(file);
107
+ }
108
+
109
+ function handleDownload() {
110
+ console.log("Download triggered");
111
+ }
112
+
113
+ return (
114
+ <FileUpload
115
+ onSelection={selectFile}
116
+ description="Spreadsheet"
117
+ acceptExtensions="xlsx"
118
+ downloadLabel="Download Excel Template"
119
+ download={handleDownload}
120
+ />
121
+ )
122
+ }
123
+ `}}},mini:{label:"Mini File Upload",description:"When the file upload component is to be placed in a small container, it should be marked as a mini file upload so that everything fits.",examples:{basic:{react:d.code`
124
+ import { FileUpload } from "@sps-woodland/file-upload";
125
+
126
+ function Component() {
127
+ function selectFile(file) {
128
+ console.log(file);
129
+ }
130
+
131
+ return (
132
+ <div className={grid.root}>
133
+ <div className={grid[4]}>
134
+ <FileUpload onSelection={selectFile} mini />
135
+ </div>
136
+ </div>
137
+ )
138
+ }
139
+ `}}},constrainContentWidth:{label:"Constrain Content Width",description:"If this prop is provided, the content will be restricted to 50% of the overall width of the component. Consult your product designer if you're not sure whether to use this variant.",examples:{basic:{react:d.code`
140
+ import { FileUpload } from "@sps-woodland/file-upload";
141
+
142
+ function Component() {
143
+ function selectFile(file) {
144
+ console.log(file);
145
+ }
146
+
147
+ return (
148
+ <div className={grid.root}>
149
+ <div className={grid[4]}>
150
+ <FileUpload onSelection={selectFile} constrainContentWidth />
151
+ </div>
152
+ </div>
153
+ )
154
+ }
155
+ `}}}}}};n.FileUpload=k,n.MANIFEST=le,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/lib/style.css CHANGED
@@ -1 +1 @@
1
- .rh07jw0{border-width:.0625rem;border-style:dashed;border-radius:.25rem;display:block;padding:1rem;position:relative}.rh07jw1{background-color:#f4ecf2;border-color:#91467f;border-style:solid}.rh07jw3{padding:1rem}.rh07jw5{border-color:#de002e}.rh07jw8{display:none}.rh07jw9{color:#4b5356;margin:0 auto;text-align:center}.rh07jwa{width:50%}.rh07jwc{font-size:.75rem;line-height:1.25rem}.rh07jwd{color:#717779;display:block;margin-bottom:.25rem}.rh07jwe{font-size:1.5rem;line-height:1.5rem}.rh07jwf{font-size:3rem;line-height:3rem}.rh07jwg{color:#de002e}.rh07jwi{font-weight:600;margin-bottom:.25rem}.rh07jwj{font-size:1rem;line-height:1.25rem}.rh07jwk{font-size:1.125rem;line-height:1.25rem}.rh07jwl{font-size:.875rem;font-weight:600;line-height:1.25rem}.rh07jwm{display:flex;justify-content:center;white-space:nowrap}.rh07jwn{max-width:50%;overflow:hidden}.rh07jwn:first-child{text-overflow:ellipsis}.rh07jwn:last-child{float:right}.rh07jwo{font-size:.75rem;line-height:1.125rem;margin-top:.25rem}.rh07jwo>span+span{margin-left:.125rem}.rh07jwp{margin-top:1rem}.rh07jwq{position:absolute;right:.5rem;top:.5rem}.rh07jwr{display:none}
1
+ .pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw0{border-width:.0625rem;border-style:dashed;border-radius:.25rem;display:block;padding:1rem;position:relative}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw1{background-color:#f4ecf2;border-color:#91467f;border-style:solid}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw3{padding:1rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw5{border-color:#de002e}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw8{display:none}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jw9{color:#4b5356;margin:0 auto;text-align:center}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwa{width:50%}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwc{font-size:.75rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwd{color:#717779;display:block;margin-bottom:.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwe{font-size:1.5rem;line-height:1.5rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwf{font-size:3rem;line-height:3rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwg{color:#de002e}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwi{font-weight:600;margin-bottom:.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwj{font-size:1rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwk{font-size:1.125rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwl{font-size:.875rem;font-weight:600;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwm{display:flex;justify-content:center;white-space:nowrap}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwn{max-width:50%;overflow:hidden}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwn:first-child{text-overflow:ellipsis}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwn:last-child{float:right}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwo{font-size:.75rem;line-height:1.125rem;margin-top:.25rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwo>span+span{margin-left:.125rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwp{margin-top:1rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwq{position:absolute;right:.5rem;top:.5rem}.pkg_sps-woodland_file-upload__version_7_19_0__hash_rh07jwr{display:none}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@sps-woodland/file-upload",
3
3
  "description": "SPS Woodland Design System file upload component",
4
- "version": "7.17.13",
4
+ "version": "7.19.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/file-upload",
8
8
  "homepage": "https://github.com/SPSCommerce/woodland/tree/master/packages/@sps-woodland/file-upload#readme",
9
- "module": "./lib/index.es.js",
10
9
  "type": "module",
11
- "main": "./lib/index.cjs.js",
10
+ "module": "./lib/index.js",
11
+ "main": "./lib/index.umd.cjs",
12
12
  "types": "./lib/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./lib/index.es.js",
16
- "require": "./lib/index.cjs.js",
17
- "default": "./lib/index.cjs.js",
15
+ "require": "./lib/index.umd.cjs",
16
+ "import": "./lib/index.js",
17
+ "default": "./lib/index.js",
18
18
  "types": "./lib/index.d.ts"
19
19
  },
20
20
  "./lib/style.css": {
@@ -30,11 +30,11 @@
30
30
  "@spscommerce/utils": "^6.12.1",
31
31
  "react": "^16.14.0",
32
32
  "react-dom": "^16.14.0",
33
- "@spscommerce/ds-colors": "7.17.13",
34
- "@sps-woodland/core": "7.17.13",
35
- "@spscommerce/ds-react": "7.17.13",
36
- "@sps-woodland/tokens": "7.17.13",
37
- "@spscommerce/ds-shared": "7.17.13"
33
+ "@sps-woodland/core": "7.19.0",
34
+ "@spscommerce/ds-colors": "7.19.0",
35
+ "@spscommerce/ds-shared": "7.19.0",
36
+ "@sps-woodland/tokens": "7.19.0",
37
+ "@spscommerce/ds-react": "7.19.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@spscommerce/ds-illustrations": "6.37.3",
@@ -43,11 +43,11 @@
43
43
  "@vanilla-extract/recipes": "^0.2.5",
44
44
  "react": "^16.14.0",
45
45
  "react-dom": "^16.14.0",
46
- "@spscommerce/ds-react": "7.17.13",
47
- "@sps-woodland/tokens": "7.17.13",
48
- "@sps-woodland/core": "7.17.13",
49
- "@spscommerce/ds-colors": "7.17.13",
50
- "@spscommerce/ds-shared": "7.17.13"
46
+ "@spscommerce/ds-react": "7.19.0",
47
+ "@sps-woodland/tokens": "7.19.0",
48
+ "@sps-woodland/core": "7.19.0",
49
+ "@spscommerce/ds-colors": "7.19.0",
50
+ "@spscommerce/ds-shared": "7.19.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "pnpm run build:js && pnpm run build:types",
package/vite.config.js CHANGED
@@ -1,16 +1,25 @@
1
1
  import path from "path";
2
2
  import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
3
3
  import { defineConfig } from "vite";
4
-
4
+ import { getVanillaExtractPluginProps } from "../../../scripts/vanilla-extract-plugin-props.js";
5
5
  import pkg from "./package.json";
6
6
 
7
+ const packageVersion = process.env.PREDICTED_VERSION || pkg.version;
8
+
7
9
  export default defineConfig({
8
- plugins: [vanillaExtractPlugin()],
10
+ plugins: [
11
+ vanillaExtractPlugin(
12
+ getVanillaExtractPluginProps({
13
+ packageName: pkg.name,
14
+ packageVersion,
15
+ })
16
+ ),
17
+ ],
9
18
  build: {
10
19
  lib: {
11
20
  entry: path.resolve(__dirname, "src/index.ts"),
12
- formats: ["es", "cjs"],
13
- fileName: (format) => `index.${format}.js`,
21
+ name: "FileUpload",
22
+ fileName: "index",
14
23
  },
15
24
  outDir: path.resolve(__dirname, "./lib"),
16
25
  emptyOutDir: false,
package/lib/index.cjs.js DELETED
@@ -1,155 +0,0 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ue=require("react"),w=require("@sps-woodland/core"),p=require("@spscommerce/utils"),R=require("@spscommerce/ds-react"),C=require("@spscommerce/ds-shared");function fe(t){if(t&&t.__esModule)return t;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(l,a,o.get?o:{enumerable:!0,get:()=>t[a]})}}return l.default=t,Object.freeze(l)}const e=fe(ue),W={"7Z":["application/x-7z-compressed"],AAC:["audio/aac"],ABW:["application/x-abiword"],ARC:["application/octet-stream"],AVI:["video/x-msvideo"],AZW:["application/vnd.amazon.ebook"],BIN:["application/octet-stream"],BMP:["image/bmp"],BZ:["application/x-bzip"],BZ2:["application/x-bzip2"],CER:["application/pkix-cert","application/x-x509-ca-cert"],CSH:["application/x-csh"],CSS:["text/css"],CSV:["text/csv,application/vnd.ms-excel"],DOC:["application/msword"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],EOT:["application/vnd.ms-fontobject"],EPUB:["application/epub+zip"],ES:["application/ecmascript"],FLV:["video/x-flv"],GIF:["image/gif"],GZ:["application/x-gzip"],HTM:["text/html"],HTML:["text/html"],ICO:["image/x-icon"],ICS:["text/calendar"],JAR:["application/java-archive"],JPEG:["image/jpeg"],JPG:["image/jpeg"],JS:["application/javascript"],JSON:["application/json"],M3U:["audio/x-mpequrl"],MID:["audio/midi"],MIDI:["audio/midi"],MOV:["video/quicktime"],MP3:["audio/mpeg3"],MP4:["video/mp4"],MPEG:["video/mpeg"],MPKG:["application/vnd.apple.installer+xml"],ODP:["application/vnd.oasis.opendocument.presentation"],ODS:["application/vnd.oasis.opendocument.spreadsheet"],ODT:["application/vnd.oasis.opendocument.text"],OGA:["audio/ogg"],OGV:["video/ogg"],OGX:["application/ogg"],OTF:["font/otf"],PNG:["image/png"],PDF:["application/pdf"],PPT:["application/vnd.ms-powerpoint"],PPTX:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],RAR:["application/x-rar-compressed"],RTF:["application/rtf"],SH:["application/x-sh"],SVG:["image/svg+xml"],SWF:["application/x-shockwave-flash"],TAR:["application/x-tar"],TIF:["image/tiff"],TIFF:["image/tiff"],TS:["application/typescript"],TTF:["font/ttf"],TXT:["text/plain"],VSD:["application/vnd.visio"],WAV:["audio/wav"],WEBA:["audio/webm"],WEBM:["video/webm"],WEBP:["image/webp"],WOFF:["font/woff"],WOFF2:["font/woff2"],XHTML:["application/xhtml+xml"],XLS:["application/vnd.ms-excel"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]};function me(t,l,a){return l in t?Object.defineProperty(t,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[l]=a,t}function z(t,l){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);l&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function L(t){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?z(Object(a),!0).forEach(function(o){me(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):z(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}var he=(t,l,a)=>{for(var o of Object.keys(t)){var n;if(t[o]!==((n=l[o])!==null&&n!==void 0?n:a[o]))return!1}return!0},j=t=>l=>{var a=t.defaultClassName,o=L(L({},t.defaultVariants),l);for(var n in o){var v,g=(v=o[n])!==null&&v!==void 0?v:t.defaultVariants[n];if(g!=null){var c=g;typeof c=="boolean"&&(c=c===!0?"true":"false");var d=t.variantClassNames[n][c];d&&(a+=" "+d)}}for(var[x,O]of t.compoundVariants)he(x,o,t.defaultVariants)&&(a+=" "+O);return a},ve="rh07jwm",k="rh07jwn",we="rh07jwl",ge=j({defaultClassName:"rh07jw0",variantClassNames:{active:{true:"rh07jw1",false:"rh07jw2"},mini:{true:"rh07jw3",false:"rh07jw4"},error:{true:"rh07jw5",false:"rh07jw6"},shown:{true:"rh07jw7",false:"rh07jw8"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0},compoundVariants:[]}),Fe="rh07jwq",xe=j({defaultClassName:"rh07jw9",variantClassNames:{constrainContentWidth:{true:"rh07jwa",false:"rh07jwb"}},defaultVariants:{constrainContentWidth:!1},compoundVariants:[]}),Se="rh07jwp",be="rh07jwr",ye=j({defaultClassName:"rh07jwd",variantClassNames:{mini:{true:"rh07jwe",false:"rh07jwf"},error:{true:"rh07jwg",false:"rh07jwh"}},defaultVariants:{mini:!1,error:!1},compoundVariants:[]}),X="rh07jwc",Ee="rh07jwo",Ue=j({defaultClassName:"rh07jwi",variantClassNames:{mini:{true:"rh07jwj",false:"rh07jwk"}},defaultVariants:{mini:!1},compoundVariants:[]});function P({constrainContentWidth:t,description:l,multiple:a=!1,dismissable:o,processing:n,mini:v,downloadLabel:g,acceptExtensions:c,maxSize:d,customRequirement:x,onSelection:O,onDismiss:M,download:A,shown:S,className:G,children:Oe,..._}){const b=e.useRef(new Set),[q,I]=e.useState(S),[De,K]=e.useState([]),[Z,H]=e.useState(""),[B,J]=e.useState(),[Y,y]=e.useState(!1),[F,E]=e.useState(!1),[D,V]=e.useState([]),[Q,$]=e.useState(""),{t:h}=e.useContext(w.I18nContext),N=h(a?"design-system:fileUpload.instructions_plural":"design-system:fileUpload.instructions").split("|"),ee=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{S&&I(S)},[S]),e.useEffect(()=>{d&&ie(d)},[d]),e.useEffect(()=>{c&&ae(c)},[c]);function te(){o&&(I(!1),M&&M())}function ie(i){try{J(p.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function ae(i){const f=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(m=>m.replace(/^\./,"")),r=f.map(m=>`.${m}`.toLowerCase());$(r.map((m,U)=>U>0&&U===r.length-1?`or ${m}`:m).join(r.length>2?", ":" ")),b.current.clear();for(const m of f){const U=Object.keys(W).includes(m.toUpperCase())?W[m.toUpperCase()]:[];for(const de of U)b.current.add(de)}H(r.concat(Array.from(b.current)).join(","))}function T(i){V([]);let s=[];const f=Array.from(i);for(const r of f)r===null?s.push("Not a file"):(c&&!b.current.has(r.type)&&s.push(r.name),d&&B&&r.size>B&&s.indexOf(r.name)===-1&&s.push(r.name));s.length?(E(!0),u.current&&u.current.value&&(u.current.value="")):(K(f),O(f)),V(s)}function oe(i){i.preventDefault(),E(!1),u.current&&u.current.click()}function le(){A&&A()}function ne(i){i.stopPropagation(),T(i.target.files||[]),u.current&&u.current.value&&(u.current.value="")}function se(i){i.preventDefault(),i.stopPropagation(),y(!0),E(!1)}function re(i){i.preventDefault(),y(!0),E(!1)}function ce(i){i.preventDefault(),y(!1)}function pe(i){i.preventDefault(),i.stopPropagation(),y(!1),i.dataTransfer.items?T(Array.from(i.dataTransfer.items).map(s=>s.getAsFile())):T(i.dataTransfer.files)}return e.createElement("div",{onDrop:pe,onDragOver:se,onDragLeave:ce,onDragEnter:re,className:w.cl(ge({active:Y,mini:v,error:F,shown:q}),G),..._},e.createElement("div",{className:w.cl(xe({constrainContentWidth:t}))},n?e.createElement("div",null,e.createElement(w.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:X},h("design-system:fileUpload.processing"))):e.createElement("div",null,e.createElement(w.Icon,{className:ye({mini:v,error:F}),icon:F?"exclamation-circle":"upload-cloud","aria-hidden":"true"}),e.createElement("div",{className:Ue({mini:v})},F?e.createElement("div",null,h(D.length>1?"design-system:fileUpload.cancelled_plural":"design-system:fileUpload.cancelled")):e.createElement("div",null,h("design-system:fileUpload.title",{description:ee}))),F?e.createElement("div",{className:we},new Set(D.map((i,s)=>{const f=Math.floor(i.length/2);return e.createElement("div",{className:ve,key:i},e.createElement("span",{className:k},i.substr(0,f)),e.createElement("div",{className:k},e.createElement("span",null,i.substr(f))),s<D.length-1?",":"")}))):e.createElement("span",null),e.createElement("div",{className:X},e.createElement("div",null,e.createElement("span",null,N[0]),e.createElement("a",{href:"",onClick:oe},N[1]),e.createElement("span",null,N[2]))),e.createElement("div",{className:Ee},c?e.createElement("span",null,"("," ",h("design-system:fileUpload.acceptedTypes",{fileTypes:Q})," ",")"):"",d?e.createElement("span",null,"( ",h("design-system:fileUpload.maximumSize",{size:d})," )"):"",x?e.createElement("span",null," ",x," "):""),g&&e.createElement("div",{className:Se},e.createElement(R.SpsButton,{kind:C.ButtonKind.LINK,icon:C.SpsIcon.DOWNLOAD_CLOUD,onClick:le},g)))),o&&!n&&e.createElement("div",{className:Fe},e.createElement(R.SpsButton,{kind:C.ButtonKind.ICON,icon:C.SpsIcon.X,title:h("design-system:fileUpload.close"),onClick:te})),e.createElement("form",{className:be},e.createElement("input",{ref:u,type:"file",accept:Z||"*/*",multiple:a||void 0,onChange:ne})))}w.Metadata.set(P,{name:"FileUpload",props:{constrainContentWidth:{type:"boolean"},description:{type:"string"},multiple:{type:"boolean"},dismissable:{type:"boolean"},mini:{type:"boolean"},downloadLabel:{type:"string"},acceptExtensions:{type:"string[] | string"},maxSize:{type:"string"},customRequirement:{type:"string"},onSelection:{type:"(files: File[]) => void",required:!0},dismissal:{type:"() => void"},download:{type:"() => void"}}});const Ce={components:[P],examples:{basic:{label:"Basic File Upload",description:"Simply allow the user to drag-and-drop or select a single file or multiple files at once.",examples:{basic:{description:"Single file upload",react:p.code`
2
- import { FileUpload } from "@sps-woodland/file-upload";
3
-
4
- function Component() {
5
- function selectFile(file) {
6
- console.log(file);
7
- }
8
-
9
- return (
10
- <FileUpload onSelection={selectFile} />
11
- )
12
- }
13
- `},multiple:{description:"Multiple file upload",react:p.code`
14
- import { FileUpload } from "@sps-woodland/file-upload";
15
-
16
- function Component() {
17
- function selectFile(file) {
18
- console.log(file);
19
- }
20
-
21
- return (
22
- <FileUpload onSelection={selectFile} multiple />
23
- )
24
- }
25
- `}}},restrictions:{label:"Restrictions",description:"You can place restrictions on what files will be accepted with an extension whitelist and/or a maximum size.",examples:{maxSize:{description:"Maximum size",react:p.code`
26
- import { FileUpload } from "@sps-woodland/file-upload";
27
-
28
- function Component() {
29
- function selectFile(file) {
30
- console.log(file);
31
- }
32
-
33
- return (
34
- <FileUpload onSelection={selectFile} maxSize="100KB" />
35
- )
36
- }
37
- `},fileWhitelist:{description:"File type whitelist",react:p.code`
38
- import { FileUpload } from "@sps-woodland/file-upload";
39
-
40
- function Component() {
41
- function selectFile(file) {
42
- console.log(file);
43
- }
44
-
45
- return (
46
- <FileUpload
47
- description="Spreadsheets"
48
- onSelection={selectFile}
49
- acceptExtensions="XLS, xlsx, .csv"
50
- multiple
51
- />
52
- )
53
- }
54
- `},bothRestrictions:{description:"Both restrictions",react:p.code`
55
- import { FileUpload } from "@sps-woodland/file-upload";
56
-
57
- function Component() {
58
- function selectFile(file) {
59
- console.log(file);
60
- }
61
-
62
- return (
63
- <FileUpload
64
- description="Spreadsheets"
65
- onSelection={selectFile}
66
- acceptExtensions="XLS, xlsx, .csv"
67
- maxSize="100KB"
68
- multiple
69
- />
70
- )
71
- }
72
- `}}},dismissable:{label:"Dismissable",description:"With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can show it again programmatically if you need to.",examples:{basic:{react:p.code`
73
- import { FileUpload } from "@sps-woodland/file-upload";
74
-
75
- function Component() {
76
- const [showFileUpload, setShowFileUpload] = React.useState(true);
77
- function handleDismissal() {
78
- setShowFileUpload(false);
79
- }
80
-
81
- function selectFile(file) {
82
- console.log(file);
83
- }
84
-
85
- return (
86
- <>
87
- <FileUpload
88
- onSelection={selectFile}
89
- dismissable
90
- onDismiss={handleDismissal}
91
- shown={showFileUpload}
92
- />
93
- {!showFileUpload && (
94
- <SpsButton onClick={() => setShowFileUpload(true)}>
95
- Reset
96
- </SpsButton>
97
- )}
98
- </>
99
- )
100
- }
101
- `}}},download:{label:"Download Button",description:"You can optionally provide a button to download a file. Typically this will be a template for whatever the user is expected to upload. They can then fill out the template, save it, and upload it.",examples:{basic:{react:p.code`
102
- import { FileUpload } from "@sps-woodland/file-upload";
103
-
104
- function Component() {
105
- function selectFile(file) {
106
- console.log(file);
107
- }
108
-
109
- function handleDownload() {
110
- console.log("Download triggered");
111
- }
112
-
113
- return (
114
- <FileUpload
115
- onSelection={selectFile}
116
- description="Spreadsheet"
117
- acceptExtensions="xlsx"
118
- downloadLabel="Download Excel Template"
119
- download={handleDownload}
120
- />
121
- )
122
- }
123
- `}}},mini:{label:"Mini File Upload",description:"When the file upload component is to be placed in a small container, it should be marked as a mini file upload so that everything fits.",examples:{basic:{react:p.code`
124
- import { FileUpload } from "@sps-woodland/file-upload";
125
-
126
- function Component() {
127
- function selectFile(file) {
128
- console.log(file);
129
- }
130
-
131
- return (
132
- <div className={grid.root}>
133
- <div className={grid[4]}>
134
- <FileUpload onSelection={selectFile} mini />
135
- </div>
136
- </div>
137
- )
138
- }
139
- `}}},constrainContentWidth:{label:"Constrain Content Width",description:"If this prop is provided, the content will be restricted to 50% of the overall width of the component. Consult your product designer if you're not sure whether to use this variant.",examples:{basic:{react:p.code`
140
- import { FileUpload } from "@sps-woodland/file-upload";
141
-
142
- function Component() {
143
- function selectFile(file) {
144
- console.log(file);
145
- }
146
-
147
- return (
148
- <div className={grid.root}>
149
- <div className={grid[4]}>
150
- <FileUpload onSelection={selectFile} constrainContentWidth />
151
- </div>
152
- </div>
153
- )
154
- }
155
- `}}}}},je={"File Upload":Ce};exports.FileUpload=P;exports.MANIFEST=je;