Skip to content

Commit ed6eac6

Browse files
committed
refactor: use next font optimisation for open sans and fira mono
1 parent 300b8ad commit ed6eac6

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

src/components/instances/JobDetails/JobInputSection/JobInputSection.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Typography,
1111
} from "@mui/material";
1212

13+
import { firaMonoFont } from "../../../../constants/fonts";
1314
import { FILE_PROTOCOL, removeFileProtocol } from "../../../../utils/app/urls";
1415
import { getErrorMessage } from "../../../../utils/next/orvalError";
1516
import { CenterLoader } from "../../../CenterLoader";
@@ -66,11 +67,7 @@ export const JobInputSection = ({ instance }: JobInputSectionProps) => {
6667
secondary={value.map((val) => (
6768
<>
6869
SMILES:{" "}
69-
<Typography
70-
component="code"
71-
key={val}
72-
sx={{ fontFamily: "'Fira Mono', monospace" }}
73-
>
70+
<Typography className={firaMonoFont.className} component="code" key={val}>
7471
{val.split("\n").join(", ")}
7572
</Typography>
7673
</>

src/components/tasks/TimeLine.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "@mui/lab";
2020
import { Box, Tooltip, Typography, useTheme } from "@mui/material";
2121

22+
import { firaMonoFont } from "../../constants/fonts";
2223
import { useEventDebugMode } from "../../state/eventDebugMode";
2324
import { LocalTime } from "../LocalTime";
2425

@@ -129,13 +130,13 @@ const TimeLineLabel = ({ children, ...typographyProps }: TimeLineLabelProps) =>
129130
if (typeof children === "string" && children.includes("\n")) {
130131
return (
131132
<Box
133+
className={firaMonoFont.className}
132134
component="pre"
133135
sx={{
134136
fontSize: "body2.fontSize",
135137
m: 0,
136138
display: "inline-block",
137139
textAlign: "left",
138-
fontFamily: "'Fira Mono', monospace",
139140
}}
140141
>
141142
{children}
@@ -144,11 +145,9 @@ const TimeLineLabel = ({ children, ...typographyProps }: TimeLineLabelProps) =>
144145
}
145146
return (
146147
<Typography
148+
className={firaMonoFont.className}
147149
component="code"
148-
sx={{
149-
fontFamily: "'Fira Mono', monospace",
150-
wordBreak: "break-word",
151-
}}
150+
sx={{ wordBreak: "break-word" }}
152151
variant="body2"
153152
{...typographyProps}
154153
>

src/constants/fonts.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Fira_Mono as firaMono, Open_Sans as openSans } from "next/font/google";
2+
3+
export const openSansFont = openSans({
4+
weight: "variable",
5+
style: ["normal", "italic"],
6+
subsets: ["latin"],
7+
display: "swap",
8+
});
9+
10+
export const firaMonoFont = firaMono({
11+
weight: "400",
12+
subsets: ["latin"],
13+
});

src/features/PlaintextViewer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Head from "next/head";
88
import Prism from "prismjs";
99
import "prismjs/plugins/line-numbers/prism-line-numbers.js";
1010
import "prismjs/plugins/line-numbers/prism-line-numbers.css";
11+
import { firaMonoFont } from "../constants/fonts";
1112

1213
export interface PlaintextViewerProps {
1314
/**
@@ -63,7 +64,11 @@ export const PlaintextViewer = ({
6364
}}
6465
>
6566
<Box sx={{ alignItems: "center", display: "flex", flex: "1 1 auto", gap: 1 }}>
66-
<Typography component="h1" sx={{ fontFamily: "monospace", wordBreak: "break-all" }}>
67+
<Typography
68+
className={firaMonoFont.className}
69+
component="h1"
70+
sx={{ wordBreak: "break-all" }}
71+
>
6772
<b>{title}</b>
6873
</Typography>
6974
<Divider flexItem orientation="vertical" />
@@ -75,7 +80,7 @@ export const PlaintextViewer = ({
7580
</Box>
7681
<Box sx={{ paddingBottom: 1, paddingX: 1 }}>
7782
<Box className="line-numbers" component="pre" sx={{ overflowX: "auto" }}>
78-
<code className="language-">{content}</code>
83+
<code className={`${firaMonoFont.className} language-`}>{content}</code>
7984
</Box>
8085
</Box>
8186
</Paper>

src/pages/_app.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ import { HydrationBoundary, QueryClient, QueryClientProvider } from "@tanstack/r
1212
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
1313
import { enableMapSet } from "immer";
1414
import { type AppProps } from "next/app";
15+
import Head from "next/head";
1516
import { SnackbarProvider } from "notistack";
1617

1718
import { ThemeProviders } from "../components/app/ThemeProviders";
1819
import { TopLevelHooks } from "../components/app/TopLevelHooks";
20+
import { openSansFont } from "../constants/fonts";
1921
import { AS_API_URL, DM_API_URL } from "../constants/proxies";
2022
import { MDXComponentProvider } from "../context/MDXComponentProvider";
2123

2224
import "../styles/globalStyles.scss";
2325

26+
const openSansFontCss = `
27+
html {
28+
font-family: ${openSansFont.style.fontFamily};
29+
}
30+
`;
31+
2432
setDMBaseUrl(DM_API_URL);
2533
setASBaseUrl(AS_API_URL);
2634

@@ -45,6 +53,9 @@ const App = ({ Component, pageProps }: CustomAppProps) => {
4553

4654
return (
4755
<AppCacheProvider {...pageProps}>
56+
<Head>
57+
<style>{openSansFontCss}</style>
58+
</Head>
4859
<ThemeProviders>
4960
<UserProvider
5061
loginUrl={`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/auth/login`}

src/styles/globalStyles.scss

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
@use "mixins/font-face-template" with ($base_url: $assetsURL);
22

3-
@include font-face-template.font-face-template("Open Sans", "OpenSans-Light", normal, 300);
4-
@include font-face-template.font-face-template("Open Sans", "OpenSans-LightItalic", italic, 300);
5-
@include font-face-template.font-face-template("Open Sans", "OpenSans-Regular", normal, 400);
6-
@include font-face-template.font-face-template("Open Sans", "OpenSans-Italic", italic, 400);
7-
@include font-face-template.font-face-template("Open Sans", "OpenSans-SemiBold", normal, 600);
8-
@include font-face-template.font-face-template("Open Sans", "OpenSans-SemiBoldItalic", italic, 600);
9-
@include font-face-template.font-face-template("Open Sans", "OpenSans-Bold", normal, 700);
10-
@include font-face-template.font-face-template("Open Sans", "OpenSans-BoldItalic", italic, 700);
11-
@include font-face-template.font-face-template("Open Sans", "OpenSans-ExtraBold", normal, 800);
12-
@include font-face-template.font-face-template("Open Sans", "OpenSans-ExtraBoldItalic", italic, 800);
13-
143
@include font-face-template.font-face-template("Raleway", "Raleway-Thin", normal, 100);
154
@include font-face-template.font-face-template("Raleway", "Raleway-ThinItalic", italic, 100);
165
@include font-face-template.font-face-template("Raleway", "Raleway-ExtraLight", normal, 200);
@@ -30,8 +19,6 @@
3019
@include font-face-template.font-face-template("Raleway", "Raleway-Black", normal, 900);
3120
@include font-face-template.font-face-template("Raleway", "Raleway-BlackItalic", italic, 900);
3221

33-
@import url("https://fonts.googleapis.com/css2?family=Fira+Mono&display=swap");
34-
3522
:root {
3623
font-size: 14px;
3724
}

0 commit comments

Comments
 (0)