Components
- Accordion
- Action BarUpdated
- Alert Dialog
- Alert
- Announcement
- Aspect Ratio
- Autocomplete
- Avatar
- BadgeUpdated
- Bottom Navigation
- Breadcrumb
- Button Group
- Button
- CalendarUpdated
- CardUpdated
- Carousel
- Chart
- Checkbox
- Circular Progress
- Circular Slider
- Clipboard
- Collapsible
- Color Picker
- Combobox
- Command
- Context MenuUpdated
- Data List
- Date Picker
- DialogUpdated
- DrawerUpdated
- Editable
- FieldUpdated
- File Upload
- Float
- Floating Panel
- Frame
- Hint
- Hover Card
- Image Cropper
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Link Overlay
- Listbox
- MarqueeUpdated
- Menu
- Native Select
- Number InputUpdated
- Pagination
- Popover
- Progress
- Prose
- QR Code
- Radio Group
- Rating
- Resizable
- Scroll Area
- Segment Group
- Select
- Separator
- Sheet
- Sidebar
- Signature Pad
- Skeleton
- Skip Nav
- Slider
- Spinner
- Status
- Steps
- Switch
- TableUpdated
- Tabs
- Textarea
- TimerUpdated
- ToastUpdated
- Toggle Group
- Toggle Tooltip
- Toggle
- Tooltip
- Tour
- Tree View
Hooks
Installation#
pnpm dlx shadcn@latest add @shark/image-cropper
Anatomy#
ImageCropper ├── ImageCropperImage ├── ImageCropperSelection ├── ImageCropperHandle └── ImageCropperGrid
Usage#
import { ImageCropper, ImageCropperImage, ImageCropperSelection, } from "@/components/ui/image-cropper";
<ImageCropper> <ImageCropperImage alt="Crop me" src="/image.jpg" /> <ImageCropperSelection /> </ImageCropper>
Examples#
Aspect ratio#
Use the aspectRatio to lock the crop area to a specific aspect ratio.
Circle crop#
Use cropShape="circle" for profile pictures or avatars.
Initial crop#
Start with a pre-defined crop area using the initialCrop prop.
Controlled zoom#
Control zoom programmatically with the zoom and onZoomChange props.
Zoom limits#
Set minZoom and maxZoom to constrain how far users can zoom.
Min and max size#
Constrain the crop area size with minWidth, minHeight, maxWidth, and maxHeight.
Fixed crop area#
Set fixedCropArea to true when the crop area should stay fixed while the image moves underneath.
API Reference#
ImageCropper#
Root wrapper. Manages crop state and handles.
| Prop | Type | Default |
|---|---|---|
aspectRatio | number | - |
cropShape | "circle" | "rectangle" | "rectangle" |
fixedCropArea | boolean | false |
initialCrop | { x: number; y: number; width: number; height: number } | - |
maxHeight | number | Infinity |
maxWidth | number | Infinity |
maxZoom | number | 5 |
minHeight | number | 40 |
minWidth | number | 40 |
minZoom | number | 1 |
onCropChange | (details: CropChangeDetails) => void | - |
onZoomChange | (details: ZoomChangeDetails) => void | - |
rotation | number | - |
zoom | number | - |
className | string | - |
| Attribute | Default |
|---|---|
--cropper-accent | var(--color-white) |
--cropper-handler-size | --spacing(2) |
--cropper-handler-width | --spacing(1) |
ImageCropperImage#
Image to crop. Pass src and alt.
| Prop | Type | Default |
|---|---|---|
alt | string | - |
src | string | - |
className | string | - |
ImageCropperSelection#
Crop selection overlay with resize handles and optional grid.
| Prop | Type | Default |
|---|---|---|
axis | "horizontal" | "vertical" | "both" | "both" |
className | string | - |
For a complete list of props, see the Ark UI documentation.