Skip to content

Loading Next.js fonts with Tailwind 4 and Storybook 8 #29994

Closed Answered by lirbank
lirbank asked this question in Help
Discussion options

You must be logged in to vote

Here is the solution:

import React from "react";
import type { Preview } from "@storybook/react";
import { Lora, Open_Sans } from "next/font/google";
import "../src/app/globals.css";

const lora = Lora({
  subsets: ["latin"],
  variable: "--font-lora-serif",
});

const openSans = Open_Sans({
  subsets: ["latin"],
  variable: "--font-open-sans",
});

const preview: Preview = {
  parameters: {
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
  },
  decorators: [
    (Story) => {
      // Access the <html> element directly
      const htmlElement = document.documentElement;

      // Add the font variable classes to the <html> e…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by lirbank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant