Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit 843fc34

Browse files
committed
fix PropType warning in Slider, allow string values, bump 0.0.13
1 parent 2541a3c commit 843fc34

File tree

9 files changed

+113
-54
lines changed

9 files changed

+113
-54
lines changed

build/react-dat-gui.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
361361

362362
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
363363

364+
function toNumber(value) {
365+
var float = parseFloat(value);
366+
return isNaN(float) ? 0 : float;
367+
}
368+
364369
var DatNumber = function (_React$Component) {
365370
_inherits(DatNumber, _React$Component);
366371

@@ -411,7 +416,7 @@ var DatNumber = function (_React$Component) {
411416
var isMin = false;
412417
var isMax = false;
413418

414-
value = this.toNumber(value);
419+
value = toNumber(value);
415420
if (hasMin && value <= min) {
416421
value = min;
417422
isMin = true;
@@ -427,12 +432,6 @@ var DatNumber = function (_React$Component) {
427432
}
428433
return value;
429434
}
430-
}, {
431-
key: 'toNumber',
432-
value: function toNumber(value) {
433-
var float = parseFloat(value);
434-
return isNaN(float) ? 0 : float;
435-
}
436435
}, {
437436
key: 'handleChange',
438437
value: function handleChange(event) {
@@ -569,6 +568,20 @@ var Slider = function (_React$Component2) {
569568
}
570569

571570
_createClass(Slider, [{
571+
key: 'componentWillMount',
572+
value: function componentWillMount() {
573+
this.setState({
574+
value: toNumber(this.props.value)
575+
});
576+
}
577+
}, {
578+
key: 'componentWillReceiveProps',
579+
value: function componentWillReceiveProps(nextProps) {
580+
this.setState({
581+
value: toNumber(nextProps.value)
582+
});
583+
}
584+
}, {
572585
key: 'handleMouseDown',
573586
value: function handleMouseDown(event) {
574587
this.update(event.pageX);
@@ -606,21 +619,23 @@ var Slider = function (_React$Component2) {
606619
var rect = _reactDom2.default.findDOMNode(this).getBoundingClientRect();
607620
var x = pageX - rect.left;
608621
var w = rect.right - rect.left;
609-
onUpdate(min + (0, _lodash2.default)(x / w, 0, 1) * (max - min), isLive);
622+
var value = min + (0, _lodash2.default)(x / w, 0, 1) * (max - min);
623+
this.setState({ value: value }, function () {
624+
onUpdate(value, isLive);
625+
});
610626
}
611627
}, {
612628
key: 'render',
613629
value: function render() {
614630
var _props4 = this.props;
615-
var value = _props4.value;
616631
var min = _props4.min;
617632
var max = _props4.max;
618633
var width = _props4.width;
619634

620-
var widthBg = (value - min) * 100 / (max - min);
635+
var widthBackground = (0, _lodash2.default)((this.state.value - min) * 100 / (max - min), 0, 100);
621636
var style = {
622637
width: width + '%',
623-
backgroundSize: widthBg + '% 100%'
638+
backgroundSize: widthBackground + '% 100%'
624639
};
625640
return _react2.default.createElement('span', {
626641
className: 'slider',
@@ -634,7 +649,7 @@ var Slider = function (_React$Component2) {
634649
}(_react2.default.Component);
635650

636651
Slider.propTypes = {
637-
value: _react.PropTypes.number,
652+
value: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string]),
638653
min: _react.PropTypes.number,
639654
max: _react.PropTypes.number,
640655
width: _react.PropTypes.number,

build/react-dat-gui.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/react-dat.gui.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-es6/build/app.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22069,6 +22069,11 @@
2206922069

2207022070
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2207122071

22072+
function toNumber(value) {
22073+
var float = parseFloat(value);
22074+
return isNaN(float) ? 0 : float;
22075+
}
22076+
2207222077
var DatNumber = function (_React$Component) {
2207322078
_inherits(DatNumber, _React$Component);
2207422079

@@ -22119,7 +22124,7 @@
2211922124
var isMin = false;
2212022125
var isMax = false;
2212122126

22122-
value = this.toNumber(value);
22127+
value = toNumber(value);
2212322128
if (hasMin && value <= min) {
2212422129
value = min;
2212522130
isMin = true;
@@ -22135,12 +22140,6 @@
2213522140
}
2213622141
return value;
2213722142
}
22138-
}, {
22139-
key: 'toNumber',
22140-
value: function toNumber(value) {
22141-
var float = parseFloat(value);
22142-
return isNaN(float) ? 0 : float;
22143-
}
2214422143
}, {
2214522144
key: 'handleChange',
2214622145
value: function handleChange(event) {
@@ -22277,6 +22276,20 @@
2227722276
}
2227822277

2227922278
_createClass(Slider, [{
22279+
key: 'componentWillMount',
22280+
value: function componentWillMount() {
22281+
this.setState({
22282+
value: toNumber(this.props.value)
22283+
});
22284+
}
22285+
}, {
22286+
key: 'componentWillReceiveProps',
22287+
value: function componentWillReceiveProps(nextProps) {
22288+
this.setState({
22289+
value: toNumber(nextProps.value)
22290+
});
22291+
}
22292+
}, {
2228022293
key: 'handleMouseDown',
2228122294
value: function handleMouseDown(event) {
2228222295
this.update(event.pageX);
@@ -22314,21 +22327,23 @@
2231422327
var rect = _reactDom2.default.findDOMNode(this).getBoundingClientRect();
2231522328
var x = pageX - rect.left;
2231622329
var w = rect.right - rect.left;
22317-
onUpdate(min + (0, _lodash2.default)(x / w, 0, 1) * (max - min), isLive);
22330+
var value = min + (0, _lodash2.default)(x / w, 0, 1) * (max - min);
22331+
this.setState({ value: value }, function () {
22332+
onUpdate(value, isLive);
22333+
});
2231822334
}
2231922335
}, {
2232022336
key: 'render',
2232122337
value: function render() {
2232222338
var _props4 = this.props;
22323-
var value = _props4.value;
2232422339
var min = _props4.min;
2232522340
var max = _props4.max;
2232622341
var width = _props4.width;
2232722342

22328-
var widthBg = (value - min) * 100 / (max - min);
22343+
var widthBackground = (0, _lodash2.default)((this.state.value - min) * 100 / (max - min), 0, 100);
2232922344
var style = {
2233022345
width: width + '%',
22331-
backgroundSize: widthBg + '% 100%'
22346+
backgroundSize: widthBackground + '% 100%'
2233222347
};
2233322348
return _react2.default.createElement('span', {
2233422349
className: 'slider',
@@ -22342,7 +22357,7 @@
2234222357
}(_react2.default.Component);
2234322358

2234422359
Slider.propTypes = {
22345-
value: _react.PropTypes.number,
22360+
value: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string]),
2234622361
min: _react.PropTypes.number,
2234722362
max: _react.PropTypes.number,
2234822363
width: _react.PropTypes.number,

example-es6/build/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/components/DatNumber.js

Lines changed: 27 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)