Skip to content

Commit 18c4196

Browse files
committed
fix(carbon): fix spacing for form template
1 parent 7d68642 commit 18c4196

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import clsx from 'clsx';
34

45
import { Form as CarbonForm, Button as CarbonButton, ButtonSet } from 'carbon-components-react';
56

67
import FormTemplate from '@data-driven-forms/common/src/form-template';
78

9+
import './form-template.scss';
10+
811
export const Button = ({ label, buttonType, ...props }) => (
912
<CarbonButton kind={buttonType === 'submit' ? 'primary' : 'secondary'} {...props}>
1013
{label}
@@ -16,13 +19,18 @@ Button.propTypes = {
1619
buttonType: PropTypes.string
1720
};
1821

19-
export const ButtonGroup = ({ children, ...props }) => <ButtonSet {...props}>{children}</ButtonSet>;
22+
export const ButtonGroup = ({ children, className, ...props }) => (
23+
<ButtonSet {...props} className={clsx('ddorg__carbon-form-template-buttons', className)}>
24+
{children}
25+
</ButtonSet>
26+
);
2027

2128
ButtonGroup.propTypes = {
22-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
29+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
30+
className: PropTypes.string
2331
};
2432

25-
export const Title = ({ children }) => <h1>{children}</h1>;
33+
export const Title = ({ children }) => <h3>{children}</h3>;
2634

2735
Title.propTypes = {
2836
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
@@ -34,16 +42,19 @@ Description.propTypes = {
3442
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
3543
};
3644

37-
export const Form = ({ children, ...props }) => (
38-
<CarbonForm noValidate {...props}>
45+
export const Form = ({ children, className, ...props }) => (
46+
<CarbonForm noValidate {...props} className={clsx('ddorg__carbon-form-template-form', className)}>
3947
{children}
4048
</CarbonForm>
4149
);
4250

4351
Form.propTypes = {
44-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
52+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
53+
className: PropTypes.string
4554
};
4655

56+
export const Header = (props) => <div className="ddorg__carbon-form-template-header" {...props} />;
57+
4758
const WrappedFormTemplate = (props) => (
4859
<FormTemplate
4960
FormWrapper={Form}
@@ -52,6 +63,7 @@ const WrappedFormTemplate = (props) => (
5263
Title={Title}
5364
Description={Description}
5465
buttonOrder={['cancel', 'reset', 'submit']}
66+
Header={Header}
5567
{...props}
5668
/>
5769
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.ddorg__carbon-form-template-buttons {
2+
margin-top: 48px;
3+
}
4+
5+
.ddorg__carbon-form-template-form {
6+
>:not(:last-child) {
7+
margin-bottom: 32px;
8+
}
9+
10+
.ddorg__carbon-form-template-header {
11+
margin-bottom: 40px;
12+
13+
div {
14+
margin-top: 8px;
15+
}
16+
}
17+
}

packages/common/src/form-template.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ const FormTemplate = ({
104104
Button,
105105
ButtonGroup,
106106
formWrapperProps,
107-
showFormControls = true,
108-
disableSubmit = [],
107+
showFormControls,
108+
disableSubmit,
109+
Header,
109110
...rest
110111
}) => {
111112
const {
@@ -116,8 +117,12 @@ const FormTemplate = ({
116117

117118
return (
118119
<FormWrapper onSubmit={handleSubmit} {...formWrapperProps}>
119-
{(title || label) && <Title>{title || label}</Title>}
120-
{description && <Description>{description}</Description>}
120+
{(title || label || description) && (
121+
<Header>
122+
{(title || label) && <Title>{title || label}</Title>}
123+
{description && <Description>{description}</Description>}
124+
</Header>
125+
)}
121126
{formFields}
122127
{showFormControls && (
123128
<FormSpy>
@@ -147,12 +152,14 @@ FormTemplate.propTypes = {
147152
ButtonGroup: PropTypes.oneOfType([PropTypes.node, PropTypes.func, PropTypes.element]).isRequired,
148153
formWrapperProps: PropTypes.object,
149154
showFormControls: PropTypes.bool,
150-
disableSubmit: PropTypes.arrayOf(PropTypes.string)
155+
disableSubmit: PropTypes.arrayOf(PropTypes.string),
156+
Header: PropTypes.oneOfType([PropTypes.node, PropTypes.func, PropTypes.element])
151157
};
152158

153159
FormTemplate.defaultProps = {
154160
showFormControls: true,
155-
disableSubmit: []
161+
disableSubmit: [],
162+
Header: React.Fragment
156163
};
157164

158165
export default FormTemplate;

0 commit comments

Comments
 (0)