Skip to content

Commit

Permalink
Merge pull request #3760 from Sage/FE-3776_remove-style-override
Browse files Browse the repository at this point in the history
refactor(styleoverride): remove styleOverride props from carbon (FE-3776)
  • Loading branch information
nicktitchmarsh authored May 14, 2021
2 parents 94f4a76 + 3ed2a45 commit c5b2e03
Show file tree
Hide file tree
Showing 45 changed files with 26 additions and 782 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Feature: Accessibility tests - Design System folder
Examples:
| story |
| default story |
| styles overriden |
| with dynamic content |

@accessibility
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Address Fieldset for Canada.
label='ZIP Code'
labelInline
labelAlign='right'
styleOverride={ { input: { width: '120px', flex: 'none' } } }
inputWidth={10}
/>
</Fieldset>
</Story>
Expand All @@ -80,7 +80,7 @@ Address Fieldset for EU.
label='Postal Code'
labelInline
labelAlign='right'
styleOverride={ { input: { width: '120px', flex: 'none' } } }
inputWidth={10}
/>
<Textbox
label='Town/City'
Expand Down Expand Up @@ -163,7 +163,7 @@ Address Fieldset for UK and Ireland.
label='Postcode'
labelInline
labelAlign='right'
styleOverride={ { input: { width: '120px', flex: 'none' } } }
inputWidth={10}
/>
</Fieldset>
</Story>
Expand Down Expand Up @@ -214,7 +214,7 @@ Address Fieldset for United States.
label='ZIP Code'
labelInline
labelAlign='right'
styleOverride={ { input: { width: '120px', flex: 'none' } } }
inputWidth={10}
/>
</Fieldset>
</Story>
Expand Down Expand Up @@ -249,7 +249,7 @@ Address Fieldset for other countries.
label='Postal Code'
labelInline
labelAlign='right'
styleOverride={ { input: { width: '120px', flex: 'none' } } }
inputWidth={10}
/>
<Select
label='Country'
Expand Down
24 changes: 1 addition & 23 deletions src/__experimental__/components/fieldset/fieldset.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,17 @@ import {
LegendContainerStyle,
FieldsetContentStyle,
} from "./fieldset.style";
import Logger from "../../../utils/logger/logger";

const marginPropTypes = filterStyledSystemMarginProps(
styledSystemPropTypes.space
);

let deprecatedWarnTriggered = false;

const Fieldset = (props) => {
if (!deprecatedWarnTriggered) {
deprecatedWarnTriggered = true;
// eslint-disable-next-line max-len
Logger.deprecate(
"`styleOverride` that is used in the `Fieldset` component is deprecated and will soon be removed."
);
}

const legend = () => {
if (!props.legend) return null;

return (
<LegendContainerStyle
inline={props.inline}
data-component="legend-style"
styleOverride={props.styleOverride.legend}
>
<LegendContainerStyle inline={props.inline} data-component="legend-style">
<legend data-element="legend">{props.legend}</legend>
</LegendContainerStyle>
);
Expand All @@ -51,7 +36,6 @@ const Fieldset = (props) => {
{...safeProps}
m={0}
{...filterStyledSystemMarginProps(props)}
styleOverride={props.styleOverride.root}
>
<FieldsetContentStyle
data-component="fieldset-style"
Expand All @@ -73,16 +57,10 @@ Fieldset.propTypes = {
legend: PropTypes.string,
/** When true, legend is placed in line with the children */
inline: PropTypes.bool,
/** Allows to override existing component styles */
styleOverride: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
legend: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};

Fieldset.defaultProps = {
inline: false,
styleOverride: {},
};

export default Fieldset;
31 changes: 1 addition & 30 deletions src/__experimental__/components/fieldset/fieldset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import React from "react";
import { shallow, mount } from "enzyme";
import Fieldset from "./fieldset.component";
import Textbox from "../textbox";
import {
LegendContainerStyle,
FieldsetStyle,
FieldsetContentStyle,
} from "./fieldset.style";
import { LegendContainerStyle, FieldsetContentStyle } from "./fieldset.style";
import {
assertStyleMatch,
testStyledSystemMargin,
Expand Down Expand Up @@ -78,29 +74,4 @@ describe("Fieldset", () => {
);
});
});

describe("style overrides", () => {
let wrapper;
const customStyleObject = {
backgroundColor: "red",
display: "flex",
fontSize: "200px",
};
const styleOverride = {
root: customStyleObject,
legend: customStyleObject,
};

beforeEach(() => {
wrapper = render({ styleOverride, legend: "Legend" }, mount);
});

it("renders root element with properly assigned styles", () => {
assertStyleMatch(customStyleObject, wrapper.find(FieldsetStyle));
});

it("renders legend element with properly assigned styles", () => {
assertStyleMatch(customStyleObject, wrapper.find(LegendContainerStyle));
});
});
});
6 changes: 3 additions & 3 deletions src/__experimental__/components/fieldset/fieldset.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ You can manipulate the spacings beetwen `Fieldset` components by passing `fieldS
label="ZIP Code"
labelInline
labelAlign="right"
styleOverride={{ input: { width: "120px", flex: "none" } }}
inputWidth={10}
/>
</Fieldset>
))}
Expand Down Expand Up @@ -178,7 +178,7 @@ You can manipulate the spacings beetwen `Fieldset` components by passing `fieldS
label="ZIP Code"
labelInline
labelAlign="right"
styleOverride={{ input: { width: "120px", flex: "none" } }}
inputWidth={10}
/>
</Fieldset>
))}
Expand Down Expand Up @@ -217,7 +217,7 @@ You can manipulate the spacings beetwen `Fieldset` components by passing `fieldS
label="ZIP Code"
labelInline
labelAlign="right"
styleOverride={{ input: { width: "120px", flex: "none" } }}
inputWidth={10}
/>
</Fieldset>
))}
Expand Down
4 changes: 0 additions & 4 deletions src/__experimental__/components/fieldset/fieldset.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const FieldsetStyle = styled.fieldset`
padding-top: 8px;
padding-bottom: 8px;
}
${({ styleOverride }) => styleOverride};
`;

FieldsetStyle.defaultProps = {
Expand Down Expand Up @@ -49,8 +47,6 @@ const LegendContainerStyle = styled.div`
${ValidationIconStyle} ${StyledIcon}:focus {
outline: 2px solid #ffb500;
}
${({ styleOverride }) => styleOverride};
`;

const FieldsetContentStyle = styled.div`
Expand Down
19 changes: 0 additions & 19 deletions src/__experimental__/components/form-field/form-field.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import Label from "../label";
import FieldHelp from "../field-help";
import OptionsHelper from "../../../utils/helpers/options-helper";
import tagComponent from "../../../utils/helpers/tags";
import Logger from "../../../utils/logger/logger";
import { TabContext } from "../../../components/tabs/tab";
import useIsAboveBreakpoint from "../../../hooks/__internal__/useIsAboveBreakpoint";

