Draft of color picker

This commit is contained in:
Lukas Martinelli 2016-12-17 21:25:00 +01:00
parent 362f7ae9a1
commit a05881a078
4 changed files with 50 additions and 25 deletions

View file

@ -90,6 +90,17 @@ export default class App extends React.Component {
this.onStyleChanged(changedStyle) this.onStyleChanged(changedStyle)
} }
onLayerChanged(layer) {
console.log(layer)
const changedStyle = this.state.mapStyle.setIn('layers', layer.get('id'), layer)
this.onStyleChanged(changedStyle)
}
onLayerChanged(layer) {
const changedStyle = this.state.mapStyle.setIn(['layers', layer.get('id')], layer)
this.onStyleChanged(changedStyle)
}
mapRenderer() { mapRenderer() {
const mapProps = { const mapProps = {
mapStyle: this.state.mapStyle, mapStyle: this.state.mapStyle,
@ -119,7 +130,9 @@ export default class App extends React.Component {
onStyleDownload={this.onStyleDownload.bind(this)} onStyleDownload={this.onStyleDownload.bind(this)}
/> />
<div style={{ <div style={{
...fullHeight, position: 'absolute',
bottom: 0,
height: "100%",
top: 50, top: 50,
left: 0, left: 0,
zIndex: 100, zIndex: 100,
@ -134,15 +147,16 @@ export default class App extends React.Component {
/> />
</div> </div>
<div style={{ <div style={{
...fullHeight, position: 'absolute',
bottom: 0,
height: "100%",
top: 50, top: 50,
left: 180, left: 180,
zIndex: 100, zIndex: 100,
width: 300, width: 300,
overflow: "hidden",
backgroundColor: colors.gray} backgroundColor: colors.gray}
}> }>
{this.state.selectedLayer && <LayerEditor layer={this.state.selectedLayer} />} {this.state.selectedLayer && <LayerEditor layer={this.state.selectedLayer} onLayerChanged={this.onLayerChanged.bind(this)} />}
</div> </div>
{this.mapRenderer()} {this.mapRenderer()}
</div> </div>

View file

@ -1,33 +1,47 @@
import React from 'react' import React from 'react'
import inputStyle from './input.js' import inputStyle from './input.js'
import ColorPicker from 'react-colorpickr'
import 'react-colorpickr/dist/colorpickr.css'
function formatColor(color) {
if(color.a !== 1) {
return `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`
}
return `rgb(${color.r}, ${color.g}, ${color.b})`
}
/*** 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.string, value: React.PropTypes.string,
default: React.PropTypes.number, default: React.PropTypes.number,
doc: React.PropTypes.string, doc: React.PropTypes.string,
} }
onChange(e) { render() {
const value = e.target.value return <div style={{...inputStyle.property, position: 'relative'}}>
return this.props.onChange(value === "" ? null: value) <div style={{
} position: 'absolute',
left: 200
}}>
<ColorPicker
value={this.props.value}
onChange={c => this.props.onChange(formatColor(c))}
/>
</div>
render() { <label style={inputStyle.label}>{this.props.name}</label>
return <div style={inputStyle.property}> <input
<label style={inputStyle.label}>{this.props.name}</label> style={inputStyle.input}
<input name={this.props.name}
style={inputStyle.input} placeholder={this.props.default}
name={this.props.name} value={this.props.value ? this.props.value : ""}
placeholder={this.props.default} onChange={(e) => this.props.onChange(e.target.value)}
value={this.props.value ? this.props.value : ""} />
onChange={this.onChange.bind(this)} </div>
/> }
</div>
}
} }
export default ColorField export default ColorField

View file

@ -36,10 +36,8 @@ class ZoomSpecField extends React.Component {
render() { render() {
if(isZoomField(this.props.value)) { if(isZoomField(this.props.value)) {
const zoomFields = this.props.value.get('stops').map(stop => { const zoomFields = this.props.value.get('stops').map(stop => {
console.log(stop)
const zoomLevel = stop.get(0) const zoomLevel = stop.get(0)
const value = stop.get(1) const value = stop.get(1)
console.log(zoomLevel, value)
return <div key={zoomLevel}> return <div key={zoomLevel}>
<b><span style={inputStyle.label}>Zoom Level {zoomLevel}</span></b> <b><span style={inputStyle.label}>Zoom Level {zoomLevel}</span></b>

View file

@ -59,6 +59,7 @@ export class LayerEditor extends React.Component {
onPaintChanged(property, newValue) { onPaintChanged(property, newValue) {
let layer = this.props.layer let layer = this.props.layer
//TODO: by using immutable records we can avoid this checking if object exists //TODO: by using immutable records we can avoid this checking if object exists
//
if(!layer.has('paint')) { if(!layer.has('paint')) {
layer = layer.set('paint', Immutable.Map()) layer = layer.set('paint', Immutable.Map())
} }
@ -143,11 +144,9 @@ export class LayerEditor extends React.Component {
<MdDelete /> <MdDelete />
</NavItem> </NavItem>
</Toolbar> </Toolbar>
<ScrollContainer>
<div style={{padding: theme.scale[2], paddingRight: 0, backgroundColor: theme.colors.black}}> <div style={{padding: theme.scale[2], paddingRight: 0, backgroundColor: theme.colors.black}}>
{this.layerFromType(this.props.layer.get('type'))} {this.layerFromType(this.props.layer.get('type'))}
</div> </div>
</ScrollContainer>
</div> </div>
} }
} }