From f694d542efa0cc5a819298f64b84d12e5af87527 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 21 May 2018 14:51:53 +0200 Subject: select component --- app/client/common/select.component.js | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/client/common/select.component.js (limited to 'app/client/common') 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 ( + + ) + }) + return ( +
+ + {this.props.children} +
+ ) + } +} + +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) -- cgit v1.2.3-70-g09d2