Skip to content

useCrop

Controls crop mode for the selected image item on the canvas.

Import

ts
import { useCrop } from '@asset-studio/core'

Usage

tsx
function CropControls() {
  const { isCropMode, changeCropMode } = useCrop()

  return (
    <button onClick={() => changeCropMode(!isCropMode)}>
      {isCropMode ? 'Cancel Crop' : 'Crop'}
    </button>
  )
}

Return Value

Property / FunctionTypeDescription
isCropModebooleanWhether crop mode is currently active.
changeCropMode(value: boolean) => voidEnable or disable crop mode for the selected item.
cropCropRect | nullThe current crop rectangle, or null if none is applied.
setCrop(crop: CropRect | null) => voidManually set the crop rectangle.

Types

ts
type CropRect = {
  x: number
  y: number
  w: number
  h: number
}

Notes

  • Crop mode only applies to the currently selected image item.
  • Calling changeCropMode(true) with no image selected has no effect.
  • Set crop to null to remove the crop from the selected item.

Released under a proprietary license.