Skip to content

Commit 2b0013f

Browse files
committed
fix: update logo component and add common logo props
1 parent dedd2b4 commit 2b0013f

File tree

4 files changed

+60
-38
lines changed

4 files changed

+60
-38
lines changed

packages/react/ds/src/footer/footer.stories.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ const meta: Meta<typeof Footer> = {
99
argTypes: {
1010
primarySlot: {
1111
control: 'object',
12-
description: 'Primary navigation links - typically main site sections',
12+
description: 'Primary slot - typically main site sections',
1313
},
1414
secondarySlot: {
1515
control: 'object',
16-
description:
17-
'Secondary navigation links - typically department/org specific links',
16+
description: 'Secondary slot - typically department/org specific links',
1817
},
1918
utilitySlot: {
2019
control: 'object',
2120
description:
22-
'Utility links - typically copyright, privacy policy, accessibility, etc.',
21+
'Utility stot - typically copyright, privacy policy, accessibility, etc.',
2322
},
24-
logoComponent: {
23+
logo: {
2524
control: 'object',
2625
description: 'Optional custom logo component',
2726
},
@@ -41,8 +40,9 @@ type Story = StoryObj<typeof Footer>;
4140

4241
export const CompleteFooter: Story = {
4342
args: {
43+
dataTestid: 'gi-footer',
4444
primarySlot: (
45-
<div className="!gi-ml-0 !gi-mr-0 gi-grid-responsive">
45+
<div className="gi-grid-responsive">
4646
<div className="gi-col-span-4 md:gi-col-span-4 lg:gi-col-span-3">
4747
<SectionBreak color="gi-border-gray-100" size="md" />
4848
<h3 className="gi-heading-sm gi-mb-4">Services</h3>

packages/react/ds/src/footer/footer.test.tsx

+3-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ describe('Footer', () => {
77
render(<Footer {...props} />);
88

99
it('should render the footer with default props', () => {
10-
renderFooter({});
10+
renderFooter({
11+
dataTestid: 'govie-footer',
12+
});
1113

1214
const footer = screen.getByRole('contentinfo');
1315
expect(footer).toBeInTheDocument();
@@ -23,24 +25,6 @@ describe('Footer', () => {
2325
expect(footer).toHaveClass('gi-footer custom-class');
2426
});
2527

26-
it('should render with custom logo component', () => {
27-
const CustomLogo = () => <div data-testid="custom-logo">Custom Logo</div>;
28-
renderFooter({ logoComponent: <CustomLogo /> });
29-
30-
expect(screen.getByTestId('custom-logo')).toBeInTheDocument();
31-
});
32-
33-
it('should render primary slot when provided', () => {
34-
const primaryContent = (
35-
<div data-testid="primary-content">Primary Content</div>
36-
);
37-
renderFooter({ primarySlot: primaryContent });
38-
39-
const primaryNav = screen.getByLabelText('Primary footer navigation');
40-
expect(primaryNav).toBeInTheDocument();
41-
expect(screen.getByTestId('primary-content')).toBeInTheDocument();
42-
});
43-
4428
it('should not render primary nav when primarySlot is not provided', () => {
4529
renderFooter({});
4630

packages/react/ds/src/footer/footer.tsx

+49-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
1+
'use client';
12
import { ReactNode } from 'react';
23
import GovieLogoHarpWithText from '../assets/logos/gov-of-ireland/harp-gold-text-green.js';
4+
import GovieLogoHarp from '../assets/logos/harp/harp-white.js';
35
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';
49

510
export type FooterProps = {
611
primarySlot?: ReactNode;
712
secondarySlot?: ReactNode;
813
utilitySlot?: ReactNode;
9-
logoComponent?: ReactNode;
14+
logo?: LogoProps;
1015
className?: string;
1116
dataTestid?: string;
1217
} & React.HTMLAttributes<HTMLDivElement>;
1318

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+
1442
export function Footer({
1543
primarySlot,
1644
secondarySlot,
1745
utilitySlot,
18-
logoComponent = <GovieLogoHarpWithText />,
46+
logo,
1947
className = '',
2048
dataTestid,
2149
...props
2250
}: 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+
};
2368
return (
2469
<footer
2570
className={`gi-footer ${className}`}
@@ -47,13 +92,11 @@ export function Footer({
4792
aria-label="Secondary footer navigation"
4893
>
4994
<div className="gi-footer-secondary-content">{secondarySlot}</div>
50-
<div className="gi-footer-logo">{logoComponent}</div>
95+
<div className="gi-footer-logo">{renderLogo()}</div>
5196
</div>
5297
)}
5398

54-
{!secondarySlot && (
55-
<div className="gi-footer-logo">{logoComponent}</div>
56-
)}
99+
{!secondarySlot && <div className="gi-footer-logo">{renderLogo()}</div>}
57100
</div>
58101
{utilitySlot && (
59102
<div className="gi-footer-utility" aria-label="Utility links">

packages/react/ds/src/header/types.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LogoProps } from '../common/types.js';
12
import { DrawerPosition } from '../drawer/drawer.js';
23
import { IconId } from '../icon/icon.js';
34

@@ -57,13 +58,7 @@ export type HeaderItem = CommonProps & ConditionalProps;
5758

5859
export type HeaderProps = {
5960
title?: string;
60-
logo?: {
61-
imageSmall?: string;
62-
imageLarge?: string;
63-
href?: string;
64-
external?: boolean;
65-
alt?: string;
66-
};
61+
logo?: LogoProps;
6762
addDefaultMobileMenu?: boolean;
6863
mobileMenuLabel?: string;
6964
items?: HeaderItem[];

0 commit comments

Comments
 (0)