-
Notifications
You must be signed in to change notification settings - Fork 832
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
Using custom fonts #542
Comments
Have you tried composing the components with the I have done Has worked for me, for what it's worth, but might not be the recommended solution either. |
Seems strange to pass a prop every single time I use one of Evergreen's components. I could create a wrapper for each, but that seems to defeat the purpose of using a component library in the first place. I understand Evergreen does not support theming, but overriding a font in CSS seems like something a lot of people would need. I'll take this as an opportunity to create wrappers around all of the components I import for Evergreen, if only so I can easily switch them out in the future. I'd really like to hear about additional ways to override the fonts though :) |
Theming actually is supported, despite not being documented. You can What you'll probably want to do is use Something like this: import { defaultTheme } from 'evergreen-ui'
import { merge } from 'lodash'
const myCustomTheme = merge({}, defaultTheme, {
typography: {
fontFamilies: {
display: '-apple-system, ...whatever other fonts',
ui: '-apple-system, sans-serif',
mono: '"SF Mono", monospace'
}
}
})
export default myCustomTheme If you are familiar with React's context feature, that's what Evergreen uses under the hood. Wrap your app with |
Aha, nice! I got confused because the FAQ on Am I supposed to do anything else than supply the theme to the |
Oof. Hate to say it but your best bet might be to mutate |
I tried mutating, but that didn't work either. Also tried a combination of both :p. Any more ideas? I would create a wrapper and pass the |
Mutating worked for me. Here's a codesandbox. |
If all else fail you can take the wrapper approach. We should dive into the problem to see why we can't always use |
Ah yes, it works when I use lodash so I must not be mutating it properly without it. Thanks for all the help! |
What properties can you have in a custom theme (Such as typography)? I'm looking for those and can't find them. |
Custom themes aren't officially supported (and that's why there are no docs for it) but you can try using the The easiest way is to override individual components using |
@mshwery, I am using /**
* Theme provided by ThemeProvider.
*/
theme?: Theme Overrding the const LayoutWrapper = styled.div`
& .📦fnt-fam_b77syt,
& .📦fnt-fam_wm9v6k {
font-family: var(--font-body) !important;
}
`; It works for now but it feels a bit hacky and bound to break on builds and updates. Whats the fix for TS imports of the ThemeProvider? I am missing something? |
@Sowed v5 includes the types for While not ideal, you could bypass this sort of typedef concern by |
@mshwery, I can confirm, as per your sandbox, mutating with With that mutation, it makes me wonder why we still need the ThemeProvider anyway because it still works without it. |
@Sowed yeah – unfortunately until we fix the theme and provide first-class support for theming the ThemeProvider only is useful for the few scenarios that don't require mutating |
Last month in #460, someone said Evergreen doesn't set fonts by default. But from what I understand, there's a default theme that sets base fonts: https://github.com/segmentio/evergreen/blob/master/src/theme/src/default-theme/typography/fontFamilies.js
I'm having trouble overwriting them. I set a font-family for
body
, and it won't overwrite the themed styles, even when including!important
. How do I use a customfont-family
across all of the components supplied by Evergreen?The text was updated successfully, but these errors were encountered: