Custom fonts
Shavin uses two font variables: --font-display for large headings and --font-body for everything else. ThemeProvider sets both, so change fonts through its props rather than in CSS. The default pairing is Space Grotesk and Inter.
Use a built-in font
Pass a name from the built-in list (the same list as the Theme configurator). Shavin loads it from Google Fonts.
<ThemeProvider displayFont="Fraunces" bodyFont="Figtree">{children}</ThemeProvider>Use your own font
Load the font yourself, then pass its CSS font-family value. Any value that is not a built-in name is used as written and not fetched. With next/font:
// app/layout.tsx
import { Fraunces, Inter } from "next/font/google";
import { ThemeProvider } from "@shavin/ui";
const display = Fraunces({ subsets: ["latin"] });
const body = Inter({ subsets: ["latin"] });
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<ThemeProvider displayFont={display.style.fontFamily} bodyFont={body.style.fontFamily}>
{children}
</ThemeProvider>
</body>
</html>
);
}With a self-hosted file:
/* globals.css */
@font-face {
font-family: "Acme Sans";
src: url("/fonts/acme-sans.woff2") format("woff2");
font-display: swap;
}
// layout
<ThemeProvider bodyFont={'"Acme Sans", system-ui, sans-serif'}>{children}</ThemeProvider>Setting --font-display or --font-body in your own CSS does not work on its own: ThemeProvider's values take precedence.
Subheadings (h3 to h6)
Heading uses the display font for h1 and h2, and --font-subheading for h3 to h6. That follows the body font by default, because display faces lose clarity at small sizes. To use the display face, or a third font:
<ThemeProvider displayFont="Playfair Display" subheadingFont="display">{children}</ThemeProvider>