From c5ab58c09d90dad34fbab72bab88a06dd4d6e271 Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Thu, 26 Jul 2018 09:24:35 -0400 Subject: [PATCH] add button field #19 --- src/components/fields/button/Button.js | 68 +++++++++++ src/components/fields/button/Button.test.js | 108 ++++++++++++++++++ .../button/__snapshots__/Button.test.js.snap | 28 +++++ 3 files changed, 204 insertions(+) create mode 100644 src/components/fields/button/Button.js create mode 100644 src/components/fields/button/Button.test.js create mode 100644 src/components/fields/button/__snapshots__/Button.test.js.snap diff --git a/src/components/fields/button/Button.js b/src/components/fields/button/Button.js new file mode 100644 index 0000000..33d44d4 --- /dev/null +++ b/src/components/fields/button/Button.js @@ -0,0 +1,68 @@ +import React from 'react'; +import {fieldPropTypes} from '../propTypes'; +import classNames from 'classnames'; +import {RenderGroup} from '../../RenderGroup'; +import PropTypes from 'prop-types'; + + +export const Button = (props) => { + /** + * Get the className prop for inputs + * + * @return {String} + */ + function inputClassName() { + return classNames( + props.fieldClassName, + RenderGroup.classNames.input + ); + } + + if ('submit' === props.inputType) { + return ( + + ); + } + + return ( + + ); +}; + +let propTypes = fieldPropTypes; +delete fieldPropTypes.onValueChange; + +/** + * Prop type definitions for Button Component + * @type {{id: (*), fieldClassName: (*), help: shim, value: shim, onValueChange: (*), inputType: shim, onClick: *}} + */ +Button.propTypes = { + ...propTypes, + innerType: PropTypes.oneOf(['submit','button'] ), + onClick: PropTypes.func.isRequired, +}; + +Button.defaultProps = { + inputType: 'submit' +} \ No newline at end of file diff --git a/src/components/fields/button/Button.test.js b/src/components/fields/button/Button.test.js new file mode 100644 index 0000000..2b9a306 --- /dev/null +++ b/src/components/fields/button/Button.test.js @@ -0,0 +1,108 @@ +import renderer from 'react-test-renderer'; +import React from 'react'; +import {shallow} from 'enzyme'; +import Enzyme from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import {Button} from "./Button"; + +Enzyme.configure({adapter: new Adapter()}); + +describe('Button component', () => { + function genericChangeHandler() { + } + + describe( 'props', () => { + it('snapshot for submit', () => { + const component = renderer.create( +