Skip to content

Commit 4f56235

Browse files
committed
feat(breadcrumbs): align with Fusion DS
Aligns Breadcrumbs component to Fusion DS. Updates styles using fusion-tokens and adds new `inverse` prop. Deprecates `isDarkBackground` prop from Breadcrumbs and `hasFocus`, `underline`, `linkSize` and `bold` props from Crumb.
1 parent c5c5949 commit 4f56235

17 files changed

+243
-400
lines changed

playwright/components/link/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Page } from "@playwright/test";
22
import { link } from "..";
3-
import { SKIP_LINK } from "./locators";
3+
import { SKIP_LINK, LINK } from "./locators";
44

55
// component preview locators
66
export const linkChildren = (page: Page) => {
@@ -12,3 +12,5 @@ export const skipLink = (page: Page) => {
1212
};
1313

1414
export const relLink = (page: Page) => link(page).locator("a");
15+
16+
export const linkComponent = (page: Page) => page.locator(LINK);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// component preview locators
2-
/* eslint-disable import/prefer-default-export */
32
export const SKIP_LINK = '[data-element="skip-link"]';
3+
export const LINK = '[data-component="link"]';

src/components/breadcrumbs/__internal__/breadcrumbs.context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createStrictContext from "../../../__internal__/utils/createStrictContext";
22

33
export type BreadcrumbsContextType = {
4-
isDarkBackground: boolean;
4+
inverse?: boolean;
55
};
66

77
const [BreadcrumbsProvider, useBreadcrumbsContext] =
@@ -10,7 +10,7 @@ const [BreadcrumbsProvider, useBreadcrumbsContext] =
1010
errorMessage:
1111
"Carbon Breadcrumbs: Context not found. Have you wrapped your Carbon subcomponents properly? See stack trace for more details.",
1212
defaultValue: {
13-
isDarkBackground: false,
13+
inverse: false,
1414
},
1515
});
1616

src/components/breadcrumbs/breadcrumbs-interaction.stories.tsx

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,34 @@
11
import React from "react";
2-
import { Breadcrumbs, BreadcrumbsProps } from ".";
3-
import { Crumb, CrumbProps } from "./crumb";
2+
import { Meta, StoryObj } from "@storybook/react";
43

