Added range slider to <NumberInput />

This commit is contained in:
orangemug 2018-10-30 20:35:22 +00:00
parent 3d2a1d5d19
commit cdd5d27908
3 changed files with 38 additions and 8 deletions

View file

@ -68,14 +68,42 @@ class NumberInput extends React.Component {
}
render() {
return <input
spellCheck="false"
className="maputnik-number"
placeholder={this.props.default}
value={this.state.value}
onChange={e => this.changeValue(e.target.value)}
onBlur={this.resetValue}
/>
let rangeEl;
if(
this.props.hasOwnProperty("min") && this.props.hasOwnProperty("max") &&
this.props.min !== undefined && this.props.max !== undefined &&
this.props.allowRange
) {
rangeEl = (
<input
style={{width: "calc(100% - 4em)", flexShrink: "0"}}
key="range"
type="range"
step="0.01"
max={this.props.max}
min={this.props.min}
spellCheck="false"
className="maputnik-number"
value={this.state.value || this.props.default}
onChange={e => this.changeValue(e.target.value)}
onBlur={this.resetValue}
/>
);
}
return <div style={{display: "flex"}}>
{rangeEl}
<input
key="text"
spellCheck="false"
className="maputnik-number"
placeholder={this.props.default}
value={this.state.value}
onChange={e => this.changeValue(e.target.value)}
onBlur={this.resetValue}
/>
</div>
}
}

View file

@ -16,6 +16,7 @@ class MaxZoomBlock extends React.Component {
data-wd-key="max-zoom"
>
<NumberInput
allowRange={true}
value={this.props.value}
onChange={this.props.onChange}
min={latest.layer.maxzoom.minimum}

View file

@ -16,6 +16,7 @@ class MinZoomBlock extends React.Component {
data-wd-key="min-zoom"
>
<NumberInput
allowRange={true}
value={this.props.value}
onChange={this.props.onChange}
min={latest.layer.minzoom.minimum}