mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-15 02:53:27 +01:00
Introduce custom input elems for modals
This commit is contained in:
parent
bdb0466436
commit
684e0d9dd0
6 changed files with 129 additions and 68 deletions
26
src/components/inputs/InputBlock.jsx
Normal file
26
src/components/inputs/InputBlock.jsx
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import React from 'react'
|
||||||
|
import input from '../../config/input'
|
||||||
|
|
||||||
|
/** Wrap a component with a label */
|
||||||
|
class InputBlock extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
label: React.PropTypes.string.isRequired,
|
||||||
|
children: React.PropTypes.element.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(e) {
|
||||||
|
const value = e.target.value
|
||||||
|
return this.props.onChange(value === "" ? null: value)
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <div style={{
|
||||||
|
display: 'block'
|
||||||
|
}}>
|
||||||
|
<label style={input.label}>{this.props.label}</label>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InputBlock
|
31
src/components/inputs/SelectInput.jsx
Normal file
31
src/components/inputs/SelectInput.jsx
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import React from 'react'
|
||||||
|
import input from '../../config/input.js'
|
||||||
|
|
||||||
|
class SelectInput 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 options = this.props.options.map(([val, label])=> {
|
||||||
|
return <option key={val} value={val}>{label}</option>
|
||||||
|
})
|
||||||
|
|
||||||
|
return <select
|
||||||
|
style={{
|
||||||
|
...input.select,
|
||||||
|
...this.props.style
|
||||||
|
}}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={e => this.props.onChange(e.target.value)}
|
||||||
|
>
|
||||||
|
{options}
|
||||||
|
</select>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SelectInput
|
23
src/components/inputs/StringInput.jsx
Normal file
23
src/components/inputs/StringInput.jsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import React from 'react'
|
||||||
|
import input from '../../config/input.js'
|
||||||
|
|
||||||
|
class StringInput extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
value: React.PropTypes.string.isRequired,
|
||||||
|
style: React.PropTypes.object,
|
||||||
|
onChange: React.PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <input
|
||||||
|
style={{
|
||||||
|
...input.input,
|
||||||
|
...this.props.style
|
||||||
|
}}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={e => this.props.onChange(e.target.value)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default StringInput
|
|
@ -16,6 +16,7 @@ class Modal extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return <Overlay isOpen={this.props.isOpen}>
|
return <Overlay isOpen={this.props.isOpen}>
|
||||||
<div style={{
|
<div style={{
|
||||||
|
minWidth: 350,
|
||||||
backgroundColor: colors.gray,
|
backgroundColor: colors.gray,
|
||||||
}}>
|
}}>
|
||||||
<div style={{
|
<div style={{
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import Select from 'rebass/dist/Select'
|
import InputBlock from '../inputs/InputBlock'
|
||||||
import Overlay from 'rebass/dist/Overlay'
|
import StringInput from '../inputs/StringInput'
|
||||||
import Panel from 'rebass/dist/Panel'
|
import SelectInput from '../inputs/SelectInput'
|
||||||
import PanelHeader from 'rebass/dist/PanelHeader'
|
import Modal from './Modal'
|
||||||
import PanelFooter from 'rebass/dist/PanelFooter'
|
import colors from '../../config/colors'
|
||||||
import Button from 'rebass/dist/Button'
|
|
||||||
import Text from 'rebass/dist/Text'
|
|
||||||
import Media from 'rebass/dist/Media'
|
|
||||||
import Close from 'rebass/dist/Close'
|
|
||||||
import Space from 'rebass/dist/Space'
|
|
||||||
import Input from 'rebass/dist/Input'
|
|
||||||
|
|
||||||
class SettingsModal extends React.Component {
|
class SettingsModal extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -35,60 +29,54 @@ class SettingsModal extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <Overlay open={this.props.open} >
|
const inputProps = {
|
||||||
<Panel theme={'secondary'}>
|
style: {
|
||||||
<PanelHeader theme={'default'}>
|
backgroundColor: colors.gray
|
||||||
Style Settings
|
}
|
||||||
<Space auto />
|
}
|
||||||
<Close onClick={this.props.toggle('modalOpen')} />
|
return <Modal
|
||||||
</PanelHeader>
|
isOpen={this.props.open}
|
||||||
<br />
|
toggleOpen={this.props.toggle}
|
||||||
<Input
|
title={'StyleSettings'}
|
||||||
name="name"
|
>
|
||||||
label="Name"
|
<InputBlock label={"Name"}>
|
||||||
|
<StringInput {...inputProps}
|
||||||
value={this.props.mapStyle.name}
|
value={this.props.mapStyle.name}
|
||||||
onChange={this.onChange.bind(this, "name")}
|
onChange={this.onChange.bind(this, "name")}
|
||||||
/>
|
/>
|
||||||
<Input
|
</InputBlock>
|
||||||
name="owner"
|
<InputBlock label={"Owner"}>
|
||||||
label="Owner"
|
<StringInput {...inputProps}
|
||||||
value={this.props.mapStyle.owner}
|
value={this.props.mapStyle.owner}
|
||||||
onChange={this.onChange.bind(this, "owner")}
|
onChange={this.onChange.bind(this, "owner")}
|
||||||
/>
|
/>
|
||||||
<Input
|
</InputBlock>
|
||||||
name="sprite"
|
<InputBlock label={"Sprite URL"}>
|
||||||
label="Sprite URL"
|
<StringInput {...inputProps}
|
||||||
value={this.props.mapStyle.sprite}
|
value={this.props.mapStyle.sprite}
|
||||||
onChange={this.onChange.bind(this, "sprite")}
|
onChange={this.onChange.bind(this, "sprite")}
|
||||||
/>
|
/>
|
||||||
<Input
|
</InputBlock>
|
||||||
name="glyphs"
|
|
||||||
label="Glyphs URL"
|
|
||||||
value={this.props.mapStyle.glyphs}
|
|
||||||
onChange={this.onChange.bind(this, "glyphs")}
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
name="glyphs"
|
|
||||||
label="Glyphs URL"
|
|
||||||
value={this.props.mapStyle.glyphs}
|
|
||||||
onChange={this.onChange.bind(this, "glyphs")}
|
|
||||||
/>
|
|
||||||
<Select
|
|
||||||
label="Style Renderer"
|
|
||||||
name="renderer"
|
|
||||||
onChange={this.onRendererChange.bind(this)}
|
|
||||||
options={[{children: 'Mapbox GL JS', value: 'mbgljs'}, {children: 'Open Layers 3', value: 'ol3'}]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<PanelFooter>
|
<InputBlock label={"Glyphs URL"}>
|
||||||
<Space auto />
|
<StringInput {...inputProps}
|
||||||
<Button theme={'default'}
|
value={this.props.mapStyle.glyphs}
|
||||||
onClick={this.props.toggle('modalOpen')}
|
onChange={this.onChange.bind(this, "glyphs")}
|
||||||
children='Close!'
|
/>
|
||||||
/>
|
</InputBlock>
|
||||||
</PanelFooter>
|
|
||||||
</Panel>
|
|
||||||
</Overlay>
|
<InputBlock label={"Style Renderer"}>
|
||||||
|
<SelectInput {...inputProps}
|
||||||
|
options={[
|
||||||
|
['mbgljs', 'MapboxGL JS'],
|
||||||
|
['ol3', 'Open Layers 3']
|
||||||
|
]}
|
||||||
|
value={(this.props.mapStyle.metadata || {})['maputnik:renderer']}
|
||||||
|
onChange={this.onRendererChange.bind(this)}
|
||||||
|
/>
|
||||||
|
</InputBlock>
|
||||||
|
</Modal>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import Space from 'rebass/dist/Space'
|
|
||||||
import Toolbar from 'rebass/dist/Toolbar'
|
|
||||||
import NavItem from 'rebass/dist/NavItem'
|
|
||||||
|
|
||||||
import Modal from './Modal'
|
import Modal from './Modal'
|
||||||
|
|
||||||
import publicTilesets from '../../config/tilesets.json'
|
import publicTilesets from '../../config/tilesets.json'
|
||||||
|
@ -18,7 +14,7 @@ class TilesetsModal extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -32,22 +28,18 @@ class TilesetsModal extends React.Component {
|
||||||
borderStyle: "solid",
|
borderStyle: "solid",
|
||||||
borderColor: theme.borderColor,
|
borderColor: theme.borderColor,
|
||||||
}}>
|
}}>
|
||||||
<Toolbar>
|
#{tileset.id}
|
||||||
<NavItem style={{fontWeight: 400}}>
|
<br />
|
||||||
#{tileset.id}
|
|
||||||
</NavItem>
|
|
||||||
<Space auto x={1} />
|
|
||||||
</Toolbar>
|
|
||||||
{tileset.url}
|
{tileset.url}
|
||||||
</div>
|
</div>
|
||||||
})
|
})
|
||||||
|
|
||||||
return <Modal
|
return <Modal
|
||||||
//isOpen={this.props.open}
|
isOpen={this.props.open}
|
||||||
isOpen={true}
|
|
||||||
toggleOpen={this.props.toggle}
|
toggleOpen={this.props.toggle}
|
||||||
title={'Tilesets'}
|
title={'Tilesets'}
|
||||||
>
|
>
|
||||||
|
<h2>Add New Tileset</h2>
|
||||||
<h2>Choose Public Tileset</h2>
|
<h2>Choose Public Tileset</h2>
|
||||||
{tilesetOptions}
|
{tilesetOptions}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
Loading…
Reference in a new issue