@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 • 8.25 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 _reactdropzone=require("react-dropzone");var _FileUploadStyles=require("./FileUploadStyles");var _hooks=require("./hooks");var _FileList=_interop_require_default(require("./FileList/FileList"));function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function _array_without_holes(arr){if(Array.isArray(arr))return _array_like_to_array(arr)}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 _interop_require_default(obj){return obj&&obj.__esModule?obj:{default:obj}}function _iterable_to_array(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter)}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}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}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _to_consumable_array(arr){return _array_without_holes(arr)||_iterable_to_array(arr)||_unsupported_iterable_to_array(arr)||_non_iterable_spread()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}var detectIsTouchScreenOnly=function(){var _window;return((_window=window)===null||_window===void 0?void 0:_window.matchMedia("(pointer: coarse)").matches)?true:false};var FileUpload=function(_param){var _Math;var getPostUrl=_param.getPostUrl,getHeaders=_param.getHeaders,droppingLabel=_param.droppingLabel,placeholder=_param.placeholder,removeLabel=_param.removeLabel,cancelLabel=_param.cancelLabel,selectFilesLabel=_param.selectFilesLabel,fileUploadErrorLabel=_param.fileUploadErrorLabel,fileUploadInProgressLabel=_param.fileUploadInProgressLabel,fileListTitle=_param.fileListTitle,onFileRemove=_param.onFileRemove,onFileSuccess=_param.onFileSuccess,onFileNameClick=_param.onFileNameClick,removeCompletedFromList=_param.removeCompletedFromList,options=_param.options,_param_storedFiles=_param.storedFiles,storedFiles=_param_storedFiles===void 0?[]:_param_storedFiles,_param_httpMethod=_param.httpMethod,httpMethod=_param_httpMethod===void 0?"POST":_param_httpMethod,otherProps=_object_without_properties(_param,["getPostUrl","getHeaders","droppingLabel","placeholder","removeLabel","cancelLabel","selectFilesLabel","fileUploadErrorLabel","fileUploadInProgressLabel","fileListTitle","onFileRemove","onFileSuccess","onFileNameClick","removeCompletedFromList","options","storedFiles","httpMethod"]);var _useState=_sliced_to_array((0,_react.useState)(0),2),numberOfDraggedFiles=_useState[0],setNumberOfDraggedFiles=_useState[1];var isTouchScreen=detectIsTouchScreenOnly();var _useFileUpload=(0,_hooks.useFileUpload)(getPostUrl,getHeaders,httpMethod,storedFiles,(_Math=Math).max.apply(_Math,_to_consumable_array(_to_consumable_array(storedFiles.length?storedFiles.map(function(file){return file.tmpId}):[0]))),onFileSuccess),files=_useFileUpload.files,handleOnDrop=_useFileUpload.handleOnDrop,handleOnCancel=_useFileUpload.handleOnCancel,handleOnFileRemove=_useFileUpload.handleOnFileRemove;var _useDropzone=(0,_reactdropzone.useDropzone)(_object_spread_props(_object_spread({},options),{onDrop:handleOnDrop,onDragEnter:function(event){setNumberOfDraggedFiles(event.dataTransfer.items.length)},noDrag:isTouchScreen})),open=_useDropzone.open,getRootProps=_useDropzone.getRootProps,getInputProps=_useDropzone.getInputProps,isDragActive=_useDropzone.isDragActive;return(0,_jsxruntime.jsx)("div",_object_spread_props(_object_spread({},otherProps),{children:(0,_jsxruntime.jsxs)(_FileUploadStyles.FileUploadStyle,_object_spread_props(_object_spread({"data-testid":"file-upload"},getRootProps({isDragActive:isDragActive})),{children:[(0,_jsxruntime.jsx)("input",_object_spread({"data-testid":"file-upload__input"},getInputProps())),(0,_jsxruntime.jsx)(_FileUploadStyles.FileUploadContentStyle,{children:(0,_jsxruntime.jsxs)(_jsxruntime.Fragment,{children:[(0,_jsxruntime.jsx)("div",{children:isDragActive?(0,_jsxruntime.jsxs)(_FileUploadStyles.FileUploadPlaceholderStyle,{children:[numberOfDraggedFiles,"\xa0",droppingLabel]}):(0,_jsxruntime.jsxs)(_jsxruntime.Fragment,{children:[(0,_jsxruntime.jsx)(_FileUploadStyles.FileUploadPlaceholderStyle,{children:placeholder}),(0,_jsxruntime.jsx)(_FileUploadStyles.FileUploadSelectFilesButtonStyle,{variant:"textButton",onClick:open,type:"button",children:selectFilesLabel})]})}),(0,_jsxruntime.jsx)(_FileList.default,{files:removeCompletedFromList?files.filter(function(file){var _file;return file.progress!==100||((_file=file)===null||_file===void 0?void 0:_file.uploadXhrError)===true}):files,onFileNameClick:onFileNameClick,removeLabel:removeLabel,cancelLabel:cancelLabel,onCancel:handleOnCancel,onFileRemove:function(file){handleOnFileRemove(file);onFileRemove&&onFileRemove(file)},fileUploadErrorLabel:fileUploadErrorLabel,fileUploadInProgressLabel:fileUploadInProgressLabel,title:fileListTitle})]})})]}))}))};var _default=FileUpload;
//# sourceMappingURL=FileUpload.js.map