UNPKG

@lanaco/lnc-react-ui

Version:

React component library

40 lines (35 loc) 2.54 kB
"use strict";const s=require("react/jsx-runtime"),I=require("react"),r=require("./emotion-styled.browser.esm-DwHBgTPn.cjs"),p=require("./Icon.cjs"),M=require("./ProgressBar.cjs"),a=require("./utils-BK6B_Y9X.cjs"),N=require("./emotion-element-f0de968e.browser.esm-B7k6i6lC.cjs"),x={small:"1.5rem",medium:"1.75rem",large:"2rem"},y={small:"2.25rem",medium:"2.5rem",large:"2.75rem"},T=r.styled.div` display: inline-flex; gap: 0.5rem; align-items: center; width: 100%; height: ${e=>e.progress?y[e.size]:x[e.size]}; height: ${e=>e.progress?y[e.size]:x[e.size]}; `,R=r.styled.div` color: ${e=>a.getColorRgbaValue(e.theme,"UploadedFile",e.color,"enabled","color")}; width: 100%; display: flex; flex-direction: column; gap: 0.1875rem; min-width: 0; flex-shrink: 1; min-height: 0; `,S=r.styled.div` display: flex; justify-content: space-between; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; ${e=>a.getComponentTypographyCss(e.theme,"UploadedFile",e.size,"enabled")}; `,_=r.styled.span` display: flex; align-items: center; justify-content: center; cursor: ${e=>e.onCancel?"pointer":"default"}; `,E=r.styled.span` white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: ${e=>e.hasOnClick?"pointer":"default"}; ${e=>a.getComponentTypographyCss(e.theme,"UploadedFile",e.size,"enabled")}; `,O=I.forwardRef((e,z)=>{const{id:w,fileName:o="file",fileSize:d=null,showFileSize:C=!1,progressPercentage:i,onFileClick:n=()=>{},onCancel:c=()=>{},size:j="small",color:B="primary",className:F="",style:v={},fileIcon:$="file",cancelIcon:k="times",...m}=e;var t={theme:N.useTheme(),size:j,color:B,progress:i&&i>0};const q=()=>o&&d&&C?`${o} (${P(d,2)})`:o||"";function P(l,u=2){if(l===0)return"0 Bytes";const f=1024,U=u<0?0:u,b=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],g=Math.floor(Math.log(l)/Math.log(f));return parseFloat((l/Math.pow(f,g)).toFixed(U))+" "+b[g]}const h={small:"1rem",medium:"1.25rem",large:"1.5rem"};return s.jsxs(T,{ref:z,id:w,...t,className:"lnc-ui-uploaded-file "+F,style:v,...m,children:[s.jsx(p,{...t,icon:$,sizeInUnits:h[e.size],style:{cursor:n?"pointer":"default"},onClick:l=>n?n(l):null}),s.jsxs(R,{...t,children:[s.jsxs(S,{...t,children:[s.jsx(E,{...t,hasOnClick:!!n,onClick:l=>n?n(l):null,children:q()}),i&&s.jsxs("div",{children:[i,"%"]})]}),(i||i==0)&&s.jsx(M,{progressPercentage:i,style:{height:"0.5rem"},...t})]}),s.jsx(_,{onCancel:c,onClick:c||null,children:s.jsx(p,{...t,icon:k,sizeInUnits:h[e.size],...m})})]})});module.exports=O;