5-
export default {
4+
import { Breadcrumbs, Crumb } from ".";
5+
import generateStyledSystemProps from "../../../.storybook/utils/styled-system-props";
6+
7+
const styledSystemProps = generateStyledSystemProps({
8+
spacing: true,
9+
});
10+
11+
const meta: Meta<typeof Breadcrumbs> = {
612
title: "Breadcrumbs/Test",
7-
includeStories: ["DefaultCrumb", "WhenFocusedCrumbBecomesCurrent"],
8-
parameters: {
9-
info: { disable: true },
10-
chromatic: {
11-
disableSnapshot: true,
12-
},
13-
},
13+
component: Breadcrumbs,
14+
subcomponents: { Crumb },
1415
argTypes: {
15-
isCurrent: {
16-
control: {
17-
type: "boolean",
18-
},
19-
},
20-
href: {
21-
control: {
22-
type: "text",
23-
},
24-
},
25-
isDarkBackground: {
26-
control: {
27-
type: "boolean",
28-
},
29-
},
16+
...styledSystemProps,
17+
},
18+
parameters: {
19+
chromatic: { disableSnapshot: true },
3020
},
3121
};
3222

33-
export const Default = (props: Partial<BreadcrumbsProps>) => {
34-
return (
35-
<Breadcrumbs {...props}>
36-
<Crumb href="#">Breadcrumb 1</Crumb>
37-
<Crumb href="#">Breadcrumb 2</Crumb>
38-
<Crumb href="#">Breadcrumb 3</Crumb>
39-
<Crumb href="#" isCurrent>
40-
Current Page
41-
</Crumb>
42-
</Breadcrumbs>
43-
);
44-
};
45-
46-
export const DefaultCrumb = (props: Partial<CrumbProps>) => {
47-
return (
48-
<Breadcrumbs>
49-
<Crumb href="#" {...props}>
50-
Breadcrumb 1
51-
</Crumb>
52-
</Breadcrumbs>
53-
);
54-
};
23+
export default meta;
24+
type Story = StoryObj<typeof Breadcrumbs>;
5525

56-
export const WhenFocusedCrumbBecomesCurrent = () => {
26+
export const WhenFocusedCrumbBecomesCurrent: Story = ({ ...args }) => {
5727
const [current, setCurrent] = React.useState(false);
5828

5929
return (
6030
<>
61-
<Breadcrumbs>
31+
<Breadcrumbs {...args}>
6232
<Crumb href="#bar" onClick={() => setCurrent(true)} isCurrent={current}>
6333
Crumb{current ? "" : " not"} current
6434
</Crumb>
@@ -68,7 +38,4 @@ export const WhenFocusedCrumbBecomesCurrent = () => {
6838
</>
6939
);
7040
};
71-
72-
Default.storyName = "default";
73-
DefaultCrumb.storyName = "single crumb";
7441
WhenFocusedCrumbBecomesCurrent.storyName = "when focused crumb becomes current";

src/components/breadcrumbs/breadcrumbs.component.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,42 @@ import tagComponent, { TagProps } from "../../__internal__/utils/helpers/tags";
44
import StyledBreadcrumbs from "./breadcrumbs.style";
55
import useLocale from "../../hooks/__internal__/useLocale";
66
import { BreadcrumbsProvider } from "./__internal__/breadcrumbs.context";
7+
import Logger from "../../__internal__/utils/logger";
8+
9+
let deprecatedIsDarkBackgroundWarn = false;
710

811
export interface BreadcrumbsProps extends TagProps, SpaceProps {
912
/** Child crumbs to display */
1013
children: React.ReactNode;
11-
/** Sets the colour styling when component is rendered on a dark background */
14+
/**
15+
* Sets the colour styling when component is rendered on a dark background
16+
* @deprecated The 'isDarkBackground' prop in Breadcrumbs is deprecated and will soon be removed. Please use the 'inverse' prop instead.
17+
*/
1218
isDarkBackground?: boolean;
19+
/** Sets the colour styling when component is to be rendered with inverse styles */
20+
inverse?: boolean;
1321
}
1422

1523
export const Breadcrumbs = React.forwardRef<HTMLElement, BreadcrumbsProps>(
16-
({ children, isDarkBackground = false, ...rest }: BreadcrumbsProps, ref) => {
17-
const l = useLocale();
24+
(
25+
{ children, isDarkBackground = false, inverse, ...rest }: BreadcrumbsProps,
26+
ref,
27+
) => {
28+
const locale = useLocale();
29+
30+
if (isDarkBackground && !deprecatedIsDarkBackgroundWarn) {
31+
Logger.deprecate(
32+
"The 'isDarkBackground' prop in Breadcrumbs is deprecated and will soon be removed. Please use the 'inverse' prop instead.",
33+
);
34+
deprecatedIsDarkBackgroundWarn = true;
35+
}
36+
1837
return (
19-
<BreadcrumbsProvider value={{ isDarkBackground }}>
38+
<BreadcrumbsProvider value={{ inverse: inverse ?? isDarkBackground }}>
2039
<StyledBreadcrumbs
2140
ref={ref}
2241
role="navigation"
23-
aria-label={l.breadcrumbs.ariaLabel()}
42+
aria-label={locale.breadcrumbs.ariaLabel()}
2443
{...rest}
2544
{...tagComponent("breadcrumbs", rest)}
2645
>

src/components/breadcrumbs/breadcrumbs.mdx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Meta, ArgTypes, Canvas } from "@storybook/blocks";
22
import TranslationKeysTable from "../../../.storybook/utils/translation-keys-table";
33

4-
import * as CrumbStories from "./crumb/crumb.stories.tsx";
54
import * as BreadcrumbsStories from "./breadcrumbs.stories.tsx";
65

76
<Meta of={BreadcrumbsStories} />
@@ -10,7 +9,7 @@ import * as BreadcrumbsStories from "./breadcrumbs.stories.tsx";
109

1110
<a
1211
target="_blank"
13-
href="https://zeroheight.com/2ccf2b601/p/32c1b6-breadcrumbs/b/87b2c7"
12+
href="https://zeroheight.com/35ee2cc26/v/latest/p/081839-breadcrumbs"
1413
style={{ color: "#007E45", fontWeight: "bold", textDecoration: "underline" }}
1514
rel="noreferrer"
1615
>
@@ -40,22 +39,16 @@ import { Breadcrumbs, Crumb } from "carbon-react/lib/components/breadcrumbs";
4039

4140
<Canvas of={BreadcrumbsStories.Default} />
4241

43-
### On Dark Background
42+
### Inverse
4443

45-
You can use the `isDarkBackground` prop to change the colour of the breadcrumbs when they are on a dark background.
44+
You can use the `inverse` prop to render the Breadcrumbs with inverse styling.
4645

47-
<Canvas of={BreadcrumbsStories.OnDarkBackground} />
46+
<Canvas of={BreadcrumbsStories.Inverse} />
4847

4948
## Props
5049

51-
### Breadcrumbs
52-
5350
<ArgTypes of={BreadcrumbsStories} />
5451

55-
### Crumb
56-
57-
<ArgTypes of={CrumbStories} />
58-
5952
## Translation keys
6053

6154
The following keys are available to override the translations for this component by passing in a custom locale object to the

0 commit comments

Comments
 (0)