@kleb/templating (0.1.1)
Published 2026-07-04 18:56:29 +02:00 by kleb
Installation
@kleb:registry=npm install @kleb/templating@0.1.1"@kleb/templating": "0.1.1"About this package
@kleb/templating
Email-focused React template rendering.
import { Body, Head, Html, Tailwind, Text } from "react-email";
import { createEmailTailwindConfig, renderEmailTemplate } from "@kleb/templating";
const theme = createEmailTailwindConfig({
colors: {
background: "#ffffff",
foreground: "#111827",
primary: "#2563eb",
primaryForeground: "#ffffff",
},
});
const WelcomeEmail = ({ name }: { name: string }) => (
<Html>
<Tailwind config={theme}>
<Head />
<Body className="bg-background text-foreground">
<Text>Hello {name}</Text>
</Body>
</Tailwind>
</Html>
);
const rendered = await renderEmailTemplate(WelcomeEmail, { name: "Ada" });
Theme values should be resolved colors. Do not pass CSS variables directly to
email templates. React Email's pixel-based Tailwind preset is included by
default; pass { pixelBasedPreset: false } to disable it.
Use placeholder rendering for subjects, text bodies, or small snippets:
import { renderHtmlTemplateString, renderTemplateString } from "@kleb/templating";
const subject = renderTemplateString("Welcome, {{user.name}}", {
user: { name: "Ada" },
});
const html = renderHtmlTemplateString("<p>Hello {{user.name}}</p>", {
user: { name: "<Ada>" },
});
Missing placeholders throw by default. Pass { missing: "keep" } or
{ missing: "empty" } when that behavior is explicitly desired.
Use a registry for reusable email templates:
import { createEmailTemplateRegistry, defineEmailTemplate } from "@kleb/templating";
const registry = createEmailTemplateRegistry([
defineEmailTemplate({
id: "welcome",
component: WelcomeEmail,
subject: "Welcome {{name}}",
preview: ({ name }) => `Hello ${name}`,
sampleProps: { name: "Ada" },
}),
]);
const rendered = await registry.render("welcome", { name: "Ada" });
Markdown content can be wrapped as an email template with
createMarkdownEmailTemplate.
Use the config integration when email theme tokens should be loaded through
@kleb/config:
import { kConfig } from "@kleb/config/server";
import { emailThemeConfig } from "@kleb/templating/config";
const loaded = kConfig("app.json").section("emailTheme", emailThemeConfig()).load();
Dependencies
Dependencies
| ID | Version |
|---|---|
| react-email | ^6.6.6 |
Development dependencies
| ID | Version |
|---|---|
| @types/react | 19.2.17 |
| @types/react-dom | 19.2.3 |
| react | 19.2.7 |
| react-dom | 19.2.7 |
Peer dependencies
| ID | Version |
|---|---|
| @kleb/config | ^0.4.0 |
| react | ^18.0 || ^19.0 || ^19.0.0-rc |
| react-dom | ^18.0 || ^19.0 || ^19.0.0-rc |