Fonts04
The fonts come with the package, so there's nothing to load. When you want your own, three variables change them everywhere.
Built in
Each personality has a display font for headings, buttons and labels, and a
body font for running text. They're bundled with Plonk as woff2 files and
declared in theme.css.
| Personality | Display | Body |
|---|---|---|
| Sticker | Baloo 2 | Nunito |
| Retro | Tiny5 | IBM Plex Mono |
| Comic | Bangers | Kalam |
| Arcade | Bungee | Rubik |
You don't pay for what you don't use. Browsers only download a font when something on the page is drawn with it, so an app that only uses Sticker never fetches Retro's pixel font.
Every font covers Latin and Latin Extended, including Turkish, Polish, Czech and other accented alphabets. All of them are licensed under the SIL Open Font License; the license files ship next to the fonts.
Use your own
Fonts are tokens like everything else:
--plonk-font-displayfor headings, buttons and labels--plonk-font-bodyfor text--plonk-font-monofor code and keyboard keys
Quarterly report
Same component, your typefaces.
import { Button, Card, PlonkProvider, usePersonality } from "plonk-ui";
export default function CustomFont() {
const personality = usePersonality();
return (
<PlonkProvider
personality={personality}
style={{
"--plonk-font-display": "Georgia, 'Times New Roman', serif",
"--plonk-font-body": "system-ui, sans-serif",
"--plonk-font-display-case": "none",
}}
>
<Card title="Quarterly report" className="w-72 max-w-full">
<div className="flex flex-col items-start gap-4">
<p>Same component, your typefaces.</p>
<Button>Download PDF</Button>
</div>
</Card>
</PlonkProvider>
);
}For every personality
:root,
[data-plonk-personality] {
--plonk-font-display: "Inter", system-ui, sans-serif;
--plonk-font-body: "Inter", system-ui, sans-serif;
}For one personality
[data-plonk-personality="retro"] {
--plonk-font-body: "JetBrains Mono", ui-monospace, monospace;
}For one part of the page
<PlonkProvider
personality="sticker"
style={{ "--plonk-font-display": "Georgia, serif" }}
>
<Article />
</PlonkProvider>;Loading the font
Plonk only points at a font name; loading it is up to you. With Next.js,
next/font gives you a CSS variable to hand over:
// app/layout.tsx
import { Inter } from "next/font/google";
const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en" className={inter.variable}>
<body>
<PlonkProvider style={{ "--plonk-font-body": "var(--font-inter)" }}>
{children}
</PlonkProvider>
</body>
</html>
);
}Anywhere else, a regular @font-face rule or a Google Fonts link works.
Fonts with only capitals
Comic's Bangers and Arcade's Bungee only draw capital letters. Plonk sets their
text to text-transform: uppercase so the browser picks the right capital for
the language: in Turkish, i becomes İ, not I. That only works when the
page knows its language, which is one reason to set
locale on the provider.
If you bring your own capitals-only font, tell Plonk:
[data-plonk-personality="sticker"] {
--plonk-font-display: "Bebas Neue", sans-serif;
--plonk-font-display-case: uppercase;
}The reverse also works: give Comic or Arcade a font with lowercase letters and
set --plonk-font-display-case: none.