summaryrefslogtreecommitdiff
path: root/app/client/common/paramGroup.component.js
blob: 25336424758e54b36c80331359d9b4f5a80f028a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { h, Component } from 'preact'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as liveActions from '../live/actions'

class ParamGroup extends Component {
  constructor(props){
    super(props)
    this.handleClick = this.handleClick.bind(this)
  }
  handleClick(e){
    clearTimeout(this.timeout)
    let new_value = e.target.checked
    this.props.actions.set_param(this.props.name, new_value)
  }
  render() {
    const props = this.props
    const checked = this.props.opt[this.props.name]
    const className = checked ? 'paramGroup active' : 'paramGroup inactive'
    return (
      <div className={className}>
        <label>
          <h3>{props.title}</h3>
          <input
            type='checkbox'
            onClick={this.handleClick}
            checked={checked}
          />
        </label>
        {props.children}
      </div>
    )
  }
}

const mapStateToProps = state => ({
  opt: state.live.opt,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(liveActions, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(ParamGroup)