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

New font loading using next/font package #333

Merged
merged 2 commits into from
Apr 13, 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
4 changes: 1 addition & 3 deletions src/components/Posts/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export const Post: FC<IPost> = ({caption, short_text, links, details, sites, add
</Link>
))}
</Stack>
<Typography variant="body1" fontWeight={275} textTransform="uppercase">
{formatDate(added_at)}
</Typography>
<Typography variant="postDate">{formatDate(added_at)}</Typography>
</Stack>
</Stack>
)
Expand Down
1 change: 0 additions & 1 deletion src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ h6 {
/* end of Josh Comeau's global CSS reset */

body {
font-family: "Poppins", sans-serif;
-moz-osx-font-smoothing: grayscale;
}

Expand Down
8 changes: 8 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ const MyApp: FC<AppProps> = ({Component, pageProps}) => {
<title>React App</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
{/* ak pouzijeme vsade <Typography>, nemuseli by sme mat takyto globalny styl... ale je to teda
safe a krajsie, nech kazdy maly (ah debug) textik je aspon nasim fontom a ne v Times :D
source: https://nextjs.org/docs/pages/building-your-application/optimizing/fonts#apply-the-font-in-head */}
<style jsx global>{`
html {
font-family: ${theme.typography.fontFamily};
}
`}</style>
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools />
<CookiesProvider>
Expand Down
4 changes: 0 additions & 4 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class MyDocument extends Document {
<meta name="theme-color" content="#000000" />
<link rel="icon" href="/favicon.ico" />
<link rel="manifest" href="/manifest.json" />
<link
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
</Head>
<body>
<Main />
Expand Down
121 changes: 102 additions & 19 deletions src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {createTheme, Theme} from '@mui/material/styles'
import {Poppins} from 'next/font/google'

// https://mui.com/material-ui/customization/typography/#adding-amp-disabling-variants
declare module '@mui/material/styles' {
Expand All @@ -9,6 +10,7 @@ declare module '@mui/material/styles' {
button3: React.CSSProperties
postTitle: React.CSSProperties
postBody: React.CSSProperties
postDate: React.CSSProperties
}

// allow configuration using `createTheme`
Expand All @@ -19,6 +21,7 @@ declare module '@mui/material/styles' {
button3?: React.CSSProperties
postTitle?: React.CSSProperties
postBody?: React.CSSProperties
postDate?: React.CSSProperties
}
}

Expand All @@ -31,6 +34,7 @@ declare module '@mui/material/Typography' {
button3: true
postTitle: true
postBody: true
postDate: true
// disable these variants
h4: false
h5: false
Expand All @@ -42,10 +46,14 @@ declare module '@mui/material/Typography' {
subtitle2: false
}
}
export const font = Poppins({
subsets: ['latin'],
weight: ['300', '400', '600', '700', '800'],
})

const _theme = createTheme({
typography: {
fontFamily: ['Poppins', 'sans-serif'].join(','),
...font.style,
// disable these variants
h4: undefined,
h5: undefined,
Expand All @@ -55,6 +63,66 @@ const _theme = createTheme({
overline: undefined,
subtitle1: undefined,
subtitle2: undefined,
h1: {
...font.style,
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
},
h2: {
...font.style,
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
},
h3: {
...font.style,
textTransform: 'uppercase',
fontWeight: 800,
},
body1: {
...font.style,
fontWeight: 400,
},
body2: {
...font.style,
fontWeight: 400,
},
body3: {
...font.style,
fontWeight: 400,
},
button1: {
...font.style,
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
},
button2: {
...font.style,
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
},
button3: {
...font.style,
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
},
postTitle: {
...font.style,
fontWeight: 800,
},
postBody: {
...font.style,
fontWeight: 400,
},
postDate: {
...font.style,
textTransform: 'uppercase',
fontWeight: 300,
},
},
components: {
MuiTypography: {
Expand All @@ -68,6 +136,7 @@ const _theme = createTheme({
button3: 'span',
postTitle: 'h1',
postBody: 'span',
postDate: 'span',
},
},
},
Expand Down Expand Up @@ -108,110 +177,124 @@ export const theme: Theme = {
typography: {
..._theme.typography,
h1: {
..._theme.typography.h1,
// original Figma fontSize: 40px
fontSize: pxToRem(32),
[sm]: {fontSize: pxToRem(32)},
[md]: {fontSize: pxToRem(32)},
[lg]: {fontSize: pxToRem(32)},
[xl]: {fontSize: pxToRem(40)},
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
lineHeight: 1.5,
},
h2: {
..._theme.typography.h2,
// original Figma fontSize: 30px
fontSize: pxToRem(24),
[sm]: {fontSize: pxToRem(24)},
[md]: {fontSize: pxToRem(24)},
[lg]: {fontSize: pxToRem(24)},
[xl]: {fontSize: pxToRem(30)},
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
lineHeight: 1.5,
},
h3: {
..._theme.typography.h3,
// original Figma fontSize: 24px
fontSize: pxToRem(18),
[sm]: {fontSize: pxToRem(18)},
[md]: {fontSize: pxToRem(18)},
[lg]: {fontSize: pxToRem(18)},
[xl]: {fontSize: pxToRem(24)},
textTransform: 'uppercase',
fontWeight: 800,
lineHeight: 1.5,
},
body1: {
..._theme.typography.body1,
// original Figma fontSize: 20px
fontSize: pxToRem(14),
[sm]: {fontSize: pxToRem(16)},
[md]: {fontSize: pxToRem(16)},
[lg]: {fontSize: pxToRem(18)},
[xl]: {fontSize: pxToRem(20)},
lineHeight: 1.5,
},
body2: {
..._theme.typography.body2,
// original Figma fontSize: 16px
fontSize: pxToRem(10),
[sm]: {fontSize: pxToRem(12)},
[md]: {fontSize: pxToRem(12)},
[lg]: {fontSize: pxToRem(14)},
[xl]: {fontSize: pxToRem(16)},
lineHeight: 1.5,
},
body3: {
..._theme.typography.body3,
// original Figma fontSize: 12px
fontSize: pxToRem(8),
[sm]: {fontSize: pxToRem(8)},
[md]: {fontSize: pxToRem(8)},
[lg]: {fontSize: pxToRem(10)},
[xl]: {fontSize: pxToRem(12)},
lineHeight: 1.5,
},
button1: {
..._theme.typography.button1,
// original Figma fontSize: 30px
fontSize: pxToRem(24),
[sm]: {fontSize: pxToRem(24)},
[md]: {fontSize: pxToRem(24)},
[lg]: {fontSize: pxToRem(24)},
[xl]: {fontSize: pxToRem(30)},
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
lineHeight: 1.5,
},
button2: {
..._theme.typography.button2,
// original Figma fontSize: 20px
fontSize: pxToRem(14),
[sm]: {fontSize: pxToRem(16)},
[md]: {fontSize: pxToRem(16)},
[lg]: {fontSize: pxToRem(18)},
[xl]: {fontSize: pxToRem(20)},
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
lineHeight: 1.5,
},
button3: {
..._theme.typography.button3,
// original Figma fontSize: 14px
fontSize: pxToRem(10),
[sm]: {fontSize: pxToRem(10)},
[md]: {fontSize: pxToRem(10)},
[lg]: {fontSize: pxToRem(12)},
[xl]: {fontSize: pxToRem(14)},
textTransform: 'uppercase',
fontWeight: 800,
fontStyle: 'italic',
lineHeight: 1.5,
},
postTitle: {
..._theme.typography.postTitle,
// original Figma fontSize: 36px
fontSize: pxToRem(30),
[sm]: {fontSize: pxToRem(30)},
[md]: {fontSize: pxToRem(30)},
[lg]: {fontSize: pxToRem(30)},
[xl]: {fontSize: pxToRem(36)},
fontWeight: 800,
lineHeight: 1.5,
},
postBody: {
..._theme.typography.postBody,
// original Figma fontSize: 30px
fontSize: pxToRem(24),
[sm]: {fontSize: pxToRem(24)},
[md]: {fontSize: pxToRem(24)},
[lg]: {fontSize: pxToRem(24)},
[xl]: {fontSize: pxToRem(30)},
lineHeight: 1.5,
},
postDate: {
..._theme.typography.postDate,
// original Figma fontSize: 20px
fontSize: pxToRem(14),
[sm]: {fontSize: pxToRem(16)},
[md]: {fontSize: pxToRem(16)},
[lg]: {fontSize: pxToRem(18)},
[xl]: {fontSize: pxToRem(20)},
lineHeight: 1.5,
},
},
}
Loading