Support propagating from different layer types

This commit is contained in:
lukasmartinelli 2016-09-13 20:30:03 +02:00
parent c630b300be
commit 4d70351848
9 changed files with 76 additions and 43 deletions

View file

@ -1,13 +1,13 @@
import React from 'react' import React from 'react'
import { Label, Input } from 'rebass' import { Label, Input } from 'rebass'
import {inputBase} from '../theme' import inputStyle from './input.js'
/*** Number fields with support for min, max and units and documentation*/ /*** Number fields with support for min, max and units and documentation*/
class ColorField extends React.Component { class ColorField extends React.Component {
static propTypes = { static propTypes = {
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
name: React.PropTypes.string.isRequired, name: React.PropTypes.string.isRequired,
value: React.PropTypes.number, value: React.PropTypes.string,
default: React.PropTypes.number, default: React.PropTypes.number,
doc: React.PropTypes.string, doc: React.PropTypes.string,
} }
@ -17,10 +17,10 @@ static propTypes = {
} }
render() { render() {
return <div> return <div style={inputStyle.property}>
<Label htmlFor={this.props.name} children={this.props.name} /> <label style={inputStyle.label}>{this.props.name}</label>
<input <input
style={inputBase} style={inputStyle.input}
name={this.props.name} name={this.props.name}
placeholder={this.props.default} placeholder={this.props.default}
value={this.props.value} value={this.props.value}

View file

@ -1,5 +1,6 @@
import React from 'react' import React from 'react'
import { Select, Input } from 'rebass' import { Select, Input } from 'rebass'
import inputStyle from './input.js'
class EnumField extends React.Component { class EnumField extends React.Component {
static propTypes = { static propTypes = {
@ -16,14 +17,19 @@ class EnumField extends React.Component {
render() { render() {
const options = this.props.allowedValues.map(val => { const options = this.props.allowedValues.map(val => {
return {children: val, value: val} return <option key={val} value={val}>{val}</option>
}) })
return <Select
onChange={this.onChange.bind(this)} return <div style={inputStyle.property}>
name={this.props.name} <label style={inputStyle.label}>{this.props.name}</label>
options={options} <select
label={this.props.name} style={inputStyle.select}
/> value={this.props.value}
onChange={this.onChange.bind(this)}
>
{options}
</select>
</div>
} }
} }

View file

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { Label, Input } from 'rebass' import { Label, Input } from 'rebass'
import {inputBase} from '../theme' import inputStyle from './input.js'
/*** Number fields with support for min, max and units and documentation*/ /*** Number fields with support for min, max and units and documentation*/
class NumberField extends React.Component { class NumberField extends React.Component {
@ -20,10 +20,10 @@ class NumberField extends React.Component {
} }
render() { render() {
return <div> return <div style={inputStyle.property}>
<Label htmlFor={this.props.name} children={this.props.name} /> <label style={inputStyle.label}>{this.props.name}</label>
<input <input
style={inputBase} style={inputStyle.input}
type="number" type="number"
name={this.props.name} name={this.props.name}
placeholder={this.props.default} placeholder={this.props.default}

View file

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { Label, Input } from 'rebass' import { Label, Input } from 'rebass'
import {inputBase} from '../theme' import inputStyle from './input.js'
/*** Number fields with support for min, max and units and documentation*/ /*** Number fields with support for min, max and units and documentation*/
class StringField extends React.Component { class StringField extends React.Component {
@ -16,11 +16,11 @@ static propTypes = {
return this.props.onChange(e.target.value) return this.props.onChange(e.target.value)
} }
render() { render() {
return <div> return <div style={inputStyle.property}>
<Label htmlFor={this.props.name} children={this.props.name} /> <label style={inputStyle.label}>{this.props.name}</label>
<input <input
style={inputBase} style={inputStyle.input}
name={this.props.name} name={this.props.name}
placeholder={this.props.default} placeholder={this.props.default}
value={this.props.value} value={this.props.value}

View file

@ -7,7 +7,8 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
export default class BackgroundLayer extends React.Component { export default class BackgroundLayer extends React.Component {
static propTypes = { static propTypes = {
layer: React.PropTypes.instanceOf(Immutable.Map).isRequired, layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onPaintChanged: React.PropTypes.func.isRequired onPaintChanged: React.PropTypes.func.isRequired,
onLayoutChanged: React.PropTypes.func.isRequired,
} }
constructor(props) { constructor(props) {
@ -15,16 +16,10 @@ export default class BackgroundLayer extends React.Component {
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
} }
onPaintChanged(property, value) {
if (property == "background-opacity" && !isNaN(parseFloat(value))) {
value = parseFloat(value)
}
this.props.onPaintChanged(property, value)
}
render() { render() {
return <div> return <div>
<PropertyGroup <PropertyGroup
onChange={this.props.onLayoutChanged.bind(this)}
layerType="background" layerType="background"
groupType="layout" groupType="layout"
properties={this.props.layer.get('layout', Immutable.Map())} properties={this.props.layer.get('layout', Immutable.Map())}

View file

@ -80,6 +80,7 @@ export class LayerEditor extends React.Component {
return <FillLayer return <FillLayer
layer={this.props.layer} layer={this.props.layer}
onPaintChanged={this.onPaintChanged.bind(this)} onPaintChanged={this.onPaintChanged.bind(this)}
onLayoutChanged={this.onLayoutChanged.bind(this)}
/> />
} }
@ -87,18 +88,23 @@ export class LayerEditor extends React.Component {
return <BackgroundLayer return <BackgroundLayer
layer={this.props.layer} layer={this.props.layer}
onPaintChanged={this.onPaintChanged.bind(this)} onPaintChanged={this.onPaintChanged.bind(this)}
onLayoutChanged={this.onLayoutChanged.bind(this)}
/> />
} }
if (type === "line") { if (type === "line") {
return <LineLayer return <LineLayer
layer={this.props.layer} layer={this.props.layer}
onPaintChanged={this.onPaintChanged.bind(this)}
onLayoutChanged={this.onLayoutChanged.bind(this)}
/> />
} }
if (type === "symbol") { if (type === "symbol") {
return <SymbolLayer return <SymbolLayer
layer={this.props.layer} layer={this.props.layer}
onPaintChanged={this.onPaintChanged.bind(this)}
onLayoutChanged={this.onLayoutChanged.bind(this)}
/> />
} }

View file

@ -7,7 +7,8 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
export default class FillLayer extends React.Component { export default class FillLayer extends React.Component {
static propTypes = { static propTypes = {
layer: React.PropTypes.instanceOf(Immutable.Map).isRequired, layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onPaintChanged: React.PropTypes.func.isRequired onPaintChanged: React.PropTypes.func.isRequired,
onLayoutChanged: React.PropTypes.func.isRequired,
} }
constructor(props) { constructor(props) {
@ -15,18 +16,10 @@ export default class FillLayer extends React.Component {
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
} }
onPaintChanged(property, e) {
let value = e.target.value
if (property == "fill-opacity") {
value = parseFloat(value)
}
this.props.onPaintChanged(property, value)
}
render() { render() {
return <div> return <div>
<PropertyGroup <PropertyGroup
onChange={this.props.onLayoutChanged.bind(this)}
layerType="fill" layerType="fill"
groupType="layout" groupType="layout"
properties={this.props.layer.get('layout', Immutable.Map())} properties={this.props.layer.get('layout', Immutable.Map())}

View file

@ -5,12 +5,24 @@ import { PropertyGroup } from '../fields/spec'
export default class LineLayer extends React.Component { export default class LineLayer extends React.Component {
static propTypes = { static propTypes = {
layer: React.PropTypes.instanceOf(Immutable.Map).isRequired, layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onPaintChanged: React.PropTypes.func.isRequired,
onLayoutChanged: React.PropTypes.func.isRequired,
} }
render() { render() {
return <div> return <div>
<PropertyGroup layerType="line" groupType="layout" properties={this.props.layer.get('layout', Immutable.Map())}/> <PropertyGroup
<PropertyGroup layerType="line" groupType="paint" properties={this.props.layer.get('paint', Immutable.Map())}/> onChange={this.props.onLayoutChanged.bind(this)}
layerType="line"
groupType="layout"
properties={this.props.layer.get('layout', Immutable.Map())}
/>
<PropertyGroup
onChange={this.props.onPaintChanged.bind(this)}
layerType="line"
groupType="paint"
properties={this.props.layer.get('paint', Immutable.Map())}
/>
</div> </div>
} }
} }

View file

@ -1,10 +1,31 @@
import React from 'react' import React from 'react'
export default class SymbolLayer extends React.Component { export default class SymbolLayer extends React.Component {
static propTypes = {
layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onPaintChanged: React.PropTypes.func.isRequired,
onLayoutChanged: React.PropTypes.func.isRequired,
}
constructor(props) {
super(props);
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
render() { render() {
return <div> return <div>
<PropertyGroup layerType="symbol" groupType="layout" properties={this.props.layer.get('layout', Immutable.Map())}/> <PropertyGroup
<PropertyGroup layerType="symbol" groupType="paint" properties={this.props.layer.get('paint', Immutable.Map())}/> onChange={this.props.onLayoutChanged.bind(this)}
layerType="symbol"
groupType="layout"
properties={this.props.layer.get('layout', Immutable.Map())}
/>
<PropertyGroup
onChange={this.props.onPaintChanged.bind(this)}
layerType="symbol"
groupType="paint"
properties={this.props.layer.get('paint', Immutable.Map())}
/>
</div> </div>
} }
} }