Skip to content

Commit 8d7ae57

Browse files
authored
Merge pull request #827 from rvsia/fixStylingCarbonComponents
fix(carbon): fix styles for wizard/subform/tabs
2 parents c2591e5 + da5ce08 commit 8d7ae57

File tree

13 files changed

+78
-18
lines changed

13 files changed

+78
-18
lines changed

packages/carbon-component-mapper/src/files/sub-form.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Field, AnyObject } from "@data-driven-forms/react-form-renderer";
22
import { ReactNode } from "react";
33

4-
export interface SubFormProps {
4+
export interface SubFormProps extends Omit<React.HTMLProps<HTMLDivElement>, 'title'> {
55
fields: Field | Field[];
66
title?: ReactNode;
77
description?: ReactNode;
88
TitleElement?: string;
99
DescriptionElement?: string;
1010
TitleProps?: AnyObject;
1111
DescriptionProps?: AnyObject;
12+
HeaderProps?: React.HTMLProps<HTMLDivElement>;
1213
}
1314

1415
declare const SubForm: React.ComponentType<SubFormProps>;

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

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

45
import { useFormApi } from '@data-driven-forms/react-form-renderer';
56

6-
const SubForm = ({ fields, component, title, description, TitleElement, DescriptionElement, TitleProps, DescriptionProps, ...rest }) => {
7+
import './sub-form.scss';
8+
9+
const SubForm = ({ fields, component, title, description, TitleElement, DescriptionElement, TitleProps, DescriptionProps, HeaderProps, ...rest }) => {
710
const formOptions = useFormApi();
811

912
return (
10-
<div {...rest}>
11-
{title && React.createElement(TitleElement, TitleProps, title)}
12-
{description && React.createElement(DescriptionElement, DescriptionProps, description)}
13+
<div {...rest} className={clsx('ddorg__carbon-sub-form', rest.className)}>
14+
{(title || description) && (
15+
<div {...HeaderProps}>
16+
{title && React.createElement(TitleElement, TitleProps, title)}
17+
{description && React.createElement(DescriptionElement, DescriptionProps, description)}
18+
</div>
19+
)}
1320
{formOptions.renderForm(fields, formOptions)}
1421
</div>
1522
);
@@ -23,7 +30,8 @@ SubForm.propTypes = {
2330
TitleElement: PropTypes.string,
2431
DescriptionElement: PropTypes.string,
2532
TitleProps: PropTypes.object,
26-
DescriptionProps: PropTypes.object
33+
DescriptionProps: PropTypes.object,
34+
HeaderProps: PropTypes.object
2735
};
2836

2937
SubForm.defaultProps = {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.ddorg__carbon-sub-form {
2+
>:not(:last-child) {
3+
margin-bottom: 32px;
4+
}
5+
}

packages/carbon-component-mapper/src/files/tabs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface TabField extends TabProps {
1212

1313
export interface TabsProps extends CarbonTabsProps {
1414
fields: TabField[];
15+
TabWrapperProps?: React.HTMLProps<HTMLDivElement>;
1516
}
1617

1718
declare const Tabs: React.ComponentType<TabsProps>;

packages/carbon-component-mapper/src/files/tabs.js

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

45
import { Tabs as CarbonTabs, Tab } from 'carbon-components-react';
56

67
import { useFormApi } from '@data-driven-forms/react-form-renderer';
78

8-
const Tabs = ({ fields, component, name, ...props }) => {
9+
import './tabs.scss';
10+
11+
const Tabs = ({ fields, component, name, TabWrapperProps, ...props }) => {
912
const formOptions = useFormApi();
1013

1114
return (
1215
<CarbonTabs {...props}>
1316
{fields.map(({ fields, name, label, title, ...rest }) => (
14-
<Tab {...rest} id={name} key={name} label={label || title}>
15-
{formOptions.renderForm(fields, formOptions)}
17+
<Tab {...rest} className="pepa" id={name} key={name} label={label || title}>
18+
<div {...TabWrapperProps} className={clsx('ddorg__carbon-form-template-tab', TabWrapperProps.className)}>
19+
{formOptions.renderForm(fields, formOptions)}
20+
</div>
1621
</Tab>
1722
))}
1823
</CarbonTabs>
1924
);
2025
};
2126

2227
Tabs.propTypes = {
28+
TabWrapperProps: PropTypes.object,
2329
component: PropTypes.string,
2430
name: PropTypes.string,
2531
fields: PropTypes.arrayOf(
@@ -32,4 +38,8 @@ Tabs.propTypes = {
3238
)
3339
};
3440

41+
Tabs.defaultProps = {
42+
TabWrapperProps: {}
43+
};
44+
3545
export default Tabs;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.ddorg__carbon-form-template-tab {
2+
>:not(:last-child) {
3+
margin-bottom: 32px;
4+
}
5+
}

packages/carbon-component-mapper/src/files/wizard.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface WizardProps {
5050
ProgressIndicatorProps?: ProgressIndicatorProps;
5151
vertical?: boolean;
5252
stepsInfo?: WizardNavItem[];
53+
WizardBodyProps?: React.HTMLProps<HTMLDivElement>;
5354
}
5455

5556
declare const Wizard: React.ComponentType<WizardProps>;

packages/carbon-component-mapper/src/files/wizard.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,38 @@ const defaultLabels = {
3939
next: 'Next'
4040
};
4141

42-
const Layout = ({ nav, fields }) => (
42+
const Layout = ({ nav, fields, WizardBodyProps }) => (
4343
<React.Fragment>
4444
{nav}
45-
{fields}
45+
<div {...WizardBodyProps} className={clsx('ddorg__carbon-wizard-body', WizardBodyProps?.className)}>
46+
{fields}
47+
</div>
4648
</React.Fragment>
4749
);
4850

4951
Layout.propTypes = {
5052
nav: PropTypes.node,
51-
fields: PropTypes.node
53+
fields: PropTypes.node,
54+
WizardBodyProps: PropTypes.object
5255
};
5356

54-
const VerticalLayout = ({ nav, fields }) => (
57+
const VerticalLayout = ({ nav, fields, WizardBodyProps }) => (
5558
<Grid narrow>
5659
<Row>
5760
<Column sm={1} md={2} lg={3}>
5861
{nav}
5962
</Column>
60-
<Column>{fields}</Column>
63+
<Column {...WizardBodyProps} className={clsx('ddorg__carbon-wizard-body', WizardBodyProps?.className)}>
64+
{fields}
65+
</Column>
6166
</Row>
6267
</Grid>
6368
);
6469

6570
VerticalLayout.propTypes = {
6671
nav: PropTypes.node,
67-
fields: PropTypes.node
72+
fields: PropTypes.node,
73+
WizardBodyProps: PropTypes.object
6874
};
6975

7076
const WizardInternal = ({
@@ -76,6 +82,7 @@ const WizardInternal = ({
7682
SubmitButtonProps,
7783
ProgressIndicatorProps,
7884
vertical,
85+
WizardBodyProps,
7986
...props
8087
}) => {
8188
const { formOptions, currentStep, handlePrev, onKeyDown, handleNext, activeStepIndex, selectNext, jumpToStep } = useContext(WizardContext);
@@ -94,7 +101,7 @@ const WizardInternal = ({
94101

95102
return (
96103
<div onKeyDown={onKeyDown} {...props}>
97-
<WizardLayout nav={nav ? nav : null} fields={fields} />
104+
<WizardLayout nav={nav ? nav : null} fields={fields} WizardBodyProps={WizardBodyProps} />
98105
<FormSpy>
99106
{({ invalid, validating, submitting }) => (
100107
<div {...ButtonSetProps} className={clsx('ddorg__carbon-wizard-button-set', ButtonSetProps.className)}>
@@ -141,15 +148,17 @@ WizardInternal.propTypes = {
141148
SubmitButtonProps: PropTypes.object,
142149
ButtonSetProps: PropTypes.object,
143150
ProgressIndicatorProps: PropTypes.object,
144-
vertical: PropTypes.bool
151+
vertical: PropTypes.bool,
152+
WizardBodyProps: PropTypes.object
145153
};
146154

147155
WizardInternal.defaultProps = {
148156
BackButtonProps: {},
149157
NextButtonProps: {},
150158
SubmitButtonProps: {},
151159
ButtonSetProps: {},
152-
ProgressIndicatorProps: {}
160+
ProgressIndicatorProps: {},
161+
WizardBodyProps: {}
153162
};
154163

155164
const Wizard = (props) => <WizardCommon Wizard={WizardInternal} {...props} />;

packages/carbon-component-mapper/src/files/wizard.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77
flex-direction: row-reverse;
88
display: flex;
99
}
10+
11+
.ddorg__carbon-wizard-body {
12+
>:not(:last-child) {
13+
margin-bottom: 32px;
14+
}
15+
}

packages/react-renderer-demo/src/doc-components/examples-texts/carbon/carbon-sub-form.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
|TitleProps|Props passed to the element wrapping title|{}|
77
|DescriptionElement|Element wrapping description|p|
88
|DescriptionProps|Props passed to the element wrapping description|{}|
9+
|HeaderProps|Props passed to a div wrapping Title and Description|undefined|

0 commit comments

Comments
 (0)