Skip to content

Commit

Permalink
CheckboxArray for multiple checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu committed Oct 6, 2016
1 parent 21b1d10 commit c0db2d4
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions caravel/assets/javascripts/explorev2/components/SelectArray.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import Select from 'react-select';
import { bindActionCreators } from 'redux';
import * as actions from '../actions/exploreActions';
import { connect } from 'react-redux';

const propTypes = {
actions: React.PropTypes.object,
selectArray: React.PropTypes.arrayOf(
React.PropTypes.shape({
key: React.PropTypes.string.isRequired,
options: React.PropTypes.array.isRequired,
value: React.PropTypes.string.isRequired,
})
).isRequired,
};

const defaultProps = {
selectArray: [],
};

class SelectArray extends React.Component {
changeSelectData(field, opt) {
const val = opt ? opt.value : null;
this.props.actions.setStateValue(field, val);
}
render() {
const selects = selectArray.map((obj) => (
<div className="col-sm-6">
<h5 className="section-heading">obj.key</h5>
<Select
name={`select-${obj.key}`}
options={obj.options.map((o) => ({ value: o, label: o }))}
value={obj.value}
autosize={false}
onChange={this.changeSelectData.bind(this, obj.key)}
/>
</div>
));
return (
<div className="panel space-1">
<div className="panel-body">
{selects}
</div>
</div>
);
}
}

SelectArray.propTypes = propTypes;
SelectArray.defaultProps = defaultProps;

function mapStateToProps(state) {
return {};
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch),
};
}

export default connect(mapStateToProps, mapDispatchToProps)(SelectArray);

0 comments on commit c0db2d4

Please sign in to comment.