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

Commit a87eb14

Browse files
committed
Add overridable labelWidth for all built-in components
1 parent 6452d55 commit a87eb14

File tree

9 files changed

+23
-33
lines changed

9 files changed

+23
-33
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ This is the main container component for your GUI and is the default export from
111111
##### optional
112112
113113
- `liveUpdate: bool` - Determines if live updates should occur, defaults to `true`
114-
- `labelWidth: number` - The width of the labels in pixels, defaults to `40`
114+
- `labelWidth: string` - The width of the labels in any valid CSS units, defaults to `40%`
115115
- `className: string` - The class name to set on the `DatGui` div
116116
- `style: object` - The style object to set on the `DatGui` div
117117
@@ -138,6 +138,7 @@ Below are docs for the required and optional props you can pass to each componen
138138
- `className: string` - A CSS class name
139139
- `style: object` - A style object for inline styles
140140
- `label: string` - The label for the controller eg., `<DatString path='message' label='Message' />`
141+
- `labelWidth: string` - The width of the labels in any valid CSS units, overrides `<DatGUI labelWidth>`
141142
142143
#### `DatBoolean`
143144

src/components/DatBoolean.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class DatBoolean extends Component {
1111
data: PropTypes.object,
1212
path: PropTypes.string,
1313
label: PropTypes.string,
14+
labelWidth: PropTypes.string.isRequired,
1415
onUpdate: PropTypes.func,
1516
_onUpdateValue: PropTypes.func
1617
};
@@ -52,13 +53,15 @@ export default class DatBoolean extends Component {
5253
};
5354

