@sps-woodland/file-upload 7.17.9 → 8.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/lib/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ue=require("react"),w=require("@sps-woodland/core"),p=require("@spscommerce/utils"),R=require("@spscommerce/ds-react"),C=require("@spscommerce/ds-shared");function fe(t){if(t&&t.__esModule)return t;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(l,a,o.get?o:{enumerable:!0,get:()=>t[a]})}}return l.default=t,Object.freeze(l)}const e=fe(ue),W={"7Z":["application/x-7z-compressed"],AAC:["audio/aac"],ABW:["application/x-abiword"],ARC:["application/octet-stream"],AVI:["video/x-msvideo"],AZW:["application/vnd.amazon.ebook"],BIN:["application/octet-stream"],BMP:["image/bmp"],BZ:["application/x-bzip"],BZ2:["application/x-bzip2"],CER:["application/pkix-cert","application/x-x509-ca-cert"],CSH:["application/x-csh"],CSS:["text/css"],CSV:["text/csv,application/vnd.ms-excel"],DOC:["application/msword"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],EOT:["application/vnd.ms-fontobject"],EPUB:["application/epub+zip"],ES:["application/ecmascript"],FLV:["video/x-flv"],GIF:["image/gif"],GZ:["application/x-gzip"],HTM:["text/html"],HTML:["text/html"],ICO:["image/x-icon"],ICS:["text/calendar"],JAR:["application/java-archive"],JPEG:["image/jpeg"],JPG:["image/jpeg"],JS:["application/javascript"],JSON:["application/json"],M3U:["audio/x-mpequrl"],MID:["audio/midi"],MIDI:["audio/midi"],MOV:["video/quicktime"],MP3:["audio/mpeg3"],MP4:["video/mp4"],MPEG:["video/mpeg"],MPKG:["application/vnd.apple.installer+xml"],ODP:["application/vnd.oasis.opendocument.presentation"],ODS:["application/vnd.oasis.opendocument.spreadsheet"],ODT:["application/vnd.oasis.opendocument.text"],OGA:["audio/ogg"],OGV:["video/ogg"],OGX:["application/ogg"],OTF:["font/otf"],PNG:["image/png"],PDF:["application/pdf"],PPT:["application/vnd.ms-powerpoint"],PPTX:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],RAR:["application/x-rar-compressed"],RTF:["application/rtf"],SH:["application/x-sh"],SVG:["image/svg+xml"],SWF:["application/x-shockwave-flash"],TAR:["application/x-tar"],TIF:["image/tiff"],TIFF:["image/tiff"],TS:["application/typescript"],TTF:["font/ttf"],TXT:["text/plain"],VSD:["application/vnd.visio"],WAV:["audio/wav"],WEBA:["audio/webm"],WEBM:["video/webm"],WEBP:["image/webp"],WOFF:["font/woff"],WOFF2:["font/woff2"],XHTML:["application/xhtml+xml"],XLS:["application/vnd.ms-excel"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]};function me(t,l,a){return l in t?Object.defineProperty(t,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[l]=a,t}function z(t,l){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);l&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function L(t){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?z(Object(a),!0).forEach(function(o){me(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):z(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}var he=(t,l,a)=>{for(var o of Object.keys(t)){var n;if(t[o]!==((n=l[o])!==null&&n!==void 0?n:a[o]))return!1}return!0},j=t=>l=>{var a=t.defaultClassName,o=L(L({},t.defaultVariants),l);for(var n in o){var v,g=(v=o[n])!==null&&v!==void 0?v:t.defaultVariants[n];if(g!=null){var c=g;typeof c=="boolean"&&(c=c===!0?"true":"false");var d=t.variantClassNames[n][c];d&&(a+=" "+d)}}for(var[x,O]of t.compoundVariants)he(x,o,t.defaultVariants)&&(a+=" "+O);return a},ve="rh07jwm",k="rh07jwn",we="rh07jwl",ge=j({defaultClassName:"rh07jw0",variantClassNames:{active:{true:"rh07jw1",false:"rh07jw2"},mini:{true:"rh07jw3",false:"rh07jw4"},error:{true:"rh07jw5",false:"rh07jw6"},shown:{true:"rh07jw7",false:"rh07jw8"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0},compoundVariants:[]}),Fe="rh07jwq",xe=j({defaultClassName:"rh07jw9",variantClassNames:{constrainContentWidth:{true:"rh07jwa",false:"rh07jwb"}},defaultVariants:{constrainContentWidth:!1},compoundVariants:[]}),Se="rh07jwp",be="rh07jwr",ye=j({defaultClassName:"rh07jwd",variantClassNames:{mini:{true:"rh07jwe",false:"rh07jwf"},error:{true:"rh07jwg",false:"rh07jwh"}},defaultVariants:{mini:!1,error:!1},compoundVariants:[]}),X="rh07jwc",Ee="rh07jwo",Ue=j({defaultClassName:"rh07jwi",variantClassNames:{mini:{true:"rh07jwj",false:"rh07jwk"}},defaultVariants:{mini:!1},compoundVariants:[]});function P({constrainContentWidth:t,description:l,multiple:a=!1,dismissable:o,processing:n,mini:v,downloadLabel:g,acceptExtensions:c,maxSize:d,customRequirement:x,onSelection:O,onDismiss:M,download:A,shown:S,className:G,children:Oe,..._}){const b=e.useRef(new Set),[q,I]=e.useState(S),[De,K]=e.useState([]),[Z,H]=e.useState(""),[B,J]=e.useState(),[Y,y]=e.useState(!1),[F,E]=e.useState(!1),[D,V]=e.useState([]),[Q,$]=e.useState(""),{t:h}=e.useContext(w.I18nContext),N=h(a?"design-system:fileUpload.instructions_plural":"design-system:fileUpload.instructions").split("|"),ee=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{S&&I(S)},[S]),e.useEffect(()=>{d&&ie(d)},[d]),e.useEffect(()=>{c&&ae(c)},[c]);function te(){o&&(I(!1),M&&M())}function ie(i){try{J(p.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function ae(i){const f=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(m=>m.replace(/^\./,"")),r=f.map(m=>`.${m}`.toLowerCase());$(r.map((m,U)=>U>0&&U===r.length-1?`or ${m}`:m).join(r.length>2?", ":" ")),b.current.clear();for(const m of f){const U=Object.keys(W).includes(m.toUpperCase())?W[m.toUpperCase()]:[];for(const de of U)b.current.add(de)}H(r.concat(Array.from(b.current)).join(","))}function T(i){V([]);let s=[];const f=Array.from(i);for(const r of f)r===null?s.push("Not a file"):(c&&!b.current.has(r.type)&&s.push(r.name),d&&B&&r.size>B&&s.indexOf(r.name)===-1&&s.push(r.name));s.length?(E(!0),u.current&&u.current.value&&(u.current.value="")):(K(f),O(f)),V(s)}function oe(i){i.preventDefault(),E(!1),u.current&&u.current.click()}function le(){A&&A()}function ne(i){i.stopPropagation(),T(i.target.files||[]),u.current&&u.current.value&&(u.current.value="")}function se(i){i.preventDefault(),i.stopPropagation(),y(!0),E(!1)}function re(i){i.preventDefault(),y(!0),E(!1)}function ce(i){i.preventDefault(),y(!1)}function pe(i){i.preventDefault(),i.stopPropagation(),y(!1),i.dataTransfer.items?T(Array.from(i.dataTransfer.items).map(s=>s.getAsFile())):T(i.dataTransfer.files)}return e.createElement("div",{onDrop:pe,onDragOver:se,onDragLeave:ce,onDragEnter:re,className:w.cl(ge({active:Y,mini:v,error:F,shown:q}),G),..._},e.createElement("div",{className:w.cl(xe({constrainContentWidth:t}))},n?e.createElement("div",null,e.createElement(w.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:X},h("design-system:fileUpload.processing"))):e.createElement("div",null,e.createElement(w.Icon,{className:ye({mini:v,error:F}),icon:F?"exclamation-circle":"upload-cloud","aria-hidden":"true"}),e.createElement("div",{className:Ue({mini:v})},F?e.createElement("div",null,h(D.length>1?"design-system:fileUpload.cancelled_plural":"design-system:fileUpload.cancelled")):e.createElement("div",null,h("design-system:fileUpload.title",{description:ee}))),F?e.createElement("div",{className:we},new Set(D.map((i,s)=>{const f=Math.floor(i.length/2);return e.createElement("div",{className:ve,key:i},e.createElement("span",{className:k},i.substr(0,f)),e.createElement("div",{className:k},e.createElement("span",null,i.substr(f))),s<D.length-1?",":"")}))):e.createElement("span",null),e.createElement("div",{className:X},e.createElement("div",null,e.createElement("span",null,N[0]),e.createElement("a",{href:"",onClick:oe},N[1]),e.createElement("span",null,N[2]))),e.createElement("div",{className:Ee},c?e.createElement("span",null,"("," ",h("design-system:fileUpload.acceptedTypes",{fileTypes:Q})," ",")"):"",d?e.createElement("span",null,"( ",h("design-system:fileUpload.maximumSize",{size:d})," )"):"",x?e.createElement("span",null," ",x," "):""),g&&e.createElement("div",{className:Se},e.createElement(R.SpsButton,{kind:C.ButtonKind.LINK,icon:C.SpsIcon.DOWNLOAD_CLOUD,onClick:le},g)))),o&&!n&&e.createElement("div",{className:Fe},e.createElement(R.SpsButton,{kind:C.ButtonKind.ICON,icon:C.SpsIcon.X,title:h("design-system:fileUpload.close"),onClick:te})),e.createElement("form",{className:be},e.createElement("input",{ref:u,type:"file",accept:Z||"*/*",multiple:a||void 0,onChange:ne})))}w.Metadata.set(P,{name:"FileUpload",props:{constrainContentWidth:{type:"boolean"},description:{type:"string"},multiple:{type:"boolean"},dismissable:{type:"boolean"},mini:{type:"boolean"},downloadLabel:{type:"string"},acceptExtensions:{type:"string[] | string"},maxSize:{type:"string"},customRequirement:{type:"string"},onSelection:{type:"(files: File[]) => void",required:!0},dismissal:{type:"() => void"},download:{type:"() => void"}}});const Ce={components:[P],examples:{basic:{label:"Basic File Upload",description:"Simply allow the user to drag-and-drop or select a single file or multiple files at once.",examples:{basic:{description:"Single file upload",react:p.code`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const de=require("react"),w=require("@sps-woodland/core"),p=require("@spscommerce/utils"),V=require("@sps-woodland/buttons");function ue(t){if(t&&t.__esModule)return t;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(l,a,o.get?o:{enumerable:!0,get:()=>t[a]})}}return l.default=t,Object.freeze(l)}const e=ue(de),z={"7Z":["application/x-7z-compressed"],AAC:["audio/aac"],ABW:["application/x-abiword"],ARC:["application/octet-stream"],AVI:["video/x-msvideo"],AZW:["application/vnd.amazon.ebook"],BIN:["application/octet-stream"],BMP:["image/bmp"],BZ:["application/x-bzip"],BZ2:["application/x-bzip2"],CER:["application/pkix-cert","application/x-x509-ca-cert"],CSH:["application/x-csh"],CSS:["text/css"],CSV:["text/csv,application/vnd.ms-excel"],DOC:["application/msword"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],EOT:["application/vnd.ms-fontobject"],EPUB:["application/epub+zip"],ES:["application/ecmascript"],FLV:["video/x-flv"],GIF:["image/gif"],GZ:["application/x-gzip"],HTM:["text/html"],HTML:["text/html"],ICO:["image/x-icon"],ICS:["text/calendar"],JAR:["application/java-archive"],JPEG:["image/jpeg"],JPG:["image/jpeg"],JS:["application/javascript"],JSON:["application/json"],M3U:["audio/x-mpequrl"],MID:["audio/midi"],MIDI:["audio/midi"],MOV:["video/quicktime"],MP3:["audio/mpeg3"],MP4:["video/mp4"],MPEG:["video/mpeg"],MPKG:["application/vnd.apple.installer+xml"],ODP:["application/vnd.oasis.opendocument.presentation"],ODS:["application/vnd.oasis.opendocument.spreadsheet"],ODT:["application/vnd.oasis.opendocument.text"],OGA:["audio/ogg"],OGV:["video/ogg"],OGX:["application/ogg"],OTF:["font/otf"],PNG:["image/png"],PDF:["application/pdf"],PPT:["application/vnd.ms-powerpoint"],PPTX:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],RAR:["application/x-rar-compressed"],RTF:["application/rtf"],SH:["application/x-sh"],SVG:["image/svg+xml"],SWF:["application/x-shockwave-flash"],TAR:["application/x-tar"],TIF:["image/tiff"],TIFF:["image/tiff"],TS:["application/typescript"],TTF:["font/ttf"],TXT:["text/plain"],VSD:["application/vnd.visio"],WAV:["audio/wav"],WEBA:["audio/webm"],WEBM:["video/webm"],WEBP:["image/webp"],WOFF:["font/woff"],WOFF2:["font/woff2"],XHTML:["application/xhtml+xml"],XLS:["application/vnd.ms-excel"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]};function fe(t,l,a){return l in t?Object.defineProperty(t,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[l]=a,t}function R(t,l){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);l&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function W(t){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?R(Object(a),!0).forEach(function(o){fe(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):R(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}var me=(t,l,a)=>{for(var o of Object.keys(t)){var n;if(t[o]!==((n=l[o])!==null&&n!==void 0?n:a[o]))return!1}return!0},j=t=>l=>{var a=t.defaultClassName,o=W(W({},t.defaultVariants),l);for(var n in o){var v,g=(v=o[n])!==null&&v!==void 0?v:t.defaultVariants[n];if(g!=null){var c=g;typeof c=="boolean"&&(c=c===!0?"true":"false");var d=t.variantClassNames[n][c];d&&(a+=" "+d)}}for(var[x,C]of t.compoundVariants)me(x,o,t.defaultVariants)&&(a+=" "+C);return a},he="rh07jwm",k="rh07jwn",ve="rh07jwl",we=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:[]}),ge="rh07jwq",Fe=j({defaultClassName:"rh07jw9",variantClassNames:{constrainContentWidth:{true:"rh07jwa",false:"rh07jwb"}},defaultVariants:{constrainContentWidth:!1},compoundVariants:[]}),xe="rh07jwp",be="rh07jwr",ye=j({defaultClassName:"rh07jwd",variantClassNames:{mini:{true:"rh07jwe",false:"rh07jwf"},error:{true:"rh07jwg",false:"rh07jwh"}},defaultVariants:{mini:!1,error:!1},compoundVariants:[]}),L="rh07jwc",Se="rh07jwo",Ee=j({defaultClassName:"rh07jwi",variantClassNames:{mini:{true:"rh07jwj",false:"rh07jwk"}},defaultVariants:{mini:!1},compoundVariants:[]});function N({constrainContentWidth:t,description:l,multiple:a=!1,dismissable:o,processing:n,mini:v,downloadLabel:g,acceptExtensions:c,maxSize:d,customRequirement:x,onSelection:C,onDismiss:P,download:M,shown:b,className:X,children:Ce,...G}){const y=e.useRef(new Set),[_,A]=e.useState(b),[Oe,q]=e.useState([]),[Z,H]=e.useState(""),[B,J]=e.useState(),[K,S]=e.useState(!1),[F,E]=e.useState(!1),[O,I]=e.useState([]),[Y,Q]=e.useState(""),{t:h}=e.useContext(w.I18nContext),D=h(a?"design-system:fileUpload.instructions_plural":"design-system:fileUpload.instructions").split("|"),$=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{b&&A(b)},[b]),e.useEffect(()=>{d&&te(d)},[d]),e.useEffect(()=>{c&&ie(c)},[c]);function ee(){o&&(A(!1),P&&P())}function te(i){try{J(p.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function ie(i){const f=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(m=>m.replace(/^\./,"")),r=f.map(m=>`.${m}`.toLowerCase());Q(r.map((m,U)=>U>0&&U===r.length-1?`or ${m}`:m).join(r.length>2?", ":" ")),y.current.clear();for(const m of f){const U=Object.keys(z).includes(m.toUpperCase())?z[m.toUpperCase()]:[];for(const pe of U)y.current.add(pe)}H(r.concat(Array.from(y.current)).join(","))}function T(i){I([]);let s=[];const f=Array.from(i);for(const r of f)r===null?s.push("Not a file"):(c&&!y.current.has(r.type)&&s.push(r.name),d&&B&&r.size>B&&s.indexOf(r.name)===-1&&s.push(r.name));s.length?(E(!0),u.current&&u.current.value&&(u.current.value="")):(q(f),C(f)),I(s)}function ae(i){i.preventDefault(),E(!1),u.current&&u.current.click()}function oe(){M&&M()}function le(i){i.stopPropagation(),T(i.target.files||[]),u.current&&u.current.value&&(u.current.value="")}function ne(i){i.preventDefault(),i.stopPropagation(),S(!0),E(!1)}function se(i){i.preventDefault(),S(!0),E(!1)}function re(i){i.preventDefault(),S(!1)}function ce(i){i.preventDefault(),i.stopPropagation(),S(!1),i.dataTransfer.items?T(Array.from(i.dataTransfer.items).map(s=>s.getAsFile())):T(i.dataTransfer.files)}return e.createElement("div",{onDrop:ce,onDragOver:ne,onDragLeave:re,onDragEnter:se,className:w.cl(we({active:K,mini:v,error:F,shown:_}),X),...G},e.createElement("div",{className:w.cl(Fe({constrainContentWidth:t}))},n?e.createElement("div",null,e.createElement(w.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:L},h("design-system:fileUpload.processing"))):e.createElement("div",null,e.createElement(w.Icon,{className:ye({mini:v,error:F}),icon:F?"exclamation-circle":"upload-cloud","aria-hidden":"true"}),e.createElement("div",{className:Ee({mini:v})},F?e.createElement("div",null,h(O.length>1?"design-system:fileUpload.cancelled_plural":"design-system:fileUpload.cancelled")):e.createElement("div",null,h("design-system:fileUpload.title",{description:$}))),F?e.createElement("div",{className:ve},new Set(O.map((i,s)=>{const f=Math.floor(i.length/2);return e.createElement("div",{className:he,key:i},e.createElement("span",{className:k},i.substr(0,f)),e.createElement("div",{className:k},e.createElement("span",null,i.substr(f))),s<O.length-1?",":"")}))):e.createElement("span",null),e.createElement("div",{className:L},e.createElement("div",null,e.createElement("span",null,D[0]),e.createElement("a",{href:"",onClick:ae},D[1]),e.createElement("span",null,D[2]))),e.createElement("div",{className:Se},c?e.createElement("span",null,"("," ",h("design-system:fileUpload.acceptedTypes",{fileTypes:Y})," ",")"):"",d?e.createElement("span",null,"( ",h("design-system:fileUpload.maximumSize",{size:d})," )"):"",x?e.createElement("span",null," ",x," "):""),g&&e.createElement("div",{className:xe},e.createElement(V.Button,{kind:"link",icon:"download-cloud",onClick:oe},g)))),o&&!n&&e.createElement("div",{className:ge},e.createElement(V.Button,{kind:"icon",icon:"x",title:h("design-system:fileUpload.close"),onClick:ee})),e.createElement("form",{className:be},e.createElement("input",{ref:u,type:"file",accept:Z||"*/*",multiple:a||void 0,onChange:le})))}w.Metadata.set(N,{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 Ue={components:[N],examples:{basic:{label:"Basic File Upload",description:"Simply allow the user to drag-and-drop or select a single file or multiple files at once.",examples:{basic:{description:"Single file upload",react:p.code`
2
2
  import { FileUpload } from "@sps-woodland/file-upload";
3
3
 
4
4
  function Component() {
@@ -71,6 +71,7 @@
71
71
  }
72
72
  `}}},dismissable:{label:"Dismissable",description:"With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can show it again programmatically if you need to.",examples:{basic:{react:p.code`
73
73
  import { FileUpload } from "@sps-woodland/file-upload";
74
+ import { Button } from "@sps-woodland/buttons";
74
75
 
75
76
  function Component() {
76
77
  const [showFileUpload, setShowFileUpload] = React.useState(true);
@@ -91,9 +92,9 @@
91
92
  shown={showFileUpload}
92
93
  />
93
94
  {!showFileUpload && (
94
- <SpsButton onClick={() => setShowFileUpload(true)}>
95
+ <Button onClick={() => setShowFileUpload(true)}>
95
96
  Reset
96
- </SpsButton>
97
+ </Button>
97
98
  )}
98
99
  </>
99
100
  )
@@ -152,4 +153,4 @@
152
153
  </div>
153
154
  )
154
155
  }
155
- `}}}}},je={"File Upload":Ce};exports.FileUpload=P;exports.MANIFEST=je;
156
+ `}}}}},je={"File Upload":Ue};exports.FileUpload=N;exports.MANIFEST=je;
package/lib/index.es.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as e from "react";
2
- import { Metadata as ue, I18nContext as me, cl as I, Spinner as he, Icon as ve } from "@sps-woodland/core";
3
- import { parseFileSize as we, code as m } from "@spscommerce/utils";
4
- import { SpsButton as B } from "@spscommerce/ds-react";
5
- import { ButtonKind as V, SpsIcon as W } from "@spscommerce/ds-shared";
6
- const L = {
2
+ import { Metadata as de, I18nContext as fe, cl as B, Spinner as ue, Icon as me } from "@sps-woodland/core";
3
+ import { parseFileSize as he, code as m } from "@spscommerce/utils";
4
+ import { Button as I } from "@sps-woodland/buttons";
5
+ const V = {
7
6
  "7Z": ["application/x-7z-compressed"],
8
7
  AAC: ["audio/aac"],
9
8
  ABW: ["application/x-abiword"],
@@ -79,7 +78,7 @@ const L = {
79
78
  XUL: ["application/vnd.mozilla.xul+xml"],
80
79
  ZIP: ["application/zip"]
81
80
  };
82
- function ge(i, o, a) {
81
+ function ve(i, o, a) {
83
82
  return o in i ? Object.defineProperty(i, o, {
84
83
  value: a,
85
84
  enumerable: !0,
@@ -87,7 +86,7 @@ function ge(i, o, a) {
87
86
  writable: !0
88
87
  }) : i[o] = a, i;
89
88
  }
90
- function z(i, o) {
89
+ function W(i, o) {
91
90
  var a = Object.keys(i);
92
91
  if (Object.getOwnPropertySymbols) {
93
92
  var l = Object.getOwnPropertySymbols(i);
@@ -97,18 +96,18 @@ function z(i, o) {
97
96
  }
98
97
  return a;
99
98
  }
100
- function R(i) {
99
+ function z(i) {
101
100
  for (var o = 1; o < arguments.length; o++) {
102
101
  var a = arguments[o] != null ? arguments[o] : {};
103
- o % 2 ? z(Object(a), !0).forEach(function(l) {
104
- ge(i, l, a[l]);
105
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(a)) : z(Object(a)).forEach(function(l) {
102
+ o % 2 ? W(Object(a), !0).forEach(function(l) {
103
+ ve(i, l, a[l]);
104
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(a)) : W(Object(a)).forEach(function(l) {
106
105
  Object.defineProperty(i, l, Object.getOwnPropertyDescriptor(a, l));
107
106
  });
108
107
  }
109
108
  return i;
110
109
  }
111
- var Fe = (i, o, a) => {
110
+ var we = (i, o, a) => {
112
111
  for (var l of Object.keys(i)) {
113
112
  var n;
114
113
  if (i[l] !== ((n = o[l]) !== null && n !== void 0 ? n : a[l]))
@@ -116,7 +115,7 @@ var Fe = (i, o, a) => {
116
115
  }
117
116
  return !0;
118
117
  }, U = (i) => (o) => {
119
- var a = i.defaultClassName, l = R(R({}, i.defaultVariants), o);
118
+ var a = i.defaultClassName, l = z(z({}, i.defaultVariants), o);
120
119
  for (var n in l) {
121
120
  var v, w = (v = l[n]) !== null && v !== void 0 ? v : i.defaultVariants[n];
122
121
  if (w != null) {
@@ -127,10 +126,10 @@ var Fe = (i, o, a) => {
127
126
  }
128
127
  }
129
128
  for (var [F, C] of i.compoundVariants)
130
- Fe(F, l, i.defaultVariants) && (a += " " + C);
129
+ we(F, l, i.defaultVariants) && (a += " " + C);
131
130
  return a;
132
- }, xe = "rh07jwm", k = "rh07jwn", ye = "rh07jwl", Se = U({ defaultClassName: "rh07jw0", variantClassNames: { active: { true: "rh07jw1", false: "rh07jw2" }, mini: { true: "rh07jw3", false: "rh07jw4" }, error: { true: "rh07jw5", false: "rh07jw6" }, shown: { true: "rh07jw7", false: "rh07jw8" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0 }, compoundVariants: [] }), be = "rh07jwq", Ee = U({ defaultClassName: "rh07jw9", variantClassNames: { constrainContentWidth: { true: "rh07jwa", false: "rh07jwb" } }, defaultVariants: { constrainContentWidth: !1 }, compoundVariants: [] }), Ue = "rh07jwp", Ce = "rh07jwr", je = U({ defaultClassName: "rh07jwd", variantClassNames: { mini: { true: "rh07jwe", false: "rh07jwf" }, error: { true: "rh07jwg", false: "rh07jwh" } }, defaultVariants: { mini: !1, error: !1 }, compoundVariants: [] }), X = "rh07jwc", Oe = "rh07jwo", De = U({ defaultClassName: "rh07jwi", variantClassNames: { mini: { true: "rh07jwj", false: "rh07jwk" } }, defaultVariants: { mini: !1 }, compoundVariants: [] });
133
- function G({
131
+ }, ge = "rh07jwm", R = "rh07jwn", Fe = "rh07jwl", xe = U({ defaultClassName: "rh07jw0", variantClassNames: { active: { true: "rh07jw1", false: "rh07jw2" }, mini: { true: "rh07jw3", false: "rh07jw4" }, error: { true: "rh07jw5", false: "rh07jw6" }, shown: { true: "rh07jw7", false: "rh07jw8" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0 }, compoundVariants: [] }), ye = "rh07jwq", be = U({ defaultClassName: "rh07jw9", variantClassNames: { constrainContentWidth: { true: "rh07jwa", false: "rh07jwb" } }, defaultVariants: { constrainContentWidth: !1 }, compoundVariants: [] }), Ee = "rh07jwp", Se = "rh07jwr", Ue = U({ defaultClassName: "rh07jwd", variantClassNames: { mini: { true: "rh07jwe", false: "rh07jwf" }, error: { true: "rh07jwg", false: "rh07jwh" } }, defaultVariants: { mini: !1, error: !1 }, compoundVariants: [] }), L = "rh07jwc", Ce = "rh07jwo", je = U({ defaultClassName: "rh07jwi", variantClassNames: { mini: { true: "rh07jwj", false: "rh07jwk" } }, defaultVariants: { mini: !1 }, compoundVariants: [] });
132
+ function k({
134
133
  constrainContentWidth: i,
135
134
  description: o,
136
135
  multiple: a = !1,
@@ -142,42 +141,42 @@ function G({
142
141
  maxSize: c,
143
142
  customRequirement: F,
144
143
  onSelection: C,
145
- onDismiss: N,
146
- download: T,
144
+ onDismiss: T,
145
+ download: N,
147
146
  shown: x,
148
- className: K,
149
- children: Te,
150
- ...Z
147
+ className: X,
148
+ children: De,
149
+ ...G
151
150
  }) {
152
- const y = e.useRef(/* @__PURE__ */ new Set()), [q, P] = e.useState(x), [Pe, H] = e.useState([]), [J, _] = e.useState(""), [A, Y] = e.useState(), [Q, S] = e.useState(!1), [g, b] = e.useState(!1), [j, M] = e.useState([]), [$, ee] = e.useState(""), { t: h } = e.useContext(me), O = h(a ? "design-system:fileUpload.instructions_plural" : "design-system:fileUpload.instructions").split("|"), te = o || (a ? "Files" : "File"), d = e.useRef(null);
151
+ const y = e.useRef(/* @__PURE__ */ new Set()), [Z, P] = e.useState(x), [Te, q] = e.useState([]), [H, J] = e.useState(""), [A, K] = e.useState(), [_, b] = e.useState(!1), [g, E] = e.useState(!1), [j, M] = e.useState([]), [Y, Q] = e.useState(""), { t: h } = e.useContext(fe), O = h(a ? "design-system:fileUpload.instructions_plural" : "design-system:fileUpload.instructions").split("|"), $ = o || (a ? "Files" : "File"), d = e.useRef(null);
153
152
  e.useEffect(() => {
154
153
  x && P(x);
155
154
  }, [x]), e.useEffect(() => {
156
- c && ae(c);
155
+ c && te(c);
157
156
  }, [c]), e.useEffect(() => {
158
- p && le(p);
157
+ p && ie(p);
159
158
  }, [p]);
160
- function ie() {
161
- l && (P(!1), N && N());
159
+ function ee() {
160
+ l && (P(!1), T && T());
162
161
  }
163
- function ae(t) {
162
+ function te(t) {
164
163
  try {
165
- Y(we(t));
164
+ K(he(t));
166
165
  } catch {
167
166
  throw new Error(`Could not parse "${t}" as a file size.`);
168
167
  }
169
168
  }
170
- function le(t) {
169
+ function ie(t) {
171
170
  const f = (Array.isArray(t) ? t : t.trim().split(/\s?,\s?/)).map((u) => u.replace(/^\./, "")), r = f.map((u) => `.${u}`.toLowerCase());
172
- ee(
173
- r.map((u, E) => E > 0 && E === r.length - 1 ? `or ${u}` : u).join(r.length > 2 ? ", " : " ")
171
+ Q(
172
+ r.map((u, S) => S > 0 && S === r.length - 1 ? `or ${u}` : u).join(r.length > 2 ? ", " : " ")
174
173
  ), y.current.clear();
175
174
  for (const u of f) {
176
- const E = Object.keys(L).includes(u.toUpperCase()) ? L[u.toUpperCase()] : [];
177
- for (const fe of E)
178
- y.current.add(fe);
175
+ const S = Object.keys(V).includes(u.toUpperCase()) ? V[u.toUpperCase()] : [];
176
+ for (const ce of S)
177
+ y.current.add(ce);
179
178
  }
180
- _(r.concat(Array.from(y.current)).join(","));
179
+ J(r.concat(Array.from(y.current)).join(","));
181
180
  }
182
181
  function D(t) {
183
182
  M([]);
@@ -185,102 +184,102 @@ function G({
185
184
  const f = Array.from(t);
186
185
  for (const r of f)
187
186
  r === null ? s.push("Not a file") : (p && !y.current.has(r.type) && s.push(r.name), c && A && r.size > A && s.indexOf(r.name) === -1 && s.push(r.name));
188
- s.length ? (b(!0), d.current && d.current.value && (d.current.value = "")) : (H(f), C(f)), M(s);
187
+ s.length ? (E(!0), d.current && d.current.value && (d.current.value = "")) : (q(f), C(f)), M(s);
188
+ }
189
+ function ae(t) {
190
+ t.preventDefault(), E(!1), d.current && d.current.click();
191
+ }
192
+ function le() {
193
+ N && N();
189
194
  }
190
195
  function oe(t) {
191
- t.preventDefault(), b(!1), d.current && d.current.click();
196
+ t.stopPropagation(), D(t.target.files || []), d.current && d.current.value && (d.current.value = "");
192
197
  }
193
- function ne() {
194
- T && T();
198
+ function ne(t) {
199
+ t.preventDefault(), t.stopPropagation(), b(!0), E(!1);
195
200
  }
196
201
  function se(t) {
197
- t.stopPropagation(), D(t.target.files || []), d.current && d.current.value && (d.current.value = "");
202
+ t.preventDefault(), b(!0), E(!1);
198
203
  }
199
204
  function re(t) {
200
- t.preventDefault(), t.stopPropagation(), S(!0), b(!1);
205
+ t.preventDefault(), b(!1);
201
206
  }
202
207
  function pe(t) {
203
- t.preventDefault(), S(!0), b(!1);
204
- }
205
- function ce(t) {
206
- t.preventDefault(), S(!1);
207
- }
208
- function de(t) {
209
- t.preventDefault(), t.stopPropagation(), S(!1), t.dataTransfer.items ? D(
208
+ t.preventDefault(), t.stopPropagation(), b(!1), t.dataTransfer.items ? D(
210
209
  Array.from(t.dataTransfer.items).map(
211
210
  (s) => s.getAsFile()
212
211
  )
213
212
  ) : D(t.dataTransfer.files);
214
213
  }
215
214
  return /* @__PURE__ */ e.createElement("div", {
216
- onDrop: de,
217
- onDragOver: re,
218
- onDragLeave: ce,
219
- onDragEnter: pe,
220
- className: I(Se({ active: Q, mini: v, error: g, shown: q }), K),
221
- ...Z
215
+ onDrop: pe,
216
+ onDragOver: ne,
217
+ onDragLeave: re,
218
+ onDragEnter: se,
219
+ className: B(xe({ active: _, mini: v, error: g, shown: Z }), X),
220
+ ...G
222
221
  }, /* @__PURE__ */ e.createElement("div", {
223
- className: I(Ee({ constrainContentWidth: i }))
224
- }, n ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(he, {
222
+ className: B(be({ constrainContentWidth: i }))
223
+ }, n ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(ue, {
225
224
  size: "md",
226
225
  "aria-hidden": "true"
227
226
  }), /* @__PURE__ */ e.createElement("div", {
228
- className: X
229
- }, h("design-system:fileUpload.processing"))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(ve, {
230
- className: je({ mini: v, error: g }),
227
+ className: L
228
+ }, h("design-system:fileUpload.processing"))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(me, {
229
+ className: Ue({ mini: v, error: g }),
231
230
  icon: g ? "exclamation-circle" : "upload-cloud",
232
231
  "aria-hidden": "true"
233
232
  }), /* @__PURE__ */ e.createElement("div", {
234
- className: De({ mini: v })
233
+ className: je({ mini: v })
235
234
  }, g ? /* @__PURE__ */ e.createElement("div", null, h(
236
235
  j.length > 1 ? "design-system:fileUpload.cancelled_plural" : "design-system:fileUpload.cancelled"
237
- )) : /* @__PURE__ */ e.createElement("div", null, h("design-system:fileUpload.title", { description: te }))), g ? /* @__PURE__ */ e.createElement("div", {
238
- className: ye
236
+ )) : /* @__PURE__ */ e.createElement("div", null, h("design-system:fileUpload.title", { description: $ }))), g ? /* @__PURE__ */ e.createElement("div", {
237
+ className: Fe
239
238
  }, new Set(
240
239
  j.map((t, s) => {
241
240
  const f = Math.floor(t.length / 2);
242
241
  return /* @__PURE__ */ e.createElement("div", {
243
- className: xe,
242
+ className: ge,
244
243
  key: t
245
244
  }, /* @__PURE__ */ e.createElement("span", {
246
- className: k
245
+ className: R
247
246
  }, t.substr(0, f)), /* @__PURE__ */ e.createElement("div", {
248
- className: k
247
+ className: R
249
248
  }, /* @__PURE__ */ e.createElement("span", null, t.substr(f))), s < j.length - 1 ? "," : "");
250
249
  })
251
250
  )) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", {
252
- className: X
251
+ className: L
253
252
  }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("span", null, O[0]), /* @__PURE__ */ e.createElement("a", {
254
253
  href: "",
255
- onClick: oe
254
+ onClick: ae
256
255
  }, O[1]), /* @__PURE__ */ e.createElement("span", null, O[2]))), /* @__PURE__ */ e.createElement("div", {
257
- className: Oe
256
+ className: Ce
258
257
  }, p ? /* @__PURE__ */ e.createElement("span", null, "(", " ", h("design-system:fileUpload.acceptedTypes", {
259
- fileTypes: $
258
+ fileTypes: Y
260
259
  }), " ", ")") : "", c ? /* @__PURE__ */ e.createElement("span", null, "( ", h("design-system:fileUpload.maximumSize", { size: c }), " )") : "", F ? /* @__PURE__ */ e.createElement("span", null, " ", F, " ") : ""), w && /* @__PURE__ */ e.createElement("div", {
261
- className: Ue
262
- }, /* @__PURE__ */ e.createElement(B, {
263
- kind: V.LINK,
264
- icon: W.DOWNLOAD_CLOUD,
265
- onClick: ne
260
+ className: Ee
261
+ }, /* @__PURE__ */ e.createElement(I, {
262
+ kind: "link",
263
+ icon: "download-cloud",
264
+ onClick: le
266
265
  }, w)))), l && !n && /* @__PURE__ */ e.createElement("div", {
267
- className: be
268
- }, /* @__PURE__ */ e.createElement(B, {
269
- kind: V.ICON,
270
- icon: W.X,
266
+ className: ye
267
+ }, /* @__PURE__ */ e.createElement(I, {
268
+ kind: "icon",
269
+ icon: "x",
271
270
  title: h("design-system:fileUpload.close"),
272
- onClick: ie
271
+ onClick: ee
273
272
  })), /* @__PURE__ */ e.createElement("form", {
274
- className: Ce
273
+ className: Se
275
274
  }, /* @__PURE__ */ e.createElement("input", {
276
275
  ref: d,
277
276
  type: "file",
278
- accept: J || "*/*",
277
+ accept: H || "*/*",
279
278
  multiple: a || void 0,
280
- onChange: se
279
+ onChange: oe
281
280
  })));
282
281
  }
283
- ue.set(G, {
282
+ de.set(k, {
284
283
  name: "FileUpload",
285
284
  props: {
286
285
  constrainContentWidth: { type: "boolean" },
@@ -297,8 +296,8 @@ ue.set(G, {
297
296
  download: { type: "() => void" }
298
297
  }
299
298
  });
300
- const Ne = {
301
- components: [G],
299
+ const Oe = {
300
+ components: [k],
302
301
  examples: {
303
302
  basic: {
304
303
  label: "Basic File Upload",
@@ -410,6 +409,7 @@ const Ne = {
410
409
  basic: {
411
410
  react: m`
412
411
  import { FileUpload } from "@sps-woodland/file-upload";
412
+ import { Button } from "@sps-woodland/buttons";
413
413
 
414
414
  function Component() {
415
415
  const [showFileUpload, setShowFileUpload] = React.useState(true);
@@ -430,9 +430,9 @@ const Ne = {
430
430
  shown={showFileUpload}
431
431
  />
432
432
  {!showFileUpload && (
433
- <SpsButton onClick={() => setShowFileUpload(true)}>
433
+ <Button onClick={() => setShowFileUpload(true)}>
434
434
  Reset
435
- </SpsButton>
435
+ </Button>
436
436
  )}
437
437
  </>
438
438
  )
@@ -523,10 +523,10 @@ const Ne = {
523
523
  }
524
524
  }
525
525
  }
526
- }, Ve = {
527
- "File Upload": Ne
526
+ }, Me = {
527
+ "File Upload": Oe
528
528
  };
529
529
  export {
530
- G as FileUpload,
531
- Ve as MANIFEST
530
+ k as FileUpload,
531
+ Me as MANIFEST
532
532
  };
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": "7.17.9",
4
+ "version": "8.0.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/file-upload",
@@ -26,28 +26,29 @@
26
26
  "access": "public"
27
27
  },
28
28
  "peerDependencies": {
29
- "@spscommerce/ds-illustrations": "6.37.3",
30
29
  "@spscommerce/utils": "^6.12.1",
30
+ "@spscommerce/ds-illustrations": "^6.12.1",
31
31
  "react": "^16.14.0",
32
32
  "react-dom": "^16.14.0",
33
- "@sps-woodland/core": "7.17.9",
34
- "@sps-woodland/tokens": "7.17.9",
35
- "@spscommerce/ds-colors": "7.17.9",
36
- "@spscommerce/ds-react": "7.17.9",
37
- "@spscommerce/ds-shared": "7.17.9"
33
+ "@sps-woodland/core": "8.0.0",
34
+ "@sps-woodland/tokens": "8.0.0",
35
+ "@sps-woodland/buttons": "8.0.0",
36
+ "@spscommerce/ds-react": "8.0.0",
37
+ "@spscommerce/ds-shared": "8.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@spscommerce/ds-illustrations": "6.37.3",
41
40
  "@spscommerce/utils": "^6.12.1",
41
+ "@spscommerce/ds-illustrations": "^6.12.1",
42
42
  "@vanilla-extract/css": "^1.9.3",
43
43
  "@vanilla-extract/recipes": "^0.2.5",
44
44
  "react": "^16.14.0",
45
45
  "react-dom": "^16.14.0",
46
- "@sps-woodland/core": "7.17.9",
47
- "@sps-woodland/tokens": "7.17.9",
48
- "@spscommerce/ds-colors": "7.17.9",
49
- "@spscommerce/ds-react": "7.17.9",
50
- "@spscommerce/ds-shared": "7.17.9"
46
+ "@sps-woodland/core": "8.0.0",
47
+ "@sps-woodland/tokens": "8.0.0",
48
+ "@sps-woodland/buttons": "8.0.0",
49
+ "@spscommerce/ds-react": "8.0.0",
50
+ "@spscommerce/ds-shared": "8.0.0",
51
+ "@spscommerce/ds-colors": "8.0.0"
51
52
  },
52
53
  "scripts": {
53
54
  "build": "pnpm run build:js && pnpm run build:types",