-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Bug]: @storybook/nextjs not loading google fonts with 3 words in name #22248
Comments
Just spent two hours on figuring out why IBM Plex Sans didn't work. |
Hi, I have found workarounds and why this issue causes. WorkaroundAlthough the class name has spaces and doesn't work, the font itself still be loaded. So you can directly refer to the Here's an example using decorator: decorators: [
(story) => (
<>
<style>
{`
/* classNames method */
.${font.className.replaceAll(' ', '.')} {
font-family: ${font.style.fontFamily};
${font.style.fontStyle ? `font-style: ${font.style.fontStyle};` : ''}
${font.style.fontWeight ? `font-weight: ${font.style.fontWeight};` : ''}
}
${
font.variable
? `
/* CSS variable method */
.__variable_${font.className.replaceAll(' ', '.')} {
--font-family-sans: '${font.style.fontFamily}';
/* ^ Note that this is the 'variable' option you set */
}
`
: ''
}
`}
</style>
{story()}
</>
),
], The WhyThe issue originates from the
The How to fixTo fix the bug, we can replace Would it be alright if I submit a pull request with the fix? |
I read Code contributions document and opened PR #23121. |
Describe the bug
Google font is not loaded correctly when it has more than 2 words (parts) in name. Loaded font's
className
andvariable
have space in name and do not work probably because of that.import font code:
output:
Fonts with 1 or 2-part names works, looks like 3rd part gets space instead of
-
in classNameTo Reproduce
https://github.com/msadura/sb-google-font-bug-repro/tree/main/nextjs/default-ts
start sotrybook and check console log from
preview.ts
- google fontclassName
andvariable
are incorrect.System
Additional context
No response
The text was updated successfully, but these errors were encountered: