Skip to content

Commit 5f9f086

Browse files
feat(slash): add headerTitle left content
1 parent 587bb14 commit 5f9f086

File tree

5 files changed

+124
-17
lines changed

5 files changed

+124
-17
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ export default TitleComponent;
3838

3939
<Canvas of={HeaderTitleStories.ComplexTitle} />
4040
<Controls of={HeaderTitleStories.ComplexTitle} />
41+
42+
### Complex Title with LefSection
43+
44+
<Canvas of={HeaderTitleStories.ComplexTitleWithLeftSection} />
45+
<Controls of={HeaderTitleStories.ComplexTitleWithLeftSection} />

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Action, HeaderTitle, Svg } from "@axa-fr/design-system-slash-react";
22
import deleteIcon from "@material-symbols/svg-400/outlined/delete.svg";
33
import mailIcon from "@material-symbols/svg-400/outlined/mail.svg";
44
import saveIcon from "@material-symbols/svg-400/outlined/save.svg";
5+
import homeIcon from "@material-symbols/svg-400/outlined/home.svg";
6+
import chevronLeftIcon from "@material-symbols/svg-400/outlined/chevron_left.svg";
57
import { Meta, StoryObj } from "@storybook/react";
68
import { fn } from "@storybook/test";
79
import { ComponentProps } from "react";
@@ -48,6 +50,19 @@ const actions = [
4850
},
4951
];
5052

53+
const leftActions = [
54+
{
55+
id: "001",
56+
icon: homeIcon,
57+
title: "Accueil",
58+
},
59+
{
60+
id: "002",
61+
icon: chevronLeftIcon,
62+
title: "Retour",
63+
},
64+
];
65+
5166
export const DefaultTitle: StoryObj<typeof HeaderTitle> = {};
5267

5368
export const ComplexTitle: StoryObj<typeof HeaderTitle> = {
@@ -69,3 +84,40 @@ export const ComplexTitle: StoryObj<typeof HeaderTitle> = {
6984
),
7085
},
7186
};
87+
88+
export const ComplexTitleWithLeftSection: StoryObj<typeof HeaderTitle> = {
89+
args: {
90+
leftSection: (
91+
<div className="af-title-bar__actions">
92+
{leftActions.map(
93+
({ icon, id, title }: ComponentProps<typeof Action>) => (
94+
<a
95+
key={id}
96+
href="/#"
97+
role="button"
98+
title={title}
99+
className="btn af-btn--circle"
100+
>
101+
<Svg src={icon} />
102+
</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+
};

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
margin-bottom: 2rem;
66
padding: 1rem 0;
77
overflow: auto;
8-
color: common.$white;
9-
background: common.$brand-primary;
8+
color: var(--white);
9+
background: var(--axablue80);
1010

1111
&--sticky {
1212
position: sticky;
@@ -31,32 +31,38 @@
3131
}
3232
}
3333

34+
&__leftSection {
35+
display: flex;
36+
align-items: center;
37+
gap: 1rem;
38+
}
39+
3440
&__title {
3541
display: inline-block;
3642
margin: 0;
3743
font-weight: 600;
38-
color: common.$white;
44+
color: var(--white);
3945
}
4046

4147
&__subtitle {
4248
margin-left: 0.25rem;
4349
font-weight: 400;
44-
color: common.$color-blue-subtitle;
50+
color: var(--bluesubtitle);
4551
}
4652

4753
&__actions {
4854
display: flex;
4955

5056
.btn {
51-
fill: common.$white;
52-
transition: fill 0.3s;
5357
display: flex;
54-
align-items: center;
5558
flex-direction: column;
59+
align-items: center;
5660
justify-content: center;
61+
transition: fill 0.3s;
62+
fill: var(--white);
5763

5864
&:hover {
59-
fill: common.$brand-primary;
65+
fill: var(--axablue80);
6066
}
6167

6268
svg {
@@ -69,12 +75,12 @@
6975
vertical-align: middle;
7076

7177
.injected-svg {
72-
color: common.$white;
78+
color: var(--white);
7379
}
7480

7581
&:focus {
76-
color: common.$white;
77-
box-shadow: 0 0 6px common.$white;
82+
color: var(--white);
83+
box-shadow: 0 0 6px var(--white);
7884
}
7985
}
8086
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { axe } from "jest-axe";
3+
import { HeaderTitle } from "./HeaderTitle";
4+
5+
describe("HeaderTitle", () => {
6+
test("should render title and subtitle", async () => {
7+
const { container } = render(
8+
<HeaderTitle title="Main Title" subtitle="Subtitle" />,
9+
);
10+
expect(await axe(container)).toHaveNoViolations();
11+
expect(
12+
screen.getByRole("heading", { name: /main title/i }),
13+
).toBeInTheDocument();
14+
expect(screen.getByText("Subtitle")).toBeInTheDocument();
15+
});
16+
17+
test("should render leftSection", async () => {
18+
const { container } = render(
19+
<HeaderTitle
20+
title="Title"
21+
leftSection={<span data-testid="left-section">Left</span>}
22+
/>,
23+
);
24+
expect(await axe(container)).toHaveNoViolations();
25+
expect(screen.getByTestId("left-section")).toHaveTextContent("Left");
26+
});
27+
28+
test("should render children", async () => {
29+
const { container } = render(
30+
<HeaderTitle title="Title">
31+
<div data-testid="child">Child content</div>
32+
</HeaderTitle>,
33+
);
34+
expect(await axe(container)).toHaveNoViolations();
35+
expect(screen.getByTestId("child")).toHaveTextContent("Child content");
36+
});
37+
});

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Props = {
1313
classModifier?: string;
1414
className?: string;
1515
isSticky?: boolean;
16+
leftSection?: ReactNode;
1617
subtitle?: string;
1718
title: string;
1819
toggleMenu?: () => void;
@@ -23,6 +24,7 @@ const HeaderTitle = ({
2324
classModifier,
2425
className,
2526
isSticky = true,
27+
leftSection,
2628
subtitle,
2729
title,
2830
toggleMenu,
@@ -48,12 +50,17 @@ const HeaderTitle = ({
4850
</ToggleButton>
4951
</div>
5052
)}
51-
<h1 className={`${defaultClassName}__title`}>
52-
{title}
53-
{subtitle && (
54-
<span className={`${defaultClassName}__subtitle`}>{subtitle}</span>
55-
)}
56-
</h1>
53+
<div className={`${defaultClassName}__leftSection`}>
54+
{leftSection}
55+
<h1 className={`${defaultClassName}__title`}>
56+
{title}
57+
{subtitle && (
58+
<span className={`${defaultClassName}__subtitle`}>
59+
{subtitle}
60+
</span>
61+
)}
62+
</h1>
63+
</div>
5764
{children}
5865
</div>
5966
</div>

0 commit comments

Comments
 (0)