Skip to content

Commit c75d814

Browse files
Ajout categoryMainText à Category (#353)
* Ajout categoryMainText à Category * fix --------- Co-authored-by: Dylan Decrulle <[email protected]>
1 parent 1112db5 commit c75d814

File tree

2 files changed

+48
-33
lines changed

2 files changed

+48
-33
lines changed

src/MainNavigation/MegaMenu.tsx

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ export namespace MegaMenuProps {
2626
};
2727

2828
export type Category = {
29-
categoryMainLink: {
30-
text: ReactNode;
31-
linkProps: RegisteredLinkProps;
32-
};
3329
links: {
3430
text: ReactNode;
3531
linkProps: RegisteredLinkProps;
3632
isActive?: boolean;
3733
}[];
38-
};
34+
} & (
35+
| {
36+
categoryMainLink: {
37+
text: ReactNode;
38+
linkProps: RegisteredLinkProps;
39+
};
40+
categoryMainText?: never;
41+
}
42+
| {
43+
categoryMainText: ReactNode;
44+
categoryMainLink?: never;
45+
}
46+
);
3947
}
4048

4149
export const MegaMenu = memo(
@@ -101,30 +109,42 @@ export const MegaMenu = memo(
101109
</div>
102110
</div>
103111
)}
104-
{categories.map(({ categoryMainLink, links }, i) => (
112+
{categories.map(({ categoryMainLink, categoryMainText, links }, i) => (
105113
<div className={fr.cx("fr-col-12", "fr-col-lg-3")} key={i}>
106-
<h5
107-
className={cx(
108-
fr.cx("fr-mega-menu__category"),
109-
classes.category
110-
)}
111-
>
112-
<Link
113-
{...categoryMainLink.linkProps}
114-
id={
115-
categoryMainLink.linkProps.id ??
116-
`${id}-category-link${generateValidHtmlId({
117-
"text": categoryMainLink.text
118-
})}-${i}`
119-
}
114+
{categoryMainLink !== undefined && (
115+
<h5
120116
className={cx(
121-
fr.cx("fr-nav__link"),
122-
categoryMainLink.linkProps.className
117+
fr.cx("fr-mega-menu__category"),
118+
classes.category
123119
)}
124120
>
125-
{categoryMainLink.text}
126-
</Link>
127-
</h5>
121+
<Link
122+
{...categoryMainLink.linkProps}
123+
id={
124+
categoryMainLink.linkProps.id ??
125+
`${id}-category-link${generateValidHtmlId({
126+
"text": categoryMainLink.text
127+
})}-${i}`
128+
}
129+
className={cx(
130+
fr.cx("fr-nav__link"),
131+
categoryMainLink.linkProps.className
132+
)}
133+
>
134+
{categoryMainLink.text}
135+
</Link>
136+
</h5>
137+
)}
138+
{categoryMainText !== undefined && (
139+
<h5
140+
className={cx(
141+
fr.cx("fr-mega-menu__category", "fr-nav__link"),
142+
classes.category
143+
)}
144+
>
145+
{categoryMainText}
146+
</h5>
147+
)}
128148
<ul className={cx(fr.cx("fr-mega-menu__list"), classes.list)}>
129149
{links.map(({ linkProps, text, isActive }, j) => (
130150
<li key={j}>

stories/MainNavigation.stories.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const { meta, getStory } = getStoryFactory({
99
"wrappedComponent": { "MainNavigation": Header },
1010
"description": `
1111
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/navigation-principale)
12-
- [See source code](https://github.com/codegouvfr/react-dsfr/tree/main/src/MainNavigation)
13-
12+
- [See source code](https://github.com/codegouvfr/react-dsfr/tree/main/src/MainNavigation)
13+
1414
This component isn't meant to be used directly but via the [\\<Header \\/\\>](https://components.react-dsfr.codegouv.studio/?path=/docs/components-header)`,
1515
"argTypes": {
1616
"brandTop": {
@@ -265,12 +265,7 @@ export const MegaMenu = getStory({
265265
]
266266
},
267267
{
268-
"categoryMainLink": {
269-
"text": "Nom de catégorie",
270-
"linkProps": {
271-
"href": "#"
272-
}
273-
},
268+
"categoryMainText": "Nom de catégorie sans lien",
274269
"links": [
275270
{
276271
"text": "Lien de navigation",

0 commit comments

Comments
 (0)