Components

Image Editor

An image editor with crop, brightness, saturation, contrast, and hue adjustments, supporting rectangle and circle stencils with zoom controls.

Client Only

Installation

pnpm dlx @docyrus/cli add @docyrus/ui-image-editor
UI Primitives(4 components)
npx shadcn@latest add button slider toggle-group tooltip
Required Packages(2 packages)
pnpm add react-advanced-cropper advanced-cropper

Usage

import { ImageEditor } from '@docyrus/ui/components/image-editor';

<ImageEditor
  src="/images/photo.jpg"
  onSave={(dataUrl) => {
    // dataUrl is a base64 canvas export
    console.log('Saved:', dataUrl);
  }}
  onUpload={(file) => {
    console.log('Uploaded:', file.name);
  }}
/>

Circle Crop with Aspect Ratio

<ImageEditor
  src="/images/avatar.jpg"
  stencilShape="circle"
  aspectRatio={1}
  onSave={handleSave}
/>

Compact Variant

<ImageEditor
  src="/images/banner.jpg"
  variant="compact"
  size="sm"
  onSave={handleSave}
/>

Variants

VariantDescription
defaultStandard editor with full border and background.
compactReduced visual weight with subtle border and muted background.

Sizes

SizeDescription
smCropper height: 300px.
defaultCropper height: 400px.
lgCropper height: 500px.

API Reference

ImageEditor

PropTypeDefaultDescription
srcstring—Initial image URL to edit.
onSave(dataUrl: string) => void—Called with the base64 canvas data URL on save.
onUpload(file: File) => void—Called when a new file is uploaded via the file input.
disabledbooleanfalseDisable all editing interactions.
stencilShape'rectangle' | 'circle''rectangle'Crop area shape.
aspectRationumber—Enforce a fixed aspect ratio for the crop area.
minCropWidthnumber—Minimum crop width in pixels.
minCropHeightnumber—Minimum crop height in pixels.
maxCropWidthnumber—Maximum crop width in pixels.
maxCropHeightnumber—Maximum crop height in pixels.
variant'default' | 'compact''default'Visual style.
size'sm' | 'default' | 'lg''default'Cropper area height.
classNamestring—Additional CSS classes.

Type Reference

EditorMode

'crop' | 'brightness' | 'saturation' | 'contrast' | 'hue'

The active editing mode. The toolbar switches between crop and adjustment sliders based on this value.

StencilShape

'rectangle' | 'circle'

Determines the crop stencil shape. Circle mode renders a circular crop area.

Adjustments

FieldTypeDefaultDescription
brightnessnumber0Brightness adjustment (0–100 scale).
saturationnumber0Saturation adjustment (0–100 scale).
huenumber0Hue rotation (0–100 scale).
contrastnumber0Contrast adjustment (0–100 scale).

Editor Controls

ControlAction
Crop modeDrag to select crop area, resize handles to adjust.
Adjustment slidersDrag slider to adjust brightness/saturation/hue/contrast.
Zoom in/outButtons to zoom the image (1.25x step).
UploadOpens file picker for a new image.
ResetReturns to crop mode with default adjustments.
SaveExports the cropped + adjusted result as a data URL.

On this page