Closed BorisZubchenko closed 3 days ago
same issue @BorisZubchenko have you found any solution ?
Unfortunately, no. I've returned to Inter for now.
ok thanks I'ill do that
Hi everyone. I used this workaround to make it work on my project:
Install and setup @storybook/nextjs
as described here https://storybook.js.org/docs/8.0/get-started/nextjs
Setup staticDirs
in .storybook/main.ts
:
staticDirs: [
{
from: "../node_modules/geist/dist/fonts/geist-sans",
to: "/fonts/geist-sans",
},
{
from: "../node_modules/geist/dist/fonts/geist-mono",
to: "/fonts/geist-mono",
},
],
};
Use localFont
directly in .storybook/preview.tsx
:
import localFont from "next/font/local";
import type { Preview } from "@storybook/react";
import "../src/app/globals.css";
const GeistSans = localFont({ src: "../fonts/geist-sans/Geist-Variable.woff2", variable: "--font-geist-sans", });
const GeistMono = localFont({ src: "../fonts/geist-mono/GeistMono-Variable.woff2", variable: "--font-geist-mono", });
const preview: Preview = {
decorators: [
(Story) => (
<div className={${GeistMono.variable} ${GeistSans.variable}
}>
</div>
),
], };
export default preview;
Using the localFont
API didn't quite work for me, I used the preview-head.html
to get this working with the same staticDirs
config... don't like it, but it works.
<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=DM+Serif+Display:ital@0;1&display=swap"
rel="stylesheet"
/>
<style>
@font-face {
font-family: "Geist Sans";
src: url("fonts/geist-sans/Geist-Variable.woff2");
}
@font-face {
font-family: "Geist Mono";
src: url("fonts/geist-mono/Geist-Variable.woff2");
}
.dm-serif-display-regular {
font-family: "DM Serif Display", serif;
font-weight: 400;
font-style: normal;
}
.dm-serif-display-regular-italic {
font-family: "DM Serif Display", serif;
font-weight: 400;
font-style: italic;
}
:root {
--font-dm_serif_display: "DM Serif Display", serif;
--font-geist-sans: "Geist Sans", sans-serif;
--font-geist-mono: "Geist Mono", monospace;
}
</style>
I think this has the same root cause as https://github.com/vercel/geist-font/issues/59
Closing this as a duplicate of that.
Font Name (Geist Sans/Geist Mono):
Description of the Issue: Importing the font into Storybook breaks it. Importing fonts via
next/font
works fine, however.Steps to Reproduce:
import cs from '~/app/_lib/react/cs' // a utility to join classes
const rootCss = cs( GeistSans.variable, GeistMono.variable, 'text-foreground max-w-full bg-background font-sans antialiased', )
export default rootCss
Expected Behavior: Should work
Screenshots:![image](https://github.com/vercel/geist-font/assets/31354262/12f2e73b-1821-4426-87b3-84bd9307d500)
Environment (please complete the following information):