Skip to content

Commit 09f902f

Browse files
authored
Merge pull request #394 from rvsia/buttonType
fix(renderer): add buttonType to form controls
2 parents f1bff65 + e1f5df2 commit 09f902f

File tree

18 files changed

+38
-16
lines changed

18 files changed

+38
-16
lines changed

__mocks__/mock-layout-mapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { layoutComponents } from "../packages/react-form-renderer/src/constants"
33

44
export const layoutMapper = {
55
[layoutComponents.FORM_WRAPPER]: ({ children, ...rest }) => <form {...rest}>{ children }</form>,
6-
[layoutComponents.BUTTON]: ({ label, ...rest }) => <button { ...rest }>{ label }</button>,
6+
[layoutComponents.BUTTON]: ({ label, buttonType, ...rest }) => <button { ...rest }>{ label }</button>,
77
[layoutComponents.BUTTON_GROUP]: ({ children }) => <div>{ children }</div>,
88
[layoutComponents.TITLE]: ({ children }) => <div>{ children }</div>,
99
[layoutComponents.DESCRIPTION]: ({ children }) => <div>{ children }</div>,

packages/mui-component-mapper/src/form-fields/layout-components.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Typography from '@material-ui/core/Typography';
66

77
const layoutMapper = {
88
[layoutComponents.FORM_WRAPPER]: ({ children, ...props }) => <form { ...props }>{ children }</form>,
9-
[layoutComponents.BUTTON]: ({ label, variant, children, ...props }) => <Button color={ variant } variant="contained" { ...props }>{ label || children }</Button>,
9+
[layoutComponents.BUTTON]: ({ label, variant, children, buttonType, ...props }) => <Button color={ variant } variant="contained" { ...props }>{ label || children }</Button>,
1010
[layoutComponents.BUTTON_GROUP]: ({ children }) => (
1111
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
1212
{ children }

packages/pf3-component-mapper/src/form-fields/layout-components.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ FormWapper.propTypes = {
1010
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]).isRequired,
1111
};
1212

13-
const FormButton = ({ label, variant, children, ...props }) => <Button bsStyle={ variant } { ...props }>{ label || children }</Button>;
13+
const FormButton = ({ label, variant, children, buttonType, ...props }) => <Button bsStyle={ variant } { ...props }>{ label || children }</Button>;
1414

1515
FormButton.propTypes = {
1616
label: PropTypes.oneOfType([ PropTypes.string, PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]),
1717
variant: PropTypes.string,
1818
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]),
19+
buttonType: PropTypes.string,
1920
};
2021

2122
const ButtonGroupWrapper = ({ children, className, ...props }) => (

packages/pf4-component-mapper/src/form-fields/layout-components.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Button } from '@patternfly/react-core/dist/js/components/Button/Button'
1010

1111
import './layout-components-styles.scss';
1212

13-
const ButtonLayout = ({ label, bsStyle, children, disabled, ...props }) =>
14-
<Button variant={ bsStyle || 'secondary' } isDisabled={ disabled } { ...props }>
13+
const ButtonLayout = ({ label, bsStyle, children, disabled, buttonType, ...props }) =>
14+
<Button variant={ buttonType === 'cancel' ? 'link' : bsStyle || 'secondary' } isDisabled={ disabled } { ...props }>
1515
{ label }{ children }
1616
</Button>;
1717

@@ -23,6 +23,7 @@ ButtonLayout.propTypes = {
2323
PropTypes.arrayOf(PropTypes.node),
2424
PropTypes.node,
2525
]),
26+
buttonType: PropTypes.string,
2627
};
2728

2829
const ButtonGroupLayout = ({ children, ...props }) =>

