|
| 1 | +'use client'; |
1 | 2 | import { ReactNode } from 'react';
|
2 | 3 | import GovieLogoHarpWithText from '../assets/logos/gov-of-ireland/harp-gold-text-green.js';
|
| 4 | +import GovieLogoHarp from '../assets/logos/harp/harp-white.js'; |
3 | 5 | import { SectionBreak } from '../section-break/section-break.js';
|
| 6 | +import Anchor from '../primitives/anchor.js'; |
| 7 | +import { LogoProps } from '../common/types.js'; |
| 8 | +import { renderToStaticMarkup } from 'react-dom/server'; |
4 | 9 |
|
5 | 10 | export type FooterProps = {
|
6 | 11 | primarySlot?: ReactNode;
|
7 | 12 | secondarySlot?: ReactNode;
|
8 | 13 | utilitySlot?: ReactNode;
|
9 |
| - logoComponent?: ReactNode; |
| 14 | + logo?: LogoProps; |
10 | 15 | className?: string;
|
11 | 16 | dataTestid?: string;
|
12 | 17 | } & React.HTMLAttributes<HTMLDivElement>;
|
13 | 18 |
|
| 19 | +function getLogo({ logo }: FooterProps) { |
| 20 | + const svgMobileString = btoa(renderToStaticMarkup(<GovieLogoHarp />)); |
| 21 | + const svgDataUriMobile = `data:image/svg+xml;base64,${svgMobileString}`; |
| 22 | + const svgDesktopString = btoa( |
| 23 | + renderToStaticMarkup(<GovieLogoHarpWithText />), |
| 24 | + ); |
| 25 | + const svgDataUriDesktop = `data:image/svg+xml;base64,${svgDesktopString}`; |
| 26 | + |
| 27 | + return ( |
| 28 | + <picture> |
| 29 | + <source |
| 30 | + srcSet={logo?.imageLarge || svgDataUriDesktop} |
| 31 | + media="(min-width: 640px)" |
| 32 | + /> |
| 33 | + <img |
| 34 | + className={'gi-h-10 sm:gi-h-14'} |
| 35 | + src={logo?.imageSmall || svgDataUriMobile} |
| 36 | + alt={logo?.alt || 'Gov.ie logo'} |
| 37 | + /> |
| 38 | + </picture> |
| 39 | + ); |
| 40 | +} |
| 41 | + |
14 | 42 | export function Footer({
|
15 | 43 | primarySlot,
|
16 | 44 | secondarySlot,
|
17 | 45 | utilitySlot,
|
18 |
| - logoComponent = <GovieLogoHarpWithText />, |
| 46 | + logo, |
19 | 47 | className = '',
|
20 | 48 | dataTestid,
|
21 | 49 | ...props
|
22 | 50 | }: FooterProps) {
|
| 51 | + const renderLogo = () => { |
| 52 | + return ( |
| 53 | + <> |
| 54 | + {logo?.href && ( |
| 55 | + <Anchor |
| 56 | + href={logo.href} |
| 57 | + aria-label="Go to the home page" |
| 58 | + data-testid={`logo-link`} |
| 59 | + external={logo.external} |
| 60 | + > |
| 61 | + {getLogo({ logo })} |
| 62 | + </Anchor> |
| 63 | + )} |
| 64 | + {!logo?.href && getLogo({ logo })} |
| 65 | + </> |
| 66 | + ); |
| 67 | + }; |
23 | 68 | return (
|
24 | 69 | <footer
|
25 | 70 | className={`gi-footer ${className}`}
|
@@ -47,13 +92,11 @@ export function Footer({
|
47 | 92 | aria-label="Secondary footer navigation"
|
48 | 93 | >
|
49 | 94 | <div className="gi-footer-secondary-content">{secondarySlot}</div>
|
50 |
| - <div className="gi-footer-logo">{logoComponent}</div> |
| 95 | + <div className="gi-footer-logo">{renderLogo()}</div> |
51 | 96 | </div>
|
52 | 97 | )}
|
53 | 98 |
|
54 |
| - {!secondarySlot && ( |
55 |
| - <div className="gi-footer-logo">{logoComponent}</div> |
56 |
| - )} |
| 99 | + {!secondarySlot && <div className="gi-footer-logo">{renderLogo()}</div>} |
57 | 100 | </div>
|
58 | 101 | {utilitySlot && (
|
59 | 102 | <div className="gi-footer-utility" aria-label="Utility links">
|
|
0 commit comments