summaryrefslogtreecommitdiff
path: root/app/client/common/selectGroup.component.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-08-30 22:59:28 +0200
committerJules Laplace <julescarbon@gmail.com>2018-08-30 22:59:28 +0200
commit70b4cc5adcef18d498b539579ecfa626aa5e6c18 (patch)
treee86c4903e9916fef2775d1131d73c9d0b65f73a5 /app/client/common/selectGroup.component.js
parentca53592e108e2189ef1b625c45d2b2a23b7ab145 (diff)
group sequences/checkpoints by folder
Diffstat (limited to 'app/client/common/selectGroup.component.js')
-rw-r--r--app/client/common/selectGroup.component.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/app/client/common/selectGroup.component.js b/app/client/common/selectGroup.component.js
new file mode 100644
index 0000000..b653fdf
--- /dev/null
+++ b/app/client/common/selectGroup.component.js
@@ -0,0 +1,66 @@
+import { h, Component } from 'preact'
+import { connect } from 'react-redux'
+import { bindActionCreators } from 'redux'
+
+class SelectGroup extends Component {
+ constructor(props){
+ super(props)
+ this.handleChange = this.handleChange.bind(this)
+ }
+ handleChange(e){
+ clearTimeout(this.timeout)
+ let new_value = e.target.value
+ if (new_value === 'PLACEHOLDER') return
+ this.props.onChange && this.props.onChange(this.props.name, new_value)
+ }
+ render() {
+ const currentValue = this.props.live ? this.props.opt[this.props.name] : this.props.value
+ let lastValue
+ const options = (this.props.options || []).map((group, i) => {
+ const groupName = group.name
+ const children = group.options.map(key => {
+ let name = key.length < 2 ? key.toUpperCase() : key
+ let value = key.replace(/_/g, ' ')
+ lastValue = value
+ return (
+ <option value={value} key={value}>
+ {value}
+ </option>
+ )
+ })
+ return (
+ <optgroup label={groupName} key={groupName}>
+ {children}
+ </optgroup>
+ )
+ })
+ return (
+ <div className='select param'>
+ <label>
+ <span>{this.props.title}</span>
+ <select
+ onChange={this.handleChange}
+ value={currentValue || lastValue}
+ >
+ {this.props.placeholder && <option value="PLACEHOLDER">{this.props.placeholder}</option>}
+ {options}
+ </select>
+ </label>
+ {this.props.children}
+ </div>
+ )
+ }
+}
+
+function capitalize(s){
+ return (s || "").replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
+}
+
+const mapStateToProps = (state, props) => ({
+ opt: props.opt || state.live.opt,
+})
+
+const mapDispatchToProps = (dispatch, ownProps) => ({
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(SelectGroup)