@sps-woodland/file-upload 7.0.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.
- package/README.md +3 -0
- package/lib/FileUpload.css.d.ts +74 -0
- package/lib/FileUpload.d.ts +18 -0
- package/lib/FileUpload.examples.d.ts +2 -0
- package/lib/index.cjs.js +155 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.es.js +456 -0
- package/lib/manifest.d.ts +2 -0
- package/lib/mime-type.enum.d.ts +75 -0
- package/lib/style.css +1 -0
- package/package.json +47 -0
- package/vite.config.js +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export declare const fileUpload: import("@vanilla-extract/recipes/dist/declarations/src/types").RuntimeFn<{
|
|
2
|
+
active: {
|
|
3
|
+
true: {
|
|
4
|
+
backgroundColor: string;
|
|
5
|
+
borderColor: string;
|
|
6
|
+
borderStyle: "solid";
|
|
7
|
+
};
|
|
8
|
+
false: {};
|
|
9
|
+
};
|
|
10
|
+
mini: {
|
|
11
|
+
true: {
|
|
12
|
+
padding: string;
|
|
13
|
+
};
|
|
14
|
+
false: {};
|
|
15
|
+
};
|
|
16
|
+
error: {
|
|
17
|
+
true: {
|
|
18
|
+
borderColor: string;
|
|
19
|
+
};
|
|
20
|
+
false: {};
|
|
21
|
+
};
|
|
22
|
+
shown: {
|
|
23
|
+
true: {};
|
|
24
|
+
false: {
|
|
25
|
+
display: "none";
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
export declare const fileUploadContent: import("@vanilla-extract/recipes/dist/declarations/src/types").RuntimeFn<{
|
|
30
|
+
constrainContentWidth: {
|
|
31
|
+
true: {
|
|
32
|
+
width: "50%";
|
|
33
|
+
};
|
|
34
|
+
false: {};
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
export declare const fileUploadInstructions: string;
|
|
38
|
+
export declare const fileUploadIcon: import("@vanilla-extract/recipes/dist/declarations/src/types").RuntimeFn<{
|
|
39
|
+
mini: {
|
|
40
|
+
true: {
|
|
41
|
+
fontSize: string;
|
|
42
|
+
lineHeight: string;
|
|
43
|
+
};
|
|
44
|
+
false: {
|
|
45
|
+
fontSize: string;
|
|
46
|
+
lineHeight: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
error: {
|
|
50
|
+
true: {
|
|
51
|
+
color: string;
|
|
52
|
+
};
|
|
53
|
+
false: {};
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
export declare const fileUploadTitle: import("@vanilla-extract/recipes/dist/declarations/src/types").RuntimeFn<{
|
|
57
|
+
mini: {
|
|
58
|
+
true: {
|
|
59
|
+
fontSize: string;
|
|
60
|
+
lineHeight: string;
|
|
61
|
+
};
|
|
62
|
+
false: {
|
|
63
|
+
fontSize: string;
|
|
64
|
+
lineHeight: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
export declare const erroredFiles: string;
|
|
69
|
+
export declare const erroredFileName: string;
|
|
70
|
+
export declare const erroredFilenameSegment: string;
|
|
71
|
+
export declare const fileUploadRequirements: string;
|
|
72
|
+
export declare const fileUploadDownloadButton: string;
|
|
73
|
+
export declare const fileUploadCloseButton: string;
|
|
74
|
+
export declare const fileUploadForm: string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ComponentProps } from "@sps-woodland/core";
|
|
3
|
+
export declare function FileUpload({ constrainContentWidth, description, multiple, dismissable, processing, mini, downloadLabel, acceptExtensions, maxSize, customRequirement, onSelection, onDismiss, download, shown, className, children, ...rest }: ComponentProps<{
|
|
4
|
+
constrainContentWidth?: boolean;
|
|
5
|
+
description?: string;
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
dismissable?: boolean;
|
|
8
|
+
processing?: boolean;
|
|
9
|
+
mini?: boolean;
|
|
10
|
+
downloadLabel?: string;
|
|
11
|
+
acceptExtensions?: string[] | string;
|
|
12
|
+
maxSize?: string;
|
|
13
|
+
customRequirement?: string;
|
|
14
|
+
shown?: boolean;
|
|
15
|
+
onSelection: (files: File[]) => void;
|
|
16
|
+
onDismiss?: () => void;
|
|
17
|
+
download?: () => void;
|
|
18
|
+
}>): React.ReactElement;
|
package/lib/index.cjs.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const pe=require("react"),w=require("@sps-woodland/core"),d=require("@spscommerce/utils"),k=require("@spscommerce/ds-react"),O=require("@spscommerce/ds-shared");function fe(e){if(e&&e.__esModule)return e;const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(o,a,l.get?l:{enumerable:!0,get:()=>e[a]})}}return o.default=e,Object.freeze(o)}const t=fe(pe);var Z=(e=>(e["7Z"]="application/x-7z-compressed",e.AAC="audio/aac",e.ABW="application/x-abiword",e.ARC="application/octet-stream",e.AVI="video/x-msvideo",e.AZW="application/vnd.amazon.ebook",e.BIN="application/octet-stream",e.BMP="image/bmp",e.BZ="application/x-bzip",e.BZ2="application/x-bzip2",e.CSH="application/x-csh",e.CSS="text/css",e.CSV="text/csv,application/vnd.ms-excel",e.DOC="application/msword",e.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",e.EOT="application/vnd.ms-fontobject",e.EPUB="application/epub+zip",e.ES="application/ecmascript",e.FLV="video/x-flv",e.GIF="image/gif",e.GZ="application/x-gzip",e.HTM="text/html",e.HTML="text/html",e.ICO="image/x-icon",e.ICS="text/calendar",e.JAR="application/java-archive",e.JPEG="image/jpeg",e.JPG="image/jpeg",e.JS="application/javascript",e.JSON="application/json",e.M3U="audio/x-mpequrl",e.MID="audio/midi",e.MIDI="audio/midi",e.MOV="video/quicktime",e.MP3="audio/mpeg3",e.MP4="video/mp4",e.MPEG="video/mpeg",e.MPKG="application/vnd.apple.installer+xml",e.ODP="application/vnd.oasis.opendocument.presentation",e.ODS="application/vnd.oasis.opendocument.spreadsheet",e.ODT="application/vnd.oasis.opendocument.text",e.OGA="audio/ogg",e.OGV="video/ogg",e.OGX="application/ogg",e.OTF="font/otf",e.PNG="image/png",e.PDF="application/pdf",e.PPT="application/vnd.ms-powerpoint",e.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",e.RAR="application/x-rar-compressed",e.RTF="application/rtf",e.SH="application/x-sh",e.SVG="image/svg+xml",e.SWF="application/x-shockwave-flash",e.TAR="application/x-tar",e.TIF="image/tiff",e.TIFF="image/tiff",e.TS="application/typescript",e.TTF="font/ttf",e.TXT="text/plain",e.VSD="application/vnd.visio",e.WAV="audio/wav",e.WEBA="audio/webm",e.WEBM="video/webm",e.WEBP="image/webp",e.WOFF="font/woff",e.WOFF2="font/woff2",e.XHTML="application/xhtml+xml",e.XLS="application/vnd.ms-excel",e.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",e.XML="application/xml",e.XUL="application/vnd.mozilla.xul+xml",e.ZIP="application/zip",e))(Z||{});function ue(e,o,a){return o in e?Object.defineProperty(e,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[o]=a,e}function G(e,o){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);o&&(l=l.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),a.push.apply(a,l)}return a}function _(e){for(var o=1;o<arguments.length;o++){var a=arguments[o]!=null?arguments[o]:{};o%2?G(Object(a),!0).forEach(function(l){ue(e,l,a[l])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):G(Object(a)).forEach(function(l){Object.defineProperty(e,l,Object.getOwnPropertyDescriptor(a,l))})}return e}var me=(e,o,a)=>{for(var l of Object.keys(e)){var n;if(e[l]!==((n=o[l])!==null&&n!==void 0?n:a[l]))return!1}return!0},D=e=>o=>{var a=e.defaultClassName,l=_(_({},e.defaultVariants),o);for(var n in l){var h,g=(h=l[n])!==null&&h!==void 0?h:e.defaultVariants[n];if(g!=null){var c=g;typeof c=="boolean"&&(c=c===!0?"true":"false");var p=e.variantClassNames[n][c];p&&(a+=" "+p)}}for(var[S,N]of e.compoundVariants)me(S,l,e.defaultVariants)&&(a+=" "+N);return a},he="rh07jwm",q="rh07jwn",ve="rh07jwl",we=D({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:[]}),ge="rh07jwq",Fe=D({defaultClassName:"rh07jw9",variantClassNames:{constrainContentWidth:{true:"rh07jwa",false:"rh07jwb"}},defaultVariants:{constrainContentWidth:!1},compoundVariants:[]}),Se="rh07jwp",be="rh07jwr",xe=D({defaultClassName:"rh07jwd",variantClassNames:{mini:{true:"rh07jwe",false:"rh07jwf"},error:{true:"rh07jwg",false:"rh07jwh"}},defaultVariants:{mini:!1,error:!1},compoundVariants:[]}),K="rh07jwc",Ue="rh07jwo",Ce=D({defaultClassName:"rh07jwi",variantClassNames:{mini:{true:"rh07jwj",false:"rh07jwk"}},defaultVariants:{mini:!1},compoundVariants:[]});function V({constrainContentWidth:e,description:o,multiple:a=!1,dismissable:l,processing:n,mini:h,downloadLabel:g,acceptExtensions:c,maxSize:p,customRequirement:S,onSelection:N,onDismiss:W,download:z,shown:b,className:H,children:De,...J}){let x=new Set;const[Y,L]=t.useState(b),[Ne,Q]=t.useState([]),[$,y]=t.useState(""),[R,E]=t.useState(),[T,U]=t.useState(!1),[F,C]=t.useState(!1),[P,X]=t.useState([]),[I,M]=t.useState(""),{t:u}=t.useContext(w.I18nContext),A=u(a?"design-system:fileUpload.instructions_plural":"design-system:fileUpload.instructions").split("|"),ee=o||(a?"Files":"File"),v=t.useRef(null);t.useEffect(()=>{b&&L(b)},[b]),t.useEffect(()=>{p&&ie(p)},[p]),t.useEffect(()=>{c&&ae(c)},[c]);function te(){l&&(L(!1),W&&W())}function ie(i){try{E(d.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());M(r.map((m,j)=>j>0&&j===r.length-1?`or ${m}`:m).join(r.length>2?", ":" ")),x.clear();for(const m of f)for(const j of Z[m.toUpperCase()].split(","))x.add(j);y(r.concat(Array.from(x)).join(","))}function B(i){X([]);let s=[];const f=Array.from(i);for(const r of f)r===null?s.push("Not a file"):(c&&!x.has(r.type)&&s.push(r.name),p&&R&&r.size>R&&s.indexOf(r.name)===-1&&s.push(r.name));s.length?(C(!0),v.current&&v.current.value&&(v.current.value="")):(Q(f),N(f)),X(s)}function le(i){i.preventDefault(),C(!1),v.current&&v.current.click()}function oe(){z&&z()}function ne(i){i.stopPropagation(),B(i.target.files||[])}function se(i){i.preventDefault(),i.stopPropagation(),U(!0),C(!1)}function re(i){i.preventDefault(),U(!0),C(!1)}function ce(i){i.preventDefault(),U(!1)}function de(i){i.preventDefault(),i.stopPropagation(),U(!1),i.dataTransfer.items?B(Array.from(i.dataTransfer.items).map(s=>s.getAsFile())):B(i.dataTransfer.files)}return t.createElement("div",{onDrop:de,onDragOver:se,onDragLeave:ce,onDragEnter:re,className:w.cl(we({active:T,mini:h,error:F,shown:Y}),H),...J},t.createElement("div",{className:w.cl(Fe({constrainContentWidth:e}))},n?t.createElement("div",null,t.createElement(w.Spinner,{size:"md","aria-hidden":"true"}),t.createElement("div",{className:K},u("design-system:fileUpload.processing"))):t.createElement("div",null,t.createElement(w.Icon,{className:xe({mini:h,error:F}),icon:F?"exclamation-circle":"upload-cloud","aria-hidden":"true"}),t.createElement("div",{className:Ce({mini:h})},F?t.createElement("div",null,u(P.length>1?"design-system:fileUpload.cancelled_plural":"design-system:fileUpload.cancelled")):t.createElement("div",null,u("design-system:fileUpload.title",{description:ee}))),F?t.createElement("div",{className:ve},new Set(P.map((i,s)=>{const f=Math.floor(i.length/2);return t.createElement("div",{className:he,key:i},t.createElement("span",{className:q},i.substr(0,f)),t.createElement("div",{className:q},t.createElement("span",null,i.substr(f))),s<P.length-1?",":"")}))):t.createElement("span",null),t.createElement("div",{className:K},t.createElement("div",null,t.createElement("span",null,A[0]),t.createElement("a",{href:"",onClick:le},A[1]),t.createElement("span",null,A[2]))),t.createElement("div",{className:Ue},c?t.createElement("span",null,"("," ",u("design-system:fileUpload.acceptedTypes",{fileTypes:I})," ",")"):"",p?t.createElement("span",null,"( ",u("design-system:fileUpload.maximumSize",{size:p})," )"):"",S?t.createElement("span",null," ",S," "):""),g&&t.createElement("div",{className:Se},t.createElement(k.SpsButton,{kind:O.ButtonKind.LINK,icon:O.SpsIcon.DOWNLOAD_CLOUD,onClick:oe},g)))),l&&!n&&t.createElement("div",{className:ge},t.createElement(k.SpsButton,{kind:O.ButtonKind.ICON,icon:O.SpsIcon.X,title:u("design-system:fileUpload.close"),onClick:te})),t.createElement("form",{className:be},t.createElement("input",{ref:v,type:"file",accept:$||"*/*",multiple:a||void 0,onChange:ne})))}w.Metadata.set(V,{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 je={components:[V],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
|
+
`}}}}},Oe={"File Upload":je};exports.FileUpload=V;exports.MANIFEST=Oe;
|
package/lib/index.d.ts
ADDED
package/lib/index.es.js
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import * as t from "react";
|
|
2
|
+
import { Metadata as fe, I18nContext as me, cl as z, Spinner as ue, Icon as he } from "@sps-woodland/core";
|
|
3
|
+
import { parseFileSize as ve, code as f } from "@spscommerce/utils";
|
|
4
|
+
import { SpsButton as R } from "@spscommerce/ds-react";
|
|
5
|
+
import { ButtonKind as X, SpsIcon as k } from "@spscommerce/ds-shared";
|
|
6
|
+
var H = /* @__PURE__ */ ((e) => (e["7Z"] = "application/x-7z-compressed", e.AAC = "audio/aac", e.ABW = "application/x-abiword", e.ARC = "application/octet-stream", e.AVI = "video/x-msvideo", e.AZW = "application/vnd.amazon.ebook", e.BIN = "application/octet-stream", e.BMP = "image/bmp", e.BZ = "application/x-bzip", e.BZ2 = "application/x-bzip2", e.CSH = "application/x-csh", e.CSS = "text/css", e.CSV = "text/csv,application/vnd.ms-excel", e.DOC = "application/msword", e.DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", e.EOT = "application/vnd.ms-fontobject", e.EPUB = "application/epub+zip", e.ES = "application/ecmascript", e.FLV = "video/x-flv", e.GIF = "image/gif", e.GZ = "application/x-gzip", e.HTM = "text/html", e.HTML = "text/html", e.ICO = "image/x-icon", e.ICS = "text/calendar", e.JAR = "application/java-archive", e.JPEG = "image/jpeg", e.JPG = "image/jpeg", e.JS = "application/javascript", e.JSON = "application/json", e.M3U = "audio/x-mpequrl", e.MID = "audio/midi", e.MIDI = "audio/midi", e.MOV = "video/quicktime", e.MP3 = "audio/mpeg3", e.MP4 = "video/mp4", e.MPEG = "video/mpeg", e.MPKG = "application/vnd.apple.installer+xml", e.ODP = "application/vnd.oasis.opendocument.presentation", e.ODS = "application/vnd.oasis.opendocument.spreadsheet", e.ODT = "application/vnd.oasis.opendocument.text", e.OGA = "audio/ogg", e.OGV = "video/ogg", e.OGX = "application/ogg", e.OTF = "font/otf", e.PNG = "image/png", e.PDF = "application/pdf", e.PPT = "application/vnd.ms-powerpoint", e.PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation", e.RAR = "application/x-rar-compressed", e.RTF = "application/rtf", e.SH = "application/x-sh", e.SVG = "image/svg+xml", e.SWF = "application/x-shockwave-flash", e.TAR = "application/x-tar", e.TIF = "image/tiff", e.TIFF = "image/tiff", e.TS = "application/typescript", e.TTF = "font/ttf", e.TXT = "text/plain", e.VSD = "application/vnd.visio", e.WAV = "audio/wav", e.WEBA = "audio/webm", e.WEBM = "video/webm", e.WEBP = "image/webp", e.WOFF = "font/woff", e.WOFF2 = "font/woff2", e.XHTML = "application/xhtml+xml", e.XLS = "application/vnd.ms-excel", e.XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", e.XML = "application/xml", e.XUL = "application/vnd.mozilla.xul+xml", e.ZIP = "application/zip", e))(H || {});
|
|
7
|
+
function we(e, o, a) {
|
|
8
|
+
return o in e ? Object.defineProperty(e, o, {
|
|
9
|
+
value: a,
|
|
10
|
+
enumerable: !0,
|
|
11
|
+
configurable: !0,
|
|
12
|
+
writable: !0
|
|
13
|
+
}) : e[o] = a, e;
|
|
14
|
+
}
|
|
15
|
+
function G(e, o) {
|
|
16
|
+
var a = Object.keys(e);
|
|
17
|
+
if (Object.getOwnPropertySymbols) {
|
|
18
|
+
var l = Object.getOwnPropertySymbols(e);
|
|
19
|
+
o && (l = l.filter(function(n) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(e, n).enumerable;
|
|
21
|
+
})), a.push.apply(a, l);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
}
|
|
25
|
+
function K(e) {
|
|
26
|
+
for (var o = 1; o < arguments.length; o++) {
|
|
27
|
+
var a = arguments[o] != null ? arguments[o] : {};
|
|
28
|
+
o % 2 ? G(Object(a), !0).forEach(function(l) {
|
|
29
|
+
we(e, l, a[l]);
|
|
30
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(a)) : G(Object(a)).forEach(function(l) {
|
|
31
|
+
Object.defineProperty(e, l, Object.getOwnPropertyDescriptor(a, l));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
var ge = (e, o, a) => {
|
|
37
|
+
for (var l of Object.keys(e)) {
|
|
38
|
+
var n;
|
|
39
|
+
if (e[l] !== ((n = o[l]) !== null && n !== void 0 ? n : a[l]))
|
|
40
|
+
return !1;
|
|
41
|
+
}
|
|
42
|
+
return !0;
|
|
43
|
+
}, j = (e) => (o) => {
|
|
44
|
+
var a = e.defaultClassName, l = K(K({}, e.defaultVariants), o);
|
|
45
|
+
for (var n in l) {
|
|
46
|
+
var h, w = (h = l[n]) !== null && h !== void 0 ? h : e.defaultVariants[n];
|
|
47
|
+
if (w != null) {
|
|
48
|
+
var c = w;
|
|
49
|
+
typeof c == "boolean" && (c = c === !0 ? "true" : "false");
|
|
50
|
+
var p = e.variantClassNames[n][c];
|
|
51
|
+
p && (a += " " + p);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (var [F, O] of e.compoundVariants)
|
|
55
|
+
ge(F, l, e.defaultVariants) && (a += " " + O);
|
|
56
|
+
return a;
|
|
57
|
+
}, Fe = "rh07jwm", Z = "rh07jwn", xe = "rh07jwl", Se = 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: [] }), be = "rh07jwq", Ue = j({ defaultClassName: "rh07jw9", variantClassNames: { constrainContentWidth: { true: "rh07jwa", false: "rh07jwb" } }, defaultVariants: { constrainContentWidth: !1 }, compoundVariants: [] }), Ce = "rh07jwp", je = "rh07jwr", Oe = j({ defaultClassName: "rh07jwd", variantClassNames: { mini: { true: "rh07jwe", false: "rh07jwf" }, error: { true: "rh07jwg", false: "rh07jwh" } }, defaultVariants: { mini: !1, error: !1 }, compoundVariants: [] }), q = "rh07jwc", De = "rh07jwo", Ne = j({ defaultClassName: "rh07jwi", variantClassNames: { mini: { true: "rh07jwj", false: "rh07jwk" } }, defaultVariants: { mini: !1 }, compoundVariants: [] });
|
|
58
|
+
function J({
|
|
59
|
+
constrainContentWidth: e,
|
|
60
|
+
description: o,
|
|
61
|
+
multiple: a = !1,
|
|
62
|
+
dismissable: l,
|
|
63
|
+
processing: n,
|
|
64
|
+
mini: h,
|
|
65
|
+
downloadLabel: w,
|
|
66
|
+
acceptExtensions: c,
|
|
67
|
+
maxSize: p,
|
|
68
|
+
customRequirement: F,
|
|
69
|
+
onSelection: O,
|
|
70
|
+
onDismiss: A,
|
|
71
|
+
download: B,
|
|
72
|
+
shown: x,
|
|
73
|
+
className: _,
|
|
74
|
+
children: Ae,
|
|
75
|
+
...Y
|
|
76
|
+
}) {
|
|
77
|
+
let S = /* @__PURE__ */ new Set();
|
|
78
|
+
const [Q, V] = t.useState(x), [Be, $] = t.useState([]), [y, E] = t.useState(""), [W, T] = t.useState(), [I, b] = t.useState(!1), [g, U] = t.useState(!1), [D, L] = t.useState([]), [M, ee] = t.useState(""), { t: m } = t.useContext(me), N = m(a ? "design-system:fileUpload.instructions_plural" : "design-system:fileUpload.instructions").split("|"), te = o || (a ? "Files" : "File"), v = t.useRef(null);
|
|
79
|
+
t.useEffect(() => {
|
|
80
|
+
x && V(x);
|
|
81
|
+
}, [x]), t.useEffect(() => {
|
|
82
|
+
p && ae(p);
|
|
83
|
+
}, [p]), t.useEffect(() => {
|
|
84
|
+
c && le(c);
|
|
85
|
+
}, [c]);
|
|
86
|
+
function ie() {
|
|
87
|
+
l && (V(!1), A && A());
|
|
88
|
+
}
|
|
89
|
+
function ae(i) {
|
|
90
|
+
try {
|
|
91
|
+
T(ve(i));
|
|
92
|
+
} catch {
|
|
93
|
+
throw new Error(`Could not parse "${i}" as a file size.`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function le(i) {
|
|
97
|
+
const d = (Array.isArray(i) ? i : i.trim().split(/\s?,\s?/)).map((u) => u.replace(/^\./, "")), r = d.map((u) => `.${u}`.toLowerCase());
|
|
98
|
+
ee(
|
|
99
|
+
r.map((u, C) => C > 0 && C === r.length - 1 ? `or ${u}` : u).join(r.length > 2 ? ", " : " ")
|
|
100
|
+
), S.clear();
|
|
101
|
+
for (const u of d)
|
|
102
|
+
for (const C of H[u.toUpperCase()].split(","))
|
|
103
|
+
S.add(C);
|
|
104
|
+
E(r.concat(Array.from(S)).join(","));
|
|
105
|
+
}
|
|
106
|
+
function P(i) {
|
|
107
|
+
L([]);
|
|
108
|
+
let s = [];
|
|
109
|
+
const d = Array.from(i);
|
|
110
|
+
for (const r of d)
|
|
111
|
+
r === null ? s.push("Not a file") : (c && !S.has(r.type) && s.push(r.name), p && W && r.size > W && s.indexOf(r.name) === -1 && s.push(r.name));
|
|
112
|
+
s.length ? (U(!0), v.current && v.current.value && (v.current.value = "")) : ($(d), O(d)), L(s);
|
|
113
|
+
}
|
|
114
|
+
function oe(i) {
|
|
115
|
+
i.preventDefault(), U(!1), v.current && v.current.click();
|
|
116
|
+
}
|
|
117
|
+
function ne() {
|
|
118
|
+
B && B();
|
|
119
|
+
}
|
|
120
|
+
function se(i) {
|
|
121
|
+
i.stopPropagation(), P(i.target.files || []);
|
|
122
|
+
}
|
|
123
|
+
function re(i) {
|
|
124
|
+
i.preventDefault(), i.stopPropagation(), b(!0), U(!1);
|
|
125
|
+
}
|
|
126
|
+
function ce(i) {
|
|
127
|
+
i.preventDefault(), b(!0), U(!1);
|
|
128
|
+
}
|
|
129
|
+
function pe(i) {
|
|
130
|
+
i.preventDefault(), b(!1);
|
|
131
|
+
}
|
|
132
|
+
function de(i) {
|
|
133
|
+
i.preventDefault(), i.stopPropagation(), b(!1), i.dataTransfer.items ? P(
|
|
134
|
+
Array.from(i.dataTransfer.items).map(
|
|
135
|
+
(s) => s.getAsFile()
|
|
136
|
+
)
|
|
137
|
+
) : P(i.dataTransfer.files);
|
|
138
|
+
}
|
|
139
|
+
return /* @__PURE__ */ t.createElement("div", {
|
|
140
|
+
onDrop: de,
|
|
141
|
+
onDragOver: re,
|
|
142
|
+
onDragLeave: pe,
|
|
143
|
+
onDragEnter: ce,
|
|
144
|
+
className: z(Se({ active: I, mini: h, error: g, shown: Q }), _),
|
|
145
|
+
...Y
|
|
146
|
+
}, /* @__PURE__ */ t.createElement("div", {
|
|
147
|
+
className: z(Ue({ constrainContentWidth: e }))
|
|
148
|
+
}, n ? /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement(ue, {
|
|
149
|
+
size: "md",
|
|
150
|
+
"aria-hidden": "true"
|
|
151
|
+
}), /* @__PURE__ */ t.createElement("div", {
|
|
152
|
+
className: q
|
|
153
|
+
}, m("design-system:fileUpload.processing"))) : /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement(he, {
|
|
154
|
+
className: Oe({ mini: h, error: g }),
|
|
155
|
+
icon: g ? "exclamation-circle" : "upload-cloud",
|
|
156
|
+
"aria-hidden": "true"
|
|
157
|
+
}), /* @__PURE__ */ t.createElement("div", {
|
|
158
|
+
className: Ne({ mini: h })
|
|
159
|
+
}, g ? /* @__PURE__ */ t.createElement("div", null, m(
|
|
160
|
+
D.length > 1 ? "design-system:fileUpload.cancelled_plural" : "design-system:fileUpload.cancelled"
|
|
161
|
+
)) : /* @__PURE__ */ t.createElement("div", null, m("design-system:fileUpload.title", { description: te }))), g ? /* @__PURE__ */ t.createElement("div", {
|
|
162
|
+
className: xe
|
|
163
|
+
}, new Set(
|
|
164
|
+
D.map((i, s) => {
|
|
165
|
+
const d = Math.floor(i.length / 2);
|
|
166
|
+
return /* @__PURE__ */ t.createElement("div", {
|
|
167
|
+
className: Fe,
|
|
168
|
+
key: i
|
|
169
|
+
}, /* @__PURE__ */ t.createElement("span", {
|
|
170
|
+
className: Z
|
|
171
|
+
}, i.substr(0, d)), /* @__PURE__ */ t.createElement("div", {
|
|
172
|
+
className: Z
|
|
173
|
+
}, /* @__PURE__ */ t.createElement("span", null, i.substr(d))), s < D.length - 1 ? "," : "");
|
|
174
|
+
})
|
|
175
|
+
)) : /* @__PURE__ */ t.createElement("span", null), /* @__PURE__ */ t.createElement("div", {
|
|
176
|
+
className: q
|
|
177
|
+
}, /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("span", null, N[0]), /* @__PURE__ */ t.createElement("a", {
|
|
178
|
+
href: "",
|
|
179
|
+
onClick: oe
|
|
180
|
+
}, N[1]), /* @__PURE__ */ t.createElement("span", null, N[2]))), /* @__PURE__ */ t.createElement("div", {
|
|
181
|
+
className: De
|
|
182
|
+
}, c ? /* @__PURE__ */ t.createElement("span", null, "(", " ", m("design-system:fileUpload.acceptedTypes", {
|
|
183
|
+
fileTypes: M
|
|
184
|
+
}), " ", ")") : "", p ? /* @__PURE__ */ t.createElement("span", null, "( ", m("design-system:fileUpload.maximumSize", { size: p }), " )") : "", F ? /* @__PURE__ */ t.createElement("span", null, " ", F, " ") : ""), w && /* @__PURE__ */ t.createElement("div", {
|
|
185
|
+
className: Ce
|
|
186
|
+
}, /* @__PURE__ */ t.createElement(R, {
|
|
187
|
+
kind: X.LINK,
|
|
188
|
+
icon: k.DOWNLOAD_CLOUD,
|
|
189
|
+
onClick: ne
|
|
190
|
+
}, w)))), l && !n && /* @__PURE__ */ t.createElement("div", {
|
|
191
|
+
className: be
|
|
192
|
+
}, /* @__PURE__ */ t.createElement(R, {
|
|
193
|
+
kind: X.ICON,
|
|
194
|
+
icon: k.X,
|
|
195
|
+
title: m("design-system:fileUpload.close"),
|
|
196
|
+
onClick: ie
|
|
197
|
+
})), /* @__PURE__ */ t.createElement("form", {
|
|
198
|
+
className: je
|
|
199
|
+
}, /* @__PURE__ */ t.createElement("input", {
|
|
200
|
+
ref: v,
|
|
201
|
+
type: "file",
|
|
202
|
+
accept: y || "*/*",
|
|
203
|
+
multiple: a || void 0,
|
|
204
|
+
onChange: se
|
|
205
|
+
})));
|
|
206
|
+
}
|
|
207
|
+
fe.set(J, {
|
|
208
|
+
name: "FileUpload",
|
|
209
|
+
props: {
|
|
210
|
+
constrainContentWidth: { type: "boolean" },
|
|
211
|
+
description: { type: "string" },
|
|
212
|
+
multiple: { type: "boolean" },
|
|
213
|
+
dismissable: { type: "boolean" },
|
|
214
|
+
mini: { type: "boolean" },
|
|
215
|
+
downloadLabel: { type: "string" },
|
|
216
|
+
acceptExtensions: { type: "string[] | string" },
|
|
217
|
+
maxSize: { type: "string" },
|
|
218
|
+
customRequirement: { type: "string" },
|
|
219
|
+
onSelection: { type: "(files: File[]) => void", required: !0 },
|
|
220
|
+
dismissal: { type: "() => void" },
|
|
221
|
+
download: { type: "() => void" }
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const Pe = {
|
|
225
|
+
components: [J],
|
|
226
|
+
examples: {
|
|
227
|
+
basic: {
|
|
228
|
+
label: "Basic File Upload",
|
|
229
|
+
description: "Simply allow the user to drag-and-drop or select a single file or multiple files at once.",
|
|
230
|
+
examples: {
|
|
231
|
+
basic: {
|
|
232
|
+
description: "Single file upload",
|
|
233
|
+
react: f`
|
|
234
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
235
|
+
|
|
236
|
+
function Component() {
|
|
237
|
+
function selectFile(file) {
|
|
238
|
+
console.log(file);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<FileUpload onSelection={selectFile} />
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
`
|
|
246
|
+
},
|
|
247
|
+
multiple: {
|
|
248
|
+
description: "Multiple file upload",
|
|
249
|
+
react: f`
|
|
250
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
251
|
+
|
|
252
|
+
function Component() {
|
|
253
|
+
function selectFile(file) {
|
|
254
|
+
console.log(file);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return (
|
|
258
|
+
<FileUpload onSelection={selectFile} multiple />
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
`
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
restrictions: {
|
|
266
|
+
label: "Restrictions",
|
|
267
|
+
description: "You can place restrictions on what files will be accepted with an extension whitelist and/or a maximum size.",
|
|
268
|
+
examples: {
|
|
269
|
+
maxSize: {
|
|
270
|
+
description: "Maximum size",
|
|
271
|
+
react: f`
|
|
272
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
273
|
+
|
|
274
|
+
function Component() {
|
|
275
|
+
function selectFile(file) {
|
|
276
|
+
console.log(file);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<FileUpload onSelection={selectFile} maxSize="100KB" />
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
`
|
|
284
|
+
},
|
|
285
|
+
fileWhitelist: {
|
|
286
|
+
description: "File type whitelist",
|
|
287
|
+
react: f`
|
|
288
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
289
|
+
|
|
290
|
+
function Component() {
|
|
291
|
+
function selectFile(file) {
|
|
292
|
+
console.log(file);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
<FileUpload
|
|
297
|
+
description="Spreadsheets"
|
|
298
|
+
onSelection={selectFile}
|
|
299
|
+
acceptExtensions="XLS, xlsx, .csv"
|
|
300
|
+
multiple
|
|
301
|
+
/>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
`
|
|
305
|
+
},
|
|
306
|
+
bothRestrictions: {
|
|
307
|
+
description: "Both restrictions",
|
|
308
|
+
react: f`
|
|
309
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
310
|
+
|
|
311
|
+
function Component() {
|
|
312
|
+
function selectFile(file) {
|
|
313
|
+
console.log(file);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<FileUpload
|
|
318
|
+
description="Spreadsheets"
|
|
319
|
+
onSelection={selectFile}
|
|
320
|
+
acceptExtensions="XLS, xlsx, .csv"
|
|
321
|
+
maxSize="100KB"
|
|
322
|
+
multiple
|
|
323
|
+
/>
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
`
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
dismissable: {
|
|
331
|
+
label: "Dismissable",
|
|
332
|
+
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.",
|
|
333
|
+
examples: {
|
|
334
|
+
basic: {
|
|
335
|
+
react: f`
|
|
336
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
337
|
+
|
|
338
|
+
function Component() {
|
|
339
|
+
const [showFileUpload, setShowFileUpload] = React.useState(true);
|
|
340
|
+
function handleDismissal() {
|
|
341
|
+
setShowFileUpload(false);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function selectFile(file) {
|
|
345
|
+
console.log(file);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return (
|
|
349
|
+
<>
|
|
350
|
+
<FileUpload
|
|
351
|
+
onSelection={selectFile}
|
|
352
|
+
dismissable
|
|
353
|
+
onDismiss={handleDismissal}
|
|
354
|
+
shown={showFileUpload}
|
|
355
|
+
/>
|
|
356
|
+
{!showFileUpload && (
|
|
357
|
+
<SpsButton onClick={() => setShowFileUpload(true)}>
|
|
358
|
+
Reset
|
|
359
|
+
</SpsButton>
|
|
360
|
+
)}
|
|
361
|
+
</>
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
`
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
download: {
|
|
369
|
+
label: "Download Button",
|
|
370
|
+
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.",
|
|
371
|
+
examples: {
|
|
372
|
+
basic: {
|
|
373
|
+
react: f`
|
|
374
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
375
|
+
|
|
376
|
+
function Component() {
|
|
377
|
+
function selectFile(file) {
|
|
378
|
+
console.log(file);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function handleDownload() {
|
|
382
|
+
console.log("Download triggered");
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return (
|
|
386
|
+
<FileUpload
|
|
387
|
+
onSelection={selectFile}
|
|
388
|
+
description="Spreadsheet"
|
|
389
|
+
acceptExtensions="xlsx"
|
|
390
|
+
downloadLabel="Download Excel Template"
|
|
391
|
+
download={handleDownload}
|
|
392
|
+
/>
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
`
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
mini: {
|
|
400
|
+
label: "Mini File Upload",
|
|
401
|
+
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.",
|
|
402
|
+
examples: {
|
|
403
|
+
basic: {
|
|
404
|
+
react: f`
|
|
405
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
406
|
+
|
|
407
|
+
function Component() {
|
|
408
|
+
function selectFile(file) {
|
|
409
|
+
console.log(file);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return (
|
|
413
|
+
<div className={grid.root}>
|
|
414
|
+
<div className={grid[4]}>
|
|
415
|
+
<FileUpload onSelection={selectFile} mini />
|
|
416
|
+
</div>
|
|
417
|
+
</div>
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
`
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
constrainContentWidth: {
|
|
425
|
+
label: "Constrain Content Width",
|
|
426
|
+
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.",
|
|
427
|
+
examples: {
|
|
428
|
+
basic: {
|
|
429
|
+
react: f`
|
|
430
|
+
import { FileUpload } from "@sps-woodland/file-upload";
|
|
431
|
+
|
|
432
|
+
function Component() {
|
|
433
|
+
function selectFile(file) {
|
|
434
|
+
console.log(file);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return (
|
|
438
|
+
<div className={grid.root}>
|
|
439
|
+
<div className={grid[4]}>
|
|
440
|
+
<FileUpload onSelection={selectFile} constrainContentWidth />
|
|
441
|
+
</div>
|
|
442
|
+
</div>
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
`
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}, Re = {
|
|
451
|
+
"File Upload": Pe
|
|
452
|
+
};
|
|
453
|
+
export {
|
|
454
|
+
J as FileUpload,
|
|
455
|
+
Re as MANIFEST
|
|
456
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare enum MIMEType {
|
|
2
|
+
"7Z" = "application/x-7z-compressed",
|
|
3
|
+
AAC = "audio/aac",
|
|
4
|
+
ABW = "application/x-abiword",
|
|
5
|
+
ARC = "application/octet-stream",
|
|
6
|
+
AVI = "video/x-msvideo",
|
|
7
|
+
AZW = "application/vnd.amazon.ebook",
|
|
8
|
+
BIN = "application/octet-stream",
|
|
9
|
+
BMP = "image/bmp",
|
|
10
|
+
BZ = "application/x-bzip",
|
|
11
|
+
BZ2 = "application/x-bzip2",
|
|
12
|
+
CSH = "application/x-csh",
|
|
13
|
+
CSS = "text/css",
|
|
14
|
+
CSV = "text/csv,application/vnd.ms-excel",
|
|
15
|
+
DOC = "application/msword",
|
|
16
|
+
DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
17
|
+
EOT = "application/vnd.ms-fontobject",
|
|
18
|
+
EPUB = "application/epub+zip",
|
|
19
|
+
ES = "application/ecmascript",
|
|
20
|
+
FLV = "video/x-flv",
|
|
21
|
+
GIF = "image/gif",
|
|
22
|
+
GZ = "application/x-gzip",
|
|
23
|
+
HTM = "text/html",
|
|
24
|
+
HTML = "text/html",
|
|
25
|
+
ICO = "image/x-icon",
|
|
26
|
+
ICS = "text/calendar",
|
|
27
|
+
JAR = "application/java-archive",
|
|
28
|
+
JPEG = "image/jpeg",
|
|
29
|
+
JPG = "image/jpeg",
|
|
30
|
+
JS = "application/javascript",
|
|
31
|
+
JSON = "application/json",
|
|
32
|
+
M3U = "audio/x-mpequrl",
|
|
33
|
+
MID = "audio/midi",
|
|
34
|
+
MIDI = "audio/midi",
|
|
35
|
+
MOV = "video/quicktime",
|
|
36
|
+
MP3 = "audio/mpeg3",
|
|
37
|
+
MP4 = "video/mp4",
|
|
38
|
+
MPEG = "video/mpeg",
|
|
39
|
+
MPKG = "application/vnd.apple.installer+xml",
|
|
40
|
+
ODP = "application/vnd.oasis.opendocument.presentation",
|
|
41
|
+
ODS = "application/vnd.oasis.opendocument.spreadsheet",
|
|
42
|
+
ODT = "application/vnd.oasis.opendocument.text",
|
|
43
|
+
OGA = "audio/ogg",
|
|
44
|
+
OGV = "video/ogg",
|
|
45
|
+
OGX = "application/ogg",
|
|
46
|
+
OTF = "font/otf",
|
|
47
|
+
PNG = "image/png",
|
|
48
|
+
PDF = "application/pdf",
|
|
49
|
+
PPT = "application/vnd.ms-powerpoint",
|
|
50
|
+
PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
51
|
+
RAR = "application/x-rar-compressed",
|
|
52
|
+
RTF = "application/rtf",
|
|
53
|
+
SH = "application/x-sh",
|
|
54
|
+
SVG = "image/svg+xml",
|
|
55
|
+
SWF = "application/x-shockwave-flash",
|
|
56
|
+
TAR = "application/x-tar",
|
|
57
|
+
TIF = "image/tiff",
|
|
58
|
+
TIFF = "image/tiff",
|
|
59
|
+
TS = "application/typescript",
|
|
60
|
+
TTF = "font/ttf",
|
|
61
|
+
TXT = "text/plain",
|
|
62
|
+
VSD = "application/vnd.visio",
|
|
63
|
+
WAV = "audio/wav",
|
|
64
|
+
WEBA = "audio/webm",
|
|
65
|
+
WEBM = "video/webm",
|
|
66
|
+
WEBP = "image/webp",
|
|
67
|
+
WOFF = "font/woff",
|
|
68
|
+
WOFF2 = "font/woff2",
|
|
69
|
+
XHTML = "application/xhtml+xml",
|
|
70
|
+
XLS = "application/vnd.ms-excel",
|
|
71
|
+
XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
72
|
+
XML = "application/xml",
|
|
73
|
+
XUL = "application/vnd.mozilla.xul+xml",
|
|
74
|
+
ZIP = "application/zip"
|
|
75
|
+
}
|
package/lib/style.css
ADDED
|
@@ -0,0 +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}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sps-woodland/file-upload",
|
|
3
|
+
"description": "SPS Woodland Design System file upload component",
|
|
4
|
+
"version": "7.0.0",
|
|
5
|
+
"author": "SPS Commerce",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/file-upload",
|
|
8
|
+
"homepage": "https://github.com/SPSCommerce/woodland/tree/master/packages/@sps-woodland/file-upload#readme",
|
|
9
|
+
"main": "./lib/index.es.js",
|
|
10
|
+
"module": "./lib/index.es.js",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@sps-woodland/core": "7.0.0",
|
|
17
|
+
"@sps-woodland/tokens": "7.0.0",
|
|
18
|
+
"@spscommerce/utils": "^6.12.1",
|
|
19
|
+
"@spscommerce/ds-react": "7.0.0",
|
|
20
|
+
"@spscommerce/ds-shared": "7.0.0",
|
|
21
|
+
"@spscommerce/ds-colors": "7.0.0",
|
|
22
|
+
"@spscommerce/illustrations": "6.37.3",
|
|
23
|
+
"react": "^16.9.0",
|
|
24
|
+
"react-dom": "^16.9.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@sps-woodland/core": "7.0.0",
|
|
28
|
+
"@sps-woodland/tokens": "7.0.0",
|
|
29
|
+
"@spscommerce/utils": "^6.12.1",
|
|
30
|
+
"@spscommerce/ds-react": "7.0.0",
|
|
31
|
+
"@spscommerce/ds-shared": "7.0.0",
|
|
32
|
+
"@spscommerce/ds-colors": "7.0.0",
|
|
33
|
+
"@spscommerce/ds-illustrations": "6.37.3",
|
|
34
|
+
"@vanilla-extract/css": "^1.9.1",
|
|
35
|
+
"@vanilla-extract/recipes": "^0.2.5",
|
|
36
|
+
"react": "^16.9.0",
|
|
37
|
+
"react-dom": "^16.9.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "pnpm run build:js && pnpm run build:types",
|
|
41
|
+
"build:js": "vite build",
|
|
42
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir lib",
|
|
43
|
+
"watch": "vite build --watch",
|
|
44
|
+
"clean": "git clean -fdX",
|
|
45
|
+
"pub": "node ../../../scripts/publish-package.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
|
|
5
|
+
import pkg from "./package.json";
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [vanillaExtractPlugin()],
|
|
9
|
+
build: {
|
|
10
|
+
lib: {
|
|
11
|
+
entry: path.resolve(__dirname, "src/index.ts"),
|
|
12
|
+
formats: ["es", "cjs"],
|
|
13
|
+
fileName: (format) => `index.${format}.js`,
|
|
14
|
+
},
|
|
15
|
+
outDir: path.resolve(__dirname, "./lib"),
|
|
16
|
+
emptyOutDir: false,
|
|
17
|
+
rollupOptions: {
|
|
18
|
+
external: pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|