Skip to content

Commit

Permalink
feat(carbon-provider): add deprecation warning for roundedCornersOptO…
Browse files Browse the repository at this point in the history
…ut & focusRedesignOptOut

deprecates both feature flags and each respective flags previous styling
  • Loading branch information
tomdavies73 committed Nov 12, 2024
1 parent 03a9f36 commit 99410b5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ export interface NewValidationContextProps {
*
* NOTE - Will eventually be set to `true` by default in the future. */
validationRedesignOptIn?: boolean;
/** Feature flag for opting out of styling components to have rounded corners.
/** (Deprecated) Feature flag for opting out of styling components to have rounded corners.
*
* NOTE - Will eventually be set to `false` by default in the future. */
* NOTE - This feature flag will soon be removed, along with the legacy styling. */
roundedCornersOptOut?: boolean;
/** (Deprecated) Feature flag for opting out of the focus redesign.
*
* NOTE - This feature flag will soon be removed, along with the legacy styling. */
focusRedesignOptOut?: boolean;
}

Expand Down
21 changes: 21 additions & 0 deletions src/components/carbon-provider/carbon-provider.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import NewValidationContext, {
NewValidationContextProps,
} from "./__internal__/new-validation.context";
import TopModalProvider from "./__internal__/top-modal-provider.component";
import Logger from "../../__internal__/utils/logger";

export interface CarbonProviderProps extends NewValidationContextProps {
/* Content for the provider to wrap */
Expand All @@ -17,6 +18,9 @@ export interface CarbonProviderProps extends NewValidationContextProps {
theme?: Partial<ThemeObject>;
}

let deprecatedRoundedCornersOptOut = false;
let deprecatedFocusRedesignOptOut = false;

export const CarbonProvider = ({
children,
theme = sageTheme,
Expand All @@ -33,6 +37,23 @@ export const CarbonProvider = ({
existingRoundedCornersOptOut || roundedCornersOptOut;
const focusRedesignOptOutValue =
existingFocusRedesignOptOut || focusRedesignOptOut;

if (!deprecatedRoundedCornersOptOut && roundedCornersOptOutValue) {
deprecatedRoundedCornersOptOut = true;
Logger.deprecate(
"The `roundedCornersOptOut` feature flag has been deprecated and will soon be removed. " +
"Along with this feature flag, the legacy pre-rounded corners styling will also be removed. ",
);
}

if (!deprecatedFocusRedesignOptOut && focusRedesignOptOutValue) {
deprecatedFocusRedesignOptOut = true;
Logger.deprecate(
"The `focusRedesignOptOut` feature flag has been deprecated and will soon be removed. " +
"Along with this feature flag, the legacy focus styling will also be removed. ",
);
}

return (
<ThemeProvider
theme={{
Expand Down
52 changes: 52 additions & 0 deletions src/components/carbon-provider/carbon-provider.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react";
import { render } from "@testing-library/react";
import CarbonProvider from ".";
import Logger from "../../__internal__/utils/logger";

test("logs a deprecation warning once when the `roundedCornersOptOut` feature flag is `true`", () => {
const loggerSpy = jest
.spyOn(Logger, "deprecate")
.mockImplementation(() => {});

render(
<>
<CarbonProvider roundedCornersOptOut>
<CarbonProvider>Hello World!</CarbonProvider>
</CarbonProvider>
<CarbonProvider roundedCornersOptOut>
<CarbonProvider>Hello World!</CarbonProvider>
</CarbonProvider>
</>,
);

expect(loggerSpy).toHaveBeenCalledWith(
"The `roundedCornersOptOut` feature flag has been deprecated and will soon be removed. " +
"Along with this feature flag, the legacy pre-rounded corners styling will also be removed. ",
);
expect(loggerSpy).toHaveBeenCalledTimes(1);
loggerSpy.mockRestore();
});

test("logs a deprecation warning once when the `focusRedesignOptOut` feature flag is `true`", () => {
const loggerSpy = jest
.spyOn(Logger, "deprecate")
.mockImplementation(() => {});

render(
<>
<CarbonProvider focusRedesignOptOut>
<CarbonProvider>Hello World!</CarbonProvider>
</CarbonProvider>
<CarbonProvider focusRedesignOptOut>
<CarbonProvider>Hello World!</CarbonProvider>
</CarbonProvider>
</>,
);

expect(loggerSpy).toHaveBeenCalledWith(
"The `focusRedesignOptOut` feature flag has been deprecated and will soon be removed. " +
"Along with this feature flag, the legacy focus styling will also be removed. ",
);
expect(loggerSpy).toHaveBeenCalledTimes(1);
loggerSpy.mockRestore();
});

0 comments on commit 99410b5

Please sign in to comment.