From 030987b7f90995fbc79387f8b1de7f297a607ada Mon Sep 17 00:00:00 2001 From: Claudiu Andrei Date: Thu, 20 Sep 2018 16:36:59 -0500 Subject: [PATCH] Add cropType property that allows round cropper (#14) * Add cropType property that allows round cropper * Fix the round area to have 3rds * Add cropArea property that controls the options for crop display * Update the example to have the new prop * Update the api to take 2 properties * Add defaults, fix naming, make shape multioption * Pass the props to CropArea --- examples/src/index.js | 4 ++++ src/index.js | 7 +++++++ src/styles.js | 24 +++++++++++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/examples/src/index.js b/examples/src/index.js index cd89e4e..c1721e6 100644 --- a/examples/src/index.js +++ b/examples/src/index.js @@ -13,6 +13,8 @@ class App extends React.Component { crop: { x: 0, y: 0 }, zoom: 1, aspect: 4 / 3, + cropShape: 'rect', + showGrid: true, } onCropChange = crop => { @@ -36,6 +38,8 @@ class App extends React.Component { crop={this.state.crop} zoom={this.state.zoom} aspect={this.state.aspect} + cropShape={this.state.cropShape} + showGrid={this.state.showGrid} onCropChange={this.onCropChange} onCropComplete={this.onCropComplete} onZoomChange={this.onZoomChange} diff --git a/src/index.js b/src/index.js index 3c7b840..9312b31 100644 --- a/src/index.js +++ b/src/index.js @@ -245,7 +245,10 @@ class Cropper extends React.Component { const { crop: { x, y }, zoom, + cropShape, + showGrid, } = this.props + return ( {this.state.cropSize && ( ({ + ...(() => { + switch (cropShape) { + case 'round': + return { ...cropperArea, ...roundShape } + case 'rect': + default: + return cropperArea + } + })(), + ...(showGrid ? gridLines : {}), +}))