🐼 PandaCSS preset for typography
A 🐼 PandaCSS typography preset inspired by the TailwindCSS typography plugin
Installation
npm install --save-dev pandacss-preset-typography
Usage
Add the preset to your PandaCSS configuration (panda.config.ts
)
import { defineConfig } from "@pandacss/dev";
import typographyPreset from "pandacss-preset-typography";
export default defineConfig({
presets: [
typographyPreset(),
"@pandacss/dev/presets",
],
});
Prose
The preset generates a prose
recipe for you that you can use to add beautiful typographic defaults to any vanilla HTML you don’t control, like HTML rendered from Markdown, or pulled from a CMS.
Usage
You can provide 5 different sizes: sm
, base
, lg
, xl
and 2xl
. If you provide no options, the default size is set as base
or as whatever you've set it as in the options.
import { prose } from "@pandacss/out/recipes";
export function Page() {
return <div className={prose({ size: "lg" })}></div>;
}
Lead
Just like in TailwindCSS, there's also an extra .lead
class you can apply to any element within the scope of prose
to get a nice lead paragraph.
Options
You can change the default options as shown below.
...
presets: [
typographyPreset({
recipe: {
name: "prose",
className: "prose",
sizes: ["sm", "base", "lg", "xl", "2xl"],
defaultSize: "base",
notProse: false,
semanticTokens: {
defaults: {
colorPalette: "slate",
},
prefix: "prose",
},
},
}),
],
Colors
Colors are currently being handled by CSS variables. The default colors are
as followed:
{
semanticTokens: {
colors: {
prose: {
body: {
value: "{colors.slate.700}",
},
heading: {
value: "{colors.slate.900}",
},
lead: {
value: "{colors.slate.600}",
},
link: {
value: "{colors.slate.900}",
},
bold: {
value: "{colors.slate.900}",
},
counter: {
value: "{colors.slate.500}",
},
bullet: {
value: "{colors.slate.300}",
},
hrBorder: {
value: "{colors.slate.200}",
},
quote: {
value: "{colors.slate.900}",
},
quoteBorder: {
value: "{colors.slate.200}",
},
caption: {
value: "{colors.slate.500}",
},
kbd: {
value: "{colors.slate.900}",
},
kbdShadow: {
value: "0 0 0",
},
code: {
value: "{colors.slate.900}",
},
preCode: {
value: "{colors.slate.200}",
},
preBg: {
value: "{colors.slate.800}",
},
thBorder: {
value: "{colors.slate.300}",
},
tdBorder: {
value: "{colors.slate.200}",
},
},
},
},
}
If you have the Radix Colors preset installed for example, you'll get dark mode support out of the box by providing the colors as shown below. These colors combinations aren't fully tested, so change according to preference.
{
semanticTokens: {
colors: {
prose: {
body: {
value: "{colors.slate.12}",
},
heading: {
value: "{colors.slate.12}",
},
lead: {
value: "{colors.slate.12}",
},
link: {
value: "{colors.blue.11}",
},
bold: {
value: "{colors.slate.12}",
},
counter: {
value: "{colors.slate.11}",
},
bullet: {
value: "{colors.slate.11}",
},
hrBorder: {
value: "{colors.slate.6}",
},
quote: {
value: "{colors.slate.11}",
},
quoteBorder: {
value: "{colors.slate.6}",
},
caption: {
value: "{colors.slate.11}",
},
kbd: {
value: "{colors.slate.11}",
},
kbdShadow: {
value: "0 0 0",
},
code: {
value: "{colors.amber.11}",
},
preCode: {
value: "{colors.slate.12}",
},
preBg: {
value: "{colors.slate.2}",
},
thBorder: {
value: "{colors.slate.6}",
},
tdBorder: {
value: "{colors.slate.6}",
},
},
},
},
}
Attributions