UNPKG

carbon-react

Version:

A library of reusable React components for easily building user interfaces.

2 lines (1 loc) 3.06 kB
import{jsx as e,jsxs as r,Fragment as t}from"react/jsx-runtime";import"react";import{Link as o}from"../../../link/link.component.js";import{ButtonMinor as n}from"../../../button-minor/button-minor.component.js";import i from"../../../typography/typography.style.js";import{StyledProgressBar as l,InnerBar as c}from"../../../progress-tracker/progress-tracker.style.js";import{LoaderBar as a}from"../../../loader-bar/loader-bar.component.js";import s from"../../../icon/icon.component.js";import{StyledFileUploadStatus as p,StyledFileUploadStatusRow as u,StyledFileLinkContainer as f}from"./file-upload-status.style.js";import m from"../../../../hooks/__internal__/useLocale/useLocale.js";function d(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function b(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},o=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),o.forEach((function(r){d(e,r,t[r])}))}return e}function y(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})),e}const g=d=>{var{status:g,filename:O,message:j,onAction:h,iconType:w="file_generic"}=d,P=function(e,r){if(null==e)return{};var t,o,n=function(e,r){if(null==e)return{};var t,o,n={},i=Object.keys(e);for(o=0;o<i.length;o++)t=i[o],r.indexOf(t)>=0||(n[t]=e[t]);return n}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)t=i[o],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(n[t]=e[t])}return n}(d,["status","filename","message","onAction","iconType"]);const v=m(),k=j||v.fileInput.fileUploadStatus();let S,I,_=null;switch(g){case"uploading":S=v.fileInput.actions.cancel(),_=void 0===P.progress?e(a,{}):e(l,{"data-element":"progress-tracker-bar","data-role":"progress-tracker-bar",progress:P.progress,"aria-hidden":"true",children:e(c,{"data-element":"inner-bar","data-role":"inner-bar",size:"medium",progress:P.progress,error:!1})});break;case"previously":case"completed":S=v.fileInput.actions.delete(),I=y(b({},P),{icon:w});break;case"error":S=v.fileInput.actions.clear()}const x=e(n,{onClick:h,buttonType:"tertiary",children:S}),D=I?e(o,y(b({download:Boolean("completed"===g)},I),{children:O})):r(t,{children:[e(s,{type:w}),e("span",{children:O})]});return r(p,{"data-role":"file-upload-status",hasError:"error"===g,children:[r(u,"previously"!==g?{children:[e(i,{as:"p",mb:0,"aria-live":"polite",children:k}),x]}:{onlyRow:!0,children:[e(f,{children:D}),x]}),"previously"!==g?e(u,{upperPadding:!0,lowerPadding:!0,children:e(f,{children:D})}):null,_]})};export{g as FileUploadStatus,g as default};