Restyle to use border box

This commit is contained in:
Lukas Martinelli 2016-12-31 12:17:02 +01:00
parent e7709dae15
commit 0eb00312f4
7 changed files with 74 additions and 61 deletions

View file

@ -82,7 +82,6 @@ class ColorField extends React.Component {
</div> </div>
return <div style={{ return <div style={{
...input.property,
position: 'relative', position: 'relative',
display: 'inline', display: 'inline',
}}> }}>

View file

@ -3,6 +3,7 @@ import Color from 'color'
import Button from '../Button' import Button from '../Button'
import SpecField from './SpecField' import SpecField from './SpecField'
import NumberInput from '../inputs/NumberInput'
import DocLabel from './DocLabel' import DocLabel from './DocLabel'
import AddIcon from 'react-icons/lib/md/add-circle-outline' import AddIcon from 'react-icons/lib/md/add-circle-outline'
@ -44,20 +45,21 @@ export default class ZoomSpecField extends React.Component {
let label = <DocLabel let label = <DocLabel
label={labelFromFieldName(this.props.fieldName)} label={labelFromFieldName(this.props.fieldName)}
doc={this.props.fieldSpec.doc} doc={this.props.fieldSpec.doc}
style={{
width: '50%',
}}
/> />
if(isZoomField(this.props.value)) { if(isZoomField(this.props.value)) {
const zoomFields = this.props.value.stops.map((stop, idx) => { const zoomFields = this.props.value.stops.map((stop, idx) => {
label = <label style={{...input.label, width: '30%'}}> label = <DocLabel
{labelFromFieldName(this.props.fieldName)} doc={this.props.fieldSpec.doc}
</label> style={{ width: '42.5%'}}
label={idx > 0 ? "" : labelFromFieldName(this.props.fieldName)}
if(idx > 0) { />
label = <label style={{...input.label, width: '30%'}}></label>
}
if(idx === 1) { if(idx === 1) {
label = <label style={{...input.label, width: '30%'}}> label = <label style={{...input.label, width: '42.5%'}}>
<Button style={{fontSize: fontSizes[5]}}> <Button style={{fontSize: fontSizes[5]}}>
Add stop Add stop
</Button> </Button>
@ -67,17 +69,19 @@ export default class ZoomSpecField extends React.Component {
const zoomLevel = stop[0] const zoomLevel = stop[0]
const value = stop[1] const value = stop[1]
return <div style={input.property} key={zoomLevel}> return <div key={zoomLevel} style={{
...input.property,
marginLeft: 0,
marginRight: 0
}}>
{label} {label}
<Button style={{backgroundColor: null}}> <Button style={{backgroundColor: null}}>
<DeleteIcon /> <DeleteIcon />
</Button> </Button>
<input <NumberInput
style={{ style={{
...input.input, width: '7%',
width: '10%',
}} }}
type="number"
value={zoomLevel} value={zoomLevel}
min={0} min={0}
max={22} max={22}
@ -85,19 +89,20 @@ export default class ZoomSpecField extends React.Component {
<SpecField {...this.props} <SpecField {...this.props}
value={value} value={value}
style={{ style={{
width: '33%', width: '42%',
marginLeft: margins[0], marginLeft: margins[0],
}} }}
/> />
</div> </div>
}) })
return <div style={input.property}> return <div style={input.property}>
{zoomFields} {zoomFields}
</div> </div>
} else { } else {
return <div style={input.property}> return <div style={input.property}>
{label} {label}
<SpecField {...this.props} /> <SpecField {...this.props} style={{ width: '50%' } }/>
</div> </div>
} }
} }

View file

@ -5,6 +5,10 @@ import input from '../../config/input.js'
import colors from '../../config/colors.js' import colors from '../../config/colors.js'
import { margins } from '../../config/scales.js' import { margins } from '../../config/scales.js'
import SelectInput from '../inputs/SelectInput'
import StringInput from '../inputs/StringInput'
import AutocompleteInput from '../inputs/AutocompleteInput'
const combiningFilterOps = ['all', 'any', 'none'] const combiningFilterOps = ['all', 'any', 'none']
const setFilterOps = ['in', '!in'] const setFilterOps = ['in', '!in']
const otherFilterOps = Object const otherFilterOps = Object
@ -35,6 +39,7 @@ class CombiningOperatorSelect extends React.Component {
}) })
return <div> return <div>
<select <select
style={{ style={{
...input.select, ...input.select,
@ -64,20 +69,15 @@ class OperatorSelect extends React.Component {
} }
render() { render() {
const options = otherFilterOps.map(op => { return <SelectInput
return <option key={op} value={op}>{op}</option>
})
return <select
style={{ style={{
...input.select,
width: '15%', width: '15%',
margin: margins[0] margin: margins[0]
}} }}
value={this.props.value} value={this.props.value}
onChange={e => this.props.onChange(e.target.value)} onChange={this.props.onChange}
> options={otherFilterOps.map(op => [op, op])}
{options} />
</select>
} }
} }
@ -104,32 +104,26 @@ class SingleFilterEditor extends React.Component {
const filterArgs = f.slice(2) const filterArgs = f.slice(2)
return <div> return <div>
<select <AutocompleteInput
style={{ wrapperStyle={{
...input.select, width: '35%',
width: '17%', margin: margins[0],
margin: margins[0]
}} }}
value={propertyName} value={propertyName}
options={Object.keys(this.props.properties).map(propName => [propName, propName])}
onChange={newPropertyName => this.onFilterPartChanged(filterOp, newPropertyName, filterArgs)} onChange={newPropertyName => this.onFilterPartChanged(filterOp, newPropertyName, filterArgs)}
> />
{Object.keys(this.props.properties).map(propName => {
return <option key={propName} value={propName}>{propName}</option>
})}
</select>
<OperatorSelect <OperatorSelect
value={filterOp} value={filterOp}
onChange={newFilterOp => this.onFilterPartChanged(newFilterOp, propertyName, filterArgs)} onChange={newFilterOp => this.onFilterPartChanged(newFilterOp, propertyName, filterArgs)}
/> />
<input <StringInput
style={{ style={{
...input.input, width: '35%',
width: '53%',
margin: margins[0] margin: margins[0]
}} }}
value={filterArgs.join(',')} value={filterArgs.join(',')}
onChange={e => { onChange={ v=> this.onFilterPartChanged(filterOp, propertyName, v.split(','))}
this.onFilterPartChanged(filterOp, propertyName, e.target.value.split(','))}}
/> />
</div> </div>
} }
@ -182,11 +176,7 @@ export default class CombiningFilterEditor extends React.Component {
return null return null
} }
return <div style={{ return <div>
padding: margins[2],
paddingRight: 0,
backgroundColor: colors.black
}}>
<CombiningOperatorSelect <CombiningOperatorSelect
value={combiningOp} value={combiningOp}
onChange={this.onFilterPartChanged.bind(this, 0)} onChange={this.onFilterPartChanged.bind(this, 0)}

