diff --git a/src/components/fields/EnumField.jsx b/src/components/fields/EnumField.jsx deleted file mode 100644 index 0bbb8ae0..00000000 --- a/src/components/fields/EnumField.jsx +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react' -import input from '../../config/input.js' - -class EnumField extends React.Component { - static propTypes = { - onChange: React.PropTypes.func.isRequired, - name: React.PropTypes.string.isRequired, - value: React.PropTypes.string, - allowedValues: React.PropTypes.array.isRequired, - doc: React.PropTypes.string, - style: React.PropTypes.object, - } - - onChange(e) { - return this.props.onChange(e.target.value) - } - - render() { - const options = this.props.allowedValues.map(val => { - return - }) - - return - } -} - -export default EnumField diff --git a/src/components/fields/SpecField.jsx b/src/components/fields/SpecField.jsx index 509a425d..a28ee25c 100644 --- a/src/components/fields/SpecField.jsx +++ b/src/components/fields/SpecField.jsx @@ -2,11 +2,11 @@ import React from 'react' import color from 'color' import GlSpec from 'mapbox-gl-style-spec/reference/latest.min.js' -import NumberField from './NumberField' -import EnumField from './EnumField' -import BooleanField from './BooleanField' import ColorField from './ColorField' -import StringField from './StringField' +import NumberInput from '../inputs/NumberInput' +import CheckboxInput from '../inputs/CheckboxInput' +import StringInput from '../inputs/StringInput' +import SelectInput from '../inputs/SelectInput' import input from '../../config/input.js' @@ -37,30 +37,29 @@ export default class SpecField extends React.Component { render() { const commonProps = { - doc: this.props.fieldSpec.doc, style: this.props.style, value: this.props.value, name: this.props.fieldName, onChange: newValue => this.props.onChange(this.props.fieldName, newValue) } + console.log(this.props.fieldName, this.props.fieldSpec.type) switch(this.props.fieldSpec.type) { case 'number': return ( - ) case 'enum': return ( - [v, v])} /> ) case 'string': return ( - ) @@ -70,7 +69,7 @@ export default class SpecField extends React.Component { /> ) case 'boolean': return ( - ) diff --git a/src/components/fields/StringField.jsx b/src/components/fields/StringField.jsx deleted file mode 100644 index 77776e48..00000000 --- a/src/components/fields/StringField.jsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react' -import input from '../../config/input.js' - -/*** Number fields with support for min, max and units and documentation*/ -class StringField extends React.Component { - static propTypes = { - onChange: React.PropTypes.func.isRequired, - name: React.PropTypes.string.isRequired, - value: React.PropTypes.string, - default: React.PropTypes.number, - doc: React.PropTypes.string, - style: React.PropTypes.object, - } - - onChange(e) { - const value = e.target.value - return this.props.onChange(value === "" ? null: value) - } - - render() { - return - } -} - -export default StringField diff --git a/src/components/fields/ZoomSpecField.jsx b/src/components/fields/ZoomSpecField.jsx index ebdbf6e4..5d396c8e 100644 --- a/src/components/fields/ZoomSpecField.jsx +++ b/src/components/fields/ZoomSpecField.jsx @@ -2,11 +2,6 @@ import React from 'react' import Color from 'color' import Button from '../Button' -import NumberField from './NumberField' -import EnumField from './EnumField' -import BooleanField from './BooleanField' -import ColorField from './ColorField' -import StringField from './StringField' import SpecField from './SpecField' import DocLabel from './DocLabel' @@ -45,7 +40,6 @@ export default class ZoomSpecField extends React.Component { } render() { - console.log(this.props.fieldSpec) let label = {this.props.onChange(!this.props.value)}} checked={this.props.value} /> @@ -72,4 +68,4 @@ class BooleanField extends React.Component { } } -export default BooleanField +export default CheckboxInput diff --git a/src/components/fields/NumberField.jsx b/src/components/inputs/NumberInput.jsx similarity index 71% rename from src/components/fields/NumberField.jsx rename to src/components/inputs/NumberInput.jsx index 24e4b334..94326b23 100644 --- a/src/components/fields/NumberField.jsx +++ b/src/components/inputs/NumberInput.jsx @@ -1,18 +1,14 @@ import React from 'react' import input from '../../config/input.js' -/*** Number fields with support for min, max and units and documentation*/ -class NumberField extends React.Component { +class NumberInput extends React.Component { static propTypes = { - onChange: React.PropTypes.func.isRequired, - name: React.PropTypes.string.isRequired, value: React.PropTypes.number, + style: React.PropTypes.object, default: React.PropTypes.number, - unit: React.PropTypes.string, min: React.PropTypes.number, max: React.PropTypes.number, - doc: React.PropTypes.string, - style: React.PropTypes.object, + onChange: React.PropTypes.func, } onChange(e) { @@ -21,7 +17,12 @@ class NumberField extends React.Component { if(this.props.min && value < this.props.min) return if(this.props.max && value > this.props.max) return */ - this.props.onChange(value) + + if(isNaN(value)) { + this.props.onChange(this.props.default) + } else { + this.props.onChange(value) + } } render() { @@ -35,11 +36,10 @@ class NumberField extends React.Component { ...input.input, ...this.props.style }} - type="number" + type={"number"} min={this.props.min} max={this.props.max} step={stepSize} - name={this.props.name} placeholder={this.props.default} value={this.props.value} onChange={this.onChange.bind(this)} @@ -47,4 +47,4 @@ class NumberField extends React.Component { } } -export default NumberField +export default NumberInput