Skip to content

Commit 7128b6b

Browse files
feat(slash): refactor component to separate children and contentRight
1 parent 3ba9ba1 commit 7128b6b

File tree

5 files changed

+67
-38
lines changed

5 files changed

+67
-38
lines changed

apps/slash-stories/src/Layout/HeaderTitle/HeaderTitle.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ export default TitleComponent;
3939
<Canvas of={HeaderTitleStories.ComplexTitle} />
4040
<Controls of={HeaderTitleStories.ComplexTitle} />
4141

42-
### Complex Title with ContentLeft
42+
### Complex Title with Content and Children
4343

44-
When you need to add an action to the title to handle a back button for example, you can use the `contentLeft` property. The property accepts a ReactNode to give you the flexibility to add any content you want.
44+
When you need to handle a navigation action , a back button for example, you can use the `contentLeft` property. For other others actions you should put them the right side of the title bar with the `contentRight` property. Passing children allows you to add additional content after the title and subtitle.
45+
The properties accepts a ReactNode to give you the flexibility to add any content you want.
4546

46-
<Canvas of={HeaderTitleStories.ComplexTitleWithContentLeft} />
47-
<Controls of={HeaderTitleStories.ComplexTitleWithContentLeft} />
47+
<Canvas of={HeaderTitleStories.ComplexTitleWithContentAndChildren} />
48+
<Controls of={HeaderTitleStories.ComplexTitleWithContentAndChildren} />

apps/slash-stories/src/Layout/HeaderTitle/HeaderTitle.stories.tsx

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Action, HeaderTitle, Svg } from "@axa-fr/design-system-slash-react";
1+
import {
2+
Action,
3+
Badge,
4+
HeaderTitle,
5+
Svg,
6+
} from "@axa-fr/design-system-slash-react";
27
import deleteIcon from "@material-symbols/svg-400/outlined/delete.svg";
38
import mailIcon from "@material-symbols/svg-400/outlined/mail.svg";
49
import saveIcon from "@material-symbols/svg-400/outlined/save.svg";
@@ -67,7 +72,7 @@ export const DefaultTitle: StoryObj<typeof HeaderTitle> = {};
6772

6873
export const ComplexTitle: StoryObj<typeof HeaderTitle> = {
6974
args: {
70-
children: (
75+
contentRight: (
7176
<div className="af-title-bar__actions">
7277
{actions.map(({ icon, id, title }: ComponentProps<typeof Action>) => (
7378
<a
@@ -85,39 +90,41 @@ export const ComplexTitle: StoryObj<typeof HeaderTitle> = {
8590
},
8691
};
8792

88-
export const ComplexTitleWithContentLeft: StoryObj<typeof HeaderTitle> = {
89-
args: {
90-
contentLeft: (
91-
<div className="af-title-bar__actions">
92-
{leftActions.map(
93-
({ icon, id, title }: ComponentProps<typeof Action>) => (
93+
export const ComplexTitleWithContentAndChildren: StoryObj<typeof HeaderTitle> =
94+
{
95+
args: {
96+
contentLeft: (
97+
<div className="af-title-bar__actions">
98+
{leftActions.map(
99+
({ icon, id, title }: ComponentProps<typeof Action>) => (
100+
<a
101+
key={id}
102+
href="/#"
103+
role="button"
104+
title={title}
105+
className="btn af-btn--circle"
106+
>
107+
<Svg src={icon} />
108+
</a>
109+
),
110+
)}
111+
</div>
112+
),
113+
children: <Badge classModifier="success"> Statut OK </Badge>,
114+
contentRight: (
115+
<div className="af-title-bar__actions">
116+
{actions.map(({ icon, id, title }: ComponentProps<typeof Action>) => (
94117
<a
95118
key={id}
96119
href="/#"
97120
role="button"
98121
title={title}
99-
className="btn af-btn--circle"
122+
className="btn af-btn--circle"
100123
>
101124
<Svg src={icon} />
102125
</a>
103-
),
104-
)}
105-
</div>
106-
),
107-
children: (
108-
<div className="af-title-bar__actions">
109-
{actions.map(({ icon, id, title }: ComponentProps<typeof Action>) => (
110-
<a
111-
key={id}
112-
href="/#"
113-
role="button"
114-
title={title}
115-
className="btn af-btn--circle"
116-
>
117-
<Svg src={icon} />
118-
</a>
119-
))}
120-
</div>
121-
),
122-
},
123-
};
126+
))}
127+
</div>
128+
),
129+
},
130+
};

slash/css/src/Layout/Header/HeaderTitle/HeaderTitle.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
gap: 1rem;
3838
}
3939

40+
&__rightSection {
41+
display: flex;
42+
align-items: center;
43+
}
44+
4045
&__title {
4146
display: inline-block;
4247
margin: 0;

slash/react/src/Layout/Header/HeaderTitle/HeaderTitle.spec.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { render, screen } from "@testing-library/react";
22
import { axe } from "jest-axe";
33
import { HeaderTitle } from "./HeaderTitle";
4+
import { Badge } from "../../../Badge/Badge";
45

56
describe("HeaderTitle", () => {
67
test("should render title and subtitle", async () => {
@@ -14,21 +15,29 @@ describe("HeaderTitle", () => {
1415
expect(screen.getByText("Subtitle")).toBeInTheDocument();
1516
});
1617

17-
test("should render leftSection", async () => {
18+
test("should render contentLeft", async () => {
1819
const { container } = render(
1920
<HeaderTitle title="Title" contentLeft={<span>Left</span>} />,
2021
);
2122
expect(await axe(container)).toHaveNoViolations();
2223
expect(screen.getByText("Left")).toBeInTheDocument();
2324
});
2425

26+
test("should render contentRight", async () => {
27+
const { container } = render(
28+
<HeaderTitle title="Title" contentRight={<span>Right</span>} />,
29+
);
30+
expect(await axe(container)).toHaveNoViolations();
31+
expect(screen.getByText("Right")).toBeInTheDocument();
32+
});
33+
2534
test("should render children", async () => {
2635
const { container } = render(
2736
<HeaderTitle title="Title">
28-
<div>Child content</div>
37+
<Badge classModifier="success"> Lorem ipsum </Badge>
2938
</HeaderTitle>,
3039
);
3140
expect(await axe(container)).toHaveNoViolations();
32-
expect(screen.getByText("Child content")).toBeInTheDocument();
41+
expect(screen.getByText("Lorem ipsum")).toBeInTheDocument();
3342
});
3443
});

slash/react/src/Layout/Header/HeaderTitle/HeaderTitle.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Props = {
1414
className?: string;
1515
isSticky?: boolean;
1616
contentLeft?: ReactNode;
17+
contentRight?: ReactNode;
1718
subtitle?: string;
1819
title: string;
1920
toggleMenu?: () => void;
@@ -25,6 +26,7 @@ const HeaderTitle = ({
2526
className,
2627
isSticky = true,
2728
contentLeft,
29+
contentRight,
2830
subtitle,
2931
title,
3032
toggleMenu,
@@ -60,8 +62,13 @@ const HeaderTitle = ({
6062
</span>
6163
)}
6264
</h1>
65+
{children}
6366
</div>
64-
{children}
67+
{contentRight && (
68+
<div className={`${defaultClassName}__rightSection`}>
69+
{contentRight}
70+
</div>
71+
)}
6572
</div>
6673
</div>
6774
);

0 commit comments

Comments
 (0)