Skip to content

Commit 9aad0b6

Browse files
committed
feat: InputCheckboxes component to select multiple options
1 parent da43b89 commit 9aad0b6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/components/InputCheckboxes.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, {Component, PropTypes} from 'react'
2+
import {observer} from 'mobx-react'
3+
4+
@observer
5+
export default class InputCheckboxes extends Component {
6+
constructor (props) {
7+
super(props)
8+
this.onChange = this.onChange.bind(this)
9+
}
10+
11+
onChange (event) {
12+
this.props.onChange(this.props.name, event.target.value)
13+
}
14+
15+
render () {
16+
const {items, name, checkedItems} = this.props
17+
return (
18+
<div className="form-group">
19+
<b>{name}</b>
20+
{
21+
items.map((item) => {
22+
return (
23+
<div className="checkbox" key={`${name}-${item}`}>
24+
<label htmlFor={`${name}-${item}`}>
25+
<input type="checkbox" name={`${name}`} value={item} id={`${name}-${item}`}
26+
checked={checkedItems.indexOf(item) > -1}
27+
onChange={this.onChange}/> {item}
28+
</label>
29+
</div>
30+
)
31+
})
32+
}
33+
</div>
34+
)
35+
}
36+
}
37+
38+
InputCheckboxes.propTypes = {
39+
onChange: PropTypes.func.isRequired,
40+
name: PropTypes.string.isRequired
41+
}

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import asForm from './asForm'
22
import InputCheckbox from './InputCheckbox'
3+
import InputCheckboxes from './InputCheckboxes'
34
import InputField from './InputField'
45
import InputRadio from './InputRadio'
56

67
export {
78
asForm,
89
InputCheckbox,
10+
InputCheckboxes,
911
InputField,
1012
InputRadio
1113
}

0 commit comments

Comments
 (0)