All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.FileUpload-CumNwlWc.js Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
import{jsxs as A,jsx as l}from"react/jsx-runtime";import{f as p,u as E,a as G}from"./CodeEditor-C-nZkUJx.js";import{m as V,bb as j,bc as O,am as H,i as $,B as z,aZ as K,d3 as Z,cr as q,d4 as J}from"./main-C7ps2lmX.js";var f=(a=>(a.text="text",a.dataURL="dataURL",a))(f||{});function M(a,o){return new Promise((d,n)=>{const i=new FileReader;switch(i.onload=()=>d(i.result),i.onerror=()=>n(i.error),o){case"text":i.readAsText(a);break;case"dataURL":i.readAsDataURL(a);break;default:n("unknown type")}})}const P=({id:a,type:o,value:d="",filename:n="",onChange:i,onBrowseButtonClick:s,onClearButtonClick:U,onTextAreaClick:D,onTextChange:h,className:F="",isDisabled:u=!1,isReadOnly:B=!1,isLoading:R=!1,spinnerAriaValueText:k,isRequired:m=!1,isDragActive:g=!1,validated:x="default","aria-label":C="File upload",filenamePlaceholder:v="Drag a file here or browse to upload",filenameAriaLabel:I=n?"Read only filename":v,browseButtonText:N="Browse...",clearButtonText:y="Clear",isClearButtonDisabled:L=!n&&!d,containerRef:b=null,allowEditingUploadedText:S=!1,hideDefaultPreview:w=!1,children:T=null,...e})=>{const r=(t,c)=>{i?.(t,n,c),h?.(t)};return A("div",{className:V(p.fileUpload,g&&p.modifiers.dragHover,R&&p.modifiers.loading,F),ref:b,...e,children:[l("div",{className:p.fileUploadFileSelect,children:A(j,{children:[l(O,{isFill:!0,children:l(H,{isDisabled:u,id:`${a}-filename`,name:`${a}-filename`,"aria-label":I,placeholder:v,"aria-describedby":`${a}-browse-button`,value:n,readOnlyVariant:"default"})}),l(O,{children:l($,{id:`${a}-browse-button`,variant:z.control,onClick:s,isDisabled:u,children:N})}),l(O,{children:l($,{variant:z.control,isDisabled:u||L,onClick:U,children:y})})]})}),A("div",{className:p.fileUploadFileDetails,children:[!w&&o===f.text&&l(K,{readOnly:B||!!n&&!S,disabled:u,isRequired:m,resizeOrientation:Z.vertical,validated:x,id:a,name:a,"aria-label":C,value:d,onChange:(t,c)=>r(c,t),onClick:D}),R&&l("div",{className:p.fileUploadFileDetailsSpinner,children:l(q,{size:J.lg,"aria-valuetext":k})})]}),T]})};P.displayName="FileUploadField";const Q=({id:a,type:o,value:d=o===f.text||o===f.dataURL?"":void 0,filename:n="",children:i=null,onChange:s,onFileInputChange:U,onReadStarted:D,onReadFinished:h,onReadFailed:F,onClearClick:u,onClick:B=x=>x.preventDefault(),onTextChange:R,onDataChange:k,dropzoneProps:m={},...g})=>{const x=(e,r)=>{if(e.length>0){const t=e[0];r?.type==="drop"&&U?.(r,t),o===f.text||o===f.dataURL?(s?.("",t.name,r),D?.(t),M(t,o).then(c=>{h?.(t),s?.(c,t.name,r),k?.(c)}).catch(c=>{F?.(c,t),h?.(t),s?.("","",r),k?.("")})):s?.(t,t.name,r)}m.onDropAccepted?.(e,r)},C=(e,r)=>{e.length>0&&s?.("",e[0].file.name,r),m.onDropRejected?.(e,r)},v=e=>{s?.("","",e),u?.(e),S("")},{getRootProps:I,getInputProps:N,isDragActive:y,open:L,inputRef:b}=E({multiple:!1,...m,onDropAccepted:x,onDropRejected:C}),S=e=>{b.current&&(b.current.value=e)},w=N(),T={...w,onChange:async e=>{w.onChange?.(e);const r=await G(e.nativeEvent);r.length===1&&U?.(e,r[0])}};return A(P,{...I({...g,refKey:"containerRef",onClick:e=>e.preventDefault()}),tabIndex:void 0,id:a,type:o,filename:n,value:d,onChange:s,isDragActive:y,onBrowseButtonClick:L,onClearButtonClick:v,onTextAreaClick:B,onTextChange:R,onClick:e=>e.stopPropagation(),children:[l("input",{...T,ref:b}),i]})};Q.displayName="FileUpload";export{Q as F};
//# sourceMappingURL=FileUpload-CumNwlWc.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy