Skip to content

Commit 0c02562

Browse files
committed
Feature operator logo in header
1 parent 58fb28e commit 0c02562

File tree

4 files changed

+104
-10
lines changed

4 files changed

+104
-10
lines changed

src/Header/Header.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ export type HeaderProps = {
1717
brandTop: ReactNode;
1818
serviceTitle?: ReactNode;
1919
serviceTagline?: ReactNode;
20-
/** Don't forget the title on the link for accessibility*/
21-
homeLinkProps: RegisteredLinkProps;
20+
homeLinkProps: RegisteredLinkProps & { title: string };
2221
navItems?: MainNavigationProps.Item[];
2322
/** There should be at most three of them */
2423
quickAccessItems?: HeaderProps.QuickAccessItem[];
24+
operatorLogo?: {
25+
orientation: "horizontal" | "vertical";
26+
/**
27+
* Expected ratio:
28+
* If "vertical": 9x16
29+
* If "horizontal": 16x9
30+
*/
31+
imgUrl: string;
32+
/** Textual alternative of the image, it MUST include the text present in the image*/
33+
alt: string;
34+
};
2535
renderSearchInput?: (
2636
/**
2737
* id and name must be forwarded to the <input /> component
@@ -94,6 +104,7 @@ export const Header = memo(
94104
homeLinkProps,
95105
navItems = [],
96106
quickAccessItems = [],
107+
operatorLogo,
97108
renderSearchInput,
98109
classes = {},
99110
...rest
@@ -142,14 +153,25 @@ export const Header = memo(
142153
);
143154
})()}
144155
</div>
145-
{/*
146-
<div class="fr-header__operator">
147-
<a href="/" title="Accueil - [À MODIFIER - texte alternatif de l’image : nom de l'opérateur ou du site serviciel] - République Française">
148-
<img class="fr-responsive-img" style="width:3.5rem;" src="../../../example/img/placeholder.9x16.png" alt="[À MODIFIER - texte alternatif de l’image]" />
149-
<!-- L’alternative de l’image (attribut alt) doit impérativement être renseignée et reprendre le texte visible dans l’image -->
150-
</a>
151-
</div>
152-
*/}
156+
{operatorLogo !== undefined && (
157+
<div className={fr.cx("fr-header__operator")}>
158+
<Link {...homeLinkProps}>
159+
<img
160+
className={fr.cx("fr-responsive-img")}
161+
style={(() => {
162+
switch (operatorLogo.orientation) {
163+
case "vertical":
164+
return { "width": "3.5rem" };
165+
case "horizontal":
166+
return { "maxWidth": "9.0625rem" };
167+
}
168+
})()}
169+
src={operatorLogo.imgUrl}
170+
alt={operatorLogo.alt}
171+
/>
172+
</Link>
173+
</div>
174+
)}
153175

154176
{(quickAccessItems.length > 0 ||
155177
renderSearchInput !== undefined) && (

stories/Header.stories.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from "react";
22
import { Header } from "../dist/Header";
33
import { sectionName } from "./sectionName";
44
import { getStoryFactory } from "./getStory";
5+
import placeholder_9x16ImgUrl from "./assets/placeholder.9x16.png";
6+
import placeholder_16x9ImgUrl from "./assets/placeholder.16x9.png";
57

68
const { meta, getStory } = getStoryFactory({
79
sectionName,
@@ -174,3 +176,73 @@ export const HeaderWithQuickAccessItemsAndSearchEngine = getStory({
174176
<input className={className} id={id} name={name} placeholder={placeholder} type={type} />
175177
)
176178
});
179+
180+
export const HeaderWithVerticalOperatorLogo = getStory({
181+
"brandTop": (
182+
<>
183+
INTITULE
184+
<br />
185+
OFFICIEL
186+
</>
187+
),
188+
"homeLinkProps": {
189+
"href": "/",
190+
"title":
191+
"Accueil - [À MODIFIER - texte alternatif de l’image : nom de l'opérateur ou du site serviciel] - République Française"
192+
},
193+
"renderSearchInput": ({ className, id, name, placeholder, type }) => (
194+
<input className={className} id={id} name={name} placeholder={placeholder} type={type} />
195+
),
196+
"operatorLogo": {
197+
"orientation": "vertical",
198+
"imgUrl": placeholder_9x16ImgUrl,
199+
"alt": "[À MODIFIER - texte alternatif de l’image]"
200+
}
201+
});
202+
203+
export const WithHorizontalOperatorLogo = getStory({
204+
"brandTop": (
205+
<>
206+
INTITULE
207+
<br />
208+
OFFICIEL
209+
</>
210+
),
211+
"homeLinkProps": {
212+
"href": "/",
213+
"title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)"
214+
},
215+
"serviceTitle": "Nom du site / service",
216+
"serviceTagline": "baseline - précisions sur l'organisation",
217+
"quickAccessItems": [
218+
{
219+
"iconId": "fr-icon-add-circle-line",
220+
"text": "Créer un espace",
221+
"linkProps": {
222+
"href": "#"
223+
}
224+
},
225+
{
226+
"iconId": "fr-icon-lock-line",
227+
"text": "Se connecter",
228+
"linkProps": {
229+
"href": "#"
230+
}
231+
},
232+
{
233+
"iconId": "fr-icon-account-line",
234+
"text": "S’enregistrer",
235+
"linkProps": {
236+
"href": "#"
237+
}
238+
}
239+
],
240+
"renderSearchInput": ({ className, id, name, placeholder, type }) => (
241+
<input className={className} id={id} name={name} placeholder={placeholder} type={type} />
242+
),
243+
"operatorLogo": {
244+
"orientation": "horizontal",
245+
"imgUrl": placeholder_16x9ImgUrl,
246+
"alt": "[À MODIFIER - texte alternatif de l’image]"
247+
}
248+
});
1.2 KB
Loading
1.18 KB
Loading

0 commit comments

Comments
 (0)