-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdropdown-checkbox-group.js
More file actions
71 lines (66 loc) · 2.29 KB
/
dropdown-checkbox-group.js
File metadata and controls
71 lines (66 loc) · 2.29 KB
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
65
66
67
68
69
70
71
import React from 'react'
import CheckboxGroup from './checkbox-group'
import {
checkboxGroupPropTypes,
DropdownSelect,
fieldOptionsType,
} from '../helpers'
import { InputLabel }from '../labels'
/**
*
* A group of checkboxes that can be used in a `redux-forms`-controlled form.
* Wraps the {@link CheckboxGroup} component in a {@link DropdownSelect} component, which displays the selected values as a list.
* Options are displayed in a scrollable `Select`-style dropdown container.
*
* The value of each checkbox is specified via the `options` prop. This prop can either be:
* - An array of strings
* - An array of key-value pairs: `{ key, value }`
*
* The value of the entire `DropdownCheckboxGroup` component is an **array** containing the values of the selected checkboxes.
* Clicking an unselected checkbox adds its value to this array, and clicking a selected checkbox removes its value from this array.
*
* @name DropdownCheckboxGroup
* @type Function
* @param {Object} input - A `redux-forms` [input](http://redux-form.com/6.5.0/docs/api/Field.md/#input-props) object
* @param {Object} meta - A `redux-forms` [meta](http://redux-form.com/6.5.0/docs/api/Field.md/#meta-props) object
* @param {Array} options - An array of checkbox values (strings or key-value pairs)
* @example
*
* function InterestsForm ({ handleSubmit, pristine, invalid, submitting }) {
* return (
* <form onSubmit={ handleSubmit }>
* <Field
* name="interests"
* component={ DropdownCheckboxGroup }
* options={[
* 'Art',
* 'Computer Science',
* 'Dance'
* ]}
* />
* <SubmitButton {...{ pristine, invalid, submitting }}>
* Submit
* </SubmitButton>
* </form>
* )
* }
*
* export default TodoForm
*/
const propTypes = {
...checkboxGroupPropTypes,
options: fieldOptionsType
}
function DropdownCheckboxGroup (props) {
const { input: { name, value }, label } = props
return (
<fieldset>
<InputLabel { ...{ label, name } } />
<DropdownSelect {...props} selectedValues={ value } className="checkboxes">
<CheckboxGroup { ...props } label={ false } />
</DropdownSelect>
</fieldset>
)
}
DropdownCheckboxGroup.propTypes = propTypes
export default DropdownCheckboxGroup