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

Commit f911276

Browse files
Rebuilt package
1 parent 3d21fb4 commit f911276

File tree

10 files changed

+52
-16
lines changed

10 files changed

+52
-16
lines changed

build/react-dat-gui.css

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

build/react-dat-gui.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,6 +4656,17 @@ function toNumber(value) {
46564656
return isNaN(float) ? 0 : float;
46574657
}
46584658

4659+
/**
4660+
* Polyfill for isInteger.
4661+
*
4662+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger#Polyfill
4663+
* @param {number} value
4664+
* @return {bool}
4665+
*/
4666+
var isInteger = exports.isInteger = Number.isInteger || function (value) {
4667+
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
4668+
};
4669+
46594670
/***/ }),
46604671
/* 48 */
46614672
/***/ (function(module, exports, __webpack_require__) {
@@ -6735,6 +6746,8 @@ var _react = __webpack_require__(0);
67356746

67366747
var _react2 = _interopRequireDefault(_react);
67376748

6749+
var _utils = __webpack_require__(47);
6750+
67386751
var _propTypes = __webpack_require__(1);
67396752

67406753
var _propTypes2 = _interopRequireDefault(_propTypes);
@@ -6755,8 +6768,6 @@ var _lodash5 = __webpack_require__(13);
67556768

67566769
var _lodash6 = _interopRequireDefault(_lodash5);
67576770

6758-
var _utils = __webpack_require__(47);
6759-
67606771
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
67616772

67626773
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -6837,6 +6848,8 @@ var DatNumber = function (_Component) {
68376848
hasMin = _ref2[0],
68386849
hasMax = _ref2[1],
68396850
hasStep = _ref2[2];
6851+
6852+
var decimalPlaces = hasStep && !(0, _utils.isInteger)(step) ? step.toString().split('.')[1].length : 0;
68406853
var isMin = false,
68416854
isMax = false;
68426855

@@ -6859,7 +6872,7 @@ var DatNumber = function (_Component) {
68596872
}
68606873
}
68616874

6862-
return value;
6875+
return value.toFixed(decimalPlaces);
68636876
}
68646877
}, {
68656878
key: 'update',
@@ -6895,7 +6908,8 @@ var DatNumber = function (_Component) {
68956908
max = _props3.max,
68966909
path = _props3.path,
68976910
label = _props3.label,
6898-
labelWidth = _props3.labelWidth;
6911+
labelWidth = _props3.labelWidth,
6912+
step = _props3.step;
68996913

69006914
var labelText = (0, _lodash4.default)(label) ? label : path;
69016915
var hasSlider = (0, _lodash2.default)(min) && (0, _lodash2.default)(max);
@@ -6917,6 +6931,7 @@ var DatNumber = function (_Component) {
69176931
hasSlider ? this.renderSlider(sliderWidth) : null,
69186932
_react2.default.createElement('input', {
69196933
type: 'number',
6934+
step: step,
69206935
inputMode: 'numeric',
69216936
value: this.state.value,
69226937
style: { width: inputWidth + '%' },
@@ -6940,6 +6955,7 @@ DatNumber.propTypes = {
69406955
path: _propTypes2.default.string,
69416956
label: _propTypes2.default.string,
69426957
labelWidth: _propTypes2.default.number,
6958+
customLabelWidth: _propTypes2.default.number,
69436959
liveUpdate: _propTypes2.default.bool,
69446960
onUpdate: _propTypes2.default.func,
69456961
_onUpdateValue: _propTypes2.default.func

build/react-dat-gui.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.

src/components/DatNumber.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { Component } from 'react';
2+
import { isInteger, toNumber } from './utils';
23

34
import PropTypes from 'prop-types';
45
import Slider from './Slider';
56
import isFinite from 'lodash.isfinite';
67
import isString from 'lodash.isstring';
78
import result from 'lodash.result';
8-
import { toNumber } from './utils';
99

1010
export default class DatNumber extends Component {
1111
static propTypes = {
@@ -16,6 +16,7 @@ export default class DatNumber extends Component {
1616
path: PropTypes.string,
1717
label: PropTypes.string,
1818
labelWidth: PropTypes.number,
19+
customLabelWidth: PropTypes.number,
1920
liveUpdate: PropTypes.bool,
2021
onUpdate: PropTypes.func,
2122
_onUpdateValue: PropTypes.func,
@@ -38,6 +39,7 @@ export default class DatNumber extends Component {
3839
applyConstraints(value) {
3940
const { min, max, step } = this.props;
4041
const [ hasMin, hasMax, hasStep ] = [ isFinite(min), isFinite(max), isFinite(step) ];
42+
const decimalPlaces = (hasStep && !isInteger(step)) ? step.toString().split('.')[1].length : 0;
4143
let [ isMin, isMax ] = [ false, false ];
4244

4345
value = toNumber(value);
@@ -58,7 +60,7 @@ export default class DatNumber extends Component {
5860
}
5961
}
6062

61-
return value;
63+
return value.toFixed(decimalPlaces);
6264
}
6365

6466
handleChange = event => {
@@ -122,7 +124,7 @@ export default class DatNumber extends Component {
122124
}
123125

124126
render() {
125-
const { min, max, path, label, labelWidth } = this.props;
127+
const { min, max, path, label, labelWidth, step } = this.props;
126128
const labelText = isString(label) ? label : path;
127129
const hasSlider = isFinite(min) && isFinite(max);
128130
const controlsWidth = 100 - labelWidth;
@@ -136,6 +138,7 @@ export default class DatNumber extends Component {
136138
{hasSlider ? this.renderSlider(sliderWidth) : null}
137139
<input
138140
type="number"
141+
step={step}
139142
inputMode="numeric"
140143
value={this.state.value}
141144
style={{ width: `${inputWidth}%` }}

src/components/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,16 @@ export function toNumber(value) {
22
const float = parseFloat(value);
33
return isNaN(float) ? 0 : float;
44
}
5+
6+
/**
7+
* Polyfill for isInteger.
8+
*
9+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger#Polyfill
10+
* @param {number} value
11+
* @return {bool}
12+
*/
13+
export const isInteger = Number.isInteger || function (value) {
14+
return typeof value === 'number' &&
15+
isFinite(value) &&
16+
Math.floor(value) === value;
17+
};

src/style/_main.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
background: $input-color;
7979
border: 3px solid $background-color;
8080
border-radius: 0;
81-
padding: 2px 5px;
8281
margin: 0;
8382
outline: none;
8483
font-size: inherit;

src/style/_number.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
input[type=text], input[type=number] {
55
color: $number-color;
6+
height: $number-height;
67
}
78

89
.slider {
@@ -15,6 +16,6 @@
1516
background-size: 0% 100%;
1617
background-repeat: no-repeat;
1718
cursor: ew-resize;
18-
height: 25px;
19+
height: $number-height;
1920
}
2021
}

src/style/_string.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
input[type=text] {
55
color: $string-color;
6+
padding: 2px 5px;
67
}
78
}

src/style/_vars.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ $folder-closed: #000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////
2323
$folder-open: #000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 48% no-repeat;
2424

2525
$nest-margin: 4px;
26+
$number-height: 25px;

src/style/dat.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
background: #303030;
6666
border: 3px solid #1a1a1a;
6767
border-radius: 0;
68-
padding: 2px 5px;
6968
margin: 0;
7069
outline: none;
7170
font-size: inherit; }
@@ -132,7 +131,8 @@
132131
border-left: 5px solid #2FA1D6; }
133132

134133
.react-dat-gui .cr.number input[type=text], .react-dat-gui .cr.number input[type=number] {
135-
color: #2FA1D6; }
134+
color: #2FA1D6;
135+
height: 25px; }
136136

137137
.react-dat-gui .cr.number .slider {
138138
display: block;
@@ -150,7 +150,8 @@
150150
border-left: 5px solid #1ed36f; }
151151

152152
.react-dat-gui .cr.string input[type=text] {
153-
color: #1ed36f; }
153+
color: #1ed36f;
154+
padding: 2px 5px; }
154155

155156
.react-dat-gui .cr.select {
156157
border-left: 5px solid #F4D450; }

0 commit comments

Comments
 (0)