-
Notifications
You must be signed in to change notification settings - Fork 161
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
(feat): Adopting next/fonts
for loading fonts from google in nextjs projects.
#771
base: development
Are you sure you want to change the base?
Conversation
next/fonts
for loading fonts from google in nextjs projects.
Here is a reference of the code changes on the component level when users are using a google font import React from 'react'
import {
Nova_Oval,
Inter,
Chivo_Mono,
Sedgwick_Ave_Display,
} from 'next/font/google'
const sedgwick_ave_display = Sedgwick_Ave_Display({
preload: false,
variable: '--sedgwick_ave_display-font',
weight: '400',
})
const chivo_mono = Chivo_Mono({
preload: false,
variable: '--chivo_mono-font',
})
const inter = Inter({
preload: false,
variable: '--inter-font',
})
const nova_oval = Nova_Oval({
preload: false,
variable: '--nova_oval-font',
weight: '400',
})
const AppComponent = (props) => {
return (
<>
<div
className={`component-container ${sedgwick_ave_display.variable} ${chivo_mono.variable} ${inter.variable} ${nova_oval.variable} `}
>
<div className="component-container1">
Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</div>
<div className="component-container2">
Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</div>
<div className="component-primary-button">
Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</div>
</div>
<style jsx>
{`
.component-container {
width: 100%;
height: 400px;
display: flex;
position: relative;
align-items: flex-start;
flex-direction: column;
}
.component-container1 {
font-family: var(--inter-font);
}
.component-container2 {
margin-top: 100px;
font-family: var(--sedgwick_ave_display-font);
font-weight: 400;
}
.component-primary-button {
margin-top: 100px;
font-family: var(--nova_oval-font);
font-weight: 400;
}
@media (max-width: 767px) {
.component-container1 {
font-family: var(--chivo_mono-font);
}
}
`}
</style>
</>
)
}
export default AppComponent |
And the styles that are added as the default styles using import "./style.css";
import { Inter } from "next/font/google";
const inter = Inter({
preload: false,
variable: "--inter-font"
});
import React from "react";
export default function MyApp({
Component: Component,
pageProps: pageProps
}) {
React.useEffect(() => {
import("@lottiefiles/lottie-player");
return;
});
return <main className={` ${inter.variable} `}><style jsx global>{`html {
font-family: ${inter.style.fontFamily};
font-size: 16px;
}
body {
font-weight: 400;
font-style: normal;
text-decoration: none;
text-transform: none;
letter-spacing: normal;
line-height: 1.15;
color: var(--dl-color-gray-black);
background-color: var(--dl-color-gray-white);
}`}</style><style jsx global>{`html {
line-height: 1.15;
}
body {
margin: 0;
}
* {
box-sizing: border-box;
border-width: 0;
border-style: solid;
}
p,
li,
ul,
pre,
div,
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
padding: 0;
}
button,
input,
optgroup,
select,
textarea {
font-family: inherit;
font-size: 100%;
line-height: 1.15;
margin: 0;
}
button,
select {
text-transform: none;
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
button:-moz-focus,
[type="button"]:-moz-focus,
[type="reset"]:-moz-focus,
[type="submit"]:-moz-focus {
outline: 1px dotted ButtonText;
}
a {
color: inherit;
text-decoration: inherit;
}
input {
padding: 2px 4px;
}
img {
display: block;
}`}</style><Component {...pageProps} /></main>;
} And we can omit injecting the whole |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## development #771 +/- ##
===============================================
- Coverage 70.52% 68.68% -1.85%
===============================================
Files 170 174 +4
Lines 6999 7204 +205
Branches 2026 2087 +61
===============================================
+ Hits 4936 4948 +12
- Misses 2060 2253 +193
Partials 3 3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Btw this will upgrade Next to |
Screen.Recording.2023-04-21.at.20.07.17.mov |
The refactor still needs to happen on
project
level. But, there are a lot of edge cases covered till nowdefault-style-sheet
link
attrs and loading fonts fromGoogle
anymore in the_app.js
file.