-
I had tried to do this with CSS variables but it does nothing //index.tsx
import { Inter } from "@next/font/google";
import { Heading } from "@chakra-ui/react";
import { AppLayout } from "@/layouts/AppLayout";
const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });
export default function Home() {
return (
<>
<main className={inter.variable}>
<AppLayout>
<Heading>Hello World</Heading>
</AppLayout>
</main>
</>
);
}
//theme.tsx
fonts: {
heading: `var(--font-inter)`,
body: `var(--font-inter)`,
}, The documentation hasn't mentioned it, any help? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
@SonMooSans you can do something like this: import { Montserrat } from '@next/font/google'
import type { AppProps } from 'next/app'
import { ChakraProvider, Text } from '@chakra-ui/react'
import { extendTheme } from '@chakra-ui/react'
const montserrat = Montserrat({ subsets: [ 'cyrillic' ] })
const theme = extendTheme({
fonts: {
montserrat: montserrat.style.fontFamily,
},
})
function MyApp({ Component, pageProps }: AppProps) {
return (
<ChakraProvider theme={theme}>
<Text fontFamily='montserrat'>I am Montserrat</Text>
<Component {...pageProps} />
</ChakraProvider>
)
}
export default MyApp |
Beta Was this translation helpful? Give feedback.
-
You can edit your Heading and Body in the theme as well so your don't have to specify all components. Although I don't see my font unless I specify display: 'swap' .
|
Beta Was this translation helpful? Give feedback.
-
Just want to add another way of doing this.
// _app.tsx
import type { AppProps } from 'next/app'
import { theme } from '../theme'
import { Inter } from 'next/font/google'
// set inter to CSS var --font-inter
const inter = Inter({ subsets: ['latin'], variable: '--font-inter' })
function MyApp({ Component, pageProps }: AppProps<{ initialSession: Session }>) {
return (
// load the font in the app globally through className={inter.className}
<main className={inter.className}>
// set ChakraUI to use the extended or custom theme using the CSS var for your font
<ChakraProvider theme={theme}>
<Component {...pageProps} />
</ChakraProvider>
</main>
)
} // theme.ts
import type { ThemeConfig, ThemeOverride } from '@chakra-ui/react'
import { extendTheme } from '@chakra-ui/react'
const base: ThemeOverride = {
...
// use the CSS var name set in _app.tsx when initializing the font
fonts: {
heading: `var(--font-inter), sans-serif`,
body: `var(--font-inter), sans-serif`,
mono: `'Menlo', monospace`
},
...
}
export const theme: ThemeOverride = extendTheme(base) |
Beta Was this translation helpful? Give feedback.
@SonMooSans you can do something like this:
pages/_app.tsx