Skip to content

Commit

Permalink
feat(header): make title-bar sticky by default
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWeb committed Jan 25, 2024
1 parent 3d847ac commit e65feb9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/Layout/header/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ export default NavBarItemActifWithChildren;

## Default

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.

### Installation

```shell script
Expand Down
1 change: 1 addition & 0 deletions packages/Layout/header/src/Title/Title.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const Default = (args) => <Title {...args} />;
Default.args = {
title: 'Toolkit Axa',
subtitle: 'Info complémentaire',
isSticky: true,
};
Default.argTypes = {
toggleMenu: { action: 'onToggle' },
Expand Down
10 changes: 10 additions & 0 deletions packages/Layout/header/src/Title/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Props = {
toggleMenu?: () => void;
className?: string;
classModifier?: string;
isSticky?: boolean;
};
const Title = ({
title,
Expand All @@ -20,7 +21,16 @@ const Title = ({
toggleMenu,
className,
classModifier,
isSticky = true,
}: Props) => {
if (isSticky) {
// eslint-disable-next-line no-param-reassign
classModifier =
!classModifier || classModifier.length === 0
? 'sticky'
: `${classModifier} sticky`;
}

const componentClassName = getComponentClassName(
className,
classModifier,
Expand Down
6 changes: 6 additions & 0 deletions packages/Layout/header/src/Title/title-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
padding: 0.66rem 0;
margin-bottom: 2rem;

&--sticky {
position: sticky;
top: 0;
z-index: 110;
}

&--fixed {
position: fixed;
width: 100%;
Expand Down
11 changes: 11 additions & 0 deletions packages/Layout/header/src/__tests__/Title.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ describe('<Title>', () => {
);
expect(asFragment()).toMatchSnapshot();
});

it('renders Title with classModifier', () => {
const { asFragment } = render(
<Title
title="Toolkit Axa"
subtitle="Info complémentaire"
classModifier="test"
/>
);
expect(asFragment()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<Title> renders Title correctly 1`] = `
<DocumentFragment>
<div
class="af-title-bar"
class="af-title-bar af-title-bar--sticky"
>
<div
class="container af-title-bar__wrapper"
Expand Down Expand Up @@ -44,7 +44,30 @@ exports[`<Title> renders Title correctly 1`] = `
exports[`<Title> renders Title correctly without menu 1`] = `
<DocumentFragment>
<div
class="af-title-bar"
class="af-title-bar af-title-bar--sticky"
>
<div
class="container af-title-bar__wrapper"
>
<h1
class="af-title-bar__title"
>
Toolkit Axa
<span
class="af-title-bar__subtitle"
>
Info complémentaire
</span>
</h1>
</div>
</div>
</DocumentFragment>
`;
exports[`<Title> renders Title with classModifier 1`] = `
<DocumentFragment>
<div
class="af-title-bar af-title-bar--test af-title-bar--sticky"
>
<div
class="container af-title-bar__wrapper"
Expand Down

0 comments on commit e65feb9

Please sign in to comment.