Skip to content

armgit / pdfcn

Public Imported from GitHub
0

Beautiful pdf components, built on Takumi and Forme. 100% Free, Zero config, one command setup.

feat: enhance theme builder with base-specific routing and font preview

Aniket-50828b641a5e403
diff --git a/app/(builder)/layout.tsx b/app/(builder)/layout.tsx
index 6ac5272..9bef22a 100644
--- a/app/(builder)/layout.tsx
+++ b/app/(builder)/layout.tsx
@@ -1,5 +1,5 @@
import { SiteHeader } from "@/components/site-header";
-import { WebMcpTools } from "@/components/web-mcp-tools";
+import { WebMcpTools } from "@/components/web-mcp/web-mcp-tools";
import { AGENT_DOCS_DIRECTIVE_TEXT } from "@/lib/agent-discovery/directive";
const ThemeBuilderLayout = ({ children }: { children: React.ReactNode }) => (
diff --git a/components/theme-builder/theme-builder.tsx b/components/theme-builder/theme-builder.tsx
index 98b46ce..2177d3c 100644
--- a/components/theme-builder/theme-builder.tsx
+++ b/components/theme-builder/theme-builder.tsx
@@ -295,20 +295,15 @@ export const ThemeBuilder = ({ base }: { base: BaseName }) => {
: "lg:grid-cols-[minmax(0,1fr)_0px]"
)}
>
- <section
- className="relative min-h-0 overflow-hidden bg-muted/35 p-6"
- aria-label="Live PDF preview"
- >
- <div className="mx-auto h-full max-w-5xl overflow-hidden rounded-xl border bg-background shadow-sm">
- <PdfPreview
- base={base}
- className="h-full rounded-none border-0"
- height="100%"
- name="invoice-classic"
- onUrlChange={handlePdfUrlChange}
- theme={previewTheme}
- />
- </div>
+ <section aria-label="Live PDF preview">
+ <PdfPreview
+ base={base}
+ className="h-full rounded-none border-0"
+ height="100%"
+ name="invoice-classic"
+ onUrlChange={handlePdfUrlChange}
+ theme={previewTheme}
+ />
<Button
className="absolute right-6 bottom-6 shadow-lg lg:hidden"
@@ -374,7 +369,7 @@ export const ThemeBuilder = ({ base }: { base: BaseName }) => {
aria-label="Theme controls"
>
<div className="flex h-full w-[390px] min-h-0 flex-col">
- <div className="flex items-start justify-between border-b px-6 py-3">
+ <div className="flex items-start justify-between border-b px-6 py-2.5">
<div className="min-w-0">
<h2 className="text-sm font-semibold">Customize</h2>
<p className="text-xs text-muted-foreground">
diff --git a/components/theme-builder/theme-controls.tsx b/components/theme-builder/theme-controls.tsx
index aa521b3..902b8aa 100644
--- a/components/theme-builder/theme-controls.tsx
+++ b/components/theme-builder/theme-controls.tsx
@@ -18,6 +18,7 @@ import { cn } from "@/lib/utils";
import type { PdfcnTheme, ThemePresetName } from "@/registry/themes";
import { THEMES } from "@/registry/themes";
+import { ThemePicker } from "./theme-picker";
import type {
ColorTokenName,
HeadingLevel,
@@ -236,33 +237,10 @@ export const ThemeControls = ({
</label>
<div className="flex items-center gap-1.5">
- <Select
- onValueChange={(value) =>
- actions.loadPreset(value as ThemePresetName)
- }
- value={basePreset}
- >
- <SelectTrigger
- className="w-full flex-1"
- id={`${idPrefix}-preset`}
- size="sm"
- >
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {THEMES.map(({ name, theme: presetTheme, title }) => (
- <SelectItem key={name} value={name}>
- <span className="flex items-center gap-2">
- <span
- className="size-2.5 shrink-0 rounded-full border"
- style={{ backgroundColor: presetTheme.colors.primary }}
- />
- {title}
- </span>
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ <ThemePicker
+ onThemeSelect={(name) => actions.loadPreset(name)}
+ selectedTheme={basePreset}
+ />
<Button
aria-label="Pick a random preset"
onClick={() => {
diff --git a/components/theme-builder/theme-picker.tsx b/components/theme-builder/theme-picker.tsx
new file mode 100644
index 0000000..de47048
--- /dev/null
+++ b/components/theme-builder/theme-picker.tsx
@@ -0,0 +1,266 @@
+"use client";
+
+import { CheckIcon } from "lucide-react";
+import { useMemo, useState } from "react";
+
+import { Button } from "@/components/ui/button";
+import {
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+ CommandList,
+} from "@/components/ui/command";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { THEMES } from "@/registry/themes";
+import type { ThemePresetName } from "@/registry/themes";
+import type { ColorTokens } from "@/registry/types/pdf-themes";
+
+const THEME_PALETTE_KEYS = [
+ "primary",
+ "accent",
+ "muted",
+ "background",
+] as const;
+
+type ThemeColors = Pick<ColorTokens, (typeof THEME_PALETTE_KEYS)[number]>;
+
+const ThemePalette = ({ colors }: { colors?: ThemeColors }) => (
+ <div className="flex shrink-0 gap-0.5">
+ {THEME_PALETTE_KEYS.map((key) => (
+ <div
+ key={key}
+ className="h-4 w-2.5 shrink-0 rounded-xs ring-1 ring-foreground/10"
+ style={{ backgroundColor: colors?.[key] ?? `var(--${key})` }}
+ />
+ ))}
+ </div>
+);
+
+const SHADCN_THEMES: { name: string; title: string; colors: ThemeColors }[] = [
+ {
+ colors: {
+ accent: "#f5f5f5",
+ background: "#ffffff",
+ muted: "#f5f5f5",
+ primary: "#171717",
+ },
+ name: "default",
+ title: "Default",
+ },
+ {
+ colors: {
+ accent: "#dbeafe",
+ background: "#ffffff",
+ muted: "#f1f5f9",
+ primary: "#1d4ed8",
+ },
+ name: "blue",
+ title: "Blue",
+ },
+ {
+ colors: {
+ accent: "#dcfce7",
+ background: "#ffffff",
+ muted: "#f0fdf4",
+ primary: "#15803d",
+ },
+ name: "green",
+ title: "Green",
+ },
+ {
+ colors: {
+ accent: "#f5f5f5",
+ background: "#ffffff",
+ muted: "#f5f5f5",
+ primary: "#171717",
+ },
+ name: "neutral",
+ title: "Neutral",
+ },
+ {
+ colors: {
+ accent: "#f5f5f4",
+ background: "#ffffff",
+ muted: "#f5f5f4",
+ primary: "#1c1917",
+ },
+ name: "stone",
+ title: "Stone",
+ },
+ {
+ colors: {
+ accent: "#f4f4f5",
+ background: "#ffffff",
+ muted: "#f4f4f5",
+ primary: "#18181b",
+ },
+ name: "zinc",
+ title: "Zinc",
+ },
+ {
+ colors: {
+ accent: "#f1f5f9",
+ background: "#ffffff",
+ muted: "#f1f5f9",
+ primary: "#0f172a",
+ },
+ name: "slate",
+ title: "Slate",
+ },
+ {
+ colors: {
+ accent: "#f3f4f6",
+ background: "#ffffff",
+ muted: "#f3f4f6",
+ primary: "#111827",
+ },
+ name: "gray",
+ title: "Gray",
+ },
+];
+
+const TWEAKCN_THEMES: { name: string; title: string; colors: ThemeColors }[] = [
+ {
+ colors: {
+ accent: "#caf0f8",
+ background: "#ffffff",
+ muted: "#f0f8ff",
+ primary: "#0077b6",
+ },
+ name: "ocean",
+ title: "Ocean",
+ },
+ {
+ colors: {
+ accent: "#d8f3dc",
+ background: "#ffffff",
+ muted: "#f0fdf4",
+ primary: "#2d6a4f",
+ },
+ name: "forest",
+ title: "Forest",
+ },
+ {
+ colors: {
+ accent: "#ffedd8",
+ background: "#ffffff",
+ muted: "#fff7ed",
+ primary: "#e85d04",
+ },
+ name: "sunset",
+ title: "Sunset",
+ },
+ {
+ colors: {
+ accent: "#ede9fe",
+ background: "#ffffff",
+ muted: "#f5f3ff",
+ primary: "#7c3aed",
+ },
+ name: "lavender",
+ title: "Lavender",
+ },
+ {
+ colors: {
+ accent: "#ffe4e6",
+ background: "#ffffff",
+ muted: "#fff1f2",
+ primary: "#e11d48",
+ },
+ name: "rose",
+ title: "Rose",
+ },
+ {
+ colors: {
+ accent: "#fef3c7",
+ background: "#ffffff",
+ muted: "#fffbeb",
+ primary: "#d97706",
+ },
+ name: "amber",
+ title: "Amber",
+ },
+];
+
+interface ThemePickerProps {
+ onThemeSelect: (name: ThemePresetName) => void;
+ selectedTheme: ThemePresetName;
+}
+
+export const ThemePicker = ({
+ onThemeSelect,
+ selectedTheme,
+}: ThemePickerProps) => {
+ const [open, setOpen] = useState(false);
+
+ const selectedThemeData = useMemo(
+ () => THEMES.find((t) => t.name === selectedTheme),
+ [selectedTheme]
+ );
+
+ return (
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger asChild>
+ <Button
+ variant="outline"
+ size="sm"
+ className="w-full justify-start gap-2 px-2"
+ aria-label="Select theme"
+ >
+ <ThemePalette colors={selectedThemeData?.theme.colors} />
+ <span className="flex-1 text-left">{selectedThemeData?.title}</span>
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-[320px] p-0" align="start">
+ <Command>
+ <CommandInput placeholder="Search theme..." />
+ <CommandList>
+ <CommandEmpty>No theme found.</CommandEmpty>
+
+ <CommandGroup heading="PDF Themes">
+ {THEMES.map(({ name, theme, title }) => (
+ <CommandItem
+ key={name}
+ onSelect={() => {
+ onThemeSelect(name);
+ setOpen(false);
+ }}
+ >
+ <ThemePalette colors={theme.colors} />
+ <span className="flex-1">{title}</span>
+ {selectedTheme === name && (
+ <CheckIcon className="size-4 shrink-0" />
+ )}
+ </CommandItem>
+ ))}
+ </CommandGroup>
+
+ <CommandGroup heading="shadcn/ui Themes">
+ {SHADCN_THEMES.map((theme) => (
+ <CommandItem key={theme.name} disabled>
+ <ThemePalette colors={theme.colors} />
+ <span className="flex-1">{theme.title}</span>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+
+ <CommandGroup heading="tweakcn Themes">
+ {TWEAKCN_THEMES.map((theme) => (
+ <CommandItem key={theme.name} disabled>
+ <ThemePalette colors={theme.colors} />
+ <span className="flex-1">{theme.title}</span>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ </CommandList>
+ </Command>
+ </PopoverContent>
+ </Popover>
+ );
+};