diff --git a/e2e/__tests__/__image_snapshots__/switch-field-test-js-components-switch-field-common-1-snap.png b/e2e/__tests__/__image_snapshots__/switch-field-test-js-components-switch-field-common-1-snap.png new file mode 100644 index 00000000..760e9b68 Binary files /dev/null and b/e2e/__tests__/__image_snapshots__/switch-field-test-js-components-switch-field-common-1-snap.png differ diff --git a/e2e/__tests__/switch-field.test.js b/e2e/__tests__/switch-field.test.js new file mode 100644 index 00000000..ad40eb38 --- /dev/null +++ b/e2e/__tests__/switch-field.test.js @@ -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); +}); + diff --git a/src/components/Switch/Switch.js b/src/components/Switch/Switch.js index 17f0746f..f7050c63 100644 --- a/src/components/Switch/Switch.js +++ b/src/components/Switch/Switch.js @@ -1,7 +1,12 @@ // @flow import React from 'react'; -import { SwitchTag, SwitchInputTag, SwitchApperanceTag, SwitchLabelTag } from './Switch.theme'; +import { + SwitchTag, + SwitchInputTag, + SwitchApperanceTag, + SwitchLabelTag, +} from './Switch.theme'; type SwitchProps = { label?: string, @@ -33,3 +38,4 @@ class Switch extends React.Component { } export { Switch }; + diff --git a/src/components/SwitchField/SwitchField.js b/src/components/SwitchField/SwitchField.js new file mode 100644 index 00000000..37b1af24 --- /dev/null +++ b/src/components/SwitchField/SwitchField.js @@ -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 ( + + + + ); +}; + +export { SwitchField }; + diff --git a/src/components/SwitchField/SwitchField.stories.js b/src/components/SwitchField/SwitchField.stories.js new file mode 100644 index 00000000..4d423bdc --- /dev/null +++ b/src/components/SwitchField/SwitchField.stories.js @@ -0,0 +1,19 @@ +import React from 'react'; + +export default (asStory) => { + asStory('Components/SwitchField', module, (story, { SwitchField, Column }) => { + story + .add('common', () => ( + + + + + + )); + }); +}; + diff --git a/src/components/SwitchField/SwitchField.test.js b/src/components/SwitchField/SwitchField.test.js new file mode 100644 index 00000000..b2ede294 --- /dev/null +++ b/src/components/SwitchField/SwitchField.test.js @@ -0,0 +1,30 @@ +// @flow +import React from 'react'; +import { SwitchField } from './SwitchField'; + +describe('', () => { + it('should pass props to the children', () => { + const onChange = jest.fn(); + const wrapper = shallow(); + + expect(wrapper).toMatchInlineSnapshot(` + + + +`); + }); +}); diff --git a/src/components/SwitchField/index.js b/src/components/SwitchField/index.js new file mode 100644 index 00000000..a394e160 --- /dev/null +++ b/src/components/SwitchField/index.js @@ -0,0 +1,4 @@ +// @flow + +export { SwitchField } from './SwitchField'; + diff --git a/src/components/components.js b/src/components/components.js index b1993722..7e68f50b 100644 --- a/src/components/components.js +++ b/src/components/components.js @@ -36,6 +36,7 @@ export { SecondaryNavigation } from './SecondaryNavigation'; export { Select } from './Select'; export { SelectField } from './SelectField'; export { Switch } from './Switch'; +export { SwitchField } from './SwitchField'; export { Table, TableBuilder } from './Table'; export { Tabs } from './Tabs'; export { Tag } from './Tag';