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

Can't add font to fontFamily in global theme #21

Closed
mzavattaro opened this issue Jan 4, 2024 · 6 comments
Closed

Can't add font to fontFamily in global theme #21

mzavattaro opened this issue Jan 4, 2024 · 6 comments

Comments

@mzavattaro
Copy link

mzavattaro commented Jan 4, 2024

I've been trying to add a specific font Jura, sans-serif to the global theme theme.ts.

I followed this guide https://mantine.dev/theming/typography/ and it doesn't work with Jura, sans-serif from Google Fonts. It does correctly change the font toVerdana, sans-serif like in the example.

How do I get this to work:

'use client';

import { createTheme } from '@mantine/core';

export const theme = createTheme({
  /* Put your mantine theme override here */
  fontFamily: 'Jura, sans-serif',
});

Also, how do I get select components to have different fonts outside of those that are set in theme.ts? There doesn't seem to be an example having the <Button /> have one font then the <Input /> adopt a different font again.

Only thing I can think of is not having Mantine theme.ts manage the fonts and do the NextJS method of font management. Is that possible?

@rtivital
Copy link
Member

rtivital commented Jan 4, 2024

@mzavattaro
Copy link
Author

mzavattaro commented Jan 4, 2024

Why doesn't it work in theme.ts? Like for example in computed it does show Jura, sans-serif as the font but it doesn't display the changes.

Edit: can confirm that solution doesn't work in the NextJS template. Something is preventing the changes to render in browser.

Happy to have this flagged as a 🐛 @rtivital, thanks for trying!

@rtivital
Copy link
Member

rtivital commented Jan 4, 2024

You did not include font files

    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Jura&display=swap"
      rel="stylesheet"
    />

@mzavattaro
Copy link
Author

mzavattaro commented Jan 4, 2024

That looks to have solved it. Is it possible to get this included in the https://mantine.dev/theming/typography/ section of the docs? I'm happy to contribute to the docs for it.

Edit: my only gripe with this method is that it ignores Next's font optimisation so it's not an optimal solution more of a work around. Nonetheless, thanks for the quick response!

@prvnbist
Copy link

An alternative way as opposed to loading font scripts would be to use next/font.

import { Jura} from 'next/font/google'

const jura = Inter({ subsets: ['latin'] })

export const theme = createTheme({
   fontFamily: jura.style.fontFamily
})

@rtivital
Copy link
Member

irevdev pushed a commit to rvise-au/rvise-ui-library that referenced this issue Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants