react-time-picker
Advanced tools
Comparing version 2.3.1 to 2.4.0
@@ -98,4 +98,4 @@ 'use strict'; | ||
var TimeInput = function (_Component) { | ||
_inherits(TimeInput, _Component); | ||
var TimeInput = function (_PureComponent) { | ||
_inherits(TimeInput, _PureComponent); | ||
@@ -113,7 +113,3 @@ function TimeInput() { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TimeInput.__proto__ || Object.getPrototypeOf(TimeInput)).call.apply(_ref, [this].concat(args))), _this), _this.state = { | ||
hour: null, | ||
minute: null, | ||
second: null | ||
}, _this.onKeyDown = function (event) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TimeInput.__proto__ || Object.getPrototypeOf(TimeInput)).call.apply(_ref, [this].concat(args))), _this), _this.state = {}, _this.onKeyDown = function (event) { | ||
switch (event.key) { | ||
@@ -176,26 +172,8 @@ case 'ArrowLeft': | ||
_createClass(TimeInput, [{ | ||
key: 'componentWillMount', | ||
value: function componentWillMount() { | ||
this.updateValues(); | ||
} | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
var nextValue = nextProps.value; | ||
var value = this.props.value; | ||
key: 'getProcessedValue', | ||
if ( | ||
// Toggling clock visibility resets values | ||
nextProps.isClockOpen !== this.props.isClockOpen || hoursAreDifferent(nextValue, value)) { | ||
this.updateValues(nextProps); | ||
} | ||
} | ||
/** | ||
* Gets current value in a desired format. | ||
*/ | ||
}, { | ||
key: 'getProcessedValue', | ||
value: function getProcessedValue(value) { | ||
@@ -213,31 +191,2 @@ var nativeValueParser = this.nativeValueParser; | ||
}, { | ||
key: 'updateValues', | ||
value: function updateValues() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props; | ||
var value = props.value; | ||
this.setState({ | ||
hour: value ? (0, _dates.getHours)(value) : null, | ||
minute: value ? (0, _dates.getMinutes)(value) : null, | ||
second: value ? (0, _dates.getSeconds)(value) : null | ||
}); | ||
} | ||
/** | ||
* Called when non-native date input is changed. | ||
*/ | ||
/** | ||
* Called when native date input is changed. | ||
*/ | ||
/** | ||
* Called after internal onChange. Checks input validity. If all fields are valid, | ||
* calls props.onChange. | ||
*/ | ||
}, { | ||
key: 'renderHour', | ||
@@ -355,5 +304,3 @@ value: function renderHour() { | ||
get: function get() { | ||
var maxDetail = this.props.maxDetail; | ||
return maxDetail; | ||
return this.props.maxDetail; | ||
} | ||
@@ -419,6 +366,59 @@ }, { | ||
} | ||
/** | ||
* Called when non-native date input is changed. | ||
*/ | ||
/** | ||
* Called when native date input is changed. | ||
*/ | ||
/** | ||
* Called after internal onChange. Checks input validity. If all fields are valid, | ||
* calls props.onChange. | ||
*/ | ||
}], [{ | ||
key: 'getDerivedStateFromProps', | ||
value: function getDerivedStateFromProps(nextProps, prevState) { | ||
var nextState = {}; | ||
/** | ||
* If isClockOpen flag has changed, we have to update it. | ||
* It's saved in state purely for use in getDerivedStateFromProps. | ||
*/ | ||
if (nextProps.isClockOpen !== prevState.isClockOpen) { | ||
nextState.isClockOpen = nextProps.isClockOpen; | ||
} | ||
/** | ||
* If the next value is different from the current one (with an exception of situation in | ||
* which values provided are limited by minDate and maxDate so that the dates are the same), | ||
* get a new one. | ||
*/ | ||
var nextValue = nextProps.value; | ||
if ( | ||
// Toggling calendar visibility resets values | ||
nextState.isClockOpen || // Flag was toggled | ||
hoursAreDifferent(nextValue, prevState.value)) { | ||
if (nextValue) { | ||
nextState.hour = (0, _dates.getHours)(nextValue); | ||
nextState.minute = (0, _dates.getMinutes)(nextValue); | ||
nextState.second = (0, _dates.getSeconds)(nextValue); | ||
} else { | ||
nextState.hour = null; | ||
nextState.minute = null; | ||
nextState.second = null; | ||
} | ||
nextState.value = nextValue; | ||
} | ||
return nextState; | ||
} | ||
}]); | ||
return TimeInput; | ||
}(_react.Component); | ||
}(_react.PureComponent); | ||
@@ -425,0 +425,0 @@ exports.default = TimeInput; |
@@ -63,5 +63,3 @@ 'use strict'; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TimePicker.__proto__ || Object.getPrototypeOf(TimePicker)).call.apply(_ref, [this].concat(args))), _this), _this.state = { | ||
isOpen: _this.props.isOpen | ||
}, _this.onClick = function (event) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TimePicker.__proto__ || Object.getPrototypeOf(TimePicker)).call.apply(_ref, [this].concat(args))), _this), _this.state = {}, _this.onClick = function (event) { | ||
if (_this.wrapper && !_this.wrapper.contains(event.target)) { | ||
@@ -110,12 +108,2 @@ _this.closeClock(); | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
var props = this.props; | ||
if (nextProps.isOpen !== props.isOpen) { | ||
this.setState({ isOpen: nextProps.isOpen }); | ||
} | ||
} | ||
}, { | ||
key: 'renderInputs', | ||
@@ -233,2 +221,14 @@ value: function renderInputs() { | ||
} | ||
}], [{ | ||
key: 'getDerivedStateFromProps', | ||
value: function getDerivedStateFromProps(nextProps, prevState) { | ||
if (nextProps.isOpen !== prevState.propsIsOpen) { | ||
return { | ||
isOpen: nextProps.isOpen, | ||
propsIsOpen: nextProps.isOpen | ||
}; | ||
} | ||
return null; | ||
} | ||
}]); | ||
@@ -235,0 +235,0 @@ |
{ | ||
"name": "react-time-picker", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "A time picker for your React app.", | ||
@@ -8,5 +8,5 @@ "main": "dist/entry.js", | ||
"scripts": { | ||
"build": "npm run build-js && npm run build-styles && npm run copy-styles", | ||
"build": "npm run build-js && npm run copy-styles && npm run build-styles", | ||
"build-js": "babel src -d dist --ignore **/__tests__", | ||
"build-styles": "lessc ./src/TimePicker.less ./src/TimePicker.css", | ||
"build-styles": "lessc ./dist/TimePicker.less ./dist/TimePicker.css", | ||
"copy-styles": "node ./copy-styles.js", | ||
@@ -44,3 +44,4 @@ "prepublishOnly": "npm run build", | ||
"prop-types": "^15.6.0", | ||
"react-clock": "^2.2.1" | ||
"react-clock": "^2.2.1", | ||
"react-lifecycles-compat": "^1.1.0" | ||
}, | ||
@@ -68,5 +69,4 @@ "devDependencies": { | ||
"less": "^2.7.3", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0", | ||
"react-test-renderer": "^16.2.0" | ||
"react": "^16.3.0", | ||
"react-dom": "^16.3.0" | ||
}, | ||
@@ -73,0 +73,0 @@ "peerDependencies": { |
@@ -1,2 +0,2 @@ | ||
![downloads](https://img.shields.io/npm/dt/react-time-picker.svg) ![build](https://img.shields.io/travis/wojtekmaj/react-time-picker.svg) ![dependencies](https://img.shields.io/david/wojtekmaj/react-time-picker.svg | ||
![downloads](https://img.shields.io/npm/dt/react-time-picker.svg) ![build](https://img.shields.io/travis/wojtekmaj/react-time-picker/master.svg) ![dependencies](https://img.shields.io/david/wojtekmaj/react-time-picker.svg | ||
) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/react-time-picker.svg | ||
@@ -3,0 +3,0 @@ ) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) |
@@ -0,0 +0,0 @@ import React from 'react'; |
@@ -0,0 +0,0 @@ import React from 'react'; |
@@ -1,2 +0,2 @@ | ||
import React, { Component } from 'react'; | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -63,26 +63,42 @@ | ||
export default class TimeInput extends Component { | ||
state = { | ||
hour: null, | ||
minute: null, | ||
second: null, | ||
} | ||
export default class TimeInput extends PureComponent { | ||
static getDerivedStateFromProps(nextProps, prevState) { | ||
const nextState = {}; | ||
componentWillMount() { | ||
this.updateValues(); | ||
} | ||
/** | ||
* If isClockOpen flag has changed, we have to update it. | ||
* It's saved in state purely for use in getDerivedStateFromProps. | ||
*/ | ||
if (nextProps.isClockOpen !== prevState.isClockOpen) { | ||
nextState.isClockOpen = nextProps.isClockOpen; | ||
} | ||
componentWillReceiveProps(nextProps) { | ||
const { value: nextValue } = nextProps; | ||
const { value } = this.props; | ||
/** | ||
* If the next value is different from the current one (with an exception of situation in | ||
* which values provided are limited by minDate and maxDate so that the dates are the same), | ||
* get a new one. | ||
*/ | ||
const nextValue = nextProps.value; | ||
if ( | ||
// Toggling clock visibility resets values | ||
(nextProps.isClockOpen !== this.props.isClockOpen) || | ||
hoursAreDifferent(nextValue, value) | ||
// Toggling calendar visibility resets values | ||
nextState.isClockOpen || // Flag was toggled | ||
hoursAreDifferent(nextValue, prevState.value) | ||
) { | ||
this.updateValues(nextProps); | ||
if (nextValue) { | ||
nextState.hour = getHours(nextValue); | ||
nextState.minute = getMinutes(nextValue); | ||
nextState.second = getSeconds(nextValue); | ||
} else { | ||
nextState.hour = null; | ||
nextState.minute = null; | ||
nextState.second = null; | ||
} | ||
nextState.value = nextValue; | ||
} | ||
return nextState; | ||
} | ||
state = {}; | ||
/** | ||
@@ -101,4 +117,3 @@ * Gets current value in a desired format. | ||
get valueType() { | ||
const { maxDetail } = this.props; | ||
return maxDetail; | ||
return this.props.maxDetail; | ||
} | ||
@@ -163,12 +178,2 @@ | ||
updateValues(props = this.props) { | ||
const { value } = props; | ||
this.setState({ | ||
hour: value ? getHours(value) : null, | ||
minute: value ? getMinutes(value) : null, | ||
second: value ? getSeconds(value) : null, | ||
}); | ||
} | ||
onKeyDown = (event) => { | ||
@@ -175,0 +180,0 @@ switch (event.key) { |
@@ -15,6 +15,15 @@ import React, { PureComponent } from 'react'; | ||
export default class TimePicker extends PureComponent { | ||
state = { | ||
isOpen: this.props.isOpen, | ||
static getDerivedStateFromProps(nextProps, prevState) { | ||
if (nextProps.isOpen !== prevState.propsIsOpen) { | ||
return { | ||
isOpen: nextProps.isOpen, | ||
propsIsOpen: nextProps.isOpen, | ||
}; | ||
} | ||
return null; | ||
} | ||
state = {}; | ||
componentDidMount() { | ||
@@ -28,10 +37,2 @@ document.addEventListener('mousedown', this.onClick); | ||
componentWillReceiveProps(nextProps) { | ||
const { props } = this; | ||
if (nextProps.isOpen !== props.isOpen) { | ||
this.setState({ isOpen: nextProps.isOpen }); | ||
} | ||
} | ||
onClick = (event) => { | ||
@@ -38,0 +39,0 @@ if (this.wrapper && !this.wrapper.contains(event.target)) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22
101967
8
38
2412
+ Addedreact-lifecycles-compat@1.1.4(transitive)