@adamosuiteservices/ui 2.18.5 → 2.18.6
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/dist/file-upload-v2.cjs +3 -3
- package/dist/file-upload-v2.js +3 -3
- package/dist/file-upload.cjs +2 -2
- package/dist/file-upload.js +41 -41
- package/package.json +1 -1
package/dist/file-upload-v2.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./jsx-runtime-BB_1_6y_.cjs"),M=require("./button-CFJs0esR.cjs"),G=require("./icon-B7joBr0A.cjs"),N=require("./typography-Bj8oEDuE.cjs"),D=require("./index-DoxiiusW.cjs"),k=require("react");function te({isDragging:c,isMultiple:o,invalid:a,disabled:t,accept:i,acceptedExtensions:m,maxSizeInMB:d,maxFiles:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./jsx-runtime-BB_1_6y_.cjs"),M=require("./button-CFJs0esR.cjs"),G=require("./icon-B7joBr0A.cjs"),N=require("./typography-Bj8oEDuE.cjs"),D=require("./index-DoxiiusW.cjs"),k=require("react");function te({isDragging:c,isMultiple:o,invalid:a,disabled:t,accept:i,acceptedExtensions:m,maxSizeInMB:d,maxFiles:f,labels:p,input:h,onDragOver:l,onDragLeave:v,onDrop:g,onFileChange:j}){const u=h?.id||`file-upload-v2-${Math.random().toString(36).substring(2,11)}`;return r.jsxRuntimeExports.jsxs("div",{onDragOver:t?void 0:l,onDragLeave:t?void 0:v,onDrop:t?void 0:g,className:D.cn(`
|
|
2
2
|
adm:flex adm:flex-col adm:items-center adm:gap-6 adm:rounded-2xl
|
|
3
3
|
adm:border-2
|
|
4
|
-
`,"adm:border-dashed adm:bg-background adm:p-6 adm:transition-colors",{"adm:border-primary":c&&!a&&!t,"adm:border-destructive":a&&!t,"adm:border-input":!c&&!a,"adm:cursor-not-allowed adm:opacity-50":t}),children:[r.jsxRuntimeExports.jsx("div",{className:D.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",a&&!t?"adm:bg-destructive/10":"adm:bg-primary-50"),children:r.jsxRuntimeExports.jsx(G.Icon,{symbol:"text_snippet",className:a&&!t?"adm:text-destructive":"adm:text-primary"})}),r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:items-center adm:gap-2",children:[r.jsxRuntimeExports.jsx(N.Typography,{color:a&&!t?"destructive":void 0,children:p?.dragDrop||(o?"Drag and drop your files here or":"Drag and drop your file here or")}),r.jsxRuntimeExports.jsxs("label",{htmlFor:u,children:[r.jsxRuntimeExports.jsx("input",{...h,id:u,type:"file",accept:i,multiple:o,onChange:j,disabled:t,className:"adm:hidden"}),r.jsxRuntimeExports.jsx(M.Button,{asChild:!0,type:"button",variant:"link",className:D.cn("adm:cursor-pointer",t&&`
|
|
4
|
+
`,"adm:border-dashed adm:bg-background adm:p-6 adm:transition-colors",{"adm:border-primary":c&&!a&&!t,"adm:border-destructive":a&&!t,"adm:border-input":!c&&!a,"adm:cursor-not-allowed adm:opacity-50":t}),children:[r.jsxRuntimeExports.jsx("div",{className:D.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",a&&!t?"adm:bg-destructive/10":"adm:bg-primary-50"),children:r.jsxRuntimeExports.jsx(G.Icon,{symbol:"text_snippet",className:a&&!t?"adm:text-destructive":"adm:text-primary"})}),r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:items-center adm:gap-2",children:[r.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-center",color:a&&!t?"destructive":void 0,children:p?.dragDrop||(o?"Drag and drop your files here or":"Drag and drop your file here or")}),r.jsxRuntimeExports.jsxs("label",{htmlFor:u,children:[r.jsxRuntimeExports.jsx("input",{...h,id:u,type:"file",accept:i,multiple:o,onChange:j,disabled:t,className:"adm:hidden"}),r.jsxRuntimeExports.jsx(M.Button,{asChild:!0,type:"button",variant:"link",className:D.cn("adm:cursor-pointer",t&&`
|
|
5
5
|
adm:pointer-events-none
|
|
6
|
-
`),disabled:t,children:r.jsxRuntimeExports.jsx("span",{children:p?.selectFile||(o?"Select files":"Select the file")})})]})]}),r.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-center",color:a&&!t?"destructive":"muted",children:p?.fileRequirements||(m&&m.length>0?`Allowed files: ${m.join(", ")}. Maximum size ${d} MB${o?`. Up to ${
|
|
6
|
+
`),disabled:t,children:r.jsxRuntimeExports.jsx("span",{className:"adm:text-center",children:p?.selectFile||(o?"Select files":"Select the file")})})]})]}),r.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-center",color:a&&!t?"destructive":"muted",children:p?.fileRequirements||(m&&m.length>0?`Allowed files: ${m.join(", ")}. Maximum size ${d} MB${o?`. Up to ${f} files`:""}.`:`Maximum size ${d} MB${o?`. Up to ${f} files`:""}.`)})]})}function re({fileWithMetadata:c,invalid:o,disabled:a,labels:t,onRemove:i}){const{file:m,status:d="idle",deletable:f=!0,disabled:p,error:h}=c,l=a||p,v=d==="uploading",g=d==="deleting",j=d==="error",u=d==="success",$=v||g,q=()=>v||g?"progress_activity":u?"check_circle":j?"error":"text_snippet",V=()=>j?"adm:text-destructive":u?"adm:text-success-600":o&&!l?"adm:text-destructive":"adm:text-primary",z=()=>j?"adm:bg-destructive/15":u?"adm:bg-success/15":v||g?"adm:bg-primary/15":o&&!l?"adm:bg-destructive/15":"adm:bg-primary/15";return r.jsxRuntimeExports.jsxs("div",{className:D.cn("adm:flex adm:items-center adm:gap-4 adm:rounded-2xl adm:border adm:p-6",j?"adm:border-destructive adm:bg-destructive/5":u?"adm:border-success-200 adm:bg-success-50":o&&!l?"adm:border-destructive adm:bg-destructive/5":"adm:border-input adm:bg-muted",l&&"adm:cursor-not-allowed adm:opacity-50"),children:[r.jsxRuntimeExports.jsx("div",{className:D.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",z()),children:r.jsxRuntimeExports.jsx(G.Icon,{symbol:q(),className:D.cn(V(),$&&"adm:animate-spin")})}),r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:min-w-0 adm:flex-1 adm:flex-col adm:gap-1",children:[r.jsxRuntimeExports.jsx(N.Typography,{className:D.cn("adm:min-w-0 adm:truncate adm:font-semibold"),children:m.name}),(h||v||g||u||j)&&r.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-xs",color:j?"destructive":u?"success":"muted",children:h||(v?t?.statusUploading||"Uploading...":g?t?.statusDeleting||"Deleting...":u?t?.statusSuccess||"Uploaded successfully":j?t?.statusError||"Upload failed":"")})]}),r.jsxRuntimeExports.jsxs(N.Typography,{className:"adm:shrink-0",color:"muted",children:[(m.size/1024/1024).toFixed(1)," MB"]}),f&&r.jsxRuntimeExports.jsx(M.Button,{variant:"destructive-medium",onClick:i,type:"button",disabled:l||$,children:r.jsxRuntimeExports.jsx(G.Icon,{symbol:"delete",className:"adm:text-destructive"})})]})}function _({files:c,isMultiple:o,invalid:a,disabled:t,labels:i,onRemoveFile:m,onClearAll:d}){return c.length===0?null:r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:gap-3",children:[o&&c.length>1&&r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:items-center adm:justify-between",children:[r.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-center adm:text-sm adm:font-medium",color:a&&!t?"destructive":void 0,children:i?.filesSelected?.(c.length)||`${c.length} file${c.length!==1?"s":""} selected`}),r.jsxRuntimeExports.jsx(M.Button,{variant:"ghost",size:"sm",onClick:d,type:"button",disabled:t,children:i?.clearAll||"Clear all"})]}),c.map((f,p)=>r.jsxRuntimeExports.jsx(re,{fileWithMetadata:f,invalid:a,disabled:t,labels:i,onRemove:()=>m(p)},f.id))]})}function se({className:c,selectedFile:o,selectedFiles:a,onFileSelect:t,onFilesSelect:i,onFileAdd:m,onFileRemove:d,onFilesAdd:f,onFilesRemove:p,onInvalidFile:h,acceptedExtensions:l,maxSizeInMB:v=50,maxFiles:g=10,multiple:j=!1,filesPosition:u="below",invalid:$=!1,disabled:q=!1,"aria-invalid":V,generateId:z,labels:I,input:F,...H}){const[J,B]=k.useState(!1),[K,P]=k.useState(!1),w=k.useRef(null);k.useEffect(()=>{const e=()=>{if(w.current){const s=w.current.closest("fieldset");P(s?.disabled??!1)}};e();const n=new MutationObserver(e);if(w.current){const s=w.current.closest("fieldset");s&&n.observe(s,{attributes:!0,attributeFilter:["disabled"]})}return()=>n.disconnect()},[]);const Q=l?.join(",")||"",X=v*1024*1024,x=j||a!==void 0||i!==void 0,R=x?a||[]:o?[o]:[],T=$||V,y=q||K,Y=z||(e=>`${Date.now()}-${Math.random().toString(36).substring(2,11)}-${e.name}`),C=e=>({id:Y(e),file:e}),Z=e=>{y||(e.preventDefault(),B(!0))},W=e=>{y||(e.preventDefault(),B(!1))},S=e=>{if(!y)if(e.preventDefault(),B(!1),x){const s=Array.from(e.dataTransfer.files).filter(U);if(s.length>0){const b=s.map(C),L=[...a||[],...b].slice(0,g);i&&i(L),f&&f(b)}}else{const n=e.dataTransfer.files[0];if(n&&U(n)){const s=C(n);t&&t(s),m&&m(s)}}},ee=e=>{if(!y){if(x){const s=(e.target.files?Array.from(e.target.files):[]).filter(U);if(s.length>0){const b=s.map(C),L=[...a||[],...b].slice(0,g);i&&i(L),f&&f(b)}}else{const n=e.target.files?.[0];if(n&&U(n)){const s=C(n);t&&t(s),m&&m(s)}}e.target.value=""}},O=e=>{if(y)return;const n=R[e];if(x){const s=R.filter((b,E)=>E!==e);i&&i(s),p&&n&&p([n])}else t&&t(null),d&&n&&d(n)},U=e=>{const n=e.name.substring(e.name.lastIndexOf(".")),s=!l||l.length===0||l.includes(n.toLowerCase()),b=e.size<=X;if(!s||!b){const E=C(e);!s&&h?h(E,"extension"):!b&&h&&h(E,"size")}return s&&b},A=()=>{if(y)return;const e=[...R];x?(i&&i([]),p&&e.length>0&&p(e)):(t&&t(null),d&&e.length>0&&d(e[0]))};return r.jsxRuntimeExports.jsxs("div",{ref:w,className:D.cn("adm:flex adm:flex-col adm:gap-4",c),...H,children:[x&&u==="above"&&r.jsxRuntimeExports.jsx(_,{files:R,isMultiple:x,invalid:T,disabled:y,labels:I,onRemoveFile:O,onClearAll:A}),(x||R.length===0)&&r.jsxRuntimeExports.jsx(te,{isDragging:J,isMultiple:x,invalid:T,disabled:y,accept:Q,acceptedExtensions:l,maxSizeInMB:v,maxFiles:g,labels:I,input:F,onDragOver:Z,onDragLeave:W,onDrop:S,onFileChange:ee}),!x&&R.length>0&&r.jsxRuntimeExports.jsx(_,{files:R,isMultiple:x,invalid:T,disabled:y,labels:I,onRemoveFile:O,onClearAll:A}),x&&u==="below"&&r.jsxRuntimeExports.jsx(_,{files:R,isMultiple:x,invalid:T,disabled:y,labels:I,onRemoveFile:O,onClearAll:A})]})}exports.FileUploadV2=se;
|
package/dist/file-upload-v2.js
CHANGED
|
@@ -58,7 +58,7 @@ function se({
|
|
|
58
58
|
}
|
|
59
59
|
),
|
|
60
60
|
/* @__PURE__ */ r.jsxs("div", { className: "adm:flex adm:flex-col adm:items-center adm:gap-2", children: [
|
|
61
|
-
/* @__PURE__ */ r.jsx(C, { color: n && !t ? "destructive" : void 0, children: g?.dragDrop || (d ? "Drag and drop your files here or" : "Drag and drop your file here or") }),
|
|
61
|
+
/* @__PURE__ */ r.jsx(C, { className: "adm:text-center", color: n && !t ? "destructive" : void 0, children: g?.dragDrop || (d ? "Drag and drop your files here or" : "Drag and drop your file here or") }),
|
|
62
62
|
/* @__PURE__ */ r.jsxs("label", { htmlFor: u, children: [
|
|
63
63
|
/* @__PURE__ */ r.jsx(
|
|
64
64
|
"input",
|
|
@@ -83,7 +83,7 @@ function se({
|
|
|
83
83
|
adm:pointer-events-none
|
|
84
84
|
`),
|
|
85
85
|
disabled: t,
|
|
86
|
-
children: /* @__PURE__ */ r.jsx("span", { children: g?.selectFile || (d ? "Select files" : "Select the file") })
|
|
86
|
+
children: /* @__PURE__ */ r.jsx("span", { className: "adm:text-center", children: g?.selectFile || (d ? "Select files" : "Select the file") })
|
|
87
87
|
}
|
|
88
88
|
)
|
|
89
89
|
] })
|
|
@@ -163,7 +163,7 @@ function ae({ fileWithMetadata: c, invalid: d, disabled: n, labels: t, onRemove:
|
|
|
163
163
|
function G({ files: c, isMultiple: d, invalid: n, disabled: t, labels: i, onRemoveFile: l, onClearAll: o }) {
|
|
164
164
|
return c.length === 0 ? null : /* @__PURE__ */ r.jsxs("div", { className: "adm:flex adm:flex-col adm:gap-3", children: [
|
|
165
165
|
d && c.length > 1 && /* @__PURE__ */ r.jsxs("div", { className: "adm:flex adm:items-center adm:justify-between", children: [
|
|
166
|
-
/* @__PURE__ */ r.jsx(C, { className: "adm:text-sm adm:font-medium", color: n && !t ? "destructive" : void 0, children: i?.filesSelected?.(c.length) || `${c.length} file${c.length !== 1 ? "s" : ""} selected` }),
|
|
166
|
+
/* @__PURE__ */ r.jsx(C, { className: "adm:text-center adm:text-sm adm:font-medium", color: n && !t ? "destructive" : void 0, children: i?.filesSelected?.(c.length) || `${c.length} file${c.length !== 1 ? "s" : ""} selected` }),
|
|
167
167
|
/* @__PURE__ */ r.jsx(
|
|
168
168
|
q,
|
|
169
169
|
{
|
package/dist/file-upload.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./jsx-runtime-BB_1_6y_.cjs"),B=require("./button-CFJs0esR.cjs"),A=require("./icon-B7joBr0A.cjs"),D=require("./typography-Bj8oEDuE.cjs"),g=require("./index-DoxiiusW.cjs"),T=require("react");function P({isDragging:i,isMultiple:o,invalid:s,disabled:t,accept:m,acceptedExtensions:l,maxSizeInMB:f,maxFiles:u,labels:c,input:j,onDragOver:h,onDragLeave:N,onDrop:v,onFileChange:q}){const y=j?.id||`file-upload-${Math.random().toString(36).substring(2,11)}`;return r.jsxRuntimeExports.jsxs("div",{onDragOver:t?void 0:h,onDragLeave:t?void 0:N,onDrop:t?void 0:v,className:g.cn(`
|
|
2
2
|
adm:flex adm:flex-col adm:items-center adm:gap-6 adm:rounded-2xl
|
|
3
3
|
adm:border-2
|
|
4
|
-
`,"adm:border-dashed adm:bg-background adm:p-6 adm:transition-colors",{"adm:border-primary":i&&!s&&!t,"adm:border-destructive":s&&!t,"adm:border-input":!i&&!s,"adm:cursor-not-allowed adm:opacity-50":t}),children:[r.jsxRuntimeExports.jsx("div",{className:g.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",s&&!t?"adm:bg-destructive/10":"adm:bg-primary-50"),children:r.jsxRuntimeExports.jsx(A.Icon,{symbol:"text_snippet",className:s&&!t?"adm:text-destructive":"adm:text-primary"})}),r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:items-center adm:gap-2",children:[r.jsxRuntimeExports.jsx(D.Typography,{color:s&&!t?"destructive":void 0,children:c?.dragDrop||(o?"Drag and drop your files here or":"Drag and drop your file here or")}),r.jsxRuntimeExports.jsxs("label",{htmlFor:y,children:[r.jsxRuntimeExports.jsx("input",{...j,id:y,type:"file",accept:m,multiple:o,onChange:q,disabled:t,className:"adm:hidden"}),r.jsxRuntimeExports.jsx(B.Button,{asChild:!0,type:"button",variant:"link",className:g.cn("adm:cursor-pointer",t&&`
|
|
4
|
+
`,"adm:border-dashed adm:bg-background adm:p-6 adm:transition-colors",{"adm:border-primary":i&&!s&&!t,"adm:border-destructive":s&&!t,"adm:border-input":!i&&!s,"adm:cursor-not-allowed adm:opacity-50":t}),children:[r.jsxRuntimeExports.jsx("div",{className:g.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",s&&!t?"adm:bg-destructive/10":"adm:bg-primary-50"),children:r.jsxRuntimeExports.jsx(A.Icon,{symbol:"text_snippet",className:s&&!t?"adm:text-destructive":"adm:text-primary"})}),r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:items-center adm:gap-2",children:[r.jsxRuntimeExports.jsx(D.Typography,{className:"adm:text-center",color:s&&!t?"destructive":void 0,children:c?.dragDrop||(o?"Drag and drop your files here or":"Drag and drop your file here or")}),r.jsxRuntimeExports.jsxs("label",{htmlFor:y,children:[r.jsxRuntimeExports.jsx("input",{...j,id:y,type:"file",accept:m,multiple:o,onChange:q,disabled:t,className:"adm:hidden"}),r.jsxRuntimeExports.jsx(B.Button,{asChild:!0,type:"button",variant:"link",className:g.cn("adm:cursor-pointer",t&&`
|
|
5
5
|
adm:pointer-events-none
|
|
6
|
-
`),disabled:t,children:r.jsxRuntimeExports.jsx("span",{children:c?.selectFile||(o?"Select files":"Select the file")})})]})]}),r.jsxRuntimeExports.jsx(D.Typography,{className:"adm:text-center",color:s&&!t?"destructive":"muted",children:c?.fileRequirements||(l&&l.length>0?`Allowed files: ${l.join(", ")}. Maximum size ${f} MB${o?`. Up to ${u} files`:""}.`:`Maximum size ${f} MB${o?`. Up to ${u} files`:""}.`)})]})}function F({file:i,invalid:o,disabled:s,onRemove:t}){return r.jsxRuntimeExports.jsxs("div",{className:g.cn("adm:flex adm:items-center adm:gap-4 adm:rounded-2xl adm:border adm:p-6",o&&!s?"adm:border-destructive adm:bg-destructive/5":"adm:border-input adm:bg-muted",s&&"adm:cursor-not-allowed adm:opacity-50"),children:[r.jsxRuntimeExports.jsx("div",{className:g.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",o&&!s?"adm:bg-destructive/15":"adm:bg-primary/15"),children:r.jsxRuntimeExports.jsx(A.Icon,{symbol:"text_snippet",className:o&&!s?"adm:text-destructive":"adm:text-primary"})}),r.jsxRuntimeExports.jsx("div",{className:"adm:flex adm:min-w-0 adm:flex-1 adm:flex-col adm:gap-1",children:r.jsxRuntimeExports.jsx(D.Typography,{className:g.cn("adm:min-w-0 adm:truncate adm:font-semibold"),children:i.name})}),r.jsxRuntimeExports.jsxs(D.Typography,{className:"adm:shrink-0",color:"muted",children:[(i.size/1024/1024).toFixed(1)," MB"]}),r.jsxRuntimeExports.jsx(B.Button,{variant:"destructive-medium",onClick:t,type:"button",disabled:s,children:r.jsxRuntimeExports.jsx(A.Icon,{symbol:"delete",className:"adm:text-destructive"})})]})}function O({files:i,isMultiple:o,invalid:s,disabled:t,labels:m,onRemoveFile:l,onClearAll:f}){return i.length===0?null:r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:gap-3",children:[o&&i.length>1&&r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:items-center adm:justify-between",children:[r.jsxRuntimeExports.jsx(D.Typography,{className:"adm:text-sm adm:font-medium",color:s&&!t?"destructive":void 0,children:m?.filesSelected?.(i.length)||`${i.length} file${i.length!==1?"s":""} selected`}),r.jsxRuntimeExports.jsx(B.Button,{variant:"ghost",size:"sm",onClick:f,type:"button",disabled:t,children:m?.clearAll||"Clear all"})]}),i.map((u,c)=>r.jsxRuntimeExports.jsx(F,{file:u,invalid:s,disabled:t,onRemove:()=>l(c)},`${u.name}-${c}`))]})}function S({className:i,selectedFile:o,selectedFiles:s,onFileSelect:t,onFilesSelect:m,onFileAdd:l,onFileRemove:f,onFilesAdd:u,onFilesRemove:c,onInvalidFile:j,acceptedExtensions:h,maxSizeInMB:N=50,maxFiles:v=10,multiple:q=!1,filesPosition:y="below",invalid:L=!1,disabled:U=!1,"aria-invalid":M,labels:$,input:V,..._}){const[G,k]=T.useState(!1),[H,J]=T.useState(!1),R=T.useRef(null);T.useEffect(()=>{const e=()=>{if(R.current){const n=R.current.closest("fieldset");J(n?.disabled??!1)}};e();const a=new MutationObserver(e);if(R.current){const n=R.current.closest("fieldset");n&&a.observe(n,{attributes:!0,attributeFilter:["disabled"]})}return()=>a.disconnect()},[]);const K=h?.join(",")||"",Q=N*1024*1024,d=q||s!==void 0||m!==void 0,p=d?s||[]:o?[o]:[],w=L||M,x=U||H,W=e=>{x||(e.preventDefault(),k(!0))},X=e=>{x||(e.preventDefault(),k(!1))},Y=e=>{if(!x)if(e.preventDefault(),k(!1),d){const n=Array.from(e.dataTransfer.files).filter(C);if(n.length>0){const E=[...s||[],...n].slice(0,v);m&&m(E),u&&u(n)}}else{const a=e.dataTransfer.files[0];a&&C(a)&&(t&&t(a),l&&l(a))}},Z=e=>{if(!x){if(d){const n=(e.target.files?Array.from(e.target.files):[]).filter(C);if(n.length>0){const E=[...s||[],...n].slice(0,v);m&&m(E),u&&u(n)}}else{const a=e.target.files?.[0];a&&C(a)&&(t&&t(a),l&&l(a))}e.target.value=""}},z=e=>{if(x)return;const a=p[e];if(d){const n=p.filter((b,E)=>E!==e);m&&m(n),c&&a&&c([a])}else t&&t(null),f&&a&&f(a)},C=e=>{const a=e.name.substring(e.name.lastIndexOf(".")),n=!h||h.length===0||h.includes(a.toLowerCase()),b=e.size<=Q;return!n&&j?j(e,"extension"):!b&&j&&j(e,"size"),n&&b},I=()=>{if(x)return;const e=[...p];d?(m&&m([]),c&&e.length>0&&c(e)):(t&&t(null),f&&e.length>0&&f(e[0]))};return r.jsxRuntimeExports.jsxs("div",{ref:R,className:g.cn("adm:flex adm:flex-col adm:gap-4",i),..._,children:[d&&y==="above"&&r.jsxRuntimeExports.jsx(O,{files:p,isMultiple:d,invalid:w,disabled:x,labels:$,onRemoveFile:z,onClearAll:I}),(d||p.length===0)&&r.jsxRuntimeExports.jsx(P,{isDragging:G,isMultiple:d,invalid:w,disabled:x,accept:K,acceptedExtensions:h,maxSizeInMB:N,maxFiles:v,labels:$,input:V,onDragOver:W,onDragLeave:X,onDrop:Y,onFileChange:Z}),!d&&p.length>0&&r.jsxRuntimeExports.jsx(O,{files:p,isMultiple:d,invalid:w,disabled:x,labels:$,onRemoveFile:z,onClearAll:I}),d&&y==="below"&&r.jsxRuntimeExports.jsx(O,{files:p,isMultiple:d,invalid:w,disabled:x,labels:$,onRemoveFile:z,onClearAll:I})]})}exports.FileUpload=S;
|
|
6
|
+
`),disabled:t,children:r.jsxRuntimeExports.jsx("span",{className:"adm:text-center",children:c?.selectFile||(o?"Select files":"Select the file")})})]})]}),r.jsxRuntimeExports.jsx(D.Typography,{className:"adm:text-center",color:s&&!t?"destructive":"muted",children:c?.fileRequirements||(l&&l.length>0?`Allowed files: ${l.join(", ")}. Maximum size ${f} MB${o?`. Up to ${u} files`:""}.`:`Maximum size ${f} MB${o?`. Up to ${u} files`:""}.`)})]})}function F({file:i,invalid:o,disabled:s,onRemove:t}){return r.jsxRuntimeExports.jsxs("div",{className:g.cn("adm:flex adm:items-center adm:gap-4 adm:rounded-2xl adm:border adm:p-6",o&&!s?"adm:border-destructive adm:bg-destructive/5":"adm:border-input adm:bg-muted",s&&"adm:cursor-not-allowed adm:opacity-50"),children:[r.jsxRuntimeExports.jsx("div",{className:g.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",o&&!s?"adm:bg-destructive/15":"adm:bg-primary/15"),children:r.jsxRuntimeExports.jsx(A.Icon,{symbol:"text_snippet",className:o&&!s?"adm:text-destructive":"adm:text-primary"})}),r.jsxRuntimeExports.jsx("div",{className:"adm:flex adm:min-w-0 adm:flex-1 adm:flex-col adm:gap-1",children:r.jsxRuntimeExports.jsx(D.Typography,{className:g.cn("adm:min-w-0 adm:truncate adm:font-semibold"),children:i.name})}),r.jsxRuntimeExports.jsxs(D.Typography,{className:"adm:shrink-0",color:"muted",children:[(i.size/1024/1024).toFixed(1)," MB"]}),r.jsxRuntimeExports.jsx(B.Button,{variant:"destructive-medium",onClick:t,type:"button",disabled:s,children:r.jsxRuntimeExports.jsx(A.Icon,{symbol:"delete",className:"adm:text-destructive"})})]})}function O({files:i,isMultiple:o,invalid:s,disabled:t,labels:m,onRemoveFile:l,onClearAll:f}){return i.length===0?null:r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:gap-3",children:[o&&i.length>1&&r.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:items-center adm:justify-between",children:[r.jsxRuntimeExports.jsx(D.Typography,{className:"adm:text-center adm:text-sm adm:font-medium",color:s&&!t?"destructive":void 0,children:m?.filesSelected?.(i.length)||`${i.length} file${i.length!==1?"s":""} selected`}),r.jsxRuntimeExports.jsx(B.Button,{variant:"ghost",size:"sm",onClick:f,type:"button",disabled:t,children:m?.clearAll||"Clear all"})]}),i.map((u,c)=>r.jsxRuntimeExports.jsx(F,{file:u,invalid:s,disabled:t,onRemove:()=>l(c)},`${u.name}-${c}`))]})}function S({className:i,selectedFile:o,selectedFiles:s,onFileSelect:t,onFilesSelect:m,onFileAdd:l,onFileRemove:f,onFilesAdd:u,onFilesRemove:c,onInvalidFile:j,acceptedExtensions:h,maxSizeInMB:N=50,maxFiles:v=10,multiple:q=!1,filesPosition:y="below",invalid:L=!1,disabled:U=!1,"aria-invalid":M,labels:$,input:V,..._}){const[G,k]=T.useState(!1),[H,J]=T.useState(!1),R=T.useRef(null);T.useEffect(()=>{const e=()=>{if(R.current){const n=R.current.closest("fieldset");J(n?.disabled??!1)}};e();const a=new MutationObserver(e);if(R.current){const n=R.current.closest("fieldset");n&&a.observe(n,{attributes:!0,attributeFilter:["disabled"]})}return()=>a.disconnect()},[]);const K=h?.join(",")||"",Q=N*1024*1024,d=q||s!==void 0||m!==void 0,p=d?s||[]:o?[o]:[],w=L||M,x=U||H,W=e=>{x||(e.preventDefault(),k(!0))},X=e=>{x||(e.preventDefault(),k(!1))},Y=e=>{if(!x)if(e.preventDefault(),k(!1),d){const n=Array.from(e.dataTransfer.files).filter(C);if(n.length>0){const E=[...s||[],...n].slice(0,v);m&&m(E),u&&u(n)}}else{const a=e.dataTransfer.files[0];a&&C(a)&&(t&&t(a),l&&l(a))}},Z=e=>{if(!x){if(d){const n=(e.target.files?Array.from(e.target.files):[]).filter(C);if(n.length>0){const E=[...s||[],...n].slice(0,v);m&&m(E),u&&u(n)}}else{const a=e.target.files?.[0];a&&C(a)&&(t&&t(a),l&&l(a))}e.target.value=""}},z=e=>{if(x)return;const a=p[e];if(d){const n=p.filter((b,E)=>E!==e);m&&m(n),c&&a&&c([a])}else t&&t(null),f&&a&&f(a)},C=e=>{const a=e.name.substring(e.name.lastIndexOf(".")),n=!h||h.length===0||h.includes(a.toLowerCase()),b=e.size<=Q;return!n&&j?j(e,"extension"):!b&&j&&j(e,"size"),n&&b},I=()=>{if(x)return;const e=[...p];d?(m&&m([]),c&&e.length>0&&c(e)):(t&&t(null),f&&e.length>0&&f(e[0]))};return r.jsxRuntimeExports.jsxs("div",{ref:R,className:g.cn("adm:flex adm:flex-col adm:gap-4",i),..._,children:[d&&y==="above"&&r.jsxRuntimeExports.jsx(O,{files:p,isMultiple:d,invalid:w,disabled:x,labels:$,onRemoveFile:z,onClearAll:I}),(d||p.length===0)&&r.jsxRuntimeExports.jsx(P,{isDragging:G,isMultiple:d,invalid:w,disabled:x,accept:K,acceptedExtensions:h,maxSizeInMB:N,maxFiles:v,labels:$,input:V,onDragOver:W,onDragLeave:X,onDrop:Y,onFileChange:Z}),!d&&p.length>0&&r.jsxRuntimeExports.jsx(O,{files:p,isMultiple:d,invalid:w,disabled:x,labels:$,onRemoveFile:z,onClearAll:I}),d&&y==="below"&&r.jsxRuntimeExports.jsx(O,{files:p,isMultiple:d,invalid:w,disabled:x,labels:$,onRemoveFile:z,onClearAll:I})]})}exports.FileUpload=S;
|
package/dist/file-upload.js
CHANGED
|
@@ -6,21 +6,21 @@ import { c as v } from "./index-CRiPKpXj.js";
|
|
|
6
6
|
import { useState as U, useRef as P, useEffect as F } from "react";
|
|
7
7
|
function S({
|
|
8
8
|
isDragging: i,
|
|
9
|
-
isMultiple:
|
|
9
|
+
isMultiple: m,
|
|
10
10
|
invalid: a,
|
|
11
11
|
disabled: t,
|
|
12
|
-
accept:
|
|
12
|
+
accept: d,
|
|
13
13
|
acceptedExtensions: c,
|
|
14
|
-
maxSizeInMB:
|
|
14
|
+
maxSizeInMB: x,
|
|
15
15
|
maxFiles: f,
|
|
16
16
|
labels: l,
|
|
17
|
-
input:
|
|
17
|
+
input: p,
|
|
18
18
|
onDragOver: g,
|
|
19
19
|
onDragLeave: w,
|
|
20
20
|
onDrop: j,
|
|
21
21
|
onFileChange: T
|
|
22
22
|
}) {
|
|
23
|
-
const y =
|
|
23
|
+
const y = p?.id || `file-upload-${Math.random().toString(36).substring(2, 11)}`;
|
|
24
24
|
return /* @__PURE__ */ r.jsxs(
|
|
25
25
|
"div",
|
|
26
26
|
{
|
|
@@ -58,16 +58,16 @@ function S({
|
|
|
58
58
|
}
|
|
59
59
|
),
|
|
60
60
|
/* @__PURE__ */ r.jsxs("div", { className: "adm:flex adm:flex-col adm:items-center adm:gap-2", children: [
|
|
61
|
-
/* @__PURE__ */ r.jsx($, { color: a && !t ? "destructive" : void 0, children: l?.dragDrop || (
|
|
61
|
+
/* @__PURE__ */ r.jsx($, { className: "adm:text-center", color: a && !t ? "destructive" : void 0, children: l?.dragDrop || (m ? "Drag and drop your files here or" : "Drag and drop your file here or") }),
|
|
62
62
|
/* @__PURE__ */ r.jsxs("label", { htmlFor: y, children: [
|
|
63
63
|
/* @__PURE__ */ r.jsx(
|
|
64
64
|
"input",
|
|
65
65
|
{
|
|
66
|
-
...
|
|
66
|
+
...p,
|
|
67
67
|
id: y,
|
|
68
68
|
type: "file",
|
|
69
|
-
accept:
|
|
70
|
-
multiple:
|
|
69
|
+
accept: d,
|
|
70
|
+
multiple: m,
|
|
71
71
|
onChange: T,
|
|
72
72
|
disabled: t,
|
|
73
73
|
className: "adm:hidden"
|
|
@@ -83,23 +83,23 @@ function S({
|
|
|
83
83
|
adm:pointer-events-none
|
|
84
84
|
`),
|
|
85
85
|
disabled: t,
|
|
86
|
-
children: /* @__PURE__ */ r.jsx("span", { children: l?.selectFile || (
|
|
86
|
+
children: /* @__PURE__ */ r.jsx("span", { className: "adm:text-center", children: l?.selectFile || (m ? "Select files" : "Select the file") })
|
|
87
87
|
}
|
|
88
88
|
)
|
|
89
89
|
] })
|
|
90
90
|
] }),
|
|
91
|
-
/* @__PURE__ */ r.jsx($, { className: "adm:text-center", color: a && !t ? "destructive" : "muted", children: l?.fileRequirements || (c && c.length > 0 ? `Allowed files: ${c.join(", ")}. Maximum size ${
|
|
91
|
+
/* @__PURE__ */ r.jsx($, { className: "adm:text-center", color: a && !t ? "destructive" : "muted", children: l?.fileRequirements || (c && c.length > 0 ? `Allowed files: ${c.join(", ")}. Maximum size ${x} MB${m ? `. Up to ${f} files` : ""}.` : `Maximum size ${x} MB${m ? `. Up to ${f} files` : ""}.`) })
|
|
92
92
|
]
|
|
93
93
|
}
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
function ee({ file: i, invalid:
|
|
96
|
+
function ee({ file: i, invalid: m, disabled: a, onRemove: t }) {
|
|
97
97
|
return /* @__PURE__ */ r.jsxs(
|
|
98
98
|
"div",
|
|
99
99
|
{
|
|
100
100
|
className: v(
|
|
101
101
|
"adm:flex adm:items-center adm:gap-4 adm:rounded-2xl adm:border adm:p-6",
|
|
102
|
-
|
|
102
|
+
m && !a ? "adm:border-destructive adm:bg-destructive/5" : "adm:border-input adm:bg-muted",
|
|
103
103
|
a && "adm:cursor-not-allowed adm:opacity-50"
|
|
104
104
|
),
|
|
105
105
|
children: [
|
|
@@ -108,13 +108,13 @@ function ee({ file: i, invalid: d, disabled: a, onRemove: t }) {
|
|
|
108
108
|
{
|
|
109
109
|
className: v(
|
|
110
110
|
"adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",
|
|
111
|
-
|
|
111
|
+
m && !a ? "adm:bg-destructive/15" : "adm:bg-primary/15"
|
|
112
112
|
),
|
|
113
113
|
children: /* @__PURE__ */ r.jsx(
|
|
114
114
|
R,
|
|
115
115
|
{
|
|
116
116
|
symbol: "text_snippet",
|
|
117
|
-
className:
|
|
117
|
+
className: m && !a ? "adm:text-destructive" : "adm:text-primary"
|
|
118
118
|
}
|
|
119
119
|
)
|
|
120
120
|
}
|
|
@@ -146,19 +146,19 @@ function ee({ file: i, invalid: d, disabled: a, onRemove: t }) {
|
|
|
146
146
|
}
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
|
-
function O({ files: i, isMultiple:
|
|
149
|
+
function O({ files: i, isMultiple: m, invalid: a, disabled: t, labels: d, onRemoveFile: c, onClearAll: x }) {
|
|
150
150
|
return i.length === 0 ? null : /* @__PURE__ */ r.jsxs("div", { className: "adm:flex adm:flex-col adm:gap-3", children: [
|
|
151
|
-
|
|
152
|
-
/* @__PURE__ */ r.jsx($, { className: "adm:text-sm adm:font-medium", color: a && !t ? "destructive" : void 0, children:
|
|
151
|
+
m && i.length > 1 && /* @__PURE__ */ r.jsxs("div", { className: "adm:flex adm:items-center adm:justify-between", children: [
|
|
152
|
+
/* @__PURE__ */ r.jsx($, { className: "adm:text-center adm:text-sm adm:font-medium", color: a && !t ? "destructive" : void 0, children: d?.filesSelected?.(i.length) || `${i.length} file${i.length !== 1 ? "s" : ""} selected` }),
|
|
153
153
|
/* @__PURE__ */ r.jsx(
|
|
154
154
|
B,
|
|
155
155
|
{
|
|
156
156
|
variant: "ghost",
|
|
157
157
|
size: "sm",
|
|
158
|
-
onClick:
|
|
158
|
+
onClick: x,
|
|
159
159
|
type: "button",
|
|
160
160
|
disabled: t,
|
|
161
|
-
children:
|
|
161
|
+
children: d?.clearAll || "Clear all"
|
|
162
162
|
}
|
|
163
163
|
)
|
|
164
164
|
] }),
|
|
@@ -174,17 +174,17 @@ function O({ files: i, isMultiple: d, invalid: a, disabled: t, labels: m, onRemo
|
|
|
174
174
|
))
|
|
175
175
|
] });
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function me({
|
|
178
178
|
className: i,
|
|
179
|
-
selectedFile:
|
|
179
|
+
selectedFile: m,
|
|
180
180
|
selectedFiles: a,
|
|
181
181
|
onFileSelect: t,
|
|
182
|
-
onFilesSelect:
|
|
182
|
+
onFilesSelect: d,
|
|
183
183
|
onFileAdd: c,
|
|
184
|
-
onFileRemove:
|
|
184
|
+
onFileRemove: x,
|
|
185
185
|
onFilesAdd: f,
|
|
186
186
|
onFilesRemove: l,
|
|
187
|
-
onInvalidFile:
|
|
187
|
+
onInvalidFile: p,
|
|
188
188
|
acceptedExtensions: g,
|
|
189
189
|
maxSizeInMB: w = 50,
|
|
190
190
|
maxFiles: j = 10,
|
|
@@ -213,7 +213,7 @@ function de({
|
|
|
213
213
|
}
|
|
214
214
|
return () => s.disconnect();
|
|
215
215
|
}, []);
|
|
216
|
-
const Q = g?.join(",") || "", W = w * 1024 * 1024, o = T || a !== void 0 ||
|
|
216
|
+
const Q = g?.join(",") || "", W = w * 1024 * 1024, o = T || a !== void 0 || d !== void 0, h = o ? a || [] : m ? [m] : [], k = V || M, u = _ || J, X = (e) => {
|
|
217
217
|
u || (e.preventDefault(), A(!0));
|
|
218
218
|
}, Y = (e) => {
|
|
219
219
|
u || (e.preventDefault(), A(!1));
|
|
@@ -223,7 +223,7 @@ function de({
|
|
|
223
223
|
const n = Array.from(e.dataTransfer.files).filter(z);
|
|
224
224
|
if (n.length > 0) {
|
|
225
225
|
const N = [...a || [], ...n].slice(0, j);
|
|
226
|
-
|
|
226
|
+
d && d(N), f && f(n);
|
|
227
227
|
}
|
|
228
228
|
} else {
|
|
229
229
|
const s = e.dataTransfer.files[0];
|
|
@@ -235,7 +235,7 @@ function de({
|
|
|
235
235
|
const n = (e.target.files ? Array.from(e.target.files) : []).filter(z);
|
|
236
236
|
if (n.length > 0) {
|
|
237
237
|
const N = [...a || [], ...n].slice(0, j);
|
|
238
|
-
|
|
238
|
+
d && d(N), f && f(n);
|
|
239
239
|
}
|
|
240
240
|
} else {
|
|
241
241
|
const s = e.target.files?.[0];
|
|
@@ -245,25 +245,25 @@ function de({
|
|
|
245
245
|
}
|
|
246
246
|
}, I = (e) => {
|
|
247
247
|
if (u) return;
|
|
248
|
-
const s =
|
|
248
|
+
const s = h[e];
|
|
249
249
|
if (o) {
|
|
250
|
-
const n =
|
|
251
|
-
|
|
250
|
+
const n = h.filter((b, N) => N !== e);
|
|
251
|
+
d && d(n), l && s && l([s]);
|
|
252
252
|
} else
|
|
253
|
-
t && t(null),
|
|
253
|
+
t && t(null), x && s && x(s);
|
|
254
254
|
}, z = (e) => {
|
|
255
255
|
const s = e.name.substring(e.name.lastIndexOf(".")), n = !g || g.length === 0 || g.includes(s.toLowerCase()), b = e.size <= W;
|
|
256
|
-
return !n &&
|
|
256
|
+
return !n && p ? p(e, "extension") : !b && p && p(e, "size"), n && b;
|
|
257
257
|
}, L = () => {
|
|
258
258
|
if (u) return;
|
|
259
|
-
const e = [...
|
|
260
|
-
o ? (
|
|
259
|
+
const e = [...h];
|
|
260
|
+
o ? (d && d([]), l && e.length > 0 && l(e)) : (t && t(null), x && e.length > 0 && x(e[0]));
|
|
261
261
|
};
|
|
262
262
|
return /* @__PURE__ */ r.jsxs("div", { ref: D, className: v("adm:flex adm:flex-col adm:gap-4", i), ...G, children: [
|
|
263
263
|
o && y === "above" && /* @__PURE__ */ r.jsx(
|
|
264
264
|
O,
|
|
265
265
|
{
|
|
266
|
-
files:
|
|
266
|
+
files: h,
|
|
267
267
|
isMultiple: o,
|
|
268
268
|
invalid: k,
|
|
269
269
|
disabled: u,
|
|
@@ -272,7 +272,7 @@ function de({
|
|
|
272
272
|
onClearAll: L
|
|
273
273
|
}
|
|
274
274
|
),
|
|
275
|
-
(o ||
|
|
275
|
+
(o || h.length === 0) && /* @__PURE__ */ r.jsx(
|
|
276
276
|
S,
|
|
277
277
|
{
|
|
278
278
|
isDragging: H,
|
|
@@ -291,10 +291,10 @@ function de({
|
|
|
291
291
|
onFileChange: E
|
|
292
292
|
}
|
|
293
293
|
),
|
|
294
|
-
!o &&
|
|
294
|
+
!o && h.length > 0 && /* @__PURE__ */ r.jsx(
|
|
295
295
|
O,
|
|
296
296
|
{
|
|
297
|
-
files:
|
|
297
|
+
files: h,
|
|
298
298
|
isMultiple: o,
|
|
299
299
|
invalid: k,
|
|
300
300
|
disabled: u,
|
|
@@ -306,7 +306,7 @@ function de({
|
|
|
306
306
|
o && y === "below" && /* @__PURE__ */ r.jsx(
|
|
307
307
|
O,
|
|
308
308
|
{
|
|
309
|
-
files:
|
|
309
|
+
files: h,
|
|
310
310
|
isMultiple: o,
|
|
311
311
|
invalid: k,
|
|
312
312
|
disabled: u,
|
|
@@ -318,5 +318,5 @@ function de({
|
|
|
318
318
|
] });
|
|
319
319
|
}
|
|
320
320
|
export {
|
|
321
|
-
|
|
321
|
+
me as FileUpload
|
|
322
322
|
};
|