diff --git a/src/components/FileSelect/FileSelect.tsx b/src/components/FileSelect/FileSelect.tsx new file mode 100644 index 0000000..a48c03b --- /dev/null +++ b/src/components/FileSelect/FileSelect.tsx @@ -0,0 +1,86 @@ +import React, { useState, useRef } from 'react'; +import { Flex, Box, Text } from '@chakra-ui/layout'; +import { Button } from '@chakra-ui/button'; +import { MdAttachFile } from 'react-icons/md'; +import * as helpres from '@educt/helpers'; + +/** + * Hooks + */ +import { useColorModeValue } from '@chakra-ui/color-mode'; +import { Input } from '@chakra-ui/input'; + +type FileSelectPropsType = { + onChange: (file: File) => void; + supportedFormats?: string[]; +}; + +const FileSelect: React.FC = ({ onChange, supportedFormats }) => { + const [selectedFile, setSelectedFile] = useState(undefined); + const fileInputRef = useRef(null); + + /** + * Handle the file input selection + */ + const onSelectFileHandler = () => { + if (fileInputRef.current) { + fileInputRef.current.click(); + } + }; + + const onChangeFileHandler = (e: React.ChangeEvent) => { + e.preventDefault(); + + const { files } = e.target; + + if (files && files.length !== 0) { + const file = files[0]; + + onChange(file); + setSelectedFile(file); + } + }; + + return ( + + + + + {selectedFile ? ( + + {selectedFile.name} +
+ + {helpres.transformBytes(selectedFile.size)} + +
+ ) : ( + + Choose a file... + + )} + {supportedFormats && ( + + + Supported formats: {supportedFormats.join(', ')} + + + )} +
+ + + +
+
+ ); +}; + +export default FileSelect; diff --git a/src/components/LoadingList/LoadingList.tsx b/src/components/LoadingList/LoadingList.tsx new file mode 100644 index 0000000..9aada87 --- /dev/null +++ b/src/components/LoadingList/LoadingList.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { Box, Text } from '@chakra-ui/layout'; + +const LoadingList: React.FC = () => { + return ( + + Wait a second... + + ); +}; + +export default LoadingList; diff --git a/src/components/LoadingList/index.ts b/src/components/LoadingList/index.ts new file mode 100644 index 0000000..f67ac9a --- /dev/null +++ b/src/components/LoadingList/index.ts @@ -0,0 +1,3 @@ +import LoadingList from './LoadingList'; + +export default LoadingList; diff --git a/src/components/Select/Select.tsx b/src/components/Select/Select.tsx index 9463395..13d2ad4 100644 --- a/src/components/Select/Select.tsx +++ b/src/components/Select/Select.tsx @@ -29,6 +29,8 @@ const Select: React.FC = props => { { }; return ( - +
@@ -67,27 +67,24 @@ const AuthForm: React.FC = () => { Login } /> - + {errors.login?.message} + Password } /> - + {errors.password?.message} +