@amsterdam/bmi-component-library
Version:
A React component library based on ASC and Material-UI aimed at repurposing and sharing components across BMI projects
2 lines • 6.36 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return _default}});var _jsxruntime=require("react/jsx-runtime");var _react=require("react");var _ascassets=require("@amsterdam/asc-assets");var _ascui=require("@amsterdam/asc-ui");var _FileListStyles=require("./FileListStyles");var _hooks=require("./hooks");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _object_without_properties(source,excluded){if(source==null)return{};var target=_object_without_properties_loose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key]}}return target}function _object_without_properties_loose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key]}return target}var isFileUploading=function(file){return file&&file.progress&&file.progress<100?true:false};var isFileUploadingIndeterminate=function(file){return file&&file.progress===0?true:false};var FileList=function(_param){var files=_param.files,cancelLabel=_param.cancelLabel,removeLabel=_param.removeLabel,onFileNameClick=_param.onFileNameClick,onFileRemove=_param.onFileRemove,onCancel=_param.onCancel,fileUploadErrorLabel=_param.fileUploadErrorLabel,fileUploadInProgressLabel=_param.fileUploadInProgressLabel,title=_param.title,otherProps=_object_without_properties(_param,["files","cancelLabel","removeLabel","onFileNameClick","onFileRemove","onCancel","fileUploadErrorLabel","fileUploadInProgressLabel","title"]);var _files;if(((_files=files)===null||_files===void 0?void 0:_files.length)===0){return null}return(0,_jsxruntime.jsxs)(_FileListStyles.FileListStyle,_object_spread_props(_object_spread({"data-testid":"file-list"},otherProps),{children:[title&&(0,_jsxruntime.jsx)(_FileListStyles.FileListTitleStyle,{children:title}),files.map(function(file,index){return(0,_jsxruntime.jsx)(FileListItem,_object_spread_props(_object_spread({onCancel:function(){return onCancel(file)},onFileRemove:function(){return onFileRemove(file)}},onFileNameClick?{onFileNameClick:function(){return onFileNameClick&&onFileNameClick(file)}}:{}),{cancelLabel:cancelLabel,removeLabel:removeLabel,file:file,fileUploadErrorLabel:fileUploadErrorLabel,fileUploadInProgressLabel:fileUploadInProgressLabel}),file.tmpId||index)})]}))};var FileListItem=function(param){var file=param.file,cancelLabel=param.cancelLabel,removeLabel=param.removeLabel,onFileNameClick=param.onFileNameClick,onFileRemove=param.onFileRemove,onCancel=param.onCancel,fileUploadErrorLabel=param.fileUploadErrorLabel,fileUploadInProgressLabel=param.fileUploadInProgressLabel;var _file,_file1,_file_file,_file2;var mountedRef=(0,_react.useRef)(true);var isUploading=isFileUploading(file);var isIndeterminate=isFileUploadingIndeterminate(file);var preview=(0,_hooks.useBase64PreviewValue)(file,mountedRef);return(0,_jsxruntime.jsxs)(_FileListStyles.FileListItemStyle,{"data-testid":"file-list-item",children:[(0,_jsxruntime.jsxs)(_jsxruntime.Fragment,{children:[!isUploading&&!isIndeterminate&&(0,_jsxruntime.jsx)(_FileListStyles.FileListItemPreviewWrapperStyle,{"data-testid":"file-list-item-preview",children:preview?(0,_jsxruntime.jsx)(_FileListStyles.FileListItemImagePreviewStyle,{src:preview,alt:file.name}):(0,_jsxruntime.jsx)(_ascui.Icon,{size:32,inline:true,children:(0,_jsxruntime.jsx)(_ascassets.Document,{})})}),((_file=file)===null||_file===void 0?void 0:_file.errors)||((_file1=file)===null||_file1===void 0?void 0:_file1.uploadXhrError)?(0,_jsxruntime.jsxs)(_FileListStyles.FileNameErrorStyle,{"data-testid":"file-list-item-error",children:[((_file2=file)===null||_file2===void 0?void 0:(_file_file=_file2.file)===null||_file_file===void 0?void 0:_file_file.name)||file.name," ",fileUploadErrorLabel]}):(0,_jsxruntime.jsxs)(_FileListStyles.FileNameStyle,_object_spread_props(_object_spread({"data-testid":"file-list-item-name"},isUploading?{}:{onClick:function(){return onFileNameClick&&onFileNameClick(file)}}),{hasClickListener:onFileNameClick?true:false,children:[file.name," ",isUploading&&fileUploadInProgressLabel]}))]}),isUploading||isIndeterminate?(0,_jsxruntime.jsxs)(_jsxruntime.Fragment,{children:[(0,_jsxruntime.jsx)(_FileListStyles.FileListItemButtonStyle,{onClick:function(){return onCancel(file)},variant:"textButton","data-testid":"file-list-item-cancel",children:cancelLabel}),(0,_jsxruntime.jsx)(_FileListStyles.FileProgressBarStyle,_object_spread_props(_object_spread({max:"100"},isUploading?{value:file.progress}:{}),{"data-testid":"file-list-item-progress"}))]}):(0,_jsxruntime.jsx)(_FileListStyles.FileListItemButtonStyle,{onClick:function(){return onFileRemove(file)},variant:"textButton","data-testid":"file-list-item-remove",children:removeLabel})]})};var _default=FileList;
//# sourceMappingURL=FileList.js.map