packages/pf4-component-mapper/src/tests/field-array/__snapshots__/field-array.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ exports[`FieldArray should render array field correctly 1`] = `
665665
className="pf-c-form__actions"
666666
>
667667
<ButtonLayout
668+
buttonType="submit"
668669
key="form-submit"
669670
label="Submit"
670671
type="submit"

packages/react-form-renderer/demo/layout-mapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { layoutComponents } from '../src/constants';
33

4-
const Button = ({ variant, label, ...rest }) => (
4+
const Button = ({ variant, label, buttonType, ...rest }) => (
55
<button
66
style={{
77
backgroundColor: variant === 'primary' ? 'red' : 'initial',

packages/react-form-renderer/src/form-renderer/form-controls.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const FormControls = ({
4747
variant="primary"
4848
disabled={ submitting || validating || disableSubmit }
4949
label={ submitLabel }
50+
buttonType="submit"
5051
/>
5152
),
5253
reset: canReset ? (
@@ -61,9 +62,12 @@ const FormControls = ({
6162
}
6263
} }
6364
label={ resetLabel }
65+
buttonType="reset"
6466
/>
6567
) : null,
66-
cancel: onCancel ? <Button key="form-cancel" type="button" onClick={ () => onCancel(values) } label={ cancelLabel } /> : null,
68+
cancel: onCancel ?
69+
<Button key="form-cancel" type="button" onClick={ () => onCancel(values) } label={ cancelLabel } buttonType="cancel"/>
70+
: null,
6771
};
6872
return (
6973
<ButtonGroup className={ buttonClassName }>

packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-controls.test.js.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ exports[`<FormControls /> should add missing buttons if not defined in button or
4646
<Component>
4747
<div>
4848
<Component
49+
buttonType="submit"
4950
key="form-submit"
5051
label="Submit"
5152
type="submit"
@@ -59,6 +60,7 @@ exports[`<FormControls /> should add missing buttons if not defined in button or
5960
</button>
6061
</Component>
6162
<Component
63+
buttonType="reset"
6264
disabled={true}
6365
key="form-reset"
6466
label="Reset"
@@ -74,6 +76,7 @@ exports[`<FormControls /> should add missing buttons if not defined in button or
7476
</button>
7577
</Component>
7678
<Component
79+
buttonType="cancel"
7780
key="form-cancel"
7881
label="Cancel"
7982
onClick={[Function]}
@@ -148,6 +151,7 @@ exports[`<FormControls /> should render all controls and with default labels 1`]
148151
<Component>
149152
<div>
150153
<Component
154+
buttonType="submit"
151155
disabled={true}
152156
key="form-submit"
153157
label="Submit"
@@ -163,6 +167,7 @@ exports[`<FormControls /> should render all controls and with default labels 1`]
163167
</button>
164168
</Component>
165169
<Component
170+
buttonType="reset"
166171
disabled={true}
167172
key="form-reset"
168173
label="Reset"
@@ -178,6 +183,7 @@ exports[`<FormControls /> should render all controls and with default labels 1`]
178183
</button>
179184
</Component>
180185
<Component
186+
buttonType="cancel"
181187
key="form-cancel"
182188
label="Cancel"
183189
onClick={[Function]}
@@ -251,6 +257,7 @@ exports[`<FormControls /> should render buttons in correct order 1`] = `
251257
<Component>
252258
<div>
253259
<Component
260+
buttonType="cancel"
254261
key="form-cancel"
255262
label="Cancel"
256263
onClick={[Function]}
@@ -264,6 +271,7 @@ exports[`<FormControls /> should render buttons in correct order 1`] = `
264271
</button>
265272
</Component>
266273
<Component
274+
buttonType="submit"
267275
key="form-submit"
268276
label="Submit"
269277
type="submit"
@@ -277,6 +285,7 @@ exports[`<FormControls /> should render buttons in correct order 1`] = `
277285
</button>
278286
</Component>
279287
<Component
288+
buttonType="reset"
280289
disabled={true}
281290
key="form-reset"
282291
label="Reset"
@@ -351,6 +360,7 @@ exports[`<FormControls /> should render only submit button 1`] = `
351360
<Component>
352361
<div>
353362
<Component
363+
buttonType="submit"
354364
key="form-submit"
355365
label="Submit"
356366
type="submit"

packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-information.test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ exports[`<FormControls /> should render with description 1`] = `
129129
className=""
130130
>
131131
<Component
132+
buttonType="submit"
132133
key="form-submit"
133134
label="Submit"
134135
type="submit"
@@ -288,6 +289,7 @@ exports[`<FormControls /> should render with title and description 1`] = `
288289
className=""
289290
>
290291
<Component
292+
buttonType="submit"
291293
key="form-submit"
292294
label="Submit"
293295
type="submit"
@@ -435,6 +437,7 @@ exports[`<FormControls /> should render without title and description 1`] = `
435437
className=""
436438
>
437439
<Component
440+
buttonType="submit"
438441
key="form-submit"
439442
label="Submit"
440443
type="submit"

packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-renderer.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ exports[`<FormRenderer /> should render form from schema 1`] = `
787787
>
788788
<div>
789789
<Component
790+
buttonType="submit"
790791
key="form-submit"
791792
label="Submit"
792793
type="submit"

0 commit comments

Comments
 (0)