Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.pnp
.pnp.js
.yarn/install-state.gz
/package-lock.json

# testing
/coverage
Expand Down
16 changes: 5 additions & 11 deletions src/components/image-cropper.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"use client"

import React, { type SyntheticEvent } from "react"

import ReactCrop, {
centerCrop,
makeAspectCrop,
type Crop,
type PixelCrop,
} from "react-image-crop"

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import {
Expand All @@ -18,7 +16,6 @@ import {
DialogFooter,
DialogTrigger,
} from "@/components/ui/dialog"

import "react-image-crop/dist/ReactCrop.css"
import { FileWithPreview } from "@/app/page"
import { CropIcon, Trash2Icon } from "lucide-react"
Expand All @@ -37,9 +34,7 @@ export function ImageCropper({
setSelectedFile,
}: ImageCropperProps) {
const aspect = 1

const imgRef = React.useRef<HTMLImageElement | null>(null)

const [crop, setCrop] = React.useState<Crop>()
const [croppedImageUrl, setCroppedImageUrl] = React.useState<string>("")
const [croppedImage, setCroppedImage] = React.useState<string>("")
Expand Down Expand Up @@ -107,8 +102,8 @@ export function ImageCropper({
<AvatarFallback>CN</AvatarFallback>
</Avatar>
</DialogTrigger>
<DialogContent className="p-0 gap-0">
<div className="p-6 size-full">
<DialogContent className="p-0 gap-0 max-w-[90vw] w-[600px] max-h-[90vh] flex flex-col">
<div className="p-6 flex-grow overflow-auto scrollbar-hide">
<ReactCrop
crop={crop}
onChange={(_, percentCrop) => setCrop(percentCrop)}
Expand All @@ -119,7 +114,7 @@ export function ImageCropper({
<Avatar className="size-full rounded-none">
<AvatarImage
ref={imgRef}
className="size-full rounded-none "
className="size-full rounded-none object-contain aspect-auto"
alt="Image Cropper Shell"
src={selectedFile?.preview}
onLoad={onImageLoad}
Expand All @@ -130,7 +125,7 @@ export function ImageCropper({
</Avatar>
</ReactCrop>
</div>
<DialogFooter className="p-6 pt-0 justify-center ">
<DialogFooter className="p-6 pt-0 justify-center shrink-0">
<DialogClose asChild>
<Button
size={"sm"}
Expand All @@ -155,7 +150,6 @@ export function ImageCropper({
)
}

// Helper function to center the crop
export function centerAspectCrop(
mediaWidth: number,
mediaHeight: number,
Expand All @@ -175,4 +169,4 @@ export function centerAspectCrop(
mediaWidth,
mediaHeight,
)
}
}
9 changes: 9 additions & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@
font-family: "Cascadia";
src: url("https://excalidraw.com/Cascadia.woff2");
}
@layer utilities {
.scrollbar-hide {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.scrollbar-hide::-webkit-scrollbar {
display: none; /* Chrome, Safari and Opera */
}
}