blob: cfe4ebfe273e2477c43e7945fe5f1451cb28a145 (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
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)
this.props.onChange && this.props.onChange(new_value)
}
render() {
const value = this.props.opt[this.props.name]
const options = (this.props.options || []).map((key,i) => {
let name, value
if (typeof key == 'string') {
name = key.length < 4 ? key.toUpperCase() : key
value = key
} else {
let frames = Math.round(key.count / 30) + ' s.'
name = key.name.replace(/_/g, ' ') + ' (' + frames + ')'
value = key.name
}
return (
<option value={value} key={i}>
{name}
</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)
|