Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(carbon): fix spacing for form template #813

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions packages/carbon-component-mapper/src/files/form-template.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';

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

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

import './form-template.scss';

export const Button = ({ label, buttonType, ...props }) => (
<CarbonButton kind={buttonType === 'submit' ? 'primary' : 'secondary'} {...props}>
{label}
Expand All @@ -16,13 +19,18 @@ Button.propTypes = {
buttonType: PropTypes.string
};

export const ButtonGroup = ({ children, ...props }) => <ButtonSet {...props}>{children}</ButtonSet>;
export const ButtonGroup = ({ children, className, ...props }) => (
<ButtonSet {...props} className={clsx('ddorg__carbon-form-template-buttons', className)}>
{children}
</ButtonSet>
);

ButtonGroup.propTypes = {
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
className: PropTypes.string
};

export const Title = ({ children }) => <h1>{children}</h1>;
export const Title = ({ children }) => <h3>{children}</h3>;

Title.propTypes = {
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
Expand All @@ -34,16 +42,19 @@ Description.propTypes = {
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
};

export const Form = ({ children, ...props }) => (
<CarbonForm noValidate {...props}>
export const Form = ({ children, className, ...props }) => (
<CarbonForm noValidate {...props} className={clsx('ddorg__carbon-form-template-form', className)}>
{children}
</CarbonForm>
);

Form.propTypes = {
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
className: PropTypes.string
};

export const Header = (props) => <div className="ddorg__carbon-form-template-header" {...props} />;

const WrappedFormTemplate = (props) => (
<FormTemplate
FormWrapper={Form}
Expand All @@ -52,6 +63,7 @@ const WrappedFormTemplate = (props) => (
Title={Title}
Description={Description}
buttonOrder={['cancel', 'reset', 'submit']}
Header={Header}
{...props}
/>
);
Expand Down
17 changes: 17 additions & 0 deletions packages/carbon-component-mapper/src/files/form-template.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.ddorg__carbon-form-template-buttons {
margin-top: 48px;
}

.ddorg__carbon-form-template-form {
>:not(:last-child) {
margin-bottom: 32px;
}

.ddorg__carbon-form-template-header {
margin-bottom: 40px;

div {
margin-top: 8px;
}
}
}
19 changes: 13 additions & 6 deletions packages/common/src/form-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ const FormTemplate = ({
Button,
ButtonGroup,
formWrapperProps,
showFormControls = true,
disableSubmit = [],
showFormControls,
disableSubmit,
Header,
...rest
}) => {
const {
Expand All @@ -116,8 +117,12 @@ const FormTemplate = ({

return (
<FormWrapper onSubmit={handleSubmit} {...formWrapperProps}>
{(title || label) && <Title>{title || label}</Title>}
{description && <Description>{description}</Description>}
{(title || label || description) && (
<Header>
{(title || label) && <Title>{title || label}</Title>}
{description && <Description>{description}</Description>}
</Header>
)}
{formFields}
{showFormControls && (
<FormSpy>
Expand Down Expand Up @@ -147,12 +152,14 @@ FormTemplate.propTypes = {
ButtonGroup: PropTypes.oneOfType([PropTypes.node, PropTypes.func, PropTypes.element]).isRequired,
formWrapperProps: PropTypes.object,
showFormControls: PropTypes.bool,
disableSubmit: PropTypes.arrayOf(PropTypes.string)
disableSubmit: PropTypes.arrayOf(PropTypes.string),
Header: PropTypes.oneOfType([PropTypes.node, PropTypes.func, PropTypes.element, PropTypes.oneOf([React.Fragment])])
};

FormTemplate.defaultProps = {
showFormControls: true,
disableSubmit: []
disableSubmit: [],
Header: React.Fragment
};

export default FormTemplate;
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ exports[`<Input Addon> should render group button before input addon correctly 1
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -948,6 +949,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -1621,6 +1623,7 @@ exports[`<Input Addon> should render single after input addon correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -2068,6 +2071,7 @@ exports[`<Input Addon> should render single before input addon correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -2510,6 +2514,7 @@ exports[`<Input Addon> should render single button after input addon correctly 1
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -2986,6 +2991,7 @@ exports[`<Input Addon> should render single button before input addon correctly
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -3706,6 +3712,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ exports[`<MultipleChoiceList /> should render correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -893,6 +894,7 @@ exports[`<MultipleChoiceList /> should render in error state 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ exports[`<Wizard /> should render Wizard correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -876,6 +877,7 @@ exports[`<Wizard /> should render Wizard with conditional steps correctly 1`] =
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -1685,6 +1687,7 @@ exports[`<Wizard /> should render Wizard with stepsInfo correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -2508,6 +2511,7 @@ exports[`<Wizard /> should render Wizard with title correctly 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
buttonOrder={Array []}
canReset={true}
Expand Down Expand Up @@ -270,6 +271,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -485,6 +487,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
buttonOrder={
Array [
Expand Down Expand Up @@ -731,6 +734,7 @@ exports[`FormTemplate PF4 Common should render only submit button 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
canReset={false}
disableSubmit={Array []}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down Expand Up @@ -1285,6 +1286,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
ButtonGroup={[Function]}
Description={[Function]}
FormWrapper={[Function]}
Header={Symbol(react.fragment)}
Title={[Function]}
disableSubmit={Array []}
formFields={
Expand Down