let deprecatedWarnTriggered = false;

const FormField = ({
children,
disabled,
Expand Down Expand Up @@ -40,18 +37,9 @@ const FormField = ({
readOnly,
useValidationIcon,
adaptiveLabelBreakpoint,
styleOverride = {},
isRequired,
...props
}) => {
if (!deprecatedWarnTriggered) {
deprecatedWarnTriggered = true;
// eslint-disable-next-line max-len
Logger.deprecate(
"`styleOverride` that is used in the `FormField` component is deprecated and will soon be removed."
);
}

const context = useContext(TabContext);
const largeScreen = useIsAboveBreakpoint(adaptiveLabelBreakpoint);
let inlineLabel = labelInline;
Expand Down Expand Up @@ -121,7 +109,6 @@ const FormField = ({
return (
<FormFieldStyle
{...tagComponent(props["data-component"], props)}
styleOverride={styleOverride.root}
{...spacingProps}
>
<FieldLineStyle inline={inlineLabel}>
Expand Down Expand Up @@ -150,7 +137,6 @@ const FormField = ({
useValidationIcon={useValidationIcon}
pr={!reverse ? labelSpacing : undefined}
pl={reverse ? labelSpacing : undefined}
styleOverride={styleOverride.label}
isRequired={isRequired}
>
{label}
Expand Down Expand Up @@ -226,11 +212,6 @@ FormField.propTypes = {
adaptiveLabelBreakpoint: PropTypes.number,
/** Flag to configure component as mandatory */
isRequired: PropTypes.bool,
/** Allows to override existing component styles */
styleOverride: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
label: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};

export default FormField;
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const FormFieldStyle = styled.div`
&&& {
${space}
}
${({ styleOverride }) => styleOverride};
`;

FormFieldStyle.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import InputPresentationStyle, {
StyledInputPresentationContainer,
} from "./input-presentation.style";
import extractProps from "../../../utils/helpers/extract-props";
import Logger from "../../../utils/logger/logger";

import {
InputContext,
InputGroupContext,
} from "../../../__internal__/input-behaviour";

let deprecatedWarnTriggered = false;

const InputPresentation = (props) => {
const { hasFocus, onMouseDown, onMouseEnter, onMouseLeave } = useContext(
InputContext
Expand All @@ -25,20 +22,7 @@ const InputPresentation = (props) => {
onMouseLeave: onGroupMouseLeave,
} = useContext(InputGroupContext);

if (!deprecatedWarnTriggered) {
deprecatedWarnTriggered = true;
// eslint-disable-next-line max-len
Logger.deprecate(
"`styleOverride` that is used in the `InputPresentation` component is deprecated and will soon be removed."
);
}
const {
children,
styleOverride,
positionedChildren,
inputWidth,
...rest
} = props;
const { children, positionedChildren, inputWidth, ...rest } = props;
const styleProps = extractProps(rest, InputPresentationStyle);

const handleMouseEnter = (e) => {
Expand All @@ -60,7 +44,6 @@ const InputPresentation = (props) => {
onMouseDown={onMouseDown}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
styleOverride={styleOverride}
{...styleProps}
>
{children}
Expand All @@ -71,7 +54,6 @@ const InputPresentation = (props) => {

InputPresentation.propTypes = {
children: PropTypes.node,
/** Allows to override existing component styles */
align: PropTypes.string,
disabled: PropTypes.bool,
hasFocus: PropTypes.bool,
Expand All @@ -82,7 +64,6 @@ InputPresentation.propTypes = {
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
warning: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
info: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
styleOverride: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};

export default InputPresentation;
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const InputPresentationStyle = styled.div`
input::-webkit-contacts-auto-fill-button {
display: none !important;
}
${({ styleOverride }) => styleOverride};
`;

function stylingForValidations({ theme, error, warning, info, disabled }) {
Expand Down Expand Up @@ -127,7 +125,6 @@ InputPresentationStyle.propTypes = {
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
warning: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
info: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
styleOverride: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};

export default InputPresentationStyle;
3 changes: 0 additions & 3 deletions src/__experimental__/components/input/input.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const StyledInput = styled.input`
css`
color: ${theme.readOnly.textboxText};
`}
${({ styleOverride }) => styleOverride};
`;

StyledInput.defaultProps = {
Expand All @@ -54,7 +52,6 @@ StyledInput.defaultProps = {

StyledInput.propTypes = {
disabled: PropTypes.bool,
styleOverride: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};

export default StyledInput;
Loading

0 comments on commit c5b2e03

Please sign in to comment.