Image Crop
Image Crop composes a source image and crop controls around local selection state.
Practical React example
Let someone choose an image crop before the application creates or uploads the final result.
Before you copy and paste
Use the composed primitives together under their required provider, where one is present. Copy components/kibo-ui/image-crop/index.tsx and its returned support files from the Code tab; preserve the project-relative paths. Install the listed primitives: pnpm dlx shadcn@latest add button. This example also uses shadcn UI primitives: button, input; install compatible versions or replace them with your existing equivalents.
Listed package dependencies: lucide-react, radix-ui, react-image-crop.
Use the Code tab for the component files and installation instructions, then adapt the imports in this example to your project.
Let someone choose an image crop before the application creates or uploads the final result
// Usage adapted from Kibo UI's pinned MIT source.
// Copyright (c) 2023 — Present shadcnblocks. See ./LICENSES.md.
"use client";
import {
ImageCrop,
ImageCropApply,
ImageCropContent,
ImageCropReset,
} from "@/components/kibo-ui/image-crop";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { XIcon } from "lucide-react";
import Image from "next/image";
import { type ChangeEvent, useState } from "react";
const Example = () => {
const [selectedFile, setSelectedFile] = useState<File | null>(null);
const [croppedImage, setCroppedImage] = useState<string | null>(null);
const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
setSelectedFile(file);
setCroppedImage(null);
}
};
const handleReset = () => {
setSelectedFile(null);
setCroppedImage(null);
};
if (!selectedFile) {
return (
<Input
accept="image/*"
className="w-fit max-w-full"
onChange={handleFileChange}
type="file"
/>
);
}
if (croppedImage) {
return (
<div className="space-y-4">
<Image
alt="Cropped"
height={100}
src={croppedImage}
unoptimized
width={100}
/>
<Button onClick={handleReset} size="icon" type="button" variant="ghost">
<XIcon className="size-4" />
</Button>
</div>
);
}
return (
<div className="space-y-4">
<ImageCrop
aspect={1}
file={selectedFile}
maxImageSize={1024 * 1024} // 1MB
onChange={console.log}
onComplete={console.log}
onCrop={setCroppedImage}
>
<ImageCropContent className="max-w-md" />
<div className="flex items-center gap-2">
<ImageCropApply />
<ImageCropReset />
<Button
onClick={handleReset}
size="icon"
type="button"
variant="ghost"
>
<XIcon className="size-4" />
</Button>
</div>
</ImageCrop>
</div>
);
};
export default Example;
Usage example adapted from Kibo UI's pinned MIT source. Retain the source licence notices when copying.
Track the original file separately from its preview URL and translate crop coordinates into your image-processing pipeline’s expected units.
Customization
- ImageCropProps.file
- Required; File.
- ImageCropProps.maxImageSize
- Optional; number.
- ImageCropProps.onCrop
- Optional; (croppedImage: string) => void.
- ImageCropProps.children
- Required; ReactNode.
- ImageCropProps.onChange
- Optional; ReactCropProps["onChange"].
- ImageCropProps.onComplete
- Optional; ReactCropProps["onComplete"].
- ImageCropContentProps.style
- Optional; CSSProperties.
- ImageCropContentProps.className
- Optional; string.
- ImageCropApplyProps.asChild
- Optional; boolean.
- ImageCropResetProps.asChild
- Optional; boolean.
- CropperProps.file
- Required; File.
- CropperProps.maxImageSize
- Optional; number.
- CropperProps.onCrop
- Optional; (croppedImage: string) => void.
- CropperProps.onChange
- Optional; ReactCropProps["onChange"].
Integration notes
- Cropping a preview does not validate image contents or persist a new asset.
- Validate the resulting upload on the server and revoke temporary object URLs when no longer needed.
Component source: Kibo UI documentation . These examples describe the version imported into Rendyn. Upstream APIs may have changed; retain the source licence notices when adapting the code.
Give your agent taste.
The best way to use Rendyn is through MCP. Let your agent find the right component, compare previews and bring the source into your project.
All components are free. Sign up only to connect MCP.