aboutsummaryrefslogtreecommitdiff
path: root/src/containers/AvatarCropModal/AvatarCropModal.tsx
diff options
context:
space:
mode:
authorilyayudovin <46264063+ilyayudovin@users.noreply.github.com>2020-11-17 15:33:02 +0300
committerGitHub <noreply@github.com>2020-11-17 15:33:02 +0300
commitdb731f1b88fdfa95f16255767e44762211f47196 (patch)
tree84750528e47ae35e136bc8f24c1a575ccc81092f /src/containers/AvatarCropModal/AvatarCropModal.tsx
parentcda51156c20c04a20a9fcfe1e0f3aa51f54e9ad2 (diff)
parent99b4e4aa53d3ade389fc270f9ba9b02904da93f6 (diff)
downloadwhich-ui-db731f1b88fdfa95f16255767e44762211f47196.tar.gz
Merge pull request #108 from which-ecosystem/avatarCrop
feat: Add avatar crop
Diffstat (limited to 'src/containers/AvatarCropModal/AvatarCropModal.tsx')
-rw-r--r--src/containers/AvatarCropModal/AvatarCropModal.tsx57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/containers/AvatarCropModal/AvatarCropModal.tsx b/src/containers/AvatarCropModal/AvatarCropModal.tsx
new file mode 100644
index 0000000..4decdfb
--- /dev/null
+++ b/src/containers/AvatarCropModal/AvatarCropModal.tsx
@@ -0,0 +1,57 @@
+import React, { useState } from 'react';
+import { makeStyles } from '@material-ui/core/styles';
+import SendIcon from "@material-ui/icons/Send";
+import { getCroppedImg } from './canvasUtils'
+
+import ImageCropAreaSelect from '../../components/ImageCropAreaSelect/ImageCropAreaSelect';
+import ModalScreen from '../../components/ModalScreen/ModalScreen';
+
+interface Area {
+ x: number;
+ y: number;
+ width?: number;
+ height?: number;
+}
+
+interface PropTypes {
+ avatar: string;
+ callback: (file: File) => void;
+}
+
+const useStyles = makeStyles(theme => ({
+ cropContainer: {
+ position: 'relative',
+ width: '100%',
+ // height: '100vh',
+ // background: '#333',
+ [theme.breakpoints.up('sm')]: {
+ // height: 400,
+ },
+ }
+}));
+
+const AvatarCropModal: React.FC<PropTypes> = ({ avatar, callback }) => {
+ const classes = useStyles();
+ const [area, setArea] = useState<Area>({ x: 0, y: 0 });
+
+ const handleAction = async () => getCroppedImg(avatar, area)
+ .then(croppedImage => callback(croppedImage));
+
+ return (
+ <ModalScreen
+ title="Choose area"
+ actionIcon={<SendIcon />}
+ handleAction={handleAction}
+ isActionDisabled={false}
+ >
+ <div className={classes.cropContainer}>
+ <ImageCropAreaSelect
+ image={avatar}
+ setArea={setArea}
+ />
+ </div>
+ </ModalScreen>
+ )
+};
+
+export default AvatarCropModal;