View file

@ -18,8 +18,8 @@ class ArrayInput extends React.Component {
render() { render() {
const values = this.props.value || this.props.default || [] const values = this.props.value || this.props.default || []
const commonStyle = { const commonStyle = {
width: '15%', width: '49%',
marginRight: margins[0], marginRight: '1%',
} }
const inputs = values.map((v, i) => { const inputs = values.map((v, i) => {
if(this.props.type === 'number') { if(this.props.type === 'number') {
@ -28,7 +28,7 @@ class ArrayInput extends React.Component {
return <StringInput key={i} value={v} style={commonStyle} /> return <StringInput key={i} value={v} style={commonStyle} />
}) })
return <div style={{display: 'inline-block', width: '51%'}}> return <div style={{display: 'inline-block', width: '50%'}}>
{inputs} {inputs}
</div> </div>
} }

View file

@ -8,7 +8,8 @@ class AutocompleteInput extends React.Component {
static propTypes = { static propTypes = {
value: React.PropTypes.string, value: React.PropTypes.string,
options: React.PropTypes.array, options: React.PropTypes.array,
style: React.PropTypes.object, wrapperStyle: React.PropTypes.object,
inputStyle: React.PropTypes.object,
onChange: React.PropTypes.func, onChange: React.PropTypes.func,
} }
@ -28,11 +29,15 @@ class AutocompleteInput extends React.Component {
background: colors.gray, background: colors.gray,
zIndex: 3, zIndex: 3,
}} }}
wrapperStyle={{
display: 'inline-block',
...this.props.wrapperStyle
}}
inputProps={{ inputProps={{
style: { style: {
...input.input, ...input.input,
width: null, width: '100%',
...this.props.style, ...this.props.inputStyle,
} }
}} }}
value={this.props.value} value={this.props.value}

View file

@ -15,15 +15,30 @@ class InputBlock extends React.Component {
return this.props.onChange(value === "" ? null: value) return this.props.onChange(value === "" ? null: value)
} }
renderChildren() {
return React.Children.map(this.props.children, child => {
return React.cloneElement(child, {
style: {
...child.props.style,
width: '50%',
}
})
})
}
render() { render() {
return <div style={{ return <div style={{
display: 'block', ...input.property,
marginTop: margins[2],
marginBottom: margins[2],
...this.props.style, ...this.props.style,
}}> }}>
<label style={input.label}>{this.props.label}</label> <label
{this.props.children} style={{
...input.label,
width: '50%',
}}>
{this.props.label}
</label>
{this.renderChildren()}
</div> </div>
} }
} }

View file

@ -3,6 +3,7 @@ import { margins, fontSizes } from './scales'
const base = { const base = {
display: 'inline-block', display: 'inline-block',
boxSizing: 'border-box',
fontSize: fontSizes[5], fontSize: fontSizes[5],
lineHeight: 2, lineHeight: 2,
paddingLeft: 5, paddingLeft: 5,
@ -11,20 +12,19 @@ const base = {
const label = { const label = {
...base, ...base,
width: '40%', padding: null,
color: colors.lowgray, color: colors.lowgray,
userSelect: 'none', userSelect: 'none',
} }
const property = { const property = {
marginTop: margins[2], display: 'block',
marginBottom: margins[2], margin: margins[2],
} }
const input = { const input = {
...base, ...base,
border: 'none', border: 'none',
width: '47%',
backgroundColor: colors.gray, backgroundColor: colors.gray,
color: colors.lowgray, color: colors.lowgray,
} }
@ -38,7 +38,6 @@ const checkbox = {
const select = { const select = {
...input, ...input,
width: '50%',
height: '2.15em', height: '2.15em',
} }