-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Valik3201/feature/avatar-upload-edit
Feature/avatar upload edit
- Loading branch information
Showing
20 changed files
with
685 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
import EasyCropper from "react-easy-crop"; | ||
import { useImageCropContext } from "@/src/providers/ImageCropProvider"; | ||
|
||
const Cropper: React.FC = () => { | ||
const { image, zoom, setZoom, rotation, crop, setCrop, onCropComplete } = | ||
useImageCropContext(); | ||
|
||
return ( | ||
<EasyCropper | ||
image={image || undefined} | ||
crop={crop} | ||
zoom={zoom} | ||
rotation={rotation} | ||
cropShape="round" | ||
aspect={1} | ||
onCropChange={(point) => setCrop((prev) => ({ ...prev, ...point }))} | ||
onCropComplete={onCropComplete} | ||
onZoomChange={setZoom} | ||
showGrid={false} | ||
cropSize={{ width: 220, height: 220 }} | ||
style={{ | ||
containerStyle: { | ||
borderRadius: 8, | ||
}, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default Cropper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useImageCropContext } from "@/src/providers/ImageCropProvider"; | ||
import AddIcon from "@/src/icons/AddIcon"; | ||
import RemoveIcon from "@/src/icons/RemoveIcon"; | ||
import RotateLeftIcon from "@/src/icons/RotateLeftIcon"; | ||
import RotateRightIcon from "@/src/icons/RotateRightIcon"; | ||
|
||
export const ZoomSlider = () => { | ||
const { | ||
zoom, | ||
setZoom, | ||
handleZoomIn, | ||
handleZoomOut, | ||
max_zoom, | ||
min_zoom, | ||
zoom_step, | ||
} = useImageCropContext(); | ||
|
||
return ( | ||
<div className="flex items-center justify-center gap-2"> | ||
<button className="p-1" onClick={handleZoomOut}> | ||
<span className="sr-only">Zoom Out</span> | ||
<RemoveIcon /> | ||
</button> | ||
<input | ||
type="range" | ||
name="volju" | ||
min={min_zoom} | ||
max={max_zoom} | ||
step={zoom_step} | ||
value={zoom} | ||
onChange={(e) => { | ||
setZoom(Number(e.target.value)); | ||
}} | ||
className="accent-primary bg-gray-light h-2 rounded-full appearance-none dark:bg-light" | ||
/> | ||
<button className="p-1" onClick={handleZoomIn}> | ||
<span className="sr-only">Zoom In</span> | ||
<AddIcon /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export const RotationSlider = () => { | ||
const { | ||
rotation, | ||
setRotation, | ||
max_rotation, | ||
min_rotation, | ||
rotation_step, | ||
handleRotateAntiCw, | ||
handleRotateCw, | ||
} = useImageCropContext(); | ||
|
||
return ( | ||
<div className="flex items-center justify-center gap-2"> | ||
<button className="p-1" onClick={handleRotateAntiCw}> | ||
<span className="sr-only">Rotate Left</span> | ||
<RotateLeftIcon /> | ||
</button> | ||
<input | ||
type="range" | ||
name="volju" | ||
min={min_rotation} | ||
max={max_rotation} | ||
step={rotation_step} | ||
value={rotation} | ||
onChange={(e) => { | ||
setRotation(Number(e.target.value)); | ||
}} | ||
className="accent-primary bg-gray-light h-2 rounded-full appearance-none dark:bg-light" | ||
/> | ||
<button className="p-1" onClick={handleRotateCw}> | ||
<span className="sr-only">Rotate Right</span> | ||
<RotateRightIcon /> | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Modal from "./Modal"; | ||
import Cropper from "../Cropper/Cropper"; | ||
import { ZoomSlider, RotationSlider } from "../Cropper/Sliders"; | ||
|
||
export default function AvatarEditModal({ | ||
isOpen, | ||
toggleState, | ||
handleDone, | ||
}: { | ||
isOpen: boolean; | ||
toggleState: () => void; | ||
handleDone: () => void; | ||
}) { | ||
return ( | ||
<Modal | ||
handleConfirm={handleDone} | ||
trigger={null} | ||
isOpen={isOpen} | ||
toggleState={toggleState} | ||
> | ||
<Modal.Header>Edit profile picture</Modal.Header> | ||
<Modal.Body> | ||
<div className="flex justify-center pt-4"> | ||
<div className="relative w-60 h-60 bg-dark rounded-lg mb-4"> | ||
<Cropper /> | ||
</div> | ||
</div> | ||
<ZoomSlider /> | ||
<RotationSlider /> | ||
</Modal.Body> | ||
|
||
<div className="flex gap-2 justify-end"> | ||
<Modal.DiscardBtn>Cancel</Modal.DiscardBtn> | ||
<Modal.ConfirmBtn variant="primary">Done & Save</Modal.ConfirmBtn> | ||
</div> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Image from "next/image"; | ||
import Avatar from "@/src/icons/Avatar"; | ||
|
||
export default function AvatarDisplay({ | ||
photoURL, | ||
}: { | ||
photoURL: string | null; | ||
}) { | ||
return ( | ||
<div className="relative w-14 h-14 lg:w-20 lg:h-20"> | ||
{photoURL ? ( | ||
<Image | ||
src={photoURL} | ||
alt="User avatar" | ||
className="rounded-full object-cover" | ||
sizes="100%" | ||
fill | ||
/> | ||
) : ( | ||
<Avatar size="lg" /> | ||
)} | ||
<label | ||
htmlFor="avatarInput" | ||
className="absolute w-full h-full top-0 left-0 flex items-center justify-center z-20 text-heading-s-variant text-white/0 bg-dark/0 hover:bg-dark/40 hover:text-white/100 rounded-full cursor-pointer transition duration-200 ease-in-out" | ||
> | ||
Upload | ||
</label> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.