Skip to content

Commit a4d6228

Browse files
committed
Use the themeable image in footer.
1 parent a1840b8 commit a4d6228

File tree

8 files changed

+201
-23
lines changed

8 files changed

+201
-23
lines changed

src/components/Footer.stories.tsx

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

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

1844
export const CopyrightOnly: Story = {
1945
args: {
20-
logo: "",
46+
logo: null,
2147
copyright: "Company",
2248
},
2349
};
2450

2551
export const CopyrightAndLogo: Story = {
26-
args: { copyright: "Company" },
52+
args: {
53+
logo: "theme",
54+
copyright: "Company"
55+
},
2756
};
2857

2958
export const WithOneLink: Story = {

src/components/Footer.test.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
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";
7-
describe("Footer", () => {
8-
test("Should render logo only", async () => {
9-
render(<Footer logo={dlsLogo} />);
6+
import {ImageColorSchemeSwitch} from './ImageColorSchemeSwitch';
107

11-
await waitFor(() => {
12-
expect(screen.getByRole("img")).toBeInTheDocument();
13-
// No copyright text
14-
expect(screen.queryByRole("paragraph")).not.toBeTruthy();
15-
});
8+
9+
jest.mock('./ImageColorSchemeSwitch');
10+
// @ts-ignore: doesn't find mockImplementation
11+
ImageColorSchemeSwitch.mockImplementation(() => <img src="src" alt="alt"/>)
12+
13+
14+
describe("Footer", () => {
15+
test("Should render logo only", () => {
16+
render(<Footer logo={{src:dlsLogo, alt:"t"}} />);
17+
18+
expect(screen.getByRole("img")).toBeInTheDocument();
19+
// No copyright text
20+
expect(screen.queryByRole("paragraph")).not.toBeInTheDocument();
1621
});
1722

1823
test("Should render copyright only", async () => {
@@ -33,13 +38,14 @@ describe("Footer", () => {
3338
test("Should render logo and copyright", async () => {
3439
const copyrightText = "add text here";
3540
const currentYear = new Date().getFullYear();
36-
render(<Footer logo={dlsLogo} copyright={copyrightText} />);
41+
render(<Footer logo={{"src":dlsLogo,"alt":""}} copyright={copyrightText} />);
3742

3843
await waitFor(() => {
3944
expect(screen.getByRole("img")).toBeInTheDocument();
40-
expect(screen.queryByRole("paragraph")).toBeInTheDocument();
41-
expect(screen.queryByRole("paragraph")?.textContent).toStrictEqual(
42-
`Copyright © ${currentYear} ${copyrightText}`,
45+
const paragraph = screen.getByRole("paragraph")
46+
expect(paragraph).toBeInTheDocument();
47+
expect(paragraph.textContent).toStrictEqual(
48+
`Copyright © ${currentYear} ${copyrightText}`
4349
);
4450
});
4551
});

src/components/Footer.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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 {ImageColorSchemeSwitch, ImageColorSchemeSwitchType} from "./ImageColorSchemeSwitch";
56

67
interface FooterLinksProps {
78
children: React.ReactElement<LinkProps> | React.ReactElement<LinkProps>[];
89
}
910

1011
interface FooterProps extends React.HTMLProps<HTMLDivElement> {
1112
/** Location/content of the logo */
12-
logo?: string | null;
13+
logo?: ImageColorSchemeSwitchType | "theme" | null;
1314
copyright?: string | null;
1415
children?: React.ReactElement | React.ReactElement[];
1516
}
@@ -58,13 +59,17 @@ const FooterLink = ({ children, ...props }: LinkProps) => {
5859
* Can be used with `FooterLinks` and `FooterLink` to display a list of links.
5960
*/
6061
const Footer = ({
61-
logo = dlsLogo as string,
62+
logo,
6263
copyright,
6364
children,
6465
...props
6566
}: FooterProps) => {
6667
const theme = useTheme();
6768

69+
if(logo === "theme") {
70+
logo = theme.logos?.short
71+
}
72+
6873
return (
6974
<footer
7075
style={{
@@ -93,7 +98,7 @@ const Footer = ({
9398
textAlign: "right",
9499
}}
95100
>
96-
{logo ? <img alt="footer-logo" src={logo} /> : null}
101+
{logo && <ImageColorSchemeSwitch image={logo} />}
97102
{copyright ? (
98103
<Typography
99104
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)