Skip to content

Commit

Permalink
Merge pull request #919 from dimaip/crop2
Browse files Browse the repository at this point in the history
BUGFIX: fix ImageCroper custom ratio controls
  • Loading branch information
skurfuerst authored Sep 9, 2017
2 parents 16231ce + 5de635a commit 7b42c78
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AspectRatioItem extends PureComponent {
key: PropTypes.any,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
changeHandler: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onFlipAspectRatio: PropTypes.func.isRequired,
isLocked: PropTypes.bool
};

Expand All @@ -28,6 +29,7 @@ class AspectRatioItem extends PureComponent {

this.handleWidthInputChange = this.handleInputChange.bind(this, 'width');
this.handleHeightInputChange = this.handleInputChange.bind(this, 'height');
this.handleFlipAspectRatio = this.props.onFlipAspectRatio.bind(this);
}

render() {
Expand Down Expand Up @@ -59,13 +61,10 @@ class AspectRatioItem extends PureComponent {
}

handleInputChange(type, val) {
const {width, height, changeHandler} = this.props;
const width = type === 'width' ? val : this.props.width;
const height = type === 'height' ? val : this.props.height;

changeHandler({
width,
height,
[type]: val
});
this.props.onChange(Number(width), Number(height));
}
}

Expand All @@ -89,6 +88,7 @@ export default class ImageCropper extends PureComponent {
this.handleSetAspectRatio = this.setAspectRatio.bind(this);
this.handleClearAspectRatio = this.clearAspectRatio.bind(this);
this.handleFlipAspectRatio = this.flipAspectRatio.bind(this);
this.handleSetCustomAspectRatioDimensions = this.setCustomAspectRatioDimensions.bind(this);
}

componentWillReceiveProps(nextProps) {
Expand All @@ -101,7 +101,6 @@ export default class ImageCropper extends PureComponent {

setAspectRatio(aspectRatioOption) {
const {cropConfiguration} = this.state;

this.setState({
cropConfiguration: cropConfiguration.selectAspectRatioOption(aspectRatioOption)
});
Expand Down Expand Up @@ -148,11 +147,13 @@ export default class ImageCropper extends PureComponent {
<div className={style.tools}>
<div className={style.aspectRatioIndicator}>
{
cropConfiguration.aspectRatioReducedLabel.map((label, index) => [
<Icon key={index} icon="crop"/>,
<span key={index} title={label}>{label}</span>,
<span key={index}>{aspectRatioLocked ? <Icon icon="lock"/> : null}</span>
]).orSome('')
cropConfiguration.aspectRatioReducedLabel.map((label, index) => (
<div key={index}>
<Icon key={index} icon="crop"/>,
<span key={index} title={label}>{label}</span>,
<span key={index}>{aspectRatioLocked ? <Icon icon="lock"/> : null}</span>
</div>
)).orSome('')
}
</div>

Expand All @@ -167,7 +168,13 @@ export default class ImageCropper extends PureComponent {

<div className={style.dimensions}>
{cropConfiguration.aspectRatioDimensions.map((props, index) => (
<AspectRatioItem {...props} isLocked={aspectRatioLocked} key={index}/>
<AspectRatioItem
{...props}
isLocked={aspectRatioLocked}
onFlipAspectRatio={this.handleFlipAspectRatio}
onChange={this.handleSetCustomAspectRatioDimensions}
key={index}
/>
)).orSome('')}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui-components/src/DropDown/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ShallowDropDownHeader.propTypes = {
* These props control the visual state of the contents, and are passed
* from the outside via the `ContextDropDownHeader` component.
*/
isOpen: PropTypes.bool.isRequired,
isOpen: PropTypes.bool,
toggleDropDown: PropTypes.func.isRequired,

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui-components/src/DropDown/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class StatelessDropDownWrapperWithoutClickOutsideBehavior extends PureComponent
<div {...rest} className={finalClassName}>
{React.Children.map(
children,
child => child.type ? <child.type {...child.props} isDropdownOpen={this.props.isOpen}/> : child
child => typeof child.type === 'string' ? child : <child.type {...child.props} isDropdownOpen={this.props.isOpen}/>
)}
</div>
);
Expand Down Expand Up @@ -151,7 +151,7 @@ export class ContextDropDownHeader extends PureComponent {
/**
* The propagated isOpen state from the dropDown
*/
isDropdownOpen: PropTypes.bool.isRequired
isDropdownOpen: PropTypes.bool
};

static contextTypes = {
Expand Down

0 comments on commit 7b42c78

Please sign in to comment.