-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
171 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { getIn } from 'formik'; | ||
import ReactSelect from 'react-select'; | ||
|
||
import Field from '../Field'; | ||
|
||
class MultipleDropDown extends Field { | ||
handleChange = (form, value) => { | ||
const { name, handleChange } = this.props; | ||
const newValue = value ? value.map(e => e.value) : null; | ||
form.setFieldValue(name, newValue); | ||
handleChange(newValue); | ||
}; | ||
|
||
renderCheckbox = (checked, label) => ( | ||
<div | ||
className={classNames('dp-pc_checkbox')} | ||
> | ||
<span | ||
className="dp-pc_checkbox__checkbox" | ||
> | ||
<input type="checkbox" checked={checked} readOnly /> | ||
<i /> | ||
<span className="dp-pc_checkbox__label"> | ||
{label} | ||
</span> | ||
</span> | ||
</div> | ||
); | ||
|
||
renderOption = (option, form) => { | ||
const { name } = this.props; | ||
const checked = form.values[name].includes(option.value); | ||
return this.renderCheckbox(checked, option.label); | ||
}; | ||
|
||
renderField = (form) => { | ||
const { name, options, ...props } = this.props; | ||
return ( | ||
<ReactSelect | ||
value={getIn(form.values, name)} | ||
name={name} | ||
clearable={false} | ||
onChange={value => this.handleChange(form, value)} | ||
onBlur={() => form.setFieldTouched(name, true)} | ||
options={options} | ||
removeSelected={false} | ||
optionRenderer={option => this.renderOption(option, form)} | ||
multi | ||
{...props} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
MultipleDropDown.propTypes = { | ||
...Field.propTypes, | ||
options: PropTypes.arrayOf(PropTypes.shape({ | ||
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired, | ||
value: PropTypes.any.isRequired | ||
})), | ||
handleChange: PropTypes.func, | ||
}; | ||
|
||
MultipleDropDown.defaultProps = { | ||
handleChange() {}, | ||
}; | ||
|
||
export default MultipleDropDown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
tests/jest/Components/Inputs/__snapshots__/testDatePicker.jsx.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Formik } from 'formik'; | ||
import { Form, MultipleDropDown, Submit } from '../../src/Components'; | ||
|
||
const options = [ | ||
{ value: 'bacon', label: 'Bacon' }, | ||
{ value: 'cheese', label: 'Cheese' }, | ||
{ value: 'jalapenos', label: 'Jalapeños' }, | ||
{ value: 'mushrooms', label: 'Mushrooms' }, | ||
{ value: 'onions', label: 'Onions' }, | ||
{ value: 'pickles', label: 'Pickles' }, | ||
]; | ||
|
||
storiesOf('Choices', module) | ||
.add('MultipleDropDown', () => ( | ||
<Formik | ||
initialValues={{ filling: ['bacon'] }} | ||
onSubmit={action('submit')} | ||
render={() => ( | ||
<Form> | ||
<MultipleDropDown | ||
name="filling" | ||
options={options} | ||
label="Filling" | ||
/> | ||
<Submit>Submit</Submit> | ||
</Form> | ||
)} | ||
/> | ||
)); |