Skip to content

Commit

Permalink
change props
Browse files Browse the repository at this point in the history
  • Loading branch information
cedcn committed Aug 29, 2016
1 parent c6aedf5 commit c2f2358
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Example extends Component {
constructor(props) {
super(props);
this.state = {
elmX: 10,
elmX: 150,
elmY: 10,
elmW: 150,
elmH: 100,
Expand Down Expand Up @@ -36,6 +36,7 @@ class Example extends Component {
elmH={this.state.elmH}
isChecked={this.state.isChecked}
isRatio={false}
minLeft={150}
onMouseMove={({ elmX, elmY }) => { this.setState({ elmX, elmY }); }}
onResize={({ elmX, elmY, elmW, elmH }) => { this.setState({ elmX, elmY, elmW, elmH }); }}
/>
Expand Down
38 changes: 20 additions & 18 deletions src/Dragresize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ class Dragresize extends Component {

// 限制拖拽范围
limitDragScopeX(value) {
const { maxLeft, minLeft } = this.props.dragScope;
const { maxLeft, minLeft } = this.props;
const max = maxLeft !== null ? maxLeft - w : null;
const min = minLeft;
return getScopeValue(value, max, min);
}

limitDragScopeY(value) {
const { maxTop, minTop } = this.props.dragScope;
const { maxTop, minTop } = this.props;
const max = maxTop !== null ? maxTop - h : null;
const min = minTop;
return getScopeValue(value, max, min);
}

// 限制缩放范围
limitScope({ ax, ay, bx, cy }) {
const { maxLeft, minLeft, maxTop, minTop } = this.props.dragScope;
const { minWidth, minHeight, maxWidth, maxHeight } = this.props.sizeScope;
const { maxLeft, minLeft, maxTop, minTop } = this.props;
const { minWidth, minHeight, maxWidth, maxHeight } = this.props;

const ax_max = minWidth !== null ? (x + w) - minWidth : x + w;
const ax_min = maxWidth !== null ? (x + w) - maxWidth : minLeft;
Expand Down Expand Up @@ -284,8 +284,14 @@ Dragresize.propTypes = {
isRatio: PropTypes.bool,
isResize: PropTypes.bool,
isChecked: PropTypes.bool,
dragScope: React.PropTypes.objectOf(React.PropTypes.number),
sizeScope: React.PropTypes.objectOf(React.PropTypes.number),
minLeft: React.PropTypes.number,
minTop: React.PropTypes.number,
maxLeft: React.PropTypes.number,
maxTop: React.PropTypes.number,
minWidth: React.PropTypes.number,
minHeight: React.PropTypes.number,
maxWidth: React.PropTypes.number,
maxHeight: React.PropTypes.number,
onMouseMove: PropTypes.func,
onResize: PropTypes.func,
onMouseDown: PropTypes.func,
Expand All @@ -300,18 +306,14 @@ Dragresize.defaultProps = {
isResize: true,
isRatio: true,
isChecked: true,
dragScope: {
minLeft: null,
minTop: null,
maxLeft: 1000,
maxTop: 600,
},
sizeScope: {
minWidth: 10,
minHeight: 10,
maxWidth: null,
maxHeight: null,
},
minLeft: null,
minTop: null,
maxLeft: 1000,
maxTop: 600,
minWidth: 10,
minHeight: 10,
maxWidth: null,
maxHeight: null,
onMouseMove: null,
onResize: null,
onMouseDown: null,
Expand Down

0 comments on commit c2f2358

Please sign in to comment.