|
|
|
@ -1,16 +1,10 @@ |
|
|
|
|
const Component = require('react').Component |
|
|
|
|
const h = require('react-hyperscript') |
|
|
|
|
const inherits = require('util').inherits |
|
|
|
|
import PropTypes from 'prop-types' |
|
|
|
|
import React, {Component} from 'react' |
|
|
|
|
|
|
|
|
|
module.exports = NewComponent |
|
|
|
|
export default class Selector extends Component { |
|
|
|
|
state = {} |
|
|
|
|
|
|
|
|
|
inherits(NewComponent, Component) |
|
|
|
|
function NewComponent () { |
|
|
|
|
Component.call(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NewComponent.prototype.render = function () { |
|
|
|
|
const props = this.props |
|
|
|
|
render () { |
|
|
|
|
const { |
|
|
|
|
states, |
|
|
|
|
selectedKey, |
|
|
|
@ -18,25 +12,38 @@ NewComponent.prototype.render = function () { |
|
|
|
|
store, |
|
|
|
|
modifyBackgroundConnection, |
|
|
|
|
backGroundConnectionModifiers, |
|
|
|
|
} = props |
|
|
|
|
|
|
|
|
|
const state = this.state || {} |
|
|
|
|
const selected = state.selected || selectedKey |
|
|
|
|
} = this.props |
|
|
|
|
const selected = this.state.selected || selectedKey |
|
|
|
|
|
|
|
|
|
return h('select', { |
|
|
|
|
style: { |
|
|
|
|
margin: '20px 20px 0px', |
|
|
|
|
}, |
|
|
|
|
value: selected, |
|
|
|
|
onChange: (event) => { |
|
|
|
|
return ( |
|
|
|
|
<select |
|
|
|
|
style={{ margin: '20px 20px 0px' }} |
|
|
|
|
value={selected} |
|
|
|
|
onChange={(event) => { |
|
|
|
|
const selectedKey = event.target.value |
|
|
|
|
const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey] |
|
|
|
|
modifyBackgroundConnection(backgroundConnectionModifier || {}) |
|
|
|
|
store.dispatch(actions.update(selectedKey)) |
|
|
|
|
this.setState({ selected: selectedKey }) |
|
|
|
|
}, |
|
|
|
|
}, Object.keys(states).map((stateName) => { |
|
|
|
|
return h('option', { value: stateName }, stateName) |
|
|
|
|
})) |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{Object.keys(states).map((stateName, index) => { |
|
|
|
|
return ( |
|
|
|
|
<option key={index} value={stateName}> |
|
|
|
|
{stateName} |
|
|
|
|
</option> |
|
|
|
|
) |
|
|
|
|
})} |
|
|
|
|
</select> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Selector.propTypes = { |
|
|
|
|
states: PropTypes.object.isRequired, |
|
|
|
|
selectedKey: PropTypes.string.isRequired, |
|
|
|
|
actions: PropTypes.object.isRequired, |
|
|
|
|
store: PropTypes.object.isRequired, |
|
|
|
|
modifyBackgroundConnection: PropTypes.func.isRequired, |
|
|
|
|
backGroundConnectionModifiers: PropTypes.object.isRequired, |
|
|
|
|
} |
|
|
|
|