@@ -44,6 +44,10 @@ Object.defineProperty(exports, 'DatButton', {
44
44
}
45
45
});
46
46
47
+ var _classnames = require('classnames');
48
+
49
+ var _classnames2 = _interopRequireDefault(_classnames);
50
+
47
51
var _lodash = require('lodash');
48
52
49
53
var _react = (window.React);
@@ -88,6 +92,7 @@ var Dat = function (_React$Component) {
88
92
var _props2 = this.props;
89
93
var children = _props2.children;
90
94
var data = _props2.data;
95
+ var labelWidth = _props2.labelWidth;
91
96
92
97
return _react2.default.Children.toArray(children).map(function (child, i) {
93
98
var liveUpdate = (0, _lodash.isUndefined)(child.props.liveUpdate) ? _this2.props.liveUpdate : child.props.liveUpdate;
@@ -96,16 +101,21 @@ var Dat = function (_React$Component) {
96
101
key: i,
97
102
data: data,
98
103
liveUpdate: liveUpdate,
104
+ _labelWidth: labelWidth,
99
105
_onUpdateValue: _this2.handleUpdateValue
100
106
});
101
107
});
102
108
}
103
109
}, {
104
110
key: 'render',
105
111
value: function render() {
112
+ var _props$style = this.props.style;
113
+ var style = _props$style === undefined ? {} : _props$style;
114
+
115
+ var className = (0, _classnames2.default)('react-dat-gui', this.props.className);
106
116
return _react2.default.createElement(
107
117
'div',
108
- { className: 'react-dat-gui' },
118
+ { className: className, style: style },
109
119
_react2.default.createElement(
110
120
'ul',
111
121
{ className: 'dg main' },
@@ -122,14 +132,17 @@ Dat.propTypes = {
122
132
data: _react.PropTypes.object.isRequired,
123
133
children: _react.PropTypes.node.isRequired,
124
134
onUpdate: _react.PropTypes.func.isRequired,
125
- liveUpdate: _react.PropTypes.bool
135
+ liveUpdate: _react.PropTypes.bool,
136
+ className: _react.PropTypes.string,
137
+ style: _react.PropTypes.object,
138
+ labelWidth: _react.PropTypes.number
126
139
};
127
140
Dat.defaultProps = {
128
141
liveUpdate: true
129
142
};
130
143
exports.default = Dat;
131
144
132
- },{"./components/DatBoolean":2,"./components/DatButton":3,"./components/DatNumber":4,"./components/DatString":5,"lodash":7}],2:[function(require,module,exports){
145
+ },{"./components/DatBoolean":2,"./components/DatButton":3,"./components/DatNumber":4,"./components/DatString":5,"classnames":6," lodash":7}],2:[function(require,module,exports){
133
146
'use strict';
134
147
135
148
Object.defineProperty(exports, "__esModule", {
@@ -396,7 +409,7 @@ var DatNumber = function (_React$Component) {
396
409
}, {
397
410
key: 'shouldComponentUpdate',
398
411
value: function shouldComponentUpdate(nextProps, nextState) {
399
- return nextProps.id !== this.props.id || nextProps.path !== this.props.path || nextProps.label !== this.props.label || nextProps.min !== this.props.value || nextProps.max !== this.props.value || nextProps.step !== this.props.value || nextState.value !== this.state.value;
412
+ return nextProps.id !== this.props.id || nextProps.path !== this.props.path || nextProps.label !== this.props.label || nextProps._labelWidth !== this.props._labelWidth || nextProps. min !== this.props.value || nextProps.max !== this.props.value || nextProps.step !== this.props.value || nextState.value !== this.state.value;
400
413
}
401
414
}, {
402
415
key: 'getValue',
@@ -533,12 +546,16 @@ var DatNumber = function (_React$Component) {
533
546
var id = _props3.id;
534
547
var min = _props3.min;
535
548
var max = _props3.max;
549
+ var _labelWidth = _props3._labelWidth;
536
550
var _state = this.state;
537
551
var value = _state.value;
538
552
var isSliderActive = _state.isSliderActive;
539
553
540
554
var label = (0, _lodash.isString)(this.props.label) ? this.props.label : this.props.path;
541
555
var hasSlider = (0, _lodash.isFinite)(min) && (0, _lodash.isFinite)(min);
556
+ var labelStyle = _labelWidth ? { width: _labelWidth + '%' } : {};
557
+ var sliderStyle = _labelWidth ? { width: 2 * (100 - _labelWidth) / 3 + '%' } : {};
558
+ var inputStyle = _labelWidth ? { width: (hasSlider ? (100 - _labelWidth) / 3 : 100 - _labelWidth) + '%' } : {};
542
559
var sliderPercent = (this.applyConstraints(value) - min) * 100 / (max - min);
543
560
var sliderBarStyle = hasSlider ? { maxWidth: sliderPercent + '%' } : {};
544
561
var sliderClassName = (0, _classnames2.default)('slider', { 'is-active': isSliderActive });
@@ -548,17 +565,18 @@ var DatNumber = function (_React$Component) {
548
565
{ className: className },
549
566
_react2.default.createElement(
550
567
'label',
551
- { htmlFor: id },
568
+ { htmlFor: id, style: labelStyle },
552
569
label
553
570
),
554
571
_react2.default.createElement(
555
572
'div',
556
- { className: sliderClassName, ref: 'slider', onMouseDown: this.handleMouseDown },
573
+ { className: sliderClassName, style: sliderStyle, ref: 'slider', onMouseDown: this.handleMouseDown },
557
574
_react2.default.createElement('div', { className: 'slider-bar', style: sliderBarStyle })
558
575
),
559
576
_react2.default.createElement('input', {
560
577
type: 'text',
561
578
inputMode: 'numeric',
579
+ style: inputStyle,
562
580
id: id,
563
581
value: value,
564
582
onChange: this.handleChange,
@@ -579,6 +597,7 @@ DatNumber.propTypes = {
579
597
liveUpdate: _react.PropTypes.bool,
580
598
onUpdate: _react.PropTypes.func,
581
599
_onUpdateValue: _react.PropTypes.func,
600
+ _labelWidth: _react.PropTypes.number,
582
601
min: _react.PropTypes.number,
583
602
max: _react.PropTypes.number,
584
603
step: _react.PropTypes.number
@@ -639,7 +658,7 @@ var DatString = function (_React$Component) {
639
658
}, {
640
659
key: 'shouldComponentUpdate',
641
660
value: function shouldComponentUpdate(nextProps, nextState) {
642
- return nextProps.id !== this.props.id || nextProps.path !== this.props.path || nextProps.label !== this.props.label || nextState.value !== this.state.value;
661
+ return nextProps.id !== this.props.id || nextProps.path !== this.props.path || nextProps.label !== this.props.label || nextProps._labelWidth !== this.props._labelWidth || nextState.value !== this.state.value;
643
662
}
644
663
}, {
645
664
key: 'getValue',
@@ -675,22 +694,27 @@ var DatString = function (_React$Component) {
675
694
}, {
676
695
key: 'render',
677
696
value: function render() {
678
- var id = this.props.id;
697
+ var _props = this.props;
698
+ var id = _props.id;
699
+ var _labelWidth = _props._labelWidth;
679
700
var value = this.state.value;
680
701
681
702
var label = (0, _lodash.isString)(this.props.label) ? this.props.label : this.props.path;
703
+ var labelStyle = _labelWidth ? { width: _labelWidth + '%' } : {};
704
+ var inputStyle = _labelWidth ? { width: 100 - _labelWidth + '%' } : {};
682
705
return _react2.default.createElement(
683
706
'li',
684
707
{ className: 'cr string' },
685
708
_react2.default.createElement(
686
709
'label',
687
- { htmlFor: id },
710
+ { htmlFor: id, style: labelStyle },
688
711
label
689
712
),
690
713
_react2.default.createElement('input', {
691
714
type: 'text',
692
715
id: id,
693
716
value: value,
717
+ style: inputStyle,
694
718
onChange: this.handleChange,
695
719
onBlur: this.handleBlur })
696
720
);
@@ -707,7 +731,8 @@ DatString.propTypes = {
707
731
label: _react.PropTypes.string,
708
732
liveUpdate: _react.PropTypes.bool,
709
733
onUpdate: _react.PropTypes.func,
710
- _onUpdateValue: _react.PropTypes.func
734
+ _onUpdateValue: _react.PropTypes.func,
735
+ _labelWidth: _react.PropTypes.number
711
736
};
712
737
exports.default = DatString;
713
738
module.exports = exports['default'];
0 commit comments