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

Commit d004a8e

Browse files
Added disableSlider prop to DatNumber, now min, max and step can be passed and a slider can be disabled if that's what you require
1 parent e49a9fc commit d004a8e

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

build/react-dat-gui.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6909,12 +6909,13 @@ var DatNumber = function (_Component) {
69096909
path = _props3.path,
69106910
label = _props3.label,
69116911
labelWidth = _props3.labelWidth,
6912-
step = _props3.step;
6912+
step = _props3.step,
6913+
disableSlider = _props3.disableSlider;
69136914

69146915
var labelText = (0, _lodash4.default)(label) ? label : path;
69156916
var hasSlider = (0, _lodash2.default)(min) && (0, _lodash2.default)(max);
69166917
var controlsWidth = 100 - labelWidth;
6917-
var inputWidth = hasSlider ? Math.round(controlsWidth / 3) : controlsWidth;
6918+
var inputWidth = hasSlider && disableSlider !== true ? Math.round(controlsWidth / 3) : controlsWidth;
69186919
var sliderWidth = controlsWidth - inputWidth;
69196920

69206921
return _react2.default.createElement(
@@ -6928,7 +6929,7 @@ var DatNumber = function (_Component) {
69286929
{ className: 'label-text', style: { width: labelWidth + '%' } },
69296930
labelText
69306931
),
6931-
hasSlider ? this.renderSlider(sliderWidth) : null,
6932+
hasSlider && disableSlider !== true ? this.renderSlider(sliderWidth) : null,
69326933
_react2.default.createElement('input', {
69336934
type: 'number',
69346935
step: step,
@@ -6960,7 +6961,8 @@ DatNumber.propTypes = {
69606961
customLabelWidth: _propTypes2.default.number,
69616962
liveUpdate: _propTypes2.default.bool,
69626963
onUpdate: _propTypes2.default.func,
6963-
_onUpdateValue: _propTypes2.default.func
6964+
_onUpdateValue: _propTypes2.default.func,
6965+
disableSlider: _propTypes2.default.bool
69646966
};
69656967
exports.default = DatNumber;
69666968
module.exports = exports['default'];

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.

dev/src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class App extends Component {
108108
<DatNumber path="number" label="Number" />
109109
<DatNumber path="float" label="Float" min={0} max={100} step={0.001} />
110110
<DatNumber path="float" label="Another Float" min={0} max={100} step={0.01} />
111+
<DatNumber path="float" label="Min Max No Slider" min={0} max={100} step={0.01} disableSlider={true} />
111112
<DatBoolean path="boolean" label="Boolean" />
112113
<DatButton label="Button" onClick={this.handleClick} />
113114
<DatSelect label="Select" path='select' options={['two', 'three', 'four']}/>

dev/src/react-dat-gui/components/DatNumber.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class DatNumber extends Component {
2020
liveUpdate: PropTypes.bool,
2121
onUpdate: PropTypes.func,
2222
_onUpdateValue: PropTypes.func,
23+
disableSlider: PropTypes.bool,
2324
};
2425

2526
state = {
@@ -124,18 +125,18 @@ export default class DatNumber extends Component {
124125
}
125126

126127
render() {
127-
const { min, max, path, label, labelWidth, step } = this.props;
128+
const { min, max, path, label, labelWidth, step, disableSlider } = this.props;
128129
const labelText = isString(label) ? label : path;
129130
const hasSlider = isFinite(min) && isFinite(max);
130131
const controlsWidth = 100 - labelWidth;
131-
const inputWidth = hasSlider ? Math.round(controlsWidth / 3) : controlsWidth;
132+
const inputWidth = hasSlider && disableSlider !== true ? Math.round(controlsWidth / 3) : controlsWidth;
132133
const sliderWidth = controlsWidth - inputWidth;
133134

134135
return (
135136
<li className="cr number">
136137
<label>
137138
<span className="label-text" style={{ width: `${labelWidth}%` }}>{labelText}</span>
138-
{hasSlider ? this.renderSlider(sliderWidth) : null}
139+
{hasSlider && disableSlider !== true ? this.renderSlider(sliderWidth) : null}
139140
<input
140141
type="number"
141142
step={step}

src/components/DatNumber.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class DatNumber extends Component {
2020
liveUpdate: PropTypes.bool,
2121
onUpdate: PropTypes.func,
2222
_onUpdateValue: PropTypes.func,
23+
disableSlider: PropTypes.bool,
2324
};
2425

2526
state = {
@@ -124,18 +125,18 @@ export default class DatNumber extends Component {
124125
}
125126

126127
render() {
127-
const { min, max, path, label, labelWidth, step } = this.props;
128+
const { min, max, path, label, labelWidth, step, disableSlider } = this.props;
128129
const labelText = isString(label) ? label : path;
129130
const hasSlider = isFinite(min) && isFinite(max);
130131
const controlsWidth = 100 - labelWidth;
131-
const inputWidth = hasSlider ? Math.round(controlsWidth / 3) : controlsWidth;
132+
const inputWidth = hasSlider && disableSlider !== true ? Math.round(controlsWidth / 3) : controlsWidth;
132133
const sliderWidth = controlsWidth - inputWidth;
133134

134135
return (
135136
<li className="cr number">
136137
<label>
137138
<span className="label-text" style={{ width: `${labelWidth}%` }}>{labelText}</span>
138-
{hasSlider ? this.renderSlider(sliderWidth) : null}
139+
{hasSlider && disableSlider !== true ? this.renderSlider(sliderWidth) : null}
139140
<input
140141
type="number"
141142
step={step}

0 commit comments

Comments
 (0)