mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-14 17:13:27 +01:00
Introduce MultiInputButton
This commit is contained in:
parent
488fdf2bd5
commit
160bd9563b
6 changed files with 67 additions and 11 deletions
|
@ -22,6 +22,7 @@
|
||||||
"codemirror": "^5.18.2",
|
"codemirror": "^5.18.2",
|
||||||
"color": "^1.0.3",
|
"color": "^1.0.3",
|
||||||
"file-saver": "^1.3.2",
|
"file-saver": "^1.3.2",
|
||||||
|
"lodash.capitalize": "^4.2.1",
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
"lodash.topairs": "^4.3.0",
|
"lodash.topairs": "^4.3.0",
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Button extends React.Component {
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
backgroundColor: colors.midgray,
|
backgroundColor: colors.midgray,
|
||||||
color: colors.lowgray,
|
color: colors.lowgray,
|
||||||
fontSize: fontSizes[4],
|
fontSize: fontSizes[5],
|
||||||
padding: margins[1],
|
padding: margins[1],
|
||||||
userSelect: 'none',
|
userSelect: 'none',
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
|
|
|
@ -7,6 +7,9 @@ import NumberInput from '../inputs/NumberInput'
|
||||||
import CheckboxInput from '../inputs/CheckboxInput'
|
import CheckboxInput from '../inputs/CheckboxInput'
|
||||||
import StringInput from '../inputs/StringInput'
|
import StringInput from '../inputs/StringInput'
|
||||||
import SelectInput from '../inputs/SelectInput'
|
import SelectInput from '../inputs/SelectInput'
|
||||||
|
import MultiButtonInput from '../inputs/MultiButtonInput'
|
||||||
|
import capitalize from 'lodash.capitalize'
|
||||||
|
|
||||||
|
|
||||||
import input from '../../config/input.js'
|
import input from '../../config/input.js'
|
||||||
|
|
||||||
|
@ -52,12 +55,19 @@ export default class SpecField extends React.Component {
|
||||||
max={this.props.fieldSpec.maximum}
|
max={this.props.fieldSpec.maximum}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
case 'enum': return (
|
case 'enum':
|
||||||
<SelectInput
|
const options = Object.keys(this.props.fieldSpec.values).map(v => [v, capitalize(v)])
|
||||||
{...commonProps}
|
if(options.length < 3) {
|
||||||
options={Object.keys(this.props.fieldSpec.values).map(v => [v, v])}
|
return <MultiButtonInput
|
||||||
/>
|
{...commonProps}
|
||||||
)
|
options={options}
|
||||||
|
/>
|
||||||
|
} else {
|
||||||
|
return <SelectInput
|
||||||
|
{...commonProps}
|
||||||
|
options={options}
|
||||||
|
/>
|
||||||
|
}
|
||||||
case 'string': return (
|
case 'string': return (
|
||||||
<StringInput
|
<StringInput
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import DocLabel from './DocLabel'
|
||||||
import AddIcon from 'react-icons/lib/md/add-circle-outline'
|
import AddIcon from 'react-icons/lib/md/add-circle-outline'
|
||||||
import DeleteIcon from 'react-icons/lib/md/delete'
|
import DeleteIcon from 'react-icons/lib/md/delete'
|
||||||
|
|
||||||
|
import capitalize from 'lodash.capitalize'
|
||||||
import input from '../../config/input.js'
|
import input from '../../config/input.js'
|
||||||
import colors from '../../config/colors.js'
|
import colors from '../../config/colors.js'
|
||||||
import { margins, fontSizes } from '../../config/scales.js'
|
import { margins, fontSizes } from '../../config/scales.js'
|
||||||
|
@ -104,8 +105,5 @@ export default class ZoomSpecField extends React.Component {
|
||||||
|
|
||||||
function labelFromFieldName(fieldName) {
|
function labelFromFieldName(fieldName) {
|
||||||
let label = fieldName.split('-').slice(1).join(' ')
|
let label = fieldName.split('-').slice(1).join(' ')
|
||||||
if(label.length > 0) {
|
return capitalize(label)
|
||||||
label = label.charAt(0).toUpperCase() + label.slice(1);
|
|
||||||
}
|
|
||||||
return label
|
|
||||||
}
|
}
|
||||||
|
|
38
src/components/inputs/MultiButtonInput.jsx
Normal file
38
src/components/inputs/MultiButtonInput.jsx
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
import React from 'react'
|
||||||
|
import Button from '../Button'
|
||||||
|
|
||||||
|
import colors from '../../config/colors'
|
||||||
|
import { margins } from '../../config/scales'
|
||||||
|
import input from '../../config/input.js'
|
||||||
|
|
||||||
|
class MultiButtonInput extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
value: React.PropTypes.string.isRequired,
|
||||||
|
options: React.PropTypes.array.isRequired,
|
||||||
|
style: React.PropTypes.object,
|
||||||
|
onChange: React.PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const selectedValue = this.props.value || this.props.options[0][0]
|
||||||
|
const buttons = this.props.options.map(([val, label])=> {
|
||||||
|
return <Button
|
||||||
|
key={val}
|
||||||
|
style={{
|
||||||
|
marginRight: margins[0],
|
||||||
|
backgroundColor: val === selectedValue ? colors.midgray : colors.gray,
|
||||||
|
}}
|
||||||
|
onClick={e => this.props.onChange(val)}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</Button>
|
||||||
|
})
|
||||||
|
|
||||||
|
return <div style={{display: 'inline-block'}}>
|
||||||
|
{buttons}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MultiButtonInput
|
|
@ -7,6 +7,9 @@ import PropertyGroup from '../fields/PropertyGroup'
|
||||||
import LayerEditorGroup from './LayerEditorGroup'
|
import LayerEditorGroup from './LayerEditorGroup'
|
||||||
import LayerSettings from './LayerSettings'
|
import LayerSettings from './LayerSettings'
|
||||||
|
|
||||||
|
import InputBlock from '../inputs/InputBlock'
|
||||||
|
import MultiButtonInput from '../inputs/MultiButtonInput'
|
||||||
|
|
||||||
import layout from '../../config/layout.json'
|
import layout from '../../config/layout.json'
|
||||||
import { margins, fontSizes } from '../../config/scales'
|
import { margins, fontSizes } from '../../config/scales'
|
||||||
import colors from '../../config/colors'
|
import colors from '../../config/colors'
|
||||||
|
@ -133,6 +136,12 @@ export default class LayerEditor extends React.Component {
|
||||||
onSourceChange={console.log}
|
onSourceChange={console.log}
|
||||||
onSourceLayerChange={console.log}
|
onSourceLayerChange={console.log}
|
||||||
/>
|
/>
|
||||||
|
<InputBlock label={"Inspection Mode"}>
|
||||||
|
<MultiButtonInput
|
||||||
|
value={"highlight"}
|
||||||
|
options={[["highlight", "Highlight"], ["normal", "Normal"]]}
|
||||||
|
/>
|
||||||
|
</InputBlock>
|
||||||
</div>
|
</div>
|
||||||
case 'properties': return <PropertyGroup
|
case 'properties': return <PropertyGroup
|
||||||
layer={this.props.layer}
|
layer={this.props.layer}
|
||||||
|
|
Loading…
Reference in a new issue