UNPKG

ponchojs

Version:

Poncho

3 lines (2 loc) 5.21 kB
import{j as e,a as t}from"./emotion-react-jsx-runtime.esm-991ce217.js";import i from"classnames";import{useField as n}from"formik";import{a as o}from"./useFormContext-57a22edf.js";import{BaseInput as a}from"./baseinput.js";import{makeStyles as s}from"@material-ui/styles";import r,{useState as l,useRef as c,useMemo as d,useCallback as p}from"react";import{IconButton as m}from"./iconbutton.js";import{M as u}from"./Modal-d2e0a7d3.js";import{u as f}from"./useInputDisable-b6a59f7b.js";import"./tslib.es6-d703c724.js";import"./styled-components.esm-0d53f334.js";import"./close-3228efe8.js";function h(){return(h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i,n=arguments[t];for(i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var g=({styles:e={},...t})=>r.createElement("svg",h({height:"512pt",viewBox:"-64 0 512 512",width:"512pt",xmlns:"http://www.w3.org/2000/svg"},t),r.createElement("path",{d:"M256 80h-32V32h-64v48h-32V0h128zm0 0",fill:"#62808c"}),r.createElement("path",{d:"M304 512H80c-26.508 0-48-21.492-48-48V128h320v336c0 26.508-21.492 48-48 48zm0 0",fill:"#e76e54"}),r.createElement("path",{d:"M384 160H0V96c0-17.672 14.328-32 32-32h320c17.672 0 32 14.328 32 32zm0 0",fill:"#77959e"}),r.createElement("path",{d:"M260 260c-6.246-6.246-16.375-6.246-22.625 0L196 301.375 154.625 260c-6.25-6.246-16.379-6.246-22.625 0s-6.246 16.375 0 22.625L173.375 324 132 365.375c-6.246 6.25-6.246 16.379 0 22.625s16.375 6.246 22.625 0L196 346.625 237.375 388c6.25 6.246 16.379 6.246 22.625 0s6.246-16.375 0-22.625L218.625 324 260 282.625c6.246-6.25 6.246-16.379 0-22.625zm0 0",fill:"#fff"}));function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i,n=arguments[t];for(i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var b=({styles:e={},...t})=>r.createElement("svg",v({height:"512pt",viewBox:"-6 0 512 512",width:"512pt",xmlns:"http://www.w3.org/2000/svg"},t),r.createElement("path",{d:"M416 512H0V104.64L122.078 0H416zm0 0",fill:"#e4edfb"}),r.createElement("path",{d:"M473.375 496L308.687 331.312l22.625-22.625L496 473.375c6.246 6.25 6.246 16.379 0 22.625s-16.375 6.246-22.625 0zm0 0",fill:"#57565c"}),r.createElement("path",{d:"M0 104.64h122.078V0zm0 0",fill:"#48c8ef"}),r.createElement("g",{fill:"#fff"},r.createElement("path",{d:"M64 416h32v32H64zm0 0M128 416h32v32h-32zm0 0M192 416h32v32h-32zm0 0"})),r.createElement("path",{d:"M368 248c0 66.273-53.727 120-120 120s-120-53.727-120-120 53.727-120 120-120 120 53.727 120 120zm0 0",fill:"#57565c"}),r.createElement("path",{d:"M336 248c0 48.602-39.398 88-88 88s-88-39.398-88-88 39.398-88 88-88 88 39.398 88 88zm0 0",fill:"#48c8ef"}));const w=s=>{const[r,h]=l(!1),v=c(null),[w,O]=l("");var{startAddon:y,id:M,initialValue:x,placeholder:z,accept:E,inputProps:V}=s;const[{value:R},,{setValue:L}]=n(M);o(Object.assign(Object.assign({},s),{initialValue:x||null}));var C=f(s),k=d((()=>R instanceof File?R.name:R||""),[R]),N=j({loading:C,showBtns:!(!w&&!R),base64:w}),B=p((({target:e})=>{e=e.files&&e.files[0];const t=new FileReader;t.onload=e=>{O((null===(e=null===(e=e.target)||void 0===e?void 0:e.result)||void 0===e?void 0:e.toString())||"")},e&&(L(e),t.readAsDataURL(e))}),[L]),{canOpen:M,isPdf:x}=d((()=>{const e=w.substring(0,w.indexOf(";base64"));return{canOpen:e.includes("pdf")||e.includes("jpg")||e.includes("jpeg")||e.includes("gif")||e.includes("png"),isPdf:e.includes("pdf")}}),[w]);return e(a,Object.assign({},s,{children:[e("div",Object.assign({className:N.root},{children:[e("div",Object.assign({className:i("input-group",N.inputRoot),onClick:()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.click()}},{children:[t("input",{disabled:C,className:i("form-control",N.input),type:"text",placeholder:z||"Haga click ACÁ",value:k,onChange:()=>{}},void 0),t("input",Object.assign({accept:E,type:"file",className:N.hidden,onChange:B,ref:e=>v.current=e},V),void 0),t("span",Object.assign({className:i("input-group-addon",N.span)},{children:y||"Cargar Archivo"}),void 0)]}),void 0),e("div",Object.assign({className:N.btnRoot},{children:[t(m,{disabled:!M,Icon:b,onClick:()=>h(!0)},void 0),t(m,{Icon:g,onClick:()=>{v.current&&(v.current.value=""),O(""),L(null)}},void 0)]}),void 0)]}),void 0),t(u,Object.assign({closeBtn:!0,open:r,onClose:()=>h(!1)},{children:x?t("embed",{src:w,className:N.pdfView},void 0):t("div",{className:N.imageView},void 0)}),void 0)]}),void 0)},j=s({root:{display:"flex",flexDirection:"row",alignItems:"center"},inputRoot:({loading:e})=>({cursor:e?"not-allowed":"pointer"}),input:({loading:e})=>({cursor:e?"not-allowed":"pointer"}),hidden:{display:"none!important"},btnRoot:({showBtns:e})=>({display:"flex",flexDirection:"row",alignItems:"center",width:e?64:0,transition:"all 0.4s",visibility:e?"visible":"hidden",position:e?"static":"absolute",opacity:e?1:0}),imageView:({base64:e})=>({width:640,height:480,backgroundSize:"cover",backgroundImage:`url(${e})`}),pdfView:{width:640,height:480},span:{borderTopLeftRadius:"0!important",borderBottomLeftRadius:"0!important",borderTopRightRadius:10,borderBottomRightRadius:10}});export{w as FileInput}; //# sourceMappingURL=fileinput.js.map