diff --git a/README.md b/README.md index 29adf0b..3a2cd62 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ class App extends React.Component { | `onCropChange` | Function | ✓ | Called everytime the crop is changed. Use it to update your `crop` state.| | `onZoomChange` | Function | | Called everytime the zoom is changed. Use it to update your `zoom` state. | | [`onCropComplete`](#onCropCompleteProp) | Function | | Called when the user stops moving the image or stops zooming. It will be passed the corresponding cropped area on the image in percentages and pixels | +| `style` | `{ containerStyle: object, imageStyle: object, cropAreaStyle: object }` | | Custom styles to be used with the Cropper. Styles passed via the style prop are merged with the defaults. | +| `classes` | `{ containerClassName: string, imageClassName: string, cropAreaClassName: string }` | | Custom class names to be used with the Cropper. Classes passed via the classes prop are merged with the defaults. | #### onCropComplete(croppedArea, cropperAreaPixels) diff --git a/src/index.js b/src/index.js index 9312b31..ed51552 100644 --- a/src/index.js +++ b/src/index.js @@ -247,6 +247,8 @@ class Cropper extends React.Component { zoom, cropShape, showGrid, + style: { containerStyle, cropAreaStyle, imageStyle }, + classes: { containerClassName, cropAreaClassName, imageClassName }, } = this.props return ( @@ -256,6 +258,8 @@ class Cropper extends React.Component { onWheel={this.onWheel} innerRef={el => (this.container = el)} data-testid="container" + containerStyle={containerStyle} + className={containerClassName} > {this.state.cropSize && ( )} @@ -289,6 +297,8 @@ Cropper.defaultProps = { minZoom: MIN_ZOOM, cropShape: 'rect', showGrid: true, + style: {}, + classes: {}, } export default Cropper diff --git a/src/styles.js b/src/styles.js index 422b89b..1c7a210 100644 --- a/src/styles.js +++ b/src/styles.js @@ -1,29 +1,34 @@ import styled from 'react-emotion' -export const Container = styled('div')({ - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - overflow: 'hidden', - background: '#222', - userSelect: 'none', - touchAction: 'none', - cursor: 'move', -}) +export const Container = styled('div')( + { + position: 'absolute', + top: 0, + left: 0, + right: 0, + bottom: 0, + overflow: 'hidden', + userSelect: 'none', + touchAction: 'none', + cursor: 'move', + }, + ({ containerStyle }) => ({ ...containerStyle }) +) -export const Img = styled('img')({ - maxWidth: '100%', - maxHeight: '100%', - margin: 'auto', - position: 'absolute', - top: 0, - bottom: 0, - left: 0, - right: 0, - willChange: 'transform', // this improves performances and prevent painting issues on iOS Chrome -}) +export const Img = styled('img')( + { + maxWidth: '100%', + maxHeight: '100%', + margin: 'auto', + position: 'absolute', + top: 0, + bottom: 0, + left: 0, + right: 0, + willChange: 'transform', // this improves performances and prevent painting issues on iOS Chrome + }, + ({ imageStyle }) => ({ ...imageStyle }) +) const lineBorder = '1px solid rgba(255, 255, 255, 0.5)' const cropperLines = { @@ -39,7 +44,8 @@ const cropperArea = { transform: 'translate(-50%, -50%)', border: lineBorder, boxSizing: 'border-box', - boxShadow: '0 0 0 9999em rgba(0, 0, 0, 0.5)', + boxShadow: '0 0 0 9999em', + color: 'rgba(0,0,0,0.5)', overflow: 'hidden', } const gridLines = { @@ -66,7 +72,7 @@ const roundShape = { borderRadius: '50%', } -export const CropArea = styled('div')({}, ({ cropShape, showGrid }) => ({ +export const CropArea = styled('div')({}, ({ cropShape, showGrid, cropAreaStyle }) => ({ ...(() => { switch (cropShape) { case 'round': @@ -77,4 +83,5 @@ export const CropArea = styled('div')({}, ({ cropShape, showGrid }) => ({ } })(), ...(showGrid ? gridLines : {}), + ...cropAreaStyle, }))