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

chore: 5397 nextjs self host font #6559

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const HUBSPOT_FORMS_URL = "https://forms.hsforms.com";

const CROSS_REF_URL = "https://api.crossref.org";

const GOOGLE_FONTS_URL = "https://fonts.gstatic.com";

const SCRIPT_SRC = [
"'self'",
"'wasm-unsafe-eval'",
Expand All @@ -45,10 +43,9 @@ const defaultSecureHeaders = {
configs.CELLGUIDE_DATA_URL,
configs.CENSUS_MODELS_DATA_URL,
CROSS_REF_URL,
GOOGLE_FONTS_URL,
],
defaultSrc: ["'self'", HUBSPOT_FORMS_URL],
fontSrc: ["'self'", GOOGLE_FONTS_URL],
fontSrc: ["'self'"],
formAction: ["'self'", HUBSPOT_FORMS_URL],
frameAncestors: ["'none'"],
// 4513(thuang): Comment out frameSrc for now until we figure out a compliant way to embed
Expand Down
20 changes: 19 additions & 1 deletion frontend/src/common/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ import {
import { createTheme } from "@mui/material/styles";
import { defaultAppTheme, makeThemeOptions } from "@czi-sds/components";

import { Inter } from "next/font/google";

export const INTER_FONT_CSS_VARIABLE = "--font-inter";

/**
* (thuang): We should only load the font once in the app.
* If loading a variable font, you don't need to specify the font weight
* `Inter` is a variable font
*/
export const inter = Inter({
subsets: ["latin"],
/**
* (thuang): We can't use the font-weight variable here, according to Next.js warning
* CSS variable here is used in CSS files
*/
variable: "--font-inter",
});

const { fontWeights } = defaultAppTheme;

const iconSizes = {
Expand Down Expand Up @@ -57,7 +75,7 @@ export const cornersS = (props: CommonThemeProps) => getCorners(props)?.s;
export const cornersNone = (props: CommonThemeProps) => getCorners(props)?.none;

const typography = {
fontFamily: "Inter",
fontFamily: inter.style.fontFamily,
styles: {
body: {
button: {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/common/staticPages/style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from "@emotion/styled";
import { inter } from "src/common/theme";

export const Layout = styled.div`
width: 100%;
Expand All @@ -10,7 +11,7 @@ export const CommonStyle = styled.div`
margin: 0px auto;
padding: 50px;
line-height: 1.5;
font-family: "Inter", sans-serif;
font-family: ${inter.style.fontFamily};

h4,
h5 {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/common/theme.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { css } from "@emotion/react";
import { inter } from "src/common/theme";

export const PT_GRID_SIZE_PX = 8;

export const PT_TEXT_COLOR = "#10161A";

export const fontStyle = css`
font-family: "Inter", sans-serif;
font-family: ${inter.style.fontFamily};
font-style: normal;
font-size: 14px;
`;
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ h5,
h6,
a,
div {
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
Expand All @@ -21,7 +21,7 @@ div[role="group"][tabindex] {

html {
min-height: 100vh;
font: "Inter", sans-serif;
font: var(--font-inter);
box-sizing: border-box;
overflow-y: auto;
}
Expand All @@ -32,7 +32,7 @@ body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: black;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: normal;
word-wrap: break-word;
font-kerning: normal;
Expand Down Expand Up @@ -104,7 +104,7 @@ h1 {
padding-top: 0;
margin-bottom: 1.45rem;
color: inherit;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: 700;
text-rendering: optimizeLegibility;
line-height: 1.1;
Expand Down Expand Up @@ -286,7 +286,7 @@ h2 {
padding-top: 0;
margin-bottom: 1.45rem;
color: inherit;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: bold;
text-rendering: optimizeLegibility;
font-size: 1.62671rem;
Expand All @@ -302,7 +302,7 @@ h3 {
padding-top: 0;
margin-bottom: 1.45rem;
color: inherit;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: bold;
text-rendering: optimizeLegibility;
font-size: 1.38316rem;
Expand All @@ -318,7 +318,7 @@ h4 {
padding-top: 0;
margin-bottom: 1.45rem;
color: inherit;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: bold;
text-rendering: optimizeLegibility;
font-size: 1rem;
Expand All @@ -334,7 +334,7 @@ h5 {
padding-top: 0;
margin-bottom: 1.45rem;
color: inherit;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: bold;
text-rendering: optimizeLegibility;
font-size: 0.85028rem;
Expand All @@ -350,7 +350,7 @@ h6 {
padding-top: 0;
margin-bottom: 1.45rem;
color: inherit;
font-family: "Inter", sans-serif;
font-family: var(--font-inter);
font-weight: bold;
text-rendering: optimizeLegibility;
font-size: 0.78405rem;
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Head, Html, Main, NextScript } from "next/document";
import { inter } from "src/common/theme";
import { API_URL } from "src/configs/configs";

export default function Document(): JSX.Element {
Expand Down Expand Up @@ -30,12 +31,8 @@ export default function Document(): JSX.Element {
/>
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
<meta name="theme-color" key="theme-color" content="#000000" />
<link
href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700,800&amp;display=swap"
rel="stylesheet"
/>
</Head>
<body data-api-url={API_URL}>
<body className={inter.className} data-api-url={API_URL}>
<Main />
<NextScript />
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Container = styled.div`

export const CellTypeLabelStyle = styled.div`
margin: auto;
font: normal 12px sans-serif;
font-size: 12px;
white-space: pre;
margin-left: 24px;
border: none;
Expand All @@ -55,7 +55,7 @@ interface TissueHeaderLabelStyleProps extends CommonThemeProps {

export const TissueHeaderLabelStyle = styled.div`
margin: auto;
font: normal 12px sans-serif;
font-size: 12px;
border: none;
width: 100%;
color: ${ECHART_AXIS_LABEL_COLOR_HEX};
Expand Down
Loading