Skip to content

Commit b05ff08

Browse files
authored
Use a themeable image in footer
1 parent a247957 commit b05ff08

File tree

9 files changed

+213
-26
lines changed

9 files changed

+213
-26
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"scripts": {
1313
"build": "tsc -b && rollup --config rollup.config.mjs",
1414
"lint": "eslint .",
15+
"lint:fix": "eslint --fix .",
1516
"lint:tsc": "pnpm tsc --noEmit",
1617
"rollup": "rollup --config rollup.config.mjs",
1718
"jest": "jest --config jest.config.js",

src/components/Footer.stories.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,47 @@ const meta: Meta<typeof Footer> = {
1111
export default meta;
1212
type Story = StoryObj<typeof meta>;
1313

14+
export const All: Story = {
15+
args: {
16+
logo: "theme",
17+
copyright: "Company",
18+
children: [
19+
<FooterLinks key="footer-links">
20+
<FooterLink href="#TheMoon" key="the-moon">
21+
The Moon
22+
</FooterLink>
23+
<FooterLink href="#Phobos" key="phobos">
24+
Phobos
25+
</FooterLink>
26+
<FooterLink href="#Ganymede" key="ganymede">
27+
Ganymede
28+
</FooterLink>
29+
<FooterLink href="#Titan" key="titan">
30+
Titan
31+
</FooterLink>
32+
</FooterLinks>,
33+
],
34+
},
35+
};
36+
1437
export const LogoOnly: Story = {
15-
args: {},
38+
args: {
39+
logo: "theme",
40+
},
1641
};
1742

1843
export const CopyrightOnly: Story = {
1944
args: {
20-
logo: "",
45+
logo: null,
2146
copyright: "Company",
2247
},
2348
};
2449

2550
export const CopyrightAndLogo: Story = {
26-
args: { copyright: "Company" },
51+
args: {
52+
logo: "theme",
53+
copyright: "Company",
54+
},
2755
};
2856

2957
export const WithOneLink: Story = {

src/components/Footer.test.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import { render, screen, waitFor } from "@testing-library/react";
22
import "@testing-library/jest-dom";
33

4-
import dlsLogo from "../public/dls.svg";
5-
4+
import dlsLogo from "../public/generic/logo-short.svg";
65
import { Footer, FooterLink, FooterLinks } from "./Footer";
6+
import { ImageColorSchemeSwitch } from "./ImageColorSchemeSwitch";
7+
import { ThemeProvider } from "../themes/ThemeProvider";
8+
9+
jest.mock("./ImageColorSchemeSwitch");
10+
// @ts-expect-error: doesn't find mockImplementation outside of testing.
11+
ImageColorSchemeSwitch.mockImplementation(() => <img src="src" alt="alt" />);
12+
713
describe("Footer", () => {
8-
test("Should render logo only", async () => {
9-
render(<Footer logo={dlsLogo} />);
14+
test("Should render logo only", () => {
15+
render(<Footer logo={{ src: dlsLogo, alt: "t" }} />);
1016

11-
await waitFor(() => {
12-
expect(screen.getByRole("img")).toBeInTheDocument();
13-
// No copyright text
14-
expect(screen.queryByRole("paragraph")).not.toBeTruthy();
15-
});
17+
expect(screen.getByRole("img")).toBeInTheDocument();
18+
// No copyright text
19+
expect(screen.queryByRole("paragraph")).not.toBeInTheDocument();
20+
});
21+
22+
test("Should render logo via theme", () => {
23+
render(
24+
<ThemeProvider>
25+
<Footer logo="theme" />
26+
</ThemeProvider>,
27+
);
28+
29+
expect(screen.getByRole("img")).toBeInTheDocument();
1630
});
1731

1832
test("Should render copyright only", async () => {
@@ -33,12 +47,15 @@ describe("Footer", () => {
3347
test("Should render logo and copyright", async () => {
3448
const copyrightText = "add text here";
3549
const currentYear = new Date().getFullYear();
36-
render(<Footer logo={dlsLogo} copyright={copyrightText} />);
50+
render(
51+
<Footer logo={{ src: dlsLogo, alt: "" }} copyright={copyrightText} />,
52+
);
3753

3854
await waitFor(() => {
3955
expect(screen.getByRole("img")).toBeInTheDocument();
40-
expect(screen.queryByRole("paragraph")).toBeInTheDocument();
41-
expect(screen.queryByRole("paragraph")?.textContent).toStrictEqual(
56+
const paragraph = screen.getByRole("paragraph");
57+
expect(paragraph).toBeInTheDocument();
58+
expect(paragraph.textContent).toStrictEqual(
4259
`Copyright © ${currentYear} ${copyrightText}`,
4360
);
4461
});

src/components/Footer.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { Link, LinkProps, Typography, useTheme } from "@mui/material";
22
import Grid from "@mui/material/Grid2";
3-
import dlsLogo from "../public/logo-short.svg";
3+
44
import React from "react";
5+
import {
6+
ImageColorSchemeSwitch,
7+
ImageColorSchemeSwitchType,
8+
} from "./ImageColorSchemeSwitch";
59

610
interface FooterLinksProps {
711
children: React.ReactElement<LinkProps> | React.ReactElement<LinkProps>[];
812
}
913

1014
interface FooterProps extends React.HTMLProps<HTMLDivElement> {
1115
/** Location/content of the logo */
12-
logo?: string | null;
16+
logo?: ImageColorSchemeSwitchType | "theme" | null;
1317
copyright?: string | null;
1418
children?: React.ReactElement | React.ReactElement[];
1519
}
@@ -57,14 +61,13 @@ const FooterLink = ({ children, ...props }: LinkProps) => {
5761
* Basic footer bar.
5862
* Can be used with `FooterLinks` and `FooterLink` to display a list of links.
5963
*/
60-
const Footer = ({
61-
logo = dlsLogo as string,
62-
copyright,
63-
children,
64-
...props
65-
}: FooterProps) => {
64+
const Footer = ({ logo, copyright, children, ...props }: FooterProps) => {
6665
const theme = useTheme();
6766

67+
if (logo === "theme") {
68+
logo = theme.logos?.short;
69+
}
70+
6871
return (
6972
<footer
7073
style={{
@@ -93,7 +96,7 @@ const Footer = ({
9396
textAlign: "right",
9497
}}
9598
>
96-
{logo ? <img alt="footer-logo" src={logo} /> : null}
99+
{logo && <ImageColorSchemeSwitch image={logo} />}
97100
{copyright ? (
98101
<Typography
99102
style={{

src/components/Navbar.stories.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,33 @@ const meta: Meta<typeof Navbar> = {
1515
export default meta;
1616
type Story = StoryObj<typeof meta>;
1717

18-
export const Empty: Story = {
19-
args: {},
18+
export const All: Story = {
19+
args: {
20+
children: [
21+
<NavLinks key="links">
22+
<NavLink href="#Mercury" key="mercury">
23+
Mercury
24+
</NavLink>
25+
<NavLink href="#Venus" key="venus">
26+
Venus
27+
</NavLink>
28+
<NavLink href="#Earth" key="earth">
29+
Earth
30+
</NavLink>
31+
<NavLink href="#Mars" key="mars">
32+
Mars
33+
</NavLink>
34+
</NavLinks>,
35+
<User
36+
key="user"
37+
onLogin={() => {}}
38+
onLogout={() => {}}
39+
user={{ name: "Name", fedid: "FedID" }}
40+
color={"white"}
41+
/>,
42+
],
43+
logo: "theme",
44+
},
2045
};
2146

2247
export const WithLogin: Story = {
@@ -133,3 +158,7 @@ export const CustomChildElement: Story = {
133158
children: <Chip label="Hello, World" sx={{ backgroundColor: "#aaaaaa" }} />,
134159
},
135160
};
161+
162+
export const Empty: Story = {
163+
args: {},
164+
};

src/public/generic/logo-short.svg

Lines changed: 98 additions & 0 deletions
Loading

src/themes/DiamondTheme.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BaseThemeOptions } from "./BaseTheme";
44

55
import logoImageDark from "../public/diamond/logo-dark.svg";
66
import logoImageLight from "../public/diamond/logo-light.svg";
7+
import logoShort from "../public/diamond/logo-short.svg";
78

89
const dlsLogoBlue = "#202740";
910
const dlsLogoYellow = "#facf07";
@@ -17,6 +18,11 @@ const DiamondTheme: Theme = createTheme({
1718
alt: "Diamond Source Logo",
1819
width: "100",
1920
},
21+
short: {
22+
src: logoShort,
23+
alt: "Diamond Source Logo",
24+
width: "65",
25+
},
2026
},
2127
colorSchemes: {
2228
// https://zenoo.github.io/mui-theme-creator/

src/themes/GenericTheme.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const GenericTheme: Theme = createTheme({
1414
alt: "Diamond Source Logo",
1515
width: "100",
1616
},
17+
short: {
18+
src: logoImageDark,
19+
alt: "Diamond Source Logo",
20+
width: "60",
21+
},
1722
},
1823
});
1924

0 commit comments

Comments
 (0)