@adamosuiteservices/ui 2.18.1 → 2.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ export type FileUploadLabels = {
4
4
  selectFile?: string;
5
5
  fileRequirements?: string;
6
6
  filesSelected?: (count: number) => string;
7
+ clearAll?: string;
7
8
  };
8
9
  export type FileUploadProps = ComponentProps<"div"> & Readonly<{
9
10
  selectedFile?: File | null;
@@ -4,11 +4,21 @@ export type FileUploadV2Labels = {
4
4
  selectFile?: string;
5
5
  fileRequirements?: string;
6
6
  filesSelected?: (count: number) => string;
7
+ clearAll?: string;
8
+ statusUploading?: string;
9
+ statusSuccess?: string;
10
+ statusDeleting?: string;
11
+ statusError?: string;
7
12
  };
13
+ export type FileStatus = "idle" | "uploading" | "success" | "error" | "deleting";
8
14
  export type FileWithMetadata = {
9
15
  id: string;
10
16
  file: File;
11
17
  metadata?: Record<string, unknown>;
18
+ status?: FileStatus;
19
+ deletable?: boolean;
20
+ disabled?: boolean;
21
+ error?: string;
12
22
  };
13
23
  export type FileUploadV2Props = ComponentProps<"div"> & Readonly<{
14
24
  selectedFile?: FileWithMetadata | null;
@@ -1,8 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-BB_1_6y_.cjs"),A=require("./button-CFJs0esR.cjs"),L=require("./icon-B7joBr0A.cjs"),N=require("./typography-Bj8oEDuE.cjs"),y=require("./index-DoxiiusW.cjs"),I=require("react");function te({isDragging:m,isMultiple:o,invalid:a,disabled:r,accept:i,acceptedExtensions:l,maxSizeInMB:p,maxFiles:c,labels:u,input:g,onDragOver:h,onDragLeave:w,onDrop:R,onFileChange:q}){const b=g?.id||`file-upload-v2-${Math.random().toString(36).substring(2,11)}`;return t.jsxRuntimeExports.jsxs("div",{onDragOver:r?void 0:h,onDragLeave:r?void 0:w,onDrop:r?void 0:R,className:y.cn(`
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:x,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":m&&!a&&!r,"adm:border-destructive":a&&!r,"adm:border-input":!m&&!a,"adm:cursor-not-allowed adm:opacity-50":r}),children:[t.jsxRuntimeExports.jsx("div",{className:y.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",a&&!r?"adm:bg-destructive/10":"adm:bg-primary-50"),children:t.jsxRuntimeExports.jsx(L.Icon,{symbol:"text_snippet",className:a&&!r?"adm:text-destructive":"adm:text-primary"})}),t.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:items-center adm:gap-2",children:[t.jsxRuntimeExports.jsx(N.Typography,{color:a&&!r?"destructive":void 0,children:u?.dragDrop||(o?"Drag and drop your files here or":"Drag and drop your file here or")}),t.jsxRuntimeExports.jsxs("label",{htmlFor:b,children:[t.jsxRuntimeExports.jsx("input",{...g,id:b,type:"file",accept:i,multiple:o,onChange:q,disabled:r,className:"adm:hidden"}),t.jsxRuntimeExports.jsx(A.Button,{asChild:!0,type:"button",variant:"link",className:y.cn("adm:cursor-pointer",r&&`
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&&`
5
5
  adm:pointer-events-none
6
- `),disabled:r,children:t.jsxRuntimeExports.jsx("span",{children:u?.selectFile||(o?"Select files":"Select the file")})})]})]}),t.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-center",color:a&&!r?"destructive":"muted",children:u?.fileRequirements||(l&&l.length>0?`Allowed files: ${l.join(", ")}. Maximum size ${p} MB${o?`. Up to ${c} files`:""}.`:`Maximum size ${p} MB${o?`. Up to ${c} files`:""}.`)})]})}function re({fileWithMetadata:m,invalid:o,disabled:a,onRemove:r}){const{file:i}=m;return t.jsxRuntimeExports.jsxs("div",{className:y.cn("adm:flex adm:items-center adm:gap-4 adm:rounded-2xl adm:border adm:p-6",o&&!a?"adm:border-destructive adm:bg-destructive/5":"adm:border-input adm:bg-muted",a&&"adm:cursor-not-allowed adm:opacity-50"),children:[t.jsxRuntimeExports.jsx("div",{className:y.cn("adm:flex adm:items-center adm:justify-center adm:rounded-xl adm:p-2.5",o&&!a?"adm:bg-destructive/10":"adm:bg-primary-50"),children:t.jsxRuntimeExports.jsx(L.Icon,{symbol:"text_snippet",className:o&&!a?"adm:text-destructive":"adm:text-primary"})}),t.jsxRuntimeExports.jsxs("div",{className:`
7
- adm:flex adm:min-w-0 adm:flex-1 adm:items-start adm:gap-3
8
- `,children:[t.jsxRuntimeExports.jsx("div",{className:"adm:min-w-0 adm:flex-1",children:t.jsxRuntimeExports.jsx(N.Typography,{className:"adm:truncate adm:font-semibold",children:i.name})}),t.jsxRuntimeExports.jsxs(N.Typography,{className:"adm:shrink-0",color:"muted",children:[(i.size/1024/1024).toFixed(1)," MB"]})]}),t.jsxRuntimeExports.jsx(A.Button,{variant:"destructive-medium",onClick:r,type:"button",disabled:a,children:t.jsxRuntimeExports.jsx(L.Icon,{symbol:"delete",className:"adm:text-destructive"})})]})}function B({files:m,isMultiple:o,invalid:a,disabled:r,labels:i,onRemoveFile:l,onClearAll:p}){return m.length===0?null:t.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:flex-col adm:gap-3",children:[o&&m.length>1&&t.jsxRuntimeExports.jsxs("div",{className:"adm:flex adm:items-center adm:justify-between",children:[t.jsxRuntimeExports.jsx(N.Typography,{className:"adm:text-sm adm:font-medium",color:a&&!r?"destructive":void 0,children:i?.filesSelected?.(m.length)||`${m.length} file${m.length!==1?"s":""} selected`}),t.jsxRuntimeExports.jsx(A.Button,{variant:"ghost",size:"sm",onClick:p,type:"button",disabled:r,children:"Clear all"})]}),m.map((c,u)=>t.jsxRuntimeExports.jsx(re,{fileWithMetadata:c,invalid:a,disabled:r,onRemove:()=>l(u)},c.id))]})}function se({className:m,selectedFile:o,selectedFiles:a,onFileSelect:r,onFilesSelect:i,onFileAdd:l,onFileRemove:p,onFilesAdd:c,onFilesRemove:u,onInvalidFile:g,acceptedExtensions:h,maxSizeInMB:w=50,maxFiles:R=10,multiple:q=!1,filesPosition:b="below",invalid:U=!1,disabled:G=!1,"aria-invalid":M,generateId:_,labels:$,input:F,...H}){const[J,V]=I.useState(!1),[K,Q]=I.useState(!1),E=I.useRef(null);I.useEffect(()=>{const e=()=>{if(E.current){const s=E.current.closest("fieldset");Q(s?.disabled??!1)}};e();const n=new MutationObserver(e);if(E.current){const s=E.current.closest("fieldset");s&&n.observe(s,{attributes:!0,attributeFilter:["disabled"]})}return()=>n.disconnect()},[]);const X=h?.join(",")||"",Y=w*1024*1024,d=q||a!==void 0||i!==void 0,j=d?a||[]:o?[o]:[],C=U||M,x=G||K,Z=_||(e=>`${Date.now()}-${Math.random().toString(36).substring(2,11)}-${e.name}`),D=e=>({id:Z(e),file:e}),P=e=>{x||(e.preventDefault(),V(!0))},W=e=>{x||(e.preventDefault(),V(!1))},S=e=>{if(!x)if(e.preventDefault(),V(!1),d){const s=Array.from(e.dataTransfer.files).filter(T);if(s.length>0){const f=s.map(D),O=[...a||[],...f].slice(0,R);i&&i(O),c&&c(f)}}else{const n=e.dataTransfer.files[0];if(n&&T(n)){const s=D(n);r&&r(s),l&&l(s)}}},ee=e=>{if(!x){if(d){const s=(e.target.files?Array.from(e.target.files):[]).filter(T);if(s.length>0){const f=s.map(D),O=[...a||[],...f].slice(0,R);i&&i(O),c&&c(f)}}else{const n=e.target.files?.[0];if(n&&T(n)){const s=D(n);r&&r(s),l&&l(s)}}e.target.value=""}},k=e=>{if(x)return;const n=j[e];if(d){const s=j.filter((f,v)=>v!==e);i&&i(s),u&&n&&u([n])}else r&&r(null),p&&n&&p(n)},T=e=>{const n=e.name.substring(e.name.lastIndexOf(".")),s=!h||h.length===0||h.includes(n.toLowerCase()),f=e.size<=Y;if(!s||!f){const v=D(e);!s&&g?g(v,"extension"):!f&&g&&g(v,"size")}return s&&f},z=()=>{if(x)return;const e=[...j];d?(i&&i([]),u&&e.length>0&&u(e)):(r&&r(null),p&&e.length>0&&p(e[0]))};return t.jsxRuntimeExports.jsxs("div",{ref:E,className:y.cn("adm:flex adm:flex-col adm:gap-4",m),...H,children:[d&&b==="above"&&t.jsxRuntimeExports.jsx(B,{files:j,isMultiple:d,invalid:C,disabled:x,labels:$,onRemoveFile:k,onClearAll:z}),(d||j.length===0)&&t.jsxRuntimeExports.jsx(te,{isDragging:J,isMultiple:d,invalid:C,disabled:x,accept:X,acceptedExtensions:h,maxSizeInMB:w,maxFiles:R,labels:$,input:F,onDragOver:P,onDragLeave:W,onDrop:S,onFileChange:ee}),!d&&j.length>0&&t.jsxRuntimeExports.jsx(B,{files:j,isMultiple:d,invalid:C,disabled:x,labels:$,onRemoveFile:k,onClearAll:z}),d&&b==="below"&&t.jsxRuntimeExports.jsx(B,{files:j,isMultiple:d,invalid:C,disabled:x,labels:$,onRemoveFile:k,onClearAll:z})]})}exports.FileUploadV2=se;
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 ${x} files`:""}.`:`Maximum size ${d} MB${o?`. Up to ${x} files`:""}.`)})]})}function re({fileWithMetadata:c,invalid:o,disabled:a,labels:t,onRemove:i}){const{file:m,status:d="idle",deletable:x=!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"]}),x&&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-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((x,p)=>r.jsxRuntimeExports.jsx(re,{fileWithMetadata:x,invalid:a,disabled:t,labels:i,onRemove:()=>m(p)},x.id))]})}function se({className:c,selectedFile:o,selectedFiles:a,onFileSelect:t,onFilesSelect:i,onFileAdd:m,onFileRemove:d,onFilesAdd:x,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,f=j||a!==void 0||i!==void 0,R=f?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),f){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),x&&x(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(f){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),x&&x(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(f){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];f?(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:[f&&u==="above"&&r.jsxRuntimeExports.jsx(_,{files:R,isMultiple:f,invalid:T,disabled:y,labels:I,onRemoveFile:O,onClearAll:A}),(f||R.length===0)&&r.jsxRuntimeExports.jsx(te,{isDragging:J,isMultiple:f,invalid:T,disabled:y,accept:Q,acceptedExtensions:l,maxSizeInMB:v,maxFiles:g,labels:I,input:F,onDragOver:Z,onDragLeave:W,onDrop:S,onFileChange:ee}),!f&&R.length>0&&r.jsxRuntimeExports.jsx(_,{files:R,isMultiple:f,invalid:T,disabled:y,labels:I,onRemoveFile:O,onClearAll:A}),f&&u==="below"&&r.jsxRuntimeExports.jsx(_,{files:R,isMultiple:f,invalid:T,disabled:y,labels:I,onRemoveFile:O,onClearAll:A})]})}exports.FileUploadV2=se;