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

Commit 10f6399

Browse files
committed
Fix label/control width calc
1 parent 1afb38c commit 10f6399

File tree

7 files changed

+36
-19
lines changed

7 files changed

+36
-19
lines changed

src/components/DatBoolean.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export default class DatBoolean extends Component {
5757
<span className="label-text" style={{ width: labelWidth }}>
5858
{labelText}
5959
</span>
60-
<span className="checkbox-container">
60+
<span
61+
className="checkbox-container"
62+
style={{ width: `calc(100% - ${labelWidth})` }}
63+
>
6164
<input
6265
type="checkbox"
6366
checked={this.state.value}

src/components/DatColor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ export default class DatColor extends Component {
9191
<span className="label-text" style={{ width: labelWidth }}>
9292
{labelText}
9393
</span>
94-
<div style={{ backgroundColor: value, width: '100%' }}>
94+
<div
95+
style={{
96+
backgroundColor: value,
97+
width: `calc(100% - ${labelWidth})`
98+
}}
99+
>
95100
<div
96101
className="swatch"
97102
onClick={this.handleClickColorPicker}

src/components/DatNumber.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,23 @@ export default class DatNumber extends Component {
143143
<span className="label-text" style={{ width: labelWidth }}>
144144
{labelText}
145145
</span>
146-
{hasSlider && disableSlider !== true
147-
? this.renderSlider(sliderWidth)
148-
: null}
149-
<input
150-
type="number"
151-
step={step}
152-
min={min}
153-
max={max}
154-
inputMode="numeric"
155-
value={this.state.value}
156-
style={{ width: `${inputWidth}%` }}
157-
onChange={this.handleChange}
158-
/>
146+
<span
147+
style={{ display: 'inherit', width: `calc(100% - ${labelWidth})` }}
148+
>
149+
{hasSlider && disableSlider !== true
150+
? this.renderSlider(sliderWidth)
151+
: null}
152+
<input
153+
type="number"
154+
step={step}
155+
min={min}
156+
max={max}
157+
inputMode="numeric"
158+
value={this.state.value}
159+
style={{ width: `${inputWidth}%` }}
160+
onChange={this.handleChange}
161+
/>
162+
</span>
159163
</label>
160164
</li>
161165
);

src/components/DatPresets.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export default class DatPresets extends Component {
6868
<span className="label-text" style={{ width: labelWidth }}>
6969
{labelText}
7070
</span>
71-
<select onChange={this.handleChange}>
71+
<select
72+
onChange={this.handleChange}
73+
style={{ width: `calc(100% - ${labelWidth})` }}
74+
>
7275
{options.map(preset => {
7376
return Object.keys(preset).map(key => {
7477
return (

src/components/DatSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class DatSelect extends Component {
6464
<select
6565
value={value}
6666
onChange={this.handleChange}
67-
style={{ width: '100%' }}
67+
style={{ width: `calc(100% - ${labelWidth})` }}
6868
>
6969
{options.map((item, index) => (
7070
// eslint-disable-next-line react/no-array-index-key

src/components/DatString.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default class DatString extends Component {
8585
{labelText}
8686
</span>
8787
<input
88+
style={{ width: `calc(100% - ${labelWidth})` }}
8889
type="text"
8990
value={this.state.value}
9091
onChange={this.handleChange}

src/index.js

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

2020
static defaultProps = {
2121
liveUpdate: true,
2222
className: null,
23-
style: null
23+
style: null,
24+
labelWidth: '40%'
2425
};
2526

2627
handleUpdateValue = (path, value) => {

0 commit comments

Comments
 (0)