Skip to content

Commit e65feb9

Browse files
committed
feat(header): make title-bar sticky by default
1 parent 3d847ac commit e65feb9

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

packages/Layout/header/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,8 @@ export default NavBarItemActifWithChildren;
895895

896896
## Default
897897

898+
By default, the title bar is sticky on the top when you scroll down the page. If you want to disable that behavior you can set to false the `isSticky` property of the component.
899+
898900
### Installation
899901

900902
```shell script

packages/Layout/header/src/Title/Title.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const Default = (args) => <Title {...args} />;
3535
Default.args = {
3636
title: 'Toolkit Axa',
3737
subtitle: 'Info complémentaire',
38+
isSticky: true,
3839
};
3940
Default.argTypes = {
4041
toggleMenu: { action: 'onToggle' },

packages/Layout/header/src/Title/Title.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Props = {
1212
toggleMenu?: () => void;
1313
className?: string;
1414
classModifier?: string;
15+
isSticky?: boolean;
1516
};
1617
const Title = ({
1718
title,
@@ -20,7 +21,16 @@ const Title = ({
2021
toggleMenu,
2122
className,
2223
classModifier,
24+
isSticky = true,
2325
}: Props) => {
26+
if (isSticky) {
27+
// eslint-disable-next-line no-param-reassign
28+
classModifier =
29+
!classModifier || classModifier.length === 0
30+
? 'sticky'
31+
: `${classModifier} sticky`;
32+
}
33+
2434
const componentClassName = getComponentClassName(
2535
className,
2636
classModifier,

packages/Layout/header/src/Title/title-bar.scss

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
padding: 0.66rem 0;
88
margin-bottom: 2rem;
99

10+
&--sticky {
11+
position: sticky;
12+
top: 0;
13+
z-index: 110;
14+
}
15+
1016
&--fixed {
1117
position: fixed;
1218
width: 100%;

packages/Layout/header/src/__tests__/Title.spec.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@ describe('<Title>', () => {
2020
);
2121
expect(asFragment()).toMatchSnapshot();
2222
});
23+
24+
it('renders Title with classModifier', () => {
25+
const { asFragment } = render(
26+
<Title
27+
title="Toolkit Axa"
28+
subtitle="Info complémentaire"
29+
classModifier="test"
30+
/>
31+
);
32+
expect(asFragment()).toMatchSnapshot();
33+
});
2334
});

packages/Layout/header/src/__tests__/__snapshots__/Title.spec.tsx.snap

+25-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`<Title> renders Title correctly 1`] = `
44
<DocumentFragment>
55
<div
6-
class="af-title-bar"
6+
class="af-title-bar af-title-bar--sticky"
77
>
88
<div
99
class="container af-title-bar__wrapper"
@@ -44,7 +44,30 @@ exports[`<Title> renders Title correctly 1`] = `
4444
exports[`<Title> renders Title correctly without menu 1`] = `
4545
<DocumentFragment>
4646
<div
47-
class="af-title-bar"
47+
class="af-title-bar af-title-bar--sticky"
48+
>
49+
<div
50+
class="container af-title-bar__wrapper"
51+
>
52+
<h1
53+
class="af-title-bar__title"
54+
>
55+
Toolkit Axa
56+
<span
57+
class="af-title-bar__subtitle"
58+
>
59+
Info complémentaire
60+
</span>
61+
</h1>
62+
</div>
63+
</div>
64+
</DocumentFragment>
65+
`;
66+
67+
exports[`<Title> renders Title with classModifier 1`] = `
68+
<DocumentFragment>
69+
<div
70+
class="af-title-bar af-title-bar--test af-title-bar--sticky"
4871
>
4972
<div
5073
class="container af-title-bar__wrapper"

0 commit comments

Comments
 (0)