diff --git a/.eslintrc b/.eslintrc index e09b5e0..8279315 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,4 +5,7 @@ "node": true, "es6": true }, + "rules": { + "react/no-unused-prop-types": [2, {skipShapeProps: true}] + } } diff --git a/CHANGELOG.md b/CHANGELOG.md index ca2071e..4733b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## 1.8.0 + +* Fixing lint, adding skip shape props. + + +## 1.7.0 + +* Fixing shortcut button class. +* Fixing styles. + ## 1.6.0 * Adding position proptype. diff --git a/package.json b/package.json index 4b57262..09ee85d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-monthrange-picker", - "version": "1.6.0", + "version": "1.8.0", "description": "ReactJS Month range picker", "main": "index.js", "scripts": { diff --git a/src/app.jsx b/src/app.jsx index 49dae21..d2ebff9 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -9,6 +9,7 @@ require('moment-range'); class App extends React.Component { constructor(props) { super(props); + this.redraw = props.redraw || false; this.handleClickFn = this.handleClick.bind(this); this.onSelectFn = this.onSelect.bind(this); this.onApplyFn = this.onApply.bind(this); @@ -18,6 +19,28 @@ class App extends React.Component { this.state = { selectedDateRange, restrictionRange, display }; this.selectedDateRange = selectedDateRange.clone(); } + componentWillReceiveProps(props) { + this.selectedDateRange = props.selectedDateRange.clone(); + const sameDates = this.props.selectedDateRange.isSame(props.selectedDateRange); + + // update state only if props are different, OR if forced + if(this.redraw || !sameDates) { + console.log('setting state to redraw', this.selectedDateRange.end.toString()); + this.state.selectedDateRange = this.selectedDateRange.clone(); + this.setState(this.state); + } else { + console.log('blocking redraw'); + } + } + componentWillReceiveProps(props) { + this.selectedDateRange = props.selectedDateRange.clone(); + const sameDates = this.props.selectedDateRange.isSame(props.selectedDateRange); + // update state only if props are different, OR if forced + if(this.redraw || !sameDates) { + this.state.selectedDateRange = this.selectedDateRange.clone(); + this.setState(this.state); + } + } componentDidMount() { if (this.props.onRender) { this.props.onRender(); @@ -49,6 +72,11 @@ class App extends React.Component { } this.setState(this.state); } + syncData() { + // force a redraw by setting state + this.state.selectedDateRange = this.selectedDateRange.clone(); + this.setState(this.state); + } handleClick(e) { e.preventDefault(); e.stopPropagation();