Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default logo and default disclaimer links for navbar and footer #592

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/footer/footer-disclaimer-links-data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ResourceScheme } from "../theme";
import { InternalDisclaimerLinks } from "./footer-helper";

const BaseDisclaimerLinks: InternalDisclaimerLinks = {
privacy: {
href: "https://www.life.gov.sg/privacy-statement",
target: "_blank",
rel: "noopener",
},
termsOfUse: {
href: "https://www.life.gov.sg/terms-of-use",
target: "_blank",
rel: "noopener",
},
reportVulnerability: {
href: "https://tech.gov.sg/report_vulnerability",
target: "_blank",
rel: "noopener",
external: true,
},
};

const BookingSgDisclaimerLinks: InternalDisclaimerLinks = {
privacy: {
href: "https://assets.life.gov.sg/bookingsg/BSG_Privacy_Policy.pdf",
target: "_blank",
rel: "noopener",
},
termsOfUse: {
href: "https://assets.life.gov.sg/bookingsg/BSG_Terms_of_Use.pdf",
target: "_blank",
rel: "noopener",
},
reportVulnerability: {
href: "https://tech.gov.sg/report_vulnerability",
target: "_blank",
rel: "noopener",
external: true,
},
};

const MyLegacyDisclaimerLinks: InternalDisclaimerLinks = {
privacy: {
href: "https://mylegacy.life.gov.sg/privacy-statement",
target: "_blank",
rel: "noopener",
},
termsOfUse: {
href: "https://mylegacy.life.gov.sg/terms-of-use",
target: "_blank",
rel: "noopener",
},
reportVulnerability: {
href: "https://tech.gov.sg/report_vulnerability",
target: "_blank",
rel: "noopener",
external: true,
},
};

export const getDefaultDisclaimerLink = (resourceScheme?: ResourceScheme) => {
qroll marked this conversation as resolved.
Show resolved Hide resolved
switch (resourceScheme) {
case "bookingsg":
return BookingSgDisclaimerLinks;
case "mylegacy":
return MyLegacyDisclaimerLinks;
default:
return BaseDisclaimerLinks;
}
};
38 changes: 25 additions & 13 deletions src/footer/footer-helper.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
import dayjs from "dayjs";
import { TextLinkProps } from "../text";
import { ResourceScheme } from "../theme";
import { getDefaultDisclaimerLink } from "./footer-disclaimer-links-data";
import { DisclaimerLinks } from "./types";

