diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-21 14:51:53 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-21 14:51:53 +0200 |
| commit | f694d542efa0cc5a819298f64b84d12e5af87527 (patch) | |
| tree | 8e0a249413a8ac84522216754fd0f4d4b792e94e /app | |
| parent | 2f2d58c735683263ef0731f540b13a025eb9a575 (diff) | |
select component
Diffstat (limited to 'app')
| -rw-r--r-- | app/client/common/select.component.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/app/client/common/select.component.js b/app/client/common/select.component.js new file mode 100644 index 0000000..9ff60ce --- /dev/null +++ b/app/client/common/select.component.js @@ -0,0 +1,54 @@ +import { h, Component } from 'preact' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import * as liveActions from '../live/actions' + +class Select extends Component { + constructor(props){ + super(props) + this.handleChange = this.handleChange.bind(this) + } + handleChange(e){ + clearTimeout(this.timeout) + let new_value = e.target.value + this.props.actions.set_param(this.props.name, new_value) + } + render() { + const value = this.props.opt[this.props.name] + const options = this.props.options.map((key,i) => { + return ( + <option value={key} key={i}> + {capitalize(key)} + </option> + ) + }) + return ( + <div className='select param'> + <label> + <span>{this.props.title}</span> + <select + onChange={this.handleChange} + value={value} + > + {options} + </select> + </label> + {this.props.children} + </div> + ) + } +} + +function capitalize(s){ + return (s || "").replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); }); +} + +const mapStateToProps = state => ({ + opt: state.live.opt, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(liveActions, dispatch) +}) + +export default connect(mapStateToProps, mapDispatchToProps)(Select) |
