-
Notifications
You must be signed in to change notification settings - Fork 11
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
Andrei Firsov
committed
Apr 9, 2019
1 parent
cee9797
commit 6c83559
Showing
8 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
Binary file added
BIN
+7.04 KB
...mage_snapshots__/switch-field-test-js-components-switch-field-common-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 @@ | ||
import { baisy } from '../setup/TestSuiter'; | ||
|
||
|
||
const SUITES = [ | ||
baisy.suite('Components/SwitchField', 'common'), | ||
]; | ||
|
||
|
||
SUITES.map(suite => { | ||
it(suite.getTestName(), suite.testStory, 20000); | ||
}); | ||
|
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,42 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
|
||
import type { InputType, MetaType } from '../../types'; | ||
import * as formUtils from '../../utils/forms'; | ||
import { Switch } from '../Switch'; | ||
import { FormField } from '../Form/FormField'; | ||
|
||
type SwitchFieldProps = { | ||
label?: string, | ||
input: InputType, | ||
meta?: MetaType, | ||
}; | ||
|
||
const SwitchField = ({ label, input, meta, ...rest }: SwitchFieldProps) => { | ||
const { | ||
name, | ||
value, | ||
onChange, | ||
onFocus, | ||
onBlur, | ||
} = input; | ||
const hasError = formUtils.hasError(meta); | ||
|
||
return ( | ||
<FormField { ...rest } input={ input } meta={ meta }> | ||
<Switch | ||
name={ name } | ||
label={ label } | ||
value={ Boolean(value) } | ||
onChange={ onChange } | ||
onBlur={ onBlur } | ||
onFocus={ onFocus } | ||
hasError={ hasError } | ||
/> | ||
</FormField> | ||
); | ||
}; | ||
|
||
export { SwitchField }; | ||
|
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,19 @@ | ||
import React from 'react'; | ||
|
||
export default (asStory) => { | ||
asStory('Components/SwitchField', module, (story, { SwitchField, Column }) => { | ||
story | ||
.add('common', () => ( | ||
<Column> | ||
<SwitchField label="Disabled" input={{}} /> | ||
<SwitchField label="Enabled" input={{ value: true }} /> | ||
<SwitchField | ||
label="With error" | ||
input={{ value: false }} | ||
meta={{ error: 'Required', touched: true }} | ||
/> | ||
</Column> | ||
)); | ||
}); | ||
}; | ||
|
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,30 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { SwitchField } from './SwitchField'; | ||
|
||
describe('<SwitchField />', () => { | ||
it('should pass props to the children', () => { | ||
const onChange = jest.fn(); | ||
const wrapper = shallow(<SwitchField input={{ onChange, value: true }} />); | ||
|
||
expect(wrapper).toMatchInlineSnapshot(` | ||
<FormField | ||
direction="column" | ||
hideErrorLabel={false} | ||
input={ | ||
Object { | ||
"onChange": [MockFunction], | ||
"value": true, | ||
} | ||
} | ||
stretch={true} | ||
> | ||
<Switch | ||
hasError={false} | ||
onChange={[MockFunction]} | ||
value={true} | ||
/> | ||
</FormField> | ||
`); | ||
}); | ||
}); |
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,4 @@ | ||
// @flow | ||
|
||
export { SwitchField } from './SwitchField'; | ||
|
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