/* Internally used. Not to be exported */
interface InternalDisclaimerLinks {
export interface InternalDisclaimerLinks {
privacy?: TextLinkProps | undefined;
termsOfUse?: TextLinkProps | undefined;
reportVulnerability?: TextLinkProps | undefined;
}

export namespace FooterHelper {
export const getCopyrightInfo = (
lastUpdated: Date = new Date()
lastUpdated: Date = new Date(),
theme?: ResourceScheme
qroll marked this conversation as resolved.
Show resolved Hide resolved
): string => {
const copyright = `${new Date().getFullYear()} LifeSG, Government of Singapore.`;
const copyText = getCopyText(theme);
const copyright = `${new Date().getFullYear()} ${copyText}`;
const lastUpdatedDateString = dayjs(lastUpdated).format("D MMMM YYYY");

return `${copyright} Last Updated ${lastUpdatedDateString}`;
};

const getCopyText = (resourceScheme: ResourceScheme) => {
qroll marked this conversation as resolved.
Show resolved Hide resolved
switch (resourceScheme) {
case "bookingsg":
return "BookingSG, Government of Singapore.";
case "mylegacy":
return "MyLegacy@LifeSG, Government of Singapore.";
case "ccube":
return "Citizen Collective Common, Government of Singapore.";
default:
return "LifeSG, Government of Singapore.";
}
};

export const getDisclaimerLinks = (
theme: ResourceScheme | undefined,
customDisclaimerLinks?: DisclaimerLinks
): InternalDisclaimerLinks => {
const defaultDisclaimerLinks = getDefaultDisclaimerLink(theme);
return {
privacy: {
href: "https://www.life.gov.sg/privacy-statement",
target: "_blank",
rel: "noopener",
...defaultDisclaimerLinks.privacy,
...(customDisclaimerLinks && customDisclaimerLinks.privacy
? customDisclaimerLinks.privacy
: {}),
children: "Privacy Statement",
},
termsOfUse: {
href: "https://www.life.gov.sg/terms-of-use",
target: "_blank",
rel: "noopener",
...defaultDisclaimerLinks.termsOfUse,
...(customDisclaimerLinks && customDisclaimerLinks.termsOfUse
? customDisclaimerLinks.termsOfUse
: {}),
children: "Terms of Use",
},
reportVulnerability: {
href: "https://tech.gov.sg/report_vulnerability",
target: "_blank",
rel: "noopener",
external: true,
...defaultDisclaimerLinks.reportVulnerability,
...(customDisclaimerLinks &&
customDisclaimerLinks.reportVulnerability
? customDisclaimerLinks.reportVulnerability
Expand Down
13 changes: 10 additions & 3 deletions src/footer/footer.tsx
qroll marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TopSection,
} from "./footer.style";
import { FooterLinkProps, FooterProps } from "./types";
import { useTheme } from "styled-components";

const LIFESG_LOGO_SRC =
"https://assets.life.gov.sg/react-design-system/img/logo/lifesg-primary-logo.svg";
Expand All @@ -36,7 +37,7 @@ export const Footer = <T,>({
// CONST, STATE, REFS
// =============================================================================
const isStretch = layout === "stretch";

const theme = useTheme();
// =============================================================================
// EVENT HANDLERS
// =============================================================================
Expand All @@ -63,7 +64,10 @@ export const Footer = <T,>({
// RENDER FUNCTIONS
// =============================================================================
const renderDisclaimerLinks = () => {
const links = FooterHelper.getDisclaimerLinks(disclaimerLinks);
const links = FooterHelper.getDisclaimerLinks(
theme?.resourceScheme,
disclaimerLinks
);

return Object.keys(links).map((key) => {
return <DisclaimerTextLink key={key} {...links[key]} />;
Expand Down Expand Up @@ -145,7 +149,10 @@ export const Footer = <T,>({
{copyrightInfo || (
<>
&copy;{" "}
{FooterHelper.getCopyrightInfo(lastUpdated)}
{FooterHelper.getCopyrightInfo(
lastUpdated,
theme?.resourceScheme
)}
</>
)}
</Text.XSmall>
Expand Down
43 changes: 43 additions & 0 deletions src/navbar/navbar-logo-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ResourceScheme } from "../theme";
import { NavbarResourcesProps } from "./types";

const DEFAULT_RESOURCES_LOGO: NavbarResourcesProps = {
primary: {
brandName: "LifeSG",
logoSrc: "https://assets.life.gov.sg/lifesg/logo-lifesg.svg",
},
};

const BOOKINGSG_RESOURCES_LOGO: NavbarResourcesProps = {
primary: {
brandName: "BookingSG",
logoSrc: "https://www.booking.gov.sg/logo.svg",
},
};

const CCUBE_RESOURCES_LOGO: NavbarResourcesProps = {
primary: {
brandName: "MyLegacy",
logoSrc: "https://assets.life.gov.sg/ccube/logo-ccube.svg",
},
};

const MYLEGACY_RESOURCES_LOGO: NavbarResourcesProps = {
primary: {
brandName: "CCube",
logoSrc: "https://mylegacy.life.gov.sg/images/site-logo.png",
},
};

export const getDefaultResourceLogo = (resourceScheme?: ResourceScheme) => {
switch (resourceScheme) {
case "bookingsg":
return BOOKINGSG_RESOURCES_LOGO;
case "mylegacy":
return MYLEGACY_RESOURCES_LOGO;
case "ccube":
return CCUBE_RESOURCES_LOGO;
default:
return DEFAULT_RESOURCES_LOGO;
}
};
20 changes: 7 additions & 13 deletions src/navbar/navbar.tsx
qroll marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import React, {
useRef,
useState,
} from "react";
import { useTheme } from "styled-components";
import { ButtonProps } from "../button/types";
import { Layout } from "../layout";
import { Masthead } from "../masthead/masthead";
import { Overlay } from "../overlay/overlay";
import { MediaWidths } from "../spec/media-spec";
import { Brand } from "./brand";
import { Drawer } from "./drawer";
import { getDefaultResourceLogo } from "./navbar-logo-data";
import { NavbarActionButtons } from "./navbar-action-buttons";
import { NavbarItems } from "./navbar-items";
import {
Expand All @@ -30,7 +32,6 @@ import {
NavbarButtonProps,
NavbarDrawerHandle,
NavbarProps,
NavbarResourcesProps,
} from "./types";

const Component = <T,>(
Expand All @@ -41,7 +42,7 @@ const Component = <T,>(
selectedId,
compress = false,
fixed = true,
resources = DEFAULT_RESOURCES,
resources,
hideNavElements = false,
hideNavBranding = false,
drawerDismissalExclusions: blockDrawerDismissalMethods = [],
Expand All @@ -62,8 +63,11 @@ const Component = <T,>(
const [showOverlay, setShowOverlay] = useState<boolean>(false);
const isStretch = layout === "stretch";
const elementRef = useRef<HTMLDivElement>();
const theme = useTheme();
const defaultResource = getDefaultResourceLogo(theme?.resourceScheme);

const { primary = DEFAULT_RESOURCES.primary, secondary } = resources;
const primary = resources?.primary || defaultResource.primary;
const secondary = resources?.secondary;

useImperativeHandle(
ref,
Expand Down Expand Up @@ -310,13 +314,3 @@ const Component = <T,>(
};

export const Navbar = forwardRef(Component);

// =============================================================================
// CONSTANTS
// =============================================================================
const DEFAULT_RESOURCES: NavbarResourcesProps = {
primary: {
brandName: "LifeSG",
logoSrc: "https://assets.life.gov.sg/lifesg/logo-lifesg.svg",
},
};
6 changes: 4 additions & 2 deletions tests/footer/footer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe("Footer", () => {
it("should be able to render the component", () => {
render(<Footer />);

const defaultDisclaimerLinks = FooterHelper.getDisclaimerLinks();
const defaultDisclaimerLinks =
FooterHelper.getDisclaimerLinks(undefined);

for (const link in defaultDisclaimerLinks) {
expect(
Expand Down Expand Up @@ -102,7 +103,8 @@ describe("Footer", () => {

render(<Footer disclaimerLinks={disclaimerLinks} />);

const defaultDisclaimerLinks = FooterHelper.getDisclaimerLinks();
const defaultDisclaimerLinks =
FooterHelper.getDisclaimerLinks(undefined);

for (const link in defaultDisclaimerLinks) {
const anchor = getAnchorElement(
Expand Down