Skip to content

Commit

Permalink
Ajout categoryMainText à Category (#353)
Browse files Browse the repository at this point in the history
* Ajout categoryMainText à Category

* fix

---------

Co-authored-by: Dylan Decrulle <dylan.decrulle@outlook.fr>
  • Loading branch information
l-vincent-l and ddecrulle authored Jan 6, 2025
1 parent 1112db5 commit c75d814
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
70 changes: 45 additions & 25 deletions src/MainNavigation/MegaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@ export namespace MegaMenuProps {
};

export type Category = {
categoryMainLink: {
text: ReactNode;
linkProps: RegisteredLinkProps;
};
links: {
text: ReactNode;
linkProps: RegisteredLinkProps;
isActive?: boolean;
}[];
};
} & (
| {
categoryMainLink: {
text: ReactNode;
linkProps: RegisteredLinkProps;
};
categoryMainText?: never;
}
| {
categoryMainText: ReactNode;
categoryMainLink?: never;
}
);
}

export const MegaMenu = memo(
Expand Down Expand Up @@ -101,30 +109,42 @@ export const MegaMenu = memo(
</div>
</div>
)}
{categories.map(({ categoryMainLink, links }, i) => (
{categories.map(({ categoryMainLink, categoryMainText, links }, i) => (
<div className={fr.cx("fr-col-12", "fr-col-lg-3")} key={i}>
<h5
className={cx(
fr.cx("fr-mega-menu__category"),
classes.category
)}
>
<Link
{...categoryMainLink.linkProps}
id={
categoryMainLink.linkProps.id ??
`${id}-category-link${generateValidHtmlId({
"text": categoryMainLink.text
})}-${i}`
}
{categoryMainLink !== undefined && (
<h5
className={cx(
fr.cx("fr-nav__link"),
categoryMainLink.linkProps.className
fr.cx("fr-mega-menu__category"),
classes.category
)}
>
{categoryMainLink.text}
</Link>
</h5>
<Link
{...categoryMainLink.linkProps}
id={
categoryMainLink.linkProps.id ??
`${id}-category-link${generateValidHtmlId({
"text": categoryMainLink.text
})}-${i}`
}
className={cx(
fr.cx("fr-nav__link"),
categoryMainLink.linkProps.className
)}
>
{categoryMainLink.text}
</Link>
</h5>
)}
{categoryMainText !== undefined && (
<h5
className={cx(
fr.cx("fr-mega-menu__category", "fr-nav__link"),
classes.category
)}
>
{categoryMainText}
</h5>
)}
<ul className={cx(fr.cx("fr-mega-menu__list"), classes.list)}>
{links.map(({ linkProps, text, isActive }, j) => (
<li key={j}>
Expand Down
11 changes: 3 additions & 8 deletions stories/MainNavigation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const { meta, getStory } = getStoryFactory({
"wrappedComponent": { "MainNavigation": Header },
"description": `
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/navigation-principale)
- [See source code](https://github.com/codegouvfr/react-dsfr/tree/main/src/MainNavigation)
- [See source code](https://github.com/codegouvfr/react-dsfr/tree/main/src/MainNavigation)
This component isn't meant to be used directly but via the [\\<Header \\/\\>](https://components.react-dsfr.codegouv.studio/?path=/docs/components-header)`,
"argTypes": {
"brandTop": {
Expand Down Expand Up @@ -265,12 +265,7 @@ export const MegaMenu = getStory({
]
},
{
"categoryMainLink": {
"text": "Nom de catégorie",
"linkProps": {
"href": "#"
}
},
"categoryMainText": "Nom de catégorie sans lien",
"links": [
{
"text": "Lien de navigation",
Expand Down

0 comments on commit c75d814

Please sign in to comment.