Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(header): make title-bar sticky by default #1113

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading