Skip to content

Commit

Permalink
Revert "Revert "feat: use next Link component in tab" (#1080)"
Browse files Browse the repository at this point in the history
This reverts commit 382a075.
  • Loading branch information
XavierJp authored May 29, 2024
1 parent 382a075 commit e2b562e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
8 changes: 8 additions & 0 deletions components/load-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default function LoadBar({ session }: { session: ISession | null }) {
const loadBar = loadBarFactory();
if (typeof window !== 'undefined') {
window.addEventListener('beforeunload', loadBar.run);
window.addEventListener('runloadbar', loadBar.run);
window.addEventListener('cancelloadbar', loadBar.cancel);
}
}, []);
return (
Expand Down Expand Up @@ -94,5 +96,11 @@ const loadBarFactory = () => {
await wait(200);
}
},
cancel: function () {
this._currentJobId = '';
if (this._loader) {
this._loader.style.width = '0';
}
},
};
};
35 changes: 35 additions & 0 deletions components/title-section/tabs/TabLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use client';
import Link from 'next/link';
import { useEffect } from 'react';
import styles from './styles.module.css';
type IProps = {
label: string;
href: string;
noFollow?: boolean;
width?: string;
active: boolean;
};
export default function TabLink({
active,
href,
label,
noFollow,
width,
}: IProps) {
useEffect(() => {
active === false && window.dispatchEvent(new Event('cancelloadbar'));
}, [active]);
return (
<Link
className={`${active ? styles.activeLink : ''} no-style-link`}
href={href}
rel={noFollow ? 'nofollow' : ''}
style={{ width }}
scroll={false}
onClick={() => window.dispatchEvent(new Event('runloadbar'))}
prefetch={false}
>
{active ? label : <h2>{label}</h2>}
</Link>
);
}
21 changes: 10 additions & 11 deletions components/title-section/tabs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Link from 'next/link';
import { PrintNever } from '#components-ui/print-visibility';
import {
checkHasLabelsAndCertificates,
Expand All @@ -10,6 +11,7 @@ import {
} from '#models/core/types';
import { EScope, hasRights } from '#models/user/rights';
import { ISession } from '#models/user/session';
import TabLink from './TabLink';
import styles from './styles.module.css';

export enum FICHE {
Expand Down Expand Up @@ -135,30 +137,27 @@ export const Tabs: React.FC<{
noFollow,
width = 'auto',
}) => (
<a
className={`${
currentFicheType === ficheType ? styles.activeLink : ''
} no-style-link`}
<TabLink
active={currentFicheType === ficheType}
href={fullPath || `${pathPrefix}${uniteLegale.siren}`}
rel={noFollow ? 'nofollow' : ''}
label={label}
noFollow={noFollow}
key={label}
style={{ width }}
>
{currentFicheType === ficheType ? label : <h2>{label}</h2>}
</a>
width={width}
/>
)
)}
{currentFicheType === FICHE.ETABLISSEMENT && (
<>
<div style={{ flexGrow: 1 }} />
<a
<Link
className={styles.activeLink + ' no-style-link'}
key="etablissement"
href=""
style={{ width: '120px' }}
>
<h2>Fiche établissement</h2>
</a>
</Link>
</>
)}
</div>
Expand Down
14 changes: 8 additions & 6 deletions components/title-section/tabs/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
border-bottom: 0;
}
}
.titleTabs > a {

.titleTabs>a {
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border: 2px solid var(--annuaire-colors-pastelBlue);
Expand All @@ -35,13 +36,13 @@
margin-bottom: -2px;
}

.titleTabs > a > h2 {
.titleTabs>a>h2 {
margin: 0;
padding: 0;
}

.titleTabs > a,
.titleTabs > a > h2 {
.titleTabs>a,
.titleTabs>a>h2 {
color: var(--annuaire-colors-frBlue);
font-weight: bold;
font-size: 0.9rem;
Expand All @@ -56,6 +57,7 @@
}
}

.titleTabs > a:hover {
.titleTabs>a:hover,
.titleTabs>a:focus {
background-color: var(--annuaire-colors-pastelBlue);
}
}

0 comments on commit e2b562e

Please sign in to comment.