@sps-woodland/file-upload 8.35.0 → 8.35.3
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.
- package/lib/FileUpload.css.d.ts +1 -0
- package/lib/index.js +166 -145
- package/lib/index.umd.cjs +11 -11
- package/lib/style.css +1 -1
- package/package.json +16 -16
package/lib/FileUpload.css.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ export declare const fileUploadTitle: import("@vanilla-extract/recipes/dist/decl
|
|
|
86
86
|
export declare const erroredFiles: string;
|
|
87
87
|
export declare const erroredFileName: string;
|
|
88
88
|
export declare const erroredFilenameSegment: string;
|
|
89
|
+
export declare const erroredFileMessage: string;
|
|
89
90
|
export declare const fileUploadRequirements: string;
|
|
90
91
|
export declare const fileUploadDownloadButton: string;
|
|
91
92
|
export declare const fileUploadCloseButton: string;
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
|
-
import { Metadata as
|
|
3
|
-
import { parseFileSize as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { GENERAL_ERROR_LARGE as
|
|
6
|
-
import { useWoodlandLanguage as
|
|
7
|
-
const
|
|
2
|
+
import { Metadata as ve, cl as I, Spinner as we } from "@sps-woodland/core";
|
|
3
|
+
import { parseFileSize as ge, code as _ } from "@spscommerce/utils";
|
|
4
|
+
import { Button as W } from "@sps-woodland/buttons";
|
|
5
|
+
import { GENERAL_ERROR_LARGE as Fe, UPLOAD_LARGE as Ee } from "@sps-woodland/illustrations";
|
|
6
|
+
import { useWoodlandLanguage as xe } from "@spscommerce/i18n";
|
|
7
|
+
const z = {
|
|
8
8
|
"7Z": ["application/x-7z-compressed"],
|
|
9
9
|
AAC: ["audio/aac"],
|
|
10
10
|
ABW: ["application/x-abiword"],
|
|
@@ -81,208 +81,229 @@ const R = {
|
|
|
81
81
|
XUL: ["application/vnd.mozilla.xul+xml"],
|
|
82
82
|
ZIP: ["application/zip"]
|
|
83
83
|
};
|
|
84
|
-
function
|
|
85
|
-
return i in
|
|
86
|
-
value:
|
|
84
|
+
function be(l, i, a) {
|
|
85
|
+
return i in l ? Object.defineProperty(l, i, {
|
|
86
|
+
value: a,
|
|
87
87
|
enumerable: !0,
|
|
88
88
|
configurable: !0,
|
|
89
89
|
writable: !0
|
|
90
|
-
}) :
|
|
90
|
+
}) : l[i] = a, l;
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
var
|
|
92
|
+
function G(l, i) {
|
|
93
|
+
var a = Object.keys(l);
|
|
94
94
|
if (Object.getOwnPropertySymbols) {
|
|
95
|
-
var t = Object.getOwnPropertySymbols(
|
|
96
|
-
i && (t = t.filter(function(
|
|
97
|
-
return Object.getOwnPropertyDescriptor(
|
|
98
|
-
})),
|
|
95
|
+
var t = Object.getOwnPropertySymbols(l);
|
|
96
|
+
i && (t = t.filter(function(r) {
|
|
97
|
+
return Object.getOwnPropertyDescriptor(l, r).enumerable;
|
|
98
|
+
})), a.push.apply(a, t);
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return a;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function X(l) {
|
|
103
103
|
for (var i = 1; i < arguments.length; i++) {
|
|
104
|
-
var
|
|
105
|
-
i % 2 ?
|
|
106
|
-
|
|
107
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(
|
|
108
|
-
Object.defineProperty(
|
|
104
|
+
var a = arguments[i] != null ? arguments[i] : {};
|
|
105
|
+
i % 2 ? G(Object(a), !0).forEach(function(t) {
|
|
106
|
+
be(l, t, a[t]);
|
|
107
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(l, Object.getOwnPropertyDescriptors(a)) : G(Object(a)).forEach(function(t) {
|
|
108
|
+
Object.defineProperty(l, t, Object.getOwnPropertyDescriptor(a, t));
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
return
|
|
111
|
+
return l;
|
|
112
112
|
}
|
|
113
|
-
var
|
|
114
|
-
for (var t of Object.keys(
|
|
115
|
-
var
|
|
116
|
-
if (
|
|
113
|
+
var Ue = (l, i, a) => {
|
|
114
|
+
for (var t of Object.keys(l)) {
|
|
115
|
+
var r;
|
|
116
|
+
if (l[t] !== ((r = i[t]) !== null && r !== void 0 ? r : a[t]))
|
|
117
117
|
return !1;
|
|
118
118
|
}
|
|
119
119
|
return !0;
|
|
120
|
-
},
|
|
121
|
-
var
|
|
122
|
-
for (var
|
|
123
|
-
var
|
|
124
|
-
if (
|
|
125
|
-
var p =
|
|
120
|
+
}, D = (l) => (i) => {
|
|
121
|
+
var a = l.defaultClassName, t = X(X({}, l.defaultVariants), i);
|
|
122
|
+
for (var r in t) {
|
|
123
|
+
var m, g = (m = t[r]) !== null && m !== void 0 ? m : l.defaultVariants[r];
|
|
124
|
+
if (g != null) {
|
|
125
|
+
var p = g;
|
|
126
126
|
typeof p == "boolean" && (p = p === !0 ? "true" : "false");
|
|
127
|
-
var
|
|
127
|
+
var s = (
|
|
128
128
|
// @ts-expect-error
|
|
129
|
-
|
|
129
|
+
l.variantClassNames[r][p]
|
|
130
130
|
);
|
|
131
|
-
|
|
131
|
+
s && (a += " " + s);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
for (var [
|
|
135
|
-
|
|
136
|
-
return
|
|
137
|
-
},
|
|
138
|
-
function
|
|
139
|
-
|
|
134
|
+
for (var [b, O] of l.compoundVariants)
|
|
135
|
+
Ue(b, t, l.defaultVariants) && (a += " " + O);
|
|
136
|
+
return a;
|
|
137
|
+
}, ye = D({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw0", variantClassNames: { active: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw1", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw2" }, mini: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw3", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw4" }, error: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw5", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw6" }, shown: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw7", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw8" }, disabled: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw9", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwa" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0, disabled: !1 }, compoundVariants: [] }), Se = D({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwb", variantClassNames: { constrainContentWidth: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwc", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwd" }, disabled: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwe", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwf" } }, defaultVariants: { constrainContentWidth: !1, disabled: !1 }, compoundVariants: [] }), Z = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwg", je = D({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwh", variantClassNames: { mini: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwi", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwj" }, error: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwk", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwl" }, disabled: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwm", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwn" } }, defaultVariants: { mini: !1, error: !1, disabled: !1 }, compoundVariants: [] }), Ce = D({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwo", variantClassNames: { mini: { true: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwp", false: "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwq" } }, defaultVariants: { mini: !1 }, compoundVariants: [] }), ke = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwr", De = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jws", $ = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwt", q = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwu", Oe = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwv", Te = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jww", Ne = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwx", Pe = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwy", Ve = "pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwz";
|
|
138
|
+
function H({ list: l }) {
|
|
139
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, l.map((i, a) => {
|
|
140
|
+
const t = Math.floor(i.length / 2);
|
|
141
|
+
return /* @__PURE__ */ e.createElement("div", { className: De, key: i }, /* @__PURE__ */ e.createElement("span", { className: $ }, i.substring(0, t)), /* @__PURE__ */ e.createElement("div", { className: $ }, /* @__PURE__ */ e.createElement("span", null, i.substring(t))), a < l.length - 1 ? "," : "");
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
function J({
|
|
145
|
+
constrainContentWidth: l,
|
|
140
146
|
description: i,
|
|
141
|
-
multiple:
|
|
147
|
+
multiple: a = !1,
|
|
142
148
|
dismissable: t,
|
|
143
|
-
processing:
|
|
144
|
-
mini:
|
|
145
|
-
downloadLabel:
|
|
149
|
+
processing: r,
|
|
150
|
+
mini: m,
|
|
151
|
+
downloadLabel: g,
|
|
146
152
|
acceptExtensions: p,
|
|
147
|
-
maxSize:
|
|
148
|
-
customRequirement:
|
|
149
|
-
onSelection:
|
|
150
|
-
onDismiss:
|
|
153
|
+
maxSize: s,
|
|
154
|
+
customRequirement: b,
|
|
155
|
+
onSelection: O,
|
|
156
|
+
onDismiss: T,
|
|
151
157
|
download: N,
|
|
152
|
-
shown:
|
|
153
|
-
className:
|
|
154
|
-
disabled:
|
|
155
|
-
children:
|
|
156
|
-
...
|
|
158
|
+
shown: U,
|
|
159
|
+
className: K,
|
|
160
|
+
disabled: d,
|
|
161
|
+
children: Me,
|
|
162
|
+
...Y
|
|
157
163
|
}) {
|
|
158
|
-
const
|
|
164
|
+
const y = e.useRef(/* @__PURE__ */ new Set()), [Q, P] = e.useState(U), [Ae, ee] = e.useState([]), [le, oe] = e.useState(""), [V, ae] = e.useState(), [te, S] = e.useState(!1), [F, j] = e.useState(!1), [h, L] = e.useState([]), [v, M] = e.useState([]), [E, ie] = e.useState(""), A = e.useMemo(() => (/* @__PURE__ */ new Set([...h, ...v])).size, [h, v]), { t: c } = xe(), C = (a ? c("fileUpload.instructions.other", {
|
|
165
|
+
defaultValue: "Drag and drop your files here or |browse for files| on your desktop."
|
|
166
|
+
}) : c("fileUpload.instructions.one", {
|
|
167
|
+
defaultValue: "Drag and drop your file here or |browse for a file| on your desktop."
|
|
168
|
+
})).split("|"), B = i || (a ? "Files" : "File"), f = e.useRef(null);
|
|
159
169
|
e.useEffect(() => {
|
|
160
|
-
|
|
161
|
-
}, [
|
|
162
|
-
|
|
163
|
-
}, [
|
|
164
|
-
p &&
|
|
170
|
+
U && P(U);
|
|
171
|
+
}, [U]), e.useEffect(() => {
|
|
172
|
+
s && se(s);
|
|
173
|
+
}, [s]), e.useEffect(() => {
|
|
174
|
+
p && re(p);
|
|
165
175
|
}, [p]);
|
|
166
|
-
function
|
|
167
|
-
t && (
|
|
176
|
+
function ne() {
|
|
177
|
+
t && (P(!1), T && T());
|
|
168
178
|
}
|
|
169
|
-
function
|
|
179
|
+
function se(o) {
|
|
170
180
|
try {
|
|
171
|
-
|
|
181
|
+
ae(ge(o));
|
|
172
182
|
} catch {
|
|
173
183
|
throw new Error(`Could not parse "${o}" as a file size.`);
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
|
-
function
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
),
|
|
181
|
-
for (const
|
|
182
|
-
const
|
|
183
|
-
for (const
|
|
184
|
-
|
|
186
|
+
function re(o) {
|
|
187
|
+
const w = (Array.isArray(o) ? o : o.trim().split(/\s?,\s?/)).map((n) => n.replace(/^\./, "")), u = w.map((n) => `.${n}`.toLowerCase());
|
|
188
|
+
ie(
|
|
189
|
+
u.map((n, k) => k > 0 && k === u.length - 1 ? `or ${n}` : n).join(u.length > 2 ? ", " : " ")
|
|
190
|
+
), y.current.clear();
|
|
191
|
+
for (const n of w) {
|
|
192
|
+
const k = Object.keys(z).includes(n.toUpperCase()) ? z[n.toUpperCase()] : [];
|
|
193
|
+
for (const he of k)
|
|
194
|
+
y.current.add(he);
|
|
185
195
|
}
|
|
186
|
-
|
|
196
|
+
oe(u.concat(Array.from(y.current)).join(","));
|
|
187
197
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
let
|
|
191
|
-
const u = Array.from(o);
|
|
192
|
-
for (const
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
function R(o) {
|
|
199
|
+
L([]), M([]);
|
|
200
|
+
let x = [], w = [];
|
|
201
|
+
const u = o ? Array.from(o) : [];
|
|
202
|
+
for (const n of u)
|
|
203
|
+
p && !y.current.has(n.type) && w.push(n.name), s && V && n.size > V && x.push(n.name);
|
|
204
|
+
x.length || w.length ? (j(!0), f.current && f.current.value && (f.current.value = "")) : (ee(u), O(u)), L(x), M(w);
|
|
195
205
|
}
|
|
196
|
-
function
|
|
197
|
-
o.preventDefault(),
|
|
206
|
+
function pe(o) {
|
|
207
|
+
o.preventDefault(), j(!1), f.current && f.current.click();
|
|
198
208
|
}
|
|
199
|
-
function
|
|
209
|
+
function de() {
|
|
200
210
|
N && N();
|
|
201
211
|
}
|
|
202
|
-
function
|
|
203
|
-
o.stopPropagation(),
|
|
212
|
+
function ce(o) {
|
|
213
|
+
o.stopPropagation(), R(o.target.files), f.current && f.current.value && (f.current.value = "");
|
|
204
214
|
}
|
|
205
|
-
function
|
|
206
|
-
o.preventDefault(), o.stopPropagation(),
|
|
215
|
+
function _e(o) {
|
|
216
|
+
o.preventDefault(), o.stopPropagation(), S(!0), j(!1);
|
|
207
217
|
}
|
|
208
|
-
function
|
|
209
|
-
o.preventDefault(),
|
|
218
|
+
function fe(o) {
|
|
219
|
+
o.preventDefault(), S(!0), j(!1);
|
|
210
220
|
}
|
|
211
|
-
function
|
|
212
|
-
o.preventDefault(),
|
|
221
|
+
function ue(o) {
|
|
222
|
+
o.preventDefault(), S(!1);
|
|
213
223
|
}
|
|
214
|
-
function
|
|
215
|
-
o.preventDefault(), o.stopPropagation(),
|
|
216
|
-
Array.from(o.dataTransfer.items).map(
|
|
217
|
-
(s) => s.getAsFile()
|
|
218
|
-
)
|
|
219
|
-
) : D(o.dataTransfer.files);
|
|
224
|
+
function me(o) {
|
|
225
|
+
o.preventDefault(), o.stopPropagation(), S(!1), o.dataTransfer.files && R(o.dataTransfer.files);
|
|
220
226
|
}
|
|
221
227
|
return /* @__PURE__ */ e.createElement(
|
|
222
228
|
"div",
|
|
223
229
|
{
|
|
224
|
-
onDrop:
|
|
225
|
-
} :
|
|
226
|
-
onDragOver:
|
|
227
|
-
} :
|
|
228
|
-
onDragLeave:
|
|
229
|
-
} :
|
|
230
|
-
onDragEnter:
|
|
231
|
-
} :
|
|
232
|
-
className:
|
|
233
|
-
...
|
|
230
|
+
onDrop: d ? () => {
|
|
231
|
+
} : me,
|
|
232
|
+
onDragOver: d ? () => {
|
|
233
|
+
} : _e,
|
|
234
|
+
onDragLeave: d ? () => {
|
|
235
|
+
} : ue,
|
|
236
|
+
onDragEnter: d ? () => {
|
|
237
|
+
} : fe,
|
|
238
|
+
className: I(ye({ active: te, mini: m, error: F, shown: Q, disabled: d }), K),
|
|
239
|
+
...Y
|
|
234
240
|
},
|
|
235
|
-
/* @__PURE__ */ e.createElement("div", { className:
|
|
241
|
+
/* @__PURE__ */ e.createElement("div", { className: I(Se({ constrainContentWidth: l, disabled: d })) }, r ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(we, { size: "md", "aria-hidden": "true" }), /* @__PURE__ */ e.createElement("div", { className: Z }, c("fileUpload.processing", { defaultValue: "Processing Upload..." }))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: je({ mini: m, error: F, disabled: d }), "aria-hidden": "true" }, /* @__PURE__ */ e.createElement(
|
|
236
242
|
"img",
|
|
237
243
|
{
|
|
238
|
-
className:
|
|
239
|
-
src:
|
|
244
|
+
className: Ve,
|
|
245
|
+
src: F ? Fe : Ee,
|
|
240
246
|
alt: "Upload Icon"
|
|
241
247
|
}
|
|
242
|
-
)), /* @__PURE__ */ e.createElement("div", { className:
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
))
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
248
|
+
)), /* @__PURE__ */ e.createElement("div", { className: Ce({ mini: m }) }, F ? /* @__PURE__ */ e.createElement("div", null, c(
|
|
249
|
+
A > 1 ? "fileUpload.cancelled.other" : "fileUpload.cancelled.one",
|
|
250
|
+
{
|
|
251
|
+
defaultValue: A > 1 ? "File Upload(s) Failed" : "File Upload Failed"
|
|
252
|
+
}
|
|
253
|
+
)) : /* @__PURE__ */ e.createElement("div", null, c("fileUpload.title", {
|
|
254
|
+
description: B,
|
|
255
|
+
defaultValue: `Upload your ${B}`
|
|
256
|
+
}))), F ? /* @__PURE__ */ e.createElement("div", { className: ke }, h.length > 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(H, { list: h }), /* @__PURE__ */ e.createElement("div", { className: q }, c(
|
|
257
|
+
h.length === 1 ? "fileUpload.error.tooLarge.one" : "fileUpload.error.tooLarge.other",
|
|
258
|
+
{
|
|
259
|
+
size: s,
|
|
260
|
+
defaultValue: h.length === 1 ? `Selected file is larger than the size limit of ${s}.` : `Selected files are larger than the size limit of ${s}.`
|
|
261
|
+
}
|
|
262
|
+
))), v.length > 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(H, { list: v }), /* @__PURE__ */ e.createElement("div", { className: q }, c(
|
|
263
|
+
v.length === 1 ? "fileUpload.error.wrongType.one" : "fileUpload.error.wrongType.other",
|
|
264
|
+
{
|
|
265
|
+
fileTypes: E,
|
|
266
|
+
defaultValue: v.length === 1 ? `Selected file is not an accepted file type: ${E}.` : `Selected files are not accepted file types: ${E}.`
|
|
267
|
+
}
|
|
268
|
+
)))) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", { className: Z }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("span", null, C[0]), d ? /* @__PURE__ */ e.createElement("u", null, C[1]) : /* @__PURE__ */ e.createElement("a", { href: "", onClick: pe }, C[1]), /* @__PURE__ */ e.createElement("span", null, C[2]))), /* @__PURE__ */ e.createElement("div", { className: Oe }, p ? /* @__PURE__ */ e.createElement("span", null, "(", " ", c("fileUpload.acceptedTypes", {
|
|
269
|
+
fileTypes: E,
|
|
270
|
+
defaultValue: `${E} format accepted`
|
|
271
|
+
}), " ", ")") : "", s ? /* @__PURE__ */ e.createElement("span", null, "(", " ", c("fileUpload.maximumSize", {
|
|
272
|
+
size: s,
|
|
273
|
+
defaultValue: `${s} maximum`
|
|
274
|
+
}), " ", ")") : "", b ? /* @__PURE__ */ e.createElement("span", null, " ", b, " ") : ""), g && /* @__PURE__ */ e.createElement("div", { className: Te }, /* @__PURE__ */ e.createElement(
|
|
275
|
+
W,
|
|
255
276
|
{
|
|
256
|
-
disabled:
|
|
277
|
+
disabled: d,
|
|
257
278
|
kind: "link",
|
|
258
279
|
icon: "download-cloud",
|
|
259
|
-
onClick:
|
|
280
|
+
onClick: de
|
|
260
281
|
},
|
|
261
|
-
|
|
282
|
+
g
|
|
262
283
|
)))),
|
|
263
|
-
t && !
|
|
264
|
-
|
|
284
|
+
t && !r && /* @__PURE__ */ e.createElement("div", { className: Ne }, /* @__PURE__ */ e.createElement(
|
|
285
|
+
W,
|
|
265
286
|
{
|
|
266
|
-
disabled:
|
|
287
|
+
disabled: d,
|
|
267
288
|
kind: "icon",
|
|
268
289
|
icon: "x",
|
|
269
|
-
title:
|
|
270
|
-
onClick:
|
|
290
|
+
title: c("fileUpload.close", { defaultValue: "Close" }),
|
|
291
|
+
onClick: ne
|
|
271
292
|
}
|
|
272
293
|
)),
|
|
273
|
-
/* @__PURE__ */ e.createElement("form", { className:
|
|
294
|
+
/* @__PURE__ */ e.createElement("form", { className: Pe }, /* @__PURE__ */ e.createElement(
|
|
274
295
|
"input",
|
|
275
296
|
{
|
|
276
297
|
ref: f,
|
|
277
298
|
type: "file",
|
|
278
|
-
accept:
|
|
279
|
-
multiple:
|
|
280
|
-
onChange:
|
|
299
|
+
accept: le || "*/*",
|
|
300
|
+
multiple: a || void 0,
|
|
301
|
+
onChange: ce
|
|
281
302
|
}
|
|
282
303
|
))
|
|
283
304
|
);
|
|
284
305
|
}
|
|
285
|
-
|
|
306
|
+
ve.set(J, {
|
|
286
307
|
name: "FileUpload",
|
|
287
308
|
props: {
|
|
288
309
|
constrainContentWidth: { type: "boolean" },
|
|
@@ -300,8 +321,8 @@ _e.set(X, {
|
|
|
300
321
|
disabled: { type: "boolean" }
|
|
301
322
|
}
|
|
302
323
|
});
|
|
303
|
-
const
|
|
304
|
-
components: [
|
|
324
|
+
const Le = {
|
|
325
|
+
components: [J],
|
|
305
326
|
examples: {
|
|
306
327
|
basic: {
|
|
307
328
|
label: "Basic File Upload",
|
|
@@ -554,10 +575,10 @@ const Oe = {
|
|
|
554
575
|
}
|
|
555
576
|
}
|
|
556
577
|
}
|
|
557
|
-
},
|
|
558
|
-
"File Upload":
|
|
578
|
+
}, Ge = {
|
|
579
|
+
"File Upload": Le
|
|
559
580
|
};
|
|
560
581
|
export {
|
|
561
|
-
|
|
562
|
-
|
|
582
|
+
J as FileUpload,
|
|
583
|
+
Ge as MANIFEST
|
|
563
584
|
};
|
package/lib/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(n,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("@sps-woodland/core"),require("@spscommerce/utils"),require("@sps-woodland/buttons"),require("@sps-woodland/illustrations"),require("@spscommerce/i18n")):typeof define=="function"&&define.amd?define(["exports","react","@sps-woodland/core","@spscommerce/utils","@sps-woodland/buttons","@sps-woodland/illustrations","@spscommerce/i18n"],g):(n=typeof globalThis<"u"?globalThis:n||self,g(n.FileUpload={},n.React,n.core,n.utils,n.buttons,n.illustrations,n.i18n))})(this,function(n,g,b,p,A,M,J){"use strict";function K(o){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const l in o)if(l!=="default"){const t=Object.getOwnPropertyDescriptor(o,l);Object.defineProperty(i,l,t.get?t:{enumerable:!0,get:()=>o[l]})}}return i.default=o,Object.freeze(i)}const e=K(g),V={"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"],EML:["application/octet-stream","message/rfc822","multipart/mixed","message/rfc5322","message/rfc6532"],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 Y(o,i,l){return i in o?Object.defineProperty(o,i,{value:l,enumerable:!0,configurable:!0,writable:!0}):o[i]=l,o}function B(o,i){var l=Object.keys(o);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(o);i&&(t=t.filter(function(s){return Object.getOwnPropertyDescriptor(o,s).enumerable})),l.push.apply(l,t)}return l}function R(o){for(var i=1;i<arguments.length;i++){var l=arguments[i]!=null?arguments[i]:{};i%2?B(Object(l),!0).forEach(function(t){Y(o,t,l[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(l)):B(Object(l)).forEach(function(t){Object.defineProperty(o,t,Object.getOwnPropertyDescriptor(l,t))})}return o}var $=(o,i,l)=>{for(var t of Object.keys(o)){var s;if(o[t]!==((s=i[t])!==null&&s!==void 0?s:l[t]))return!1}return!0},E=o=>i=>{var l=o.defaultClassName,t=R(R({},o.defaultVariants),i);for(var s in t){var v,F=(v=t[s])!==null&&v!==void 0?v:o.defaultVariants[s];if(F!=null){var c=F;typeof c=="boolean"&&(c=c===!0?"true":"false");var _=o.variantClassNames[s][c];_&&(l+=" "+_)}}for(var[U,N]of o.compoundVariants)$(U,t,o.defaultVariants)&&(l+=" "+N);return l},Q=E({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw0",variantClassNames:{active:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw1",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw2"},mini:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw3",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw4"},error:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw5",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw6"},shown:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw7",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw8"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jw9",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwa"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0,disabled:!1},compoundVariants:[]}),ee=E({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwb",variantClassNames:{constrainContentWidth:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwc",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwd"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwe",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwf"}},defaultVariants:{constrainContentWidth:!1,disabled:!1},compoundVariants:[]}),I="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwg",oe=E({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwh",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwi",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwj"},error:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwk",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwl"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwm",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwn"}},defaultVariants:{mini:!1,error:!1,disabled:!1},compoundVariants:[]}),ae=E({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwo",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwp",false:"pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwq"}},defaultVariants:{mini:!1},compoundVariants:[]}),le="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwr",te="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jws",L="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwt",ie="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwu",ne="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwv",se="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jww",re="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwx",pe="pkg_sps-woodland_file-upload__version_8_35_0__hash_rh07jwy";function T({constrainContentWidth:o,description:i,multiple:l=!1,dismissable:t,processing:s,mini:v,downloadLabel:F,acceptExtensions:c,maxSize:_,customRequirement:U,onSelection:N,onDismiss:W,download:z,shown:y,className:ce,disabled:f,children:Te,..._e}){const S=e.useRef(new Set),[fe,G]=e.useState(y),[Ne,ue]=e.useState([]),[me,he]=e.useState(""),[X,we]=e.useState(),[ve,j]=e.useState(!1),[x,k]=e.useState(!1),[C,q]=e.useState([]),[Z,ge]=e.useState(""),{t:w}=J.useWoodlandLanguage(),O=(l?w("fileUpload.instructions.other",{defaultValue:"Drag and drop your files here or |browse for files| on your desktop."}):w("fileUpload.instructions.one",{defaultValue:"Drag and drop your file here or |browse for a file| on your desktop."})).split("|"),H=i||(l?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{y&&G(y)},[y]),e.useEffect(()=>{_&&xe(_)},[_]),e.useEffect(()=>{c&&be(c)},[c]);function Fe(){t&&(G(!1),W&&W())}function xe(a){try{we(p.parseFileSize(a))}catch{throw new Error(`Could not parse "${a}" as a file size.`)}}function be(a){const m=(Array.isArray(a)?a:a.trim().split(/\s?,\s?/)).map(h=>h.replace(/^\./,"")),d=m.map(h=>`.${h}`.toLowerCase());ge(d.map((h,D)=>D>0&&D===d.length-1?`or ${h}`:h).join(d.length>2?", ":" ")),S.current.clear();for(const h of m){const D=Object.keys(V).includes(h.toUpperCase())?V[h.toUpperCase()]:[];for(const Oe of D)S.current.add(Oe)}he(d.concat(Array.from(S.current)).join(","))}function P(a){q([]);let r=[];const m=Array.from(a);for(const d of m)d===null?r.push("Not a file"):(c&&!S.current.has(d.type)&&r.push(d.name),_&&X&&d.size>X&&r.indexOf(d.name)===-1&&r.push(d.name));r.length?(k(!0),u.current&&u.current.value&&(u.current.value="")):(ue(m),N(m)),q(r)}function Ee(a){a.preventDefault(),k(!1),u.current&&u.current.click()}function Ue(){z&&z()}function ye(a){a.stopPropagation(),P(a.target.files||[]),u.current&&u.current.value&&(u.current.value="")}function Se(a){a.preventDefault(),a.stopPropagation(),j(!0),k(!1)}function je(a){a.preventDefault(),j(!0),k(!1)}function ke(a){a.preventDefault(),j(!1)}function Ce(a){a.preventDefault(),a.stopPropagation(),j(!1),a.dataTransfer.items?P(Array.from(a.dataTransfer.items).map(r=>r.getAsFile())):P(a.dataTransfer.files)}return e.createElement("div",{onDrop:f?()=>{}:Ce,onDragOver:f?()=>{}:Se,onDragLeave:f?()=>{}:ke,onDragEnter:f?()=>{}:je,className:b.cl(Q({active:ve,mini:v,error:x,shown:fe,disabled:f}),ce),..._e},e.createElement("div",{className:b.cl(ee({constrainContentWidth:o,disabled:f}))},s?e.createElement("div",null,e.createElement(b.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:I},w("fileUpload.processing",{defaultValue:"Processing Upload..."}))):e.createElement("div",null,e.createElement("div",{className:oe({mini:v,error:x,disabled:f}),"aria-hidden":"true"},e.createElement("img",{className:pe,src:x?M.GENERAL_ERROR_LARGE:M.UPLOAD_LARGE,alt:"Upload Icon"})),e.createElement("div",{className:ae({mini:v})},x?e.createElement("div",null,w(C.length>1?"fileUpload.cancelled.other":"fileUpload.cancelled.one",{defaultValue:C.length>1?"File Upload(s) Failed":"File Upload Failed"})):e.createElement("div",null,w("fileUpload.title",{description:H,defaultValue:`Upload your ${H}`}))),x?e.createElement("div",{className:le},new Set(C.map((a,r)=>{const m=Math.floor(a.length/2);return e.createElement("div",{className:te,key:a},e.createElement("span",{className:L},a.substr(0,m)),e.createElement("div",{className:L},e.createElement("span",null,a.substr(m))),r<C.length-1?",":"")}))):e.createElement("span",null),e.createElement("div",{className:I},e.createElement("div",null,e.createElement("span",null,O[0]),f?e.createElement("u",null,O[1]):e.createElement("a",{href:"",onClick:Ee},O[1]),e.createElement("span",null,O[2]))),e.createElement("div",{className:ie},c?e.createElement("span",null,"("," ",w("fileUpload.acceptedTypes",{fileTypes:Z,defaultValue:`${Z} format accepted`})," ",")"):"",_?e.createElement("span",null,"( ",w("fileUpload.maximumSize",{size:_,defaultValue:`${_} maximum`})," )"):"",U?e.createElement("span",null," ",U," "):""),F&&e.createElement("div",{className:ne},e.createElement(A.Button,{disabled:f,kind:"link",icon:"download-cloud",onClick:Ue},F)))),t&&!s&&e.createElement("div",{className:se},e.createElement(A.Button,{disabled:f,kind:"icon",icon:"x",title:w("fileUpload.close",{defaultValue:"Close"}),onClick:Fe})),e.createElement("form",{className:re},e.createElement("input",{ref:u,type:"file",accept:me||"*/*",multiple:l||void 0,onChange:ye})))}b.Metadata.set(T,{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"},disabled:{type:"boolean"}}});const de={"File Upload":{components:[T],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`
|
|
1
|
+
(function(s,F){typeof exports=="object"&&typeof module<"u"?F(exports,require("react"),require("@sps-woodland/core"),require("@spscommerce/utils"),require("@sps-woodland/buttons"),require("@sps-woodland/illustrations"),require("@spscommerce/i18n")):typeof define=="function"&&define.amd?define(["exports","react","@sps-woodland/core","@spscommerce/utils","@sps-woodland/buttons","@sps-woodland/illustrations","@spscommerce/i18n"],F):(s=typeof globalThis<"u"?globalThis:s||self,F(s.FileUpload={},s.React,s.core,s.utils,s.buttons,s.illustrations,s.i18n))})(this,function(s,F,U,d,V,A,ee){"use strict";function oe(o){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const l in o)if(l!=="default"){const t=Object.getOwnPropertyDescriptor(o,l);Object.defineProperty(a,l,t.get?t:{enumerable:!0,get:()=>o[l]})}}return a.default=o,Object.freeze(a)}const e=oe(F),L={"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"],EML:["application/octet-stream","message/rfc822","multipart/mixed","message/rfc5322","message/rfc6532"],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 le(o,a,l){return a in o?Object.defineProperty(o,a,{value:l,enumerable:!0,configurable:!0,writable:!0}):o[a]=l,o}function B(o,a){var l=Object.keys(o);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(o);a&&(t=t.filter(function(p){return Object.getOwnPropertyDescriptor(o,p).enumerable})),l.push.apply(l,t)}return l}function R(o){for(var a=1;a<arguments.length;a++){var l=arguments[a]!=null?arguments[a]:{};a%2?B(Object(l),!0).forEach(function(t){le(o,t,l[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(l)):B(Object(l)).forEach(function(t){Object.defineProperty(o,t,Object.getOwnPropertyDescriptor(l,t))})}return o}var ae=(o,a,l)=>{for(var t of Object.keys(o)){var p;if(o[t]!==((p=a[t])!==null&&p!==void 0?p:l[t]))return!1}return!0},S=o=>a=>{var l=o.defaultClassName,t=R(R({},o.defaultVariants),a);for(var p in t){var h,E=(h=t[p])!==null&&h!==void 0?h:o.defaultVariants[p];if(E!=null){var c=E;typeof c=="boolean"&&(c=c===!0?"true":"false");var r=o.variantClassNames[p][c];r&&(l+=" "+r)}}for(var[j,M]of o.compoundVariants)ae(j,t,o.defaultVariants)&&(l+=" "+M);return l},te=S({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw0",variantClassNames:{active:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw1",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw2"},mini:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw3",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw4"},error:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw5",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw6"},shown:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw7",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw8"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw9",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwa"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0,disabled:!1},compoundVariants:[]}),ie=S({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwb",variantClassNames:{constrainContentWidth:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwc",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwd"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwe",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwf"}},defaultVariants:{constrainContentWidth:!1,disabled:!1},compoundVariants:[]}),I="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwg",ne=S({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwh",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwi",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwj"},error:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwk",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwl"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwm",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwn"}},defaultVariants:{mini:!1,error:!1,disabled:!1},compoundVariants:[]}),se=S({defaultClassName:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwo",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwp",false:"pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwq"}},defaultVariants:{mini:!1},compoundVariants:[]}),re="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwr",pe="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jws",W="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwt",z="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwu",de="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwv",ce="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jww",_e="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwx",fe="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwy",ue="pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwz";function G({list:o}){return e.createElement(e.Fragment,null,o.map((a,l)=>{const t=Math.floor(a.length/2);return e.createElement("div",{className:pe,key:a},e.createElement("span",{className:W},a.substring(0,t)),e.createElement("div",{className:W},e.createElement("span",null,a.substring(t))),l<o.length-1?",":"")}))}function P({constrainContentWidth:o,description:a,multiple:l=!1,dismissable:t,processing:p,mini:h,downloadLabel:E,acceptExtensions:c,maxSize:r,customRequirement:j,onSelection:M,onDismiss:X,download:q,shown:k,className:he,disabled:_,children:Ae,...we}){const C=e.useRef(new Set),[ve,Z]=e.useState(k),[Le,ge]=e.useState([]),[Fe,Ee]=e.useState(""),[$,be]=e.useState(),[ye,O]=e.useState(!1),[b,D]=e.useState(!1),[w,H]=e.useState([]),[v,J]=e.useState([]),[y,xe]=e.useState(""),K=e.useMemo(()=>new Set([...w,...v]).size,[w,v]),{t:f}=ee.useWoodlandLanguage(),T=(l?f("fileUpload.instructions.other",{defaultValue:"Drag and drop your files here or |browse for files| on your desktop."}):f("fileUpload.instructions.one",{defaultValue:"Drag and drop your file here or |browse for a file| on your desktop."})).split("|"),Y=a||(l?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{k&&Z(k)},[k]),e.useEffect(()=>{r&&Se(r)},[r]),e.useEffect(()=>{c&&je(c)},[c]);function Ue(){t&&(Z(!1),X&&X())}function Se(i){try{be(d.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function je(i){const g=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(n=>n.replace(/^\./,"")),m=g.map(n=>`.${n}`.toLowerCase());xe(m.map((n,N)=>N>0&&N===m.length-1?`or ${n}`:n).join(m.length>2?", ":" ")),C.current.clear();for(const n of g){const N=Object.keys(L).includes(n.toUpperCase())?L[n.toUpperCase()]:[];for(const Me of N)C.current.add(Me)}Ee(m.concat(Array.from(C.current)).join(","))}function Q(i){H([]),J([]);let x=[],g=[];const m=i?Array.from(i):[];for(const n of m)c&&!C.current.has(n.type)&&g.push(n.name),r&&$&&n.size>$&&x.push(n.name);x.length||g.length?(D(!0),u.current&&u.current.value&&(u.current.value="")):(ge(m),M(m)),H(x),J(g)}function ke(i){i.preventDefault(),D(!1),u.current&&u.current.click()}function Ce(){q&&q()}function Oe(i){i.stopPropagation(),Q(i.target.files),u.current&&u.current.value&&(u.current.value="")}function De(i){i.preventDefault(),i.stopPropagation(),O(!0),D(!1)}function Te(i){i.preventDefault(),O(!0),D(!1)}function Ne(i){i.preventDefault(),O(!1)}function Pe(i){i.preventDefault(),i.stopPropagation(),O(!1),i.dataTransfer.files&&Q(i.dataTransfer.files)}return e.createElement("div",{onDrop:_?()=>{}:Pe,onDragOver:_?()=>{}:De,onDragLeave:_?()=>{}:Ne,onDragEnter:_?()=>{}:Te,className:U.cl(te({active:ye,mini:h,error:b,shown:ve,disabled:_}),he),...we},e.createElement("div",{className:U.cl(ie({constrainContentWidth:o,disabled:_}))},p?e.createElement("div",null,e.createElement(U.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:I},f("fileUpload.processing",{defaultValue:"Processing Upload..."}))):e.createElement("div",null,e.createElement("div",{className:ne({mini:h,error:b,disabled:_}),"aria-hidden":"true"},e.createElement("img",{className:ue,src:b?A.GENERAL_ERROR_LARGE:A.UPLOAD_LARGE,alt:"Upload Icon"})),e.createElement("div",{className:se({mini:h})},b?e.createElement("div",null,f(K>1?"fileUpload.cancelled.other":"fileUpload.cancelled.one",{defaultValue:K>1?"File Upload(s) Failed":"File Upload Failed"})):e.createElement("div",null,f("fileUpload.title",{description:Y,defaultValue:`Upload your ${Y}`}))),b?e.createElement("div",{className:re},w.length>0&&e.createElement(e.Fragment,null,e.createElement(G,{list:w}),e.createElement("div",{className:z},f(w.length===1?"fileUpload.error.tooLarge.one":"fileUpload.error.tooLarge.other",{size:r,defaultValue:w.length===1?`Selected file is larger than the size limit of ${r}.`:`Selected files are larger than the size limit of ${r}.`}))),v.length>0&&e.createElement(e.Fragment,null,e.createElement(G,{list:v}),e.createElement("div",{className:z},f(v.length===1?"fileUpload.error.wrongType.one":"fileUpload.error.wrongType.other",{fileTypes:y,defaultValue:v.length===1?`Selected file is not an accepted file type: ${y}.`:`Selected files are not accepted file types: ${y}.`})))):e.createElement("span",null),e.createElement("div",{className:I},e.createElement("div",null,e.createElement("span",null,T[0]),_?e.createElement("u",null,T[1]):e.createElement("a",{href:"",onClick:ke},T[1]),e.createElement("span",null,T[2]))),e.createElement("div",{className:de},c?e.createElement("span",null,"("," ",f("fileUpload.acceptedTypes",{fileTypes:y,defaultValue:`${y} format accepted`})," ",")"):"",r?e.createElement("span",null,"("," ",f("fileUpload.maximumSize",{size:r,defaultValue:`${r} maximum`})," ",")"):"",j?e.createElement("span",null," ",j," "):""),E&&e.createElement("div",{className:ce},e.createElement(V.Button,{disabled:_,kind:"link",icon:"download-cloud",onClick:Ce},E)))),t&&!p&&e.createElement("div",{className:_e},e.createElement(V.Button,{disabled:_,kind:"icon",icon:"x",title:f("fileUpload.close",{defaultValue:"Close"}),onClick:Ue})),e.createElement("form",{className:fe},e.createElement("input",{ref:u,type:"file",accept:Fe||"*/*",multiple:l||void 0,onChange:Oe})))}U.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"},disabled:{type:"boolean"}}});const me={"File Upload":{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:d.code`
|
|
2
2
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
3
3
|
|
|
4
4
|
function Component() {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<FileUpload onSelection={selectFile} />
|
|
11
11
|
)
|
|
12
12
|
}
|
|
13
|
-
`},multiple:{description:"Multiple file upload",react:
|
|
13
|
+
`},multiple:{description:"Multiple file upload",react:d.code`
|
|
14
14
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
15
15
|
|
|
16
16
|
function Component() {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<FileUpload onSelection={selectFile} multiple />
|
|
23
23
|
)
|
|
24
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:
|
|
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
26
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
27
27
|
|
|
28
28
|
function Component() {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
<FileUpload onSelection={selectFile} maxSize="100KB" />
|
|
35
35
|
)
|
|
36
36
|
}
|
|
37
|
-
`},fileWhitelist:{description:"File type whitelist",react:
|
|
37
|
+
`},fileWhitelist:{description:"File type whitelist",react:d.code`
|
|
38
38
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
39
39
|
|
|
40
40
|
function Component() {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
/>
|
|
52
52
|
)
|
|
53
53
|
}
|
|
54
|
-
`},bothRestrictions:{description:"Both restrictions",react:
|
|
54
|
+
`},bothRestrictions:{description:"Both restrictions",react:d.code`
|
|
55
55
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
56
56
|
|
|
57
57
|
function Component() {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
/>
|
|
70
70
|
)
|
|
71
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:
|
|
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
73
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
74
74
|
import { Button } from "@sps-woodland/buttons";
|
|
75
75
|
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
</>
|
|
100
100
|
)
|
|
101
101
|
}
|
|
102
|
-
`}}},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:
|
|
102
|
+
`}}},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`
|
|
103
103
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
104
104
|
|
|
105
105
|
function Component() {
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
/>
|
|
122
122
|
)
|
|
123
123
|
}
|
|
124
|
-
`}}},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:
|
|
124
|
+
`}}},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`
|
|
125
125
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
126
126
|
|
|
127
127
|
function Component() {
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
</div>
|
|
138
138
|
)
|
|
139
139
|
}
|
|
140
|
-
`}}},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:
|
|
140
|
+
`}}},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`
|
|
141
141
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
142
142
|
|
|
143
143
|
function Component() {
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
</div>
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
|
-
`}}},disabled:{label:"Disabled State",description:"File Upload have a disabled style for each possible state.",examples:{basic:{description:"Disabled File Upload",react:
|
|
156
|
+
`}}},disabled:{label:"Disabled State",description:"File Upload have a disabled style for each possible state.",examples:{basic:{description:"Disabled File Upload",react:d.code`
|
|
157
157
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
158
158
|
|
|
159
159
|
function Component() {
|
|
@@ -170,4 +170,4 @@
|
|
|
170
170
|
onSelection={selectFile} />
|
|
171
171
|
)
|
|
172
172
|
}
|
|
173
|
-
`}}}}}};
|
|
173
|
+
`}}}}}};s.FileUpload=P,s.MANIFEST=me,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/lib/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.pkg_sps-woodland_file-
|
|
1
|
+
.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw0{border-width:.0625rem;border-style:dashed;border-radius:.25rem;display:block;padding:1rem;position:relative}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw1{background-color:#f4ecf2;border-color:#91467f;border-style:solid}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw3{padding:1rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw5{border-color:#de002e}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw8{display:none}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jw9{border-color:#d2d4d4}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwb{color:#4b5356;margin:0 auto;text-align:center}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwc{width:50%}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwe{color:#717779}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwg{font-size:.75rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwh{color:#717779;display:block;margin-bottom:1rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwi{font-size:1.5rem;line-height:1.5rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwj{font-size:3rem;line-height:3rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwk{color:#de002e}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwm{opacity:.5}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwo{font-weight:600;margin-bottom:.25rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwp{font-size:1rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwq{font-size:1.125rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwr{font-size:.875rem;font-weight:600;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jws{display:flex;justify-content:center;white-space:nowrap}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwt{max-width:50%;overflow:hidden}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwt:first-child{text-overflow:ellipsis}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwt:last-child{float:right}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwu{font-weight:400}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwv{font-size:.75rem;line-height:1.125rem;margin-top:.25rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwv>span+span{margin-left:.125rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jww{margin-top:1rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwx{position:absolute;right:.5rem;top:.5rem}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwy{display:none}.pkg_sps-woodland_file-upload__version_8_35_3__hash_rh07jwz{height:3rem}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sps-woodland/file-upload",
|
|
3
3
|
"description": "SPS Woodland Design System file upload component",
|
|
4
|
-
"version": "8.35.
|
|
4
|
+
"version": "8.35.3",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/file-upload",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"@spscommerce/utils": "^7.0.0 || ^8.0.0",
|
|
31
31
|
"react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
32
32
|
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
33
|
-
"@sps-woodland/buttons": "8.35.
|
|
34
|
-
"@sps-woodland/core": "8.35.
|
|
35
|
-
"@sps-woodland/illustrations": "8.35.
|
|
36
|
-
"@sps-woodland/tokens": "8.35.
|
|
37
|
-
"@spscommerce/ds-react": "8.35.
|
|
38
|
-
"@spscommerce/ds-shared": "8.35.
|
|
39
|
-
"@spscommerce/i18n": "8.35.
|
|
33
|
+
"@sps-woodland/buttons": "8.35.3",
|
|
34
|
+
"@sps-woodland/core": "8.35.3",
|
|
35
|
+
"@sps-woodland/illustrations": "8.35.3",
|
|
36
|
+
"@sps-woodland/tokens": "8.35.3",
|
|
37
|
+
"@spscommerce/ds-react": "8.35.3",
|
|
38
|
+
"@spscommerce/ds-shared": "8.35.3",
|
|
39
|
+
"@spscommerce/i18n": "8.35.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@spscommerce/ds-illustrations": "^6.12.1",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"@vanilla-extract/recipes": "^0.2.5",
|
|
46
46
|
"react": "^16.14.0",
|
|
47
47
|
"react-dom": "^16.14.0",
|
|
48
|
-
"@sps-woodland/buttons": "8.35.
|
|
49
|
-
"@sps-woodland/core": "8.35.
|
|
50
|
-
"@sps-woodland/illustrations": "8.35.
|
|
51
|
-
"@sps-woodland/tokens": "8.35.
|
|
52
|
-
"@spscommerce/ds-colors": "8.35.
|
|
53
|
-
"@spscommerce/ds-react": "8.35.
|
|
54
|
-
"@spscommerce/ds-shared": "8.35.
|
|
55
|
-
"@spscommerce/i18n": "8.35.
|
|
48
|
+
"@sps-woodland/buttons": "8.35.3",
|
|
49
|
+
"@sps-woodland/core": "8.35.3",
|
|
50
|
+
"@sps-woodland/illustrations": "8.35.3",
|
|
51
|
+
"@sps-woodland/tokens": "8.35.3",
|
|
52
|
+
"@spscommerce/ds-colors": "8.35.3",
|
|
53
|
+
"@spscommerce/ds-react": "8.35.3",
|
|
54
|
+
"@spscommerce/ds-shared": "8.35.3",
|
|
55
|
+
"@spscommerce/i18n": "8.35.3"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "pnpm run build:js && pnpm run build:types",
|