Skip to content

Commit

Permalink
feat: improve avatar input
Browse files Browse the repository at this point in the history
  • Loading branch information
Shchepotin committed Sep 23, 2023
1 parent b3ccc66 commit 333c936
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/components/form/avatar-input/form-avatar-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Avatar from "@mui/material/Avatar";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography";
import { styled } from "@mui/material/styles";
import { useCallback, useState } from "react";
import { useDropzone } from "react-dropzone";
import {
Expand All @@ -23,6 +24,23 @@ type AvatarInputProps = {
disabled?: boolean;
};

const AvatarInputContainer = styled(Box)(({ theme }) => ({
display: "flex",
position: "relative",
flexDirection: "column",
alignItems: "center",
padding: theme.spacing(2),
marginTop: theme.spacing(2),
border: "1px dashed",
borderColor: theme.palette.divider,
borderRadius: theme.shape.borderRadius,
cursor: "pointer",

"&:hover": {
borderColor: theme.palette.text.primary,
},
}));

function AvatarInput(props: AvatarInputProps) {
const { t } = useTranslation();
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -50,17 +68,7 @@ function AvatarInput(props: AvatarInputProps) {
});

return (
<Box
{...getRootProps()}
sx={{
display: "flex",
position: "relative",
flexDirection: "column",
alignItems: "center",
p: 2,
mt: 2,
}}
>
<AvatarInputContainer {...getRootProps()}>
{isDragActive && (
<Box
sx={{
Expand Down Expand Up @@ -101,12 +109,19 @@ function AvatarInput(props: AvatarInputProps) {
<input {...getInputProps()} />
</Button>
</Box>

<Box sx={{ mt: 1 }}>
<Typography>
{t("common:formInputs.avatarInput.dragAndDrop")}
</Typography>
</Box>

{props.error && (
<Box sx={{ mt: 1 }}>
<Typography sx={{ color: "red" }}>{props.error}</Typography>
</Box>
)}
</Box>
</AvatarInputContainer>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/services/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"formInputs": {
"avatarInput": {
"dropzoneText": "Drop the image here ...",
"dragAndDrop": "Or drag 'n' drop some files here",
"selectFile": "Select an image"
}
},
Expand Down

0 comments on commit 333c936

Please sign in to comment.