Skip to content

Commit b291e65

Browse files
committed
fix(renderer): add buttonType to form controls
- allows to customize each button depending on its type (submit, cancel, reset)
1 parent 733eb87 commit b291e65

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

packages/common/src/form-template.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ export const FormControls = ({
4343
const { submitting, pristine, validating } = formSpyProps;
4444

4545
const buttons = {
46-
submit: <Button key="form-submit" type="submit" variant="primary" disabled={submitting || validating || disableSubmit} label={submitLabel} />,
47-
reset: canReset ? <Button key="form-reset" type="button" disabled={pristine} onClick={onReset} label={resetLabel} /> : null,
48-
cancel: onCancel ? <Button key="form-cancel" type="button" onClick={onCancel} label={cancelLabel} /> : null
46+
submit: (
47+
<Button
48+
key="form-submit"
49+
type="submit"
50+
variant="primary"
51+
buttonType="submit"
52+
disabled={submitting || validating || disableSubmit}
53+
label={submitLabel}
54+
/>
55+
),
56+
reset: canReset ? <Button key="form-reset" type="button" buttonType="reset" disabled={pristine} onClick={onReset} label={resetLabel} /> : null,
57+
cancel: onCancel ? <Button key="form-cancel" type="button" buttonType="cancel" onClick={onCancel} label={cancelLabel} /> : null
4958
};
5059

5160
return <ButtonGroup className={buttonClassName}>{completeButtons(buttonOrder).map((button) => buttons[button])}</ButtonGroup>;

packages/mui-component-mapper/src/files/form-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Title = ({ children }) => (
2020
</Grid>
2121
);
2222
const ButtonGroup = ({ children }) => <div style={{ display: 'flex', justifyContent: 'flex-end' }}>{children}</div>;
23-
const Button = ({ label, variant, children, ...props }) => (
23+
const Button = ({ label, variant, children, buttonType, ...props }) => (
2424
<MUIButton color={variant} variant="contained" {...props}>
2525
{label || children}
2626
</MUIButton>

packages/pf3-component-mapper/src/files/form-template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FormWrapper.propTypes = {
1010
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]).isRequired
1111
};
1212

13-
export const Button = ({ label, variant, children, ...props }) => (
13+
export const Button = ({ label, variant, children, buttonType, ...props }) => (
1414
<PF3Button bsStyle={variant} {...props}>
1515
{label || children}
1616
</PF3Button>
@@ -19,7 +19,8 @@ export const Button = ({ label, variant, children, ...props }) => (
1919
Button.propTypes = {
2020
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
2121
variant: PropTypes.string,
22-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)])
22+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
23+
buttonType: PropTypes.string
2324
};
2425

2526
export const ButtonGroup = ({ children, className, ...props }) => (

packages/pf4-component-mapper/src/files/form-template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Button as PF4Button, ActionGroup, Form, TextContent, Text, TextVariants
77

88
import './form-template.scss';
99

10-
export const Button = ({ label, bsStyle, children, disabled, ...props }) => (
10+
export const Button = ({ label, bsStyle, children, disabled, buttonType, ...props }) => (
1111
<PF4Button variant={bsStyle || 'secondary'} isDisabled={disabled} {...props}>
1212
{label}
1313
{children}
@@ -18,7 +18,8 @@ Button.propTypes = {
1818
label: PropTypes.string.isRequired,
1919
bsStyle: PropTypes.string,
2020
disabled: PropTypes.bool,
21-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
21+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
22+
buttonType: PropTypes.string
2223
};
2324

2425
export const ButtonGroup = ({ children, ...props }) => <ActionGroup {...props}>{children}</ActionGroup>;

packages/pf4-component-mapper/src/tests/__snapshots__/form-template-common.test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
135135
className="pf-c-form__actions"
136136
>
137137
<Button
138+
buttonType="submit"
138139
key="form-submit"
139140
label="Submit"
140141
type="submit"
@@ -184,6 +185,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
184185
</Component>
185186
</Button>
186187
<Button
188+
buttonType="reset"
187189
disabled={true}
188190
key="form-reset"
189191
label="Reset"
@@ -240,6 +242,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
240242
</Component>
241243
</Button>
242244
<Button
245+
buttonType="cancel"
243246
key="form-cancel"
244247
label="Cancel"
245248
onClick={[MockFunction]}
@@ -443,6 +446,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
443446
className="pf-c-form__actions"
444447
>
445448
<Button
449+
buttonType="submit"
446450
key="form-submit"
447451
label="Submit"
448452
type="submit"
@@ -492,6 +496,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
492496
</Component>
493497
</Button>
494498
<Button
499+
buttonType="cancel"
495500
key="form-cancel"
496501
label="Cancel"
497502
onClick={[MockFunction]}
@@ -713,6 +718,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
713718
className="pf-c-form__actions"
714719
>
715720
<Button
721+
buttonType="cancel"
716722
key="form-cancel"
717723
label="Cancel"
718724
onClick={[MockFunction]}
@@ -766,6 +772,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
766772
</Component>
767773
</Button>
768774
<Button
775+
buttonType="submit"
769776
key="form-submit"
770777
label="Submit"
771778
type="submit"
@@ -815,6 +822,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
815822
</Component>
816823
</Button>
817824
<Button
825+
buttonType="reset"
818826
disabled={true}
819827
key="form-reset"
820828
label="Reset"
@@ -1022,6 +1030,7 @@ exports[`FormTemplate PF4 Common should render only submit button 1`] = `
10221030
className="pf-c-form__actions"
10231031
>
10241032
<Button
1033+
buttonType="submit"
10251034
key="form-submit"
10261035
label="Submit"
10271036
type="submit"

0 commit comments

Comments
 (0)