5455
render() {
55-
const { path, label, className, style } = this.props;
56+
const { path, label, labelWidth, className, style } = this.props;
5657
const labelText = isString(label) ? label : path;
5758

5859
return (
5960
<li className={cx('cr', 'boolean', className)} style={style}>
6061
<label>
61-
<span className="label-text">{labelText}</span>
62+
<span className="label-text" style={{ width: labelWidth }}>
63+
{labelText}
64+
</span>
6265
<input
6366
type="checkbox"
6467
checked={this.state.value}

src/components/DatColor.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class DatColor extends Component {
1212
data: PropTypes.object,
1313
path: PropTypes.string,
1414
label: PropTypes.string,
15-
labelWidth: PropTypes.number,
15+
labelWidth: PropTypes.string.isRequired,
1616
liveUpdate: PropTypes.bool,
1717
onUpdate: PropTypes.func,
1818
_onUpdateValue: PropTypes.func
@@ -24,7 +24,6 @@ export default class DatColor extends Component {
2424
data: null,
2525
path: null,
2626
label: null,
27-
labelWidth: null,
2827
liveUpdate: null,
2928
onUpdate: () => null,
3029
_onUpdateValue: () => null
@@ -96,15 +95,10 @@ export default class DatColor extends Component {
9695
style={{ borderLeftColor: `${value}`, ...style }}
9796
>
9897
<label>
99-
<span className="label-text" style={{ width: `${labelWidth}%` }}>
98+
<span className="label-text" style={{ width: labelWidth }}>
10099
{labelText}
101100
</span>
102-
<div
103-
style={{
104-
width: `${100 - labelWidth}%`,
105-
backgroundColor: `${value}`
106-
}}
107-
>
101+
<div style={{ backgroundColor: value, width: '100%' }}>
108102
<div
109103
className="swatch"
110104
onClick={this.handleClickColorPicker}

src/components/DatNumber.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class DatNumber extends Component {
4949
data: PropTypes.object,
5050
path: PropTypes.string,
5151
label: PropTypes.string,
52-
labelWidth: PropTypes.number,
52+
labelWidth: PropTypes.string.isRequired,
5353
liveUpdate: PropTypes.bool,
5454
onUpdate: PropTypes.func,
5555
_onUpdateValue: PropTypes.func,
@@ -65,7 +65,6 @@ export default class DatNumber extends Component {
6565
data: null,
6666
path: null,
6767
label: null,
68-
labelWidth: null,
6968
liveUpdate: null,
7069
onUpdate: () => null,
7170
_onUpdateValue: () => null,
@@ -138,7 +137,7 @@ export default class DatNumber extends Component {
138137
} = this.props;
139138
const labelText = isString(label) ? label : path;
140139
const hasSlider = isFinite(min) && isFinite(max);
141-
const controlsWidth = 100 - labelWidth;
140+
const controlsWidth = 100;
142141
const inputWidth =
143142
hasSlider && disableSlider !== true
144143
? Math.round(controlsWidth / 3)
@@ -148,7 +147,7 @@ export default class DatNumber extends Component {
148147
return (
149148
<li className={cx('cr', 'number', className)} style={style}>
150149
<label>
151-
<span className="label-text" style={{ width: `${labelWidth}%` }}>
150+
<span className="label-text" style={{ width: labelWidth }}>
152151
{labelText}
153152
</span>
154153
{hasSlider && disableSlider !== true

src/components/DatPresets.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class DatPresets extends Component {
1414
path: PropTypes.string,
1515
label: PropTypes.string.isRequired,
1616
options: PropTypes.array.isRequired,
17-
labelWidth: PropTypes.number,
17+
labelWidth: PropTypes.string.isRequired,
1818
liveUpdate: PropTypes.bool,
1919
onUpdate: PropTypes.func
2020
};
@@ -24,7 +24,6 @@ export default class DatPresets extends Component {
2424
style: null,
2525
data: null,
2626
path: null,
27-
labelWidth: 40,
2827
liveUpdate: true,
2928
onUpdate: () => null
3029
};
@@ -69,13 +68,10 @@ export default class DatPresets extends Component {
6968
return (
7069
<li className={cx('cr', 'presets', className)} style={style}>
7170
<label>
72-
<span className="label-text" style={{ width: `${labelWidth}%` }}>
71+
<span className="label-text" style={{ width: labelWidth }}>
7372
{labelText}
7473
</span>
75-
<select
76-
style={{ width: `${100 - labelWidth}%` }}
77-
onChange={this.handleChange}
78-
>
74+
<select onChange={this.handleChange}>
7975
{options.map(preset => {
8076
return Object.keys(preset).map(key => {
8177
return (

src/components/DatSelect.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class DatSelect extends Component {
1212
path: PropTypes.string,
1313
label: PropTypes.string,
1414
options: PropTypes.array.isRequired,
15-
labelWidth: PropTypes.number,
15+
labelWidth: PropTypes.string.isRequired,
1616
liveUpdate: PropTypes.bool,
1717
onUpdate: PropTypes.func,
1818
_onUpdateValue: PropTypes.func
@@ -24,7 +24,6 @@ export default class DatSelect extends Component {
2424
data: null,
2525
path: null,
2626
label: null,
27-
labelWidth: null,
2827
liveUpdate: true,
2928
onUpdate: () => null,
3029
_onUpdateValue: () => null
@@ -62,13 +61,13 @@ export default class DatSelect extends Component {
6261
return (
6362
<li className={cx('cr', 'select', className)} style={style}>
6463
<label>
65-
<span className="label-text" style={{ width: `${labelWidth}%` }}>
64+
<span className="label-text" style={{ width: labelWidth }}>
6665
{labelText}
6766
</span>
6867
<select
6968
value={value}
70-
style={{ width: `${100 - labelWidth}%` }}
7169
onChange={this.handleChange}
70+
style={{ width: '100%' }}
7271
>
7372
{options.map((item, index) => (
7473
// eslint-disable-next-line react/no-array-index-key

src/components/DatString.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class DatString extends Component {
1111
data: PropTypes.object,
1212
path: PropTypes.string,
1313
label: PropTypes.string,
14-
labelWidth: PropTypes.number,
14+
labelWidth: PropTypes.string.isRequired,
1515
liveUpdate: PropTypes.bool,
1616
onUpdate: PropTypes.func,
1717
_onUpdateValue: PropTypes.func
@@ -23,7 +23,6 @@ export default class DatString extends Component {
2323
data: null,
2424
path: null,
2525
label: null,
26-
labelWidth: 40,
2726
liveUpdate: true,
2827
onUpdate: () => null,
2928
_onUpdateValue: () => null
@@ -85,13 +84,12 @@ export default class DatString extends Component {
8584
return (
8685
<li className={cx('cr', 'string', className)} style={style}>
8786
<label>
88-
<span className="label-text" style={{ width: `${labelWidth}%` }}>
87+
<span className="label-text" style={{ width: labelWidth }}>
8988
{labelText}
9089
</span>
9190
<input
9291
type="text"
9392
value={this.state.value}
94-
style={{ width: `${100 - labelWidth}%` }}
9593
onChange={this.handleChange}
9694
onFocus={this.handleFocus}
9795
onBlur={this.handleBlur}

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ export default class DatGui extends Component {
1212
children: PropTypes.node.isRequired,
1313
onUpdate: PropTypes.func.isRequired,
1414
liveUpdate: PropTypes.bool,
15-
labelWidth: PropTypes.number,
15+
labelWidth: PropTypes.string.isRequired,
1616
className: PropTypes.string,
1717
style: PropTypes.object
1818
};
1919

2020
static defaultProps = {
2121
liveUpdate: true,
22-
labelWidth: 40,
2322
className: null,
2423
style: null
2524
};

src/style/_string.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
input[type='text'] {
55
color: $string-color;
66
padding: 2px 5px;
7+
width: 100%;
78
}
89
}

0 commit comments

Comments
 (0)