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: add landing page PDF showcase section

Aniket-5081f98ca53d54e
diff --git a/app/(app)/(root)/page.tsx b/app/(app)/(root)/page.tsx
index ed0c133..e9e353a 100644
--- a/app/(app)/(root)/page.tsx
+++ b/app/(app)/(root)/page.tsx
@@ -1,5 +1,6 @@
import { CommandBox } from "@/components/command-box";
import { HomeCtas } from "@/components/home-ctas";
+import { HomePdfShowcase } from "@/components/home-pdf-showcase";
import { PageHero } from "@/components/page-hero";
import { PageTransition } from "@/components/page-transition";
import { ROUTES } from "@/constants/routes";
@@ -32,6 +33,8 @@ const IndexPage = () => (
</div>
</section>
</PageTransition>
+
+ <HomePdfShowcase />
</>
);
export default IndexPage;
diff --git a/components/home-pdf-preview.tsx b/components/home-pdf-preview.tsx
new file mode 100644
index 0000000..d56e8b7
--- /dev/null
+++ b/components/home-pdf-preview.tsx
@@ -0,0 +1,660 @@
+"use client";
+
+import { BoxIcon } from "lucide-react";
+
+import { LogoMark } from "@/components/logo";
+import { Badge } from "@/components/ui/badge";
+import { cn } from "@/lib/utils";
+
+export const homePdfComponentCatalog = {
+ alert: {
+ codeName: "Alert",
+ description:
+ "A callout block for warnings, notes, and important information.",
+ docsPath: "components/alert",
+ label: "Alert",
+ },
+ badge: {
+ codeName: "Badge",
+ description:
+ "A styled label for status indicators, tags, and inline annotations.",
+ docsPath: "components/badge",
+ label: "Badge",
+ },
+ card: {
+ codeName: "Card",
+ description:
+ "A contained layout for grouping related content with border and padding.",
+ docsPath: "components/card",
+ label: "Card",
+ },
+ "data-table": {
+ codeName: "DataTable",
+ description:
+ "A full-featured data table with sorting, pagination, and cell formatting.",
+ docsPath: "components/data-table",
+ label: "Data table",
+ },
+ divider: {
+ codeName: "Divider",
+ description:
+ "A visual separator with configurable color, thickness, and margin.",
+ docsPath: "components/divider",
+ label: "Divider",
+ },
+ graph: {
+ codeName: "Graph",
+ description:
+ "A data visualization component for charts and statistical graphics.",
+ docsPath: "components/graph",
+ label: "Graph",
+ },
+ "key-value": {
+ codeName: "KeyValue",
+ description:
+ "A flexible key-value layout for metadata, summaries, and label pairs.",
+ docsPath: "components/key-value",
+ label: "Key-value",
+ },
+ list: {
+ codeName: "List",
+ description:
+ "An ordered or unordered list with custom markers and nested items.",
+ docsPath: "components/list",
+ label: "List",
+ },
+ "page-footer": {
+ codeName: "PageFooter",
+ description:
+ "A compact document footer with page numbers, legal text, and brand marks.",
+ docsPath: "components/page-footer",
+ label: "Page footer",
+ },
+ "page-header": {
+ codeName: "PageHeader",
+ description:
+ "A branded document header with logo, company details, and document title.",
+ docsPath: "components/page-header",
+ label: "Page header",
+ },
+ "pdf-image": {
+ codeName: "PdfImage",
+ description:
+ "An image component optimized for PDF rendering with aspect ratio and sizing.",
+ docsPath: "components/pdf-image",
+ label: "Image",
+ },
+ section: {
+ codeName: "Section",
+ description:
+ "A grouped content section with optional title, padding, and background.",
+ docsPath: "components/section",
+ label: "Section",
+ },
+ signature: {
+ codeName: "Signature",
+ description:
+ "A signature block for authorized signatories and approval lines.",
+ docsPath: "components/signature",
+ label: "Signature",
+ },
+ table: {
+ codeName: "Table",
+ description:
+ "A structured data table with headers, rows, and responsive column widths.",
+ docsPath: "components/table",
+ label: "Table",
+ },
+ text: {
+ codeName: "Text",
+ description:
+ "A versatile text component for headings, paragraphs, and inline content.",
+ docsPath: "components/text",
+ label: "Text",
+ },
+} as const;
+
+export type ComponentPartId = keyof typeof homePdfComponentCatalog;
+export type CodeOutput = "react" | "html";
+export type HomePdfBase = "takumi" | "forme";
+
+export const homePdfBases: {
+ id: HomePdfBase;
+ label: string;
+}[] = [
+ { id: "takumi", label: "Takumi" },
+ { id: "forme", label: "Forme" },
+];
+
+export const homePdfCodeOutputs: { id: CodeOutput; label: string }[] = [
+ { id: "react", label: "React" },
+ { id: "html", label: "HTML" },
+];
+
+export interface PdfRecipe {
+ actionHref: string;
+ actionLabel: string;
+ componentIds: readonly ComponentPartId[];
+ defaultComponentId: ComponentPartId;
+ description: string;
+ eyebrow: string;
+ filename: string;
+ heading: string;
+ id: PdfRecipeId;
+ name: string;
+ previewText: string;
+}
+
+export type PdfRecipeId =
+ | "corporate-invoice"
+ | "financial-report"
+ | "minimal-invoice";
+
+export const homePdfPreviews = [
+ {
+ actionHref: "https://pdfcn.run/docs/components",
+ actionLabel: "Explore the collection",
+ componentIds: [
+ "page-header",
+ "key-value",
+ "table",
+ "section",
+ "text",
+ "page-footer",
+ ],
+ defaultComponentId: "table",
+ description:
+ "Production-ready document layouts for invoices, reports, and more — built with composable components.",
+ eyebrow: "The document drop · 01",
+ filename: "corporate-invoice.tsx",
+ heading: "Build PDFs at component speed.",
+ id: "corporate-invoice",
+ name: "Corporate invoice",
+ previewText: "A new component collection from pdfcn",
+ },
+ {
+ actionHref: "https://pdfcn.run/docs/installation",
+ actionLabel: "Build your first PDF",
+ componentIds: ["page-header", "text", "graph", "data-table", "page-footer"],
+ defaultComponentId: "graph",
+ description:
+ "Start with a component, make it yours, and render confidently. Everything you need is ready.",
+ eyebrow: "Financial overview",
+ filename: "financial-report.tsx",
+ heading: "Your PDF workspace is ready.",
+ id: "financial-report",
+ name: "Financial report",
+ previewText: "Start building your first PDF",
+ },
+ {
+ actionHref: "https://pdfcn.run/docs/components",
+ actionLabel: "Browse components",
+ componentIds: [
+ "page-header",
+ "text",
+ "divider",
+ "key-value",
+ "page-footer",
+ ],
+ defaultComponentId: "text",
+ description:
+ "A clean, minimal invoice layout with essential billing details and payment terms.",
+ eyebrow: "Invoice #INV-2026-042",
+ filename: "minimal-invoice.tsx",
+ heading: "Simple, clean, professional.",
+ id: "minimal-invoice",
+ name: "Minimal invoice",
+ previewText: "Minimal invoice from pdfcn",
+ },
+] as const satisfies readonly PdfRecipe[];
+
+export const getHomePdfSource = (recipe: PdfRecipe, base: HomePdfBase) => {
+ const imports = recipe.componentIds
+ .map((id) => {
+ const component = homePdfComponentCatalog[id];
+ return `import { ${component.codeName} } from "@/registry/bases/${base}/components/${id}";`;
+ })
+ .join("\n");
+ const components = recipe.componentIds
+ .map((id) => ` <${homePdfComponentCatalog[id].codeName} />`)
+ .join("\n");
+ const functionName = recipe.id
+ .split("-")
+ .map((part) => `${part[0]?.toUpperCase()}${part.slice(1)}`)
+ .join("");
+
+ const shell =
+ base === "takumi"
+ ? {
+ close: "Page",
+ import: 'import { Page } from "takumi-pdf";',
+ open: "Page",
+ }
+ : {
+ close: "Document",
+ import: 'import { Document, Page } from "@formepdf/react";',
+ open: "Document",
+ };
+
+ return `${shell.import}
+${imports}
+
+export function ${functionName}Document() {
+ return (
+ <${shell.open}>
+ <${shell.open === "Document" ? "Page" : "Page"}>
+${components}
+ </${shell.open === "Document" ? "Page" : "Page"}>
+ </${shell.close}>
+ );
+}`;
+};
+
+const SelectablePdfPart = ({
+ children,
+ id,
+ selectedId,
+ onSelect,
+ className,
+}: {
+ children: React.ReactNode;
+ id: ComponentPartId;
+ selectedId: ComponentPartId;
+ onSelect: (id: ComponentPartId) => void;
+ className?: string;
+}) => {
+ const isSelected = selectedId === id;
+
+ return (
+ <button
+ type="button"
+ aria-label={`Inspect ${homePdfComponentCatalog[id].label}`}
+ aria-pressed={isSelected}
+ className={cn(
+ "group/pdf-part relative block w-full cursor-pointer text-left outline-none transition-[box-shadow] duration-200",
+ "hover:z-10 hover:shadow-[inset_0_0_0_2px_rgb(96_165_250)]",
+ "focus-visible:z-10 focus-visible:shadow-[inset_0_0_0_3px_rgb(59_130_246)]",
+ isSelected && "z-10 shadow-[inset_0_0_0_2px_rgb(59_130_246)]",
+ className
+ )}
+ onClick={() => onSelect(id)}
+ >
+ {children}
+ <Badge
+ className={cn(
+ "pointer-events-none absolute top-0 right-3 z-20 -translate-y-1/2 bg-blue-600 py-1 text-[9px] leading-none font-semibold tracking-wide text-white uppercase shadow-sm transition-opacity",
+ isSelected
+ ? "opacity-100"
+ : "opacity-0 group-hover/pdf-part:opacity-100 group-focus-visible/pdf-part:opacity-100"
+ )}
+ >
+ <BoxIcon className="size-2.5" aria-hidden="true" />
+ {id}
+ </Badge>
+ </button>
+ );
+};
+
+const CorporateInvoicePreview = ({
+ selectedId,
+ onSelect,
+}: PdfPreviewContentProps) => (
+ <div className="w-full bg-white font-sans text-foreground">
+ <SelectablePdfPart
+ id="page-header"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-5 sm:px-8"
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2 text-sm font-semibold">
+ <span className="flex size-7 items-center justify-center rounded-lg bg-primary text-primary-foreground">
+ <LogoMark className="size-4" />
+ </span>
+ PDFx Inc.
+ </div>
+ <div className="text-right">
+ <p className="text-[9px] font-bold tracking-[0.18em] text-muted-foreground uppercase">
+ Invoice
+ </p>
+ <p className="mt-0.5 text-[10px] font-medium">INV-2026-004</p>
+ </div>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="key-value"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-5 sm:px-8"
+ >
+ <div className="grid grid-cols-2 gap-4 text-[10px]">
+ <div>
+ <p className="font-semibold text-muted-foreground uppercase">
+ Bill To
+ </p>
+ <p className="mt-1 font-medium">Global Industries Ltd.</p>
+ <p className="text-muted-foreground">[email protected]</p>
+ <p className="text-muted-foreground">+1 (555) 888-9999</p>
+ </div>
+ <div>
+ <p className="font-semibold text-muted-foreground uppercase">
+ Details
+ </p>
+ <p className="mt-1 text-muted-foreground">Date: Feb 22, 2026</p>
+ <p className="text-muted-foreground">Due: Mar 24, 2026</p>
+ <p className="text-muted-foreground">Net 30 terms</p>
+ </div>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="table"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-4 sm:px-8"
+ >
+ <div className="rounded-lg border">
+ <table className="w-full text-[10px]">
+ <thead>
+ <tr className="border-b bg-muted/50">
+ <th className="px-3 py-2 text-left font-semibold">Description</th>
+ <th className="px-3 py-2 text-center font-semibold">Qty</th>
+ <th className="px-3 py-2 text-right font-semibold">Price</th>
+ <th className="px-3 py-2 text-right font-semibold">Total</th>
+ </tr>
+ </thead>
+ <tbody className="divide-y">
+ {[
+ ["Enterprise Software License", "5", "$4,500", "$22,500"],
+ ["Implementation Services", "1", "$18,000", "$18,000"],
+ ["Training Workshop", "3", "$2,500", "$7,500"],
+ ["Annual Support Package", "1", "$8,500", "$8,500"],
+ ].map(([desc, qty, price, total]) => (
+ <tr key={desc} className="divide-x">
+ <td className="px-3 py-2 font-medium">{desc}</td>
+ <td className="px-3 py-2 text-center">{qty}</td>
+ <td className="px-3 py-2 text-right text-muted-foreground">
+ {price}
+ </td>
+ <td className="px-3 py-2 text-right font-medium">{total}</td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="section"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-muted/30 px-6 py-4 sm:px-8"
+ >
+ <div className="ml-auto w-48 text-[10px]">
+ <div className="flex justify-between py-1">
+ <span className="text-muted-foreground">Subtotal</span>
+ <span>$56,500</span>
+ </div>
+ <div className="flex justify-between py-1">
+ <span className="text-muted-foreground">Tax (8%)</span>
+ <span>$4,520</span>
+ </div>
+ <div className="flex justify-between border-t py-1.5 font-semibold">
+ <span>Total</span>
+ <span>$61,020</span>
+ </div>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="text"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-4 sm:px-8"
+ >
+ <p className="text-[9px] text-muted-foreground">
+ Corporate billing — Net 30 terms apply. For inquiries, contact
+ </p>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="page-footer"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-primary px-6 py-4 text-primary-foreground/60 sm:px-8"
+ >
+ <div className="flex items-center justify-between text-[9px]">
+ <div className="flex items-center gap-1.5">
+ <LogoMark className="size-3" />
+ pdfcn
+ </div>
+ <span>Page 1 of 1</span>
+ </div>
+ </SelectablePdfPart>
+ </div>
+);
+
+const FinancialReportPreview = ({
+ selectedId,
+ onSelect,
+}: PdfPreviewContentProps) => (
+ <div className="w-full bg-white font-sans text-foreground">
+ <SelectablePdfPart
+ id="page-header"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-5 sm:px-8"
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2 text-sm font-semibold">
+ <span className="flex size-7 items-center justify-center rounded-lg bg-emerald-600 text-white">
+ <LogoMark className="size-4" />
+ </span>
+ PDFx Inc.
+ </div>
+ <span className="rounded-full bg-emerald-50 px-2.5 py-0.5 text-[9px] font-semibold text-emerald-700">
+ Q4 2025
+ </span>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="text"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-6 text-center sm:px-8"
+ >
+ <p className="text-[9px] font-bold tracking-[0.22em] text-emerald-600 uppercase">
+ Financial Overview
+ </p>
+ <h3 className="mt-2 text-2xl font-semibold tracking-tight">
+ Quarterly Revenue Report
+ </h3>
+ <p className="mx-auto mt-2 max-w-sm text-[11px] text-muted-foreground">
+ Summary of financial performance for Q4 2025 across all business units.
+ </p>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="graph"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-muted/30 px-6 py-5 sm:px-8"
+ >
+ <div className="flex items-end justify-center gap-2 h-24">
+ {[65, 45, 80, 55, 70, 90].map((h, i) => (
+ <div key={i} className="flex flex-col items-center gap-1">
+ <div
+ className="w-8 rounded-t bg-emerald-500/80"
+ style={{ height: `${h}%` }}
+ />
+ <span className="text-[8px] text-muted-foreground">
+ {["Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][i]}
+ </span>
+ </div>
+ ))}
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="data-table"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-background px-6 py-4 sm:px-8"
+ >
+ <div className="rounded-lg border">
+ <table className="w-full text-[10px]">
+ <thead>
+ <tr className="border-b bg-muted/50">
+ <th className="px-3 py-2 text-left font-semibold">Segment</th>
+ <th className="px-3 py-2 text-right font-semibold">Revenue</th>
+ <th className="px-3 py-2 text-right font-semibold">Growth</th>
+ </tr>
+ </thead>
+ <tbody className="divide-y">
+ {[
+ ["Enterprise", "$2.4M", "+18%"],
+ ["SMB", "$1.1M", "+24%"],
+ ["Consumer", "$890K", "+12%"],
+ ].map(([segment, revenue, growth]) => (
+ <tr key={segment} className="divide-x">
+ <td className="px-3 py-2 font-medium">{segment}</td>
+ <td className="px-3 py-2 text-right">{revenue}</td>
+ <td className="px-3 py-2 text-right font-medium text-emerald-600">
+ {growth}
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="page-footer"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="bg-emerald-600 px-6 py-4 text-emerald-100/60 sm:px-8"
+ >
+ <div className="flex items-center justify-between text-[9px]">
+ <div className="flex items-center gap-1.5">
+ <LogoMark className="size-3" />
+ pdfcn
+ </div>
+ <span>Page 1 of 1</span>
+ </div>
+ </SelectablePdfPart>
+ </div>
+);
+
+const MinimalInvoicePreview = ({
+ selectedId,
+ onSelect,
+}: PdfPreviewContentProps) => (
+ <div className="w-full bg-white font-sans text-foreground">
+ <SelectablePdfPart
+ id="page-header"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="px-6 py-6 sm:px-10"
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2 text-sm font-semibold">
+ <span className="flex size-7 items-center justify-center rounded-lg bg-foreground text-background">
+ <LogoMark className="size-4" />
+ </span>
+ pdfcn
+ </div>
+ <div className="text-right">
+ <p className="text-[9px] font-bold tracking-[0.18em] text-muted-foreground uppercase">
+ Invoice
+ </p>
+ <p className="mt-0.5 text-[10px] font-medium">INV-2026-042</p>
+ </div>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="text"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="px-6 py-4 sm:px-10"
+ >
+ <p className="text-lg font-semibold">Invoice for Design Services</p>
+ <p className="mt-1 text-[11px] text-muted-foreground">
+ Professional design consultation and brand identity package.
+ </p>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="divider"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="px-6 sm:px-10"
+ >
+ <div className="h-px bg-border" />
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="key-value"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="px-6 py-4 sm:px-10"
+ >
+ <div className="grid grid-cols-2 gap-6 text-[10px]">
+ <div>
+ <p className="font-semibold text-muted-foreground uppercase">From</p>
+ <p className="mt-1 font-medium">PDFx Inc.</p>
+ <p className="text-muted-foreground">[email protected]</p>
+ </div>
+ <div>
+ <p className="font-semibold text-muted-foreground uppercase">To</p>
+ <p className="mt-1 font-medium">Acme Corp</p>
+ <p className="text-muted-foreground">[email protected]</p>
+ </div>
+ </div>
+ </SelectablePdfPart>
+
+ <SelectablePdfPart
+ id="page-footer"
+ selectedId={selectedId}
+ onSelect={onSelect}
+ className="px-6 py-4 sm:px-10"
+ >
+ <div className="flex items-center justify-between text-[9px] text-muted-foreground">
+ <div className="flex items-center gap-1.5">
+ <LogoMark className="size-3" />
+ pdfcn
+ </div>
+ <span>Page 1 of 1</span>
+ </div>
+ </SelectablePdfPart>
+ </div>
+);
+
+interface PdfPreviewContentProps {
+ selectedId: ComponentPartId;
+ onSelect: (id: ComponentPartId) => void;
+}
+
+export const HomePdfPreview = ({
+ pdfId,
+ selectedId,
+ onSelect,
+}: PdfPreviewContentProps & { pdfId: PdfRecipeId }) => {
+ if (pdfId === "financial-report") {
+ return (
+ <FinancialReportPreview selectedId={selectedId} onSelect={onSelect} />
+ );
+ }
+ if (pdfId === "minimal-invoice") {
+ return (
+ <MinimalInvoicePreview selectedId={selectedId} onSelect={onSelect} />
+ );
+ }
+ return (
+ <CorporateInvoicePreview selectedId={selectedId} onSelect={onSelect} />
+ );
+};
diff --git a/components/home-pdf-showcase.tsx b/components/home-pdf-showcase.tsx
new file mode 100644
index 0000000..f20f4bb
--- /dev/null
+++ b/components/home-pdf-showcase.tsx
@@ -0,0 +1,595 @@
+"use client";
+
+import {
+ ArrowUpRightIcon,
+ CodeXmlIcon,
+ EyeIcon,
+ FileIcon,
+ MonitorIcon,
+ SmartphoneIcon,
+} from "lucide-react";
+import Link from "next/link";
+import { useEffect, useState } from "react";
+
+import { CodeBlockCommand } from "@/components/code-block-command";
+import { CopyButton } from "@/components/copy-button";
+import {
+ HomePdfPreview,
+ getHomePdfSource,
+ homePdfBases,
+ homePdfCodeOutputs,
+ homePdfComponentCatalog,
+ homePdfPreviews,
+} from "@/components/home-pdf-preview";
+import type {
+ CodeOutput,
+ ComponentPartId,
+ HomePdfBase,
+ PdfRecipe,
+ PdfRecipeId,
+} from "@/components/home-pdf-preview";
+import { FormeIcon, TakumiIcon } from "@/components/icons";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import {
+ NativeSelect,
+ NativeSelectOption,
+} from "@/components/ui/native-select";
+import { Separator } from "@/components/ui/separator";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { Toggle } from "@/components/ui/toggle";
+import { cn } from "@/lib/utils";
+
+type PreviewViewport = "desktop" | "mobile";
+type WorkspaceTab = "preview" | "code";
+
+interface HomePdfCodeOutput {
+ code: string;
+ highlightedCode: string;
+}
+
+const codeCache = new Map<string, HomePdfCodeOutput>();
+const homePdfBaseIcons: Record<HomePdfBase, typeof TakumiIcon> = {
+ forme: FormeIcon,
+ takumi: TakumiIcon,
+};
+
+const PdfBaseIcon = ({
+ base,
+ className,
+}: {
+ base: HomePdfBase;
+ className?: string;
+}) => {
+ const Icon = homePdfBaseIcons[base];
+ return <Icon className={className} aria-hidden="true" />;
+};
+
+const CodeViewer = ({
+ availableOutputs,
+ error,
+ isLoading,
+ output,
+ selectedOutput,
+ onOutputChange,
+}: {
+ availableOutputs: { id: CodeOutput; label: string }[];
+ error: string | null;
+ isLoading: boolean;
+ output: CodeOutput;
+ selectedOutput: HomePdfCodeOutput | null;
+ onOutputChange: (output: CodeOutput) => void;
+}) => (
+ <div className="flex h-full min-h-[560px] flex-col bg-code text-code-foreground lg:min-h-0">
+ <div className="flex h-12 shrink-0 items-center px-4">
+ <Tabs
+ value={output}
+ onValueChange={(value) => onOutputChange(value as CodeOutput)}
+ className="gap-0"
+ >
+ <TabsList className="bg-background/8 p-0.5">
+ {availableOutputs.map((item) => (
+ <TabsTrigger
+ key={item.id}
+ value={item.id}
+ sound="toggleOn"
+ className="h-8 px-3"
+ >
+ {item.label}
+ </TabsTrigger>
+ ))}
+ </TabsList>
+ </Tabs>
+ <CopyButton
+ className="static ml-auto bg-transparent"
+ value={selectedOutput?.code ?? ""}
+ event="copy_block_code"
+ />
+ </div>
+ <Separator className="bg-border/50" />
+
+ <div className="no-scrollbar min-h-0 flex-1 overflow-auto">
+ {isLoading ? (
+ <div
+ className="flex h-full min-h-72 items-center justify-center text-sm text-code-foreground/60"
+ role="status"
+ >
+ Rendering document…
+ </div>
+ ) : null}
+ {error ? (
+ <div
+ className="flex h-full min-h-72 items-center justify-center px-6 text-center text-sm text-red-400"
+ role="alert"
+ >
+ {error}
+ </div>
+ ) : null}
+ {selectedOutput && !isLoading ? (
+ <figure
+ data-rehype-pretty-code-figure=""
+ className="!m-0 min-h-full !rounded-none text-sm [&>div]:min-h-full [&_pre]:min-h-full"
+ >
+ <div
+ // Shiki returns trusted HTML generated from the provided source code.
+ // eslint-disable-next-line react/no-danger
+ dangerouslySetInnerHTML={{
+ __html: selectedOutput.highlightedCode,
+ }}
+ />
+ </figure>
+ ) : null}
+ </div>
+ </div>
+);
+
+const findPdf = (id: PdfRecipeId): PdfRecipe =>
+ homePdfPreviews.find((pdf) => pdf.id === id) ?? homePdfPreviews[0];
+
+export const HomePdfShowcase = () => {
+ const [selectedPdfId, setSelectedPdfId] =
+ useState<PdfRecipeId>("corporate-invoice");
+ const [selectedComponentId, setSelectedComponentId] =
+ useState<ComponentPartId>("page-header");
+ const [workspaceTab, setWorkspaceTab] = useState<WorkspaceTab>("preview");
+ const [viewport, setViewport] = useState<PreviewViewport>("desktop");
+ const [codeOutput, setCodeOutput] = useState<CodeOutput>("react");
+ const [pdfBase, setPdfBase] = useState<HomePdfBase>("forme");
+ const [codeRequest, setCodeRequest] = useState<{
+ data: HomePdfCodeOutput | null;
+ error: string | null;
+ isLoading: boolean;
+ key: string;
+ }>({
+ data: null,
+ error: null,
+ isLoading: false,
+ key: "",
+ });
+
+ const selectedPdf = findPdf(selectedPdfId);
+ const selectedComponent = homePdfComponentCatalog[selectedComponentId];
+ const registryItem = `@pdfcn/${pdfBase}/${selectedComponentId}`;
+ const codeRequestKey = `${pdfBase}:${selectedPdf.id}:${codeOutput}`;
+ const selectedCodeOutput =
+ codeRequest.key === codeRequestKey ? codeRequest.data : null;
+ const availableCodeOutputs = homePdfCodeOutputs;
+
+ useEffect(() => {
+ if (workspaceTab !== "code") {
+ return;
+ }
+
+ const cached = codeCache.get(codeRequestKey);
+ if (cached) {
+ setCodeRequest({
+ data: cached,
+ error: null,
+ isLoading: false,
+ key: codeRequestKey,
+ });
+ return;
+ }
+
+ let cancelled = false;
+ const loadCode = async () => {
+ setCodeRequest({
+ data: null,
+ error: null,
+ isLoading: true,
+ key: codeRequestKey,
+ });
+
+ try {
+ let code: string | null;
+ let language: string;
+
+ if (codeOutput === "react") {
+ code = getHomePdfSource(selectedPdf, pdfBase);
+ language = "tsx";
+ } else {
+ throw new Error(
+ "HTML output is not available for the selected base."
+ );
+ }
+
+ if (!code) {
+ throw new Error(
+ "This format is not available for the selected base."
+ );
+ }
+
+ const { highlightCode } = await import("@/lib/highlight-code");
+ const output = {
+ code,
+ highlightedCode: await highlightCode(code, language),
+ };
+ codeCache.set(codeRequestKey, output);
+
+ if (cancelled) {
+ return;
+ }
+
+ setCodeRequest({
+ data: output,
+ error: null,
+ isLoading: false,
+ key: codeRequestKey,
+ });
+ } catch (error) {
+ if (cancelled) {
+ return;
+ }
+ setCodeRequest({
+ data: null,
+ error:
+ error instanceof Error
+ ? error.message
+ : "Could not render this document.",
+ isLoading: false,
+ key: codeRequestKey,
+ });
+ }
+ };
+
+ void loadCode();
+ return () => {
+ cancelled = true;
+ };
+ }, [codeOutput, codeRequestKey, pdfBase, selectedPdf, workspaceTab]);
+
+ const handlePdfBaseChange = (base: HomePdfBase) => {
+ setPdfBase(base);
+ };
+
+ const handlePdfChange = (pdfId: PdfRecipeId) => {
+ const nextPdf = findPdf(pdfId);
+ setSelectedPdfId(pdfId);
+ setSelectedComponentId(nextPdf.defaultComponentId);
+ };
+
+ const handleComponentChange = (componentId: ComponentPartId) => {
+ setSelectedComponentId(componentId);
+ setWorkspaceTab("preview");
+ };
+
+ return (
+ <section className="container-wrapper pb-12 md:pb-16 lg:pb-24">
+ <div className="container">
+ <Card className="gap-0 overflow-hidden py-0">
+ <CardHeader className="block px-0">
+ <div className="grid min-h-12 grid-cols-[1fr_minmax(0,auto)_1fr] items-center gap-2 px-3 lg:gap-3 lg:px-4">
+ <div
+ className="col-start-1 row-start-1 hidden justify-self-start gap-1.5 lg:flex"
+ aria-hidden="true"
+ >
+ <span className="size-2.5 rounded-full bg-red-400" />
+ <span className="size-2.5 rounded-full bg-amber-400" />
+ <span className="size-2.5 rounded-full bg-emerald-400" />
+ </div>
+ <h2
+ className="col-start-2 row-start-1 flex min-w-0 max-w-[70vw] items-center justify-self-center gap-2 px-2 text-sm font-medium text-muted-foreground lg:max-w-full"
+ title={selectedPdf.filename}
+ >
+ <FileIcon className="size-3.5 shrink-0" aria-hidden="true" />
+ <span className="truncate">{selectedPdf.filename}</span>
+ </h2>
+
+ <div
+ className="col-start-3 row-start-1 hidden justify-self-end rounded-lg bg-muted p-0.5 lg:flex"
+ role="radiogroup"
+ aria-label="PDF base"
+ >
+ {homePdfBases.map((base) => (
+ <Toggle
+ key={base.id}
+ size="sm"
+ pressed={pdfBase === base.id}
+ onPressedChange={() => handlePdfBaseChange(base.id)}
+ aria-label={base.label}
+ className="h-7 gap-1.5 border border-transparent px-2 text-xs data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-sm data-[state=on]:hover:bg-background data-[state=on]:hover:text-foreground dark:data-[state=on]:border-input dark:data-[state=on]:bg-input/30 dark:data-[state=on]:hover:bg-input/30"
+ >
+ <PdfBaseIcon base={base.id} className="size-3.5" />
+ {base.label}
+ </Toggle>
+ ))}
+ </div>
+ </div>
+
+ <Separator className="lg:hidden" />
+
+ <div className="flex h-12 items-center justify-between gap-3 px-3 lg:hidden">
+ <label
+ htmlFor="home-pdf-base"
+ className="text-sm font-medium text-muted-foreground"
+ >
+ Choose base
+ </label>
+ <NativeSelect
+ id="home-pdf-base"
+ size="sm"
+ value={pdfBase}
+ onChange={(e) =>
+ handlePdfBaseChange(e.target.value as HomePdfBase)
+ }
+ className="w-40 min-w-0 sm:w-48"
+ >
+ {homePdfBases.map((base) => (
+ <NativeSelectOption key={base.id} value={base.id}>
+ {base.label}
+ </NativeSelectOption>
+ ))}
+ </NativeSelect>
+ </div>
+ </CardHeader>
+
+ <Separator />
+
+ <CardContent className="p-0 lg:grid lg:h-[720px] lg:grid-cols-[14rem_minmax(0,1fr)_20rem]">
+ <aside
+ aria-label="PDF examples"
+ className="hidden flex-col bg-card lg:flex lg:border-r"
+ >
+ <div className="flex h-12 shrink-0 items-center px-4">
+ <CardTitle className="text-sm">Documents</CardTitle>
+ </div>
+ <Separator />
+
+ <div className="no-scrollbar flex flex-1 flex-col gap-1 overflow-y-auto p-2">
+ {homePdfPreviews.map((pdf) => {
+ const isSelected = selectedPdfId === pdf.id;
+
+ return (
+ <Button
+ key={pdf.id}
+ type="button"
+ variant="ghost"
+ size="sm"
+ sound="click"
+ aria-pressed={isSelected}
+ className={cn(
+ "h-9 justify-start border px-2 text-left",
+ isSelected
+ ? "border-border bg-muted text-foreground hover:bg-muted hover:text-foreground dark:hover:bg-muted"
+ : "border-transparent text-muted-foreground hover:bg-muted/70 hover:text-foreground"
+ )}
+ onClick={() => handlePdfChange(pdf.id)}
+ >
+ <span className="truncate">{pdf.name}</span>
+ </Button>
+ );
+ })}
+ </div>
+ </aside>
+
+ <Tabs
+ value={workspaceTab}
+ onValueChange={(value) => setWorkspaceTab(value as WorkspaceTab)}
+ className="min-w-0 gap-0 bg-muted/55 lg:h-full"
+ >
+ <div className="flex h-12 shrink-0 items-center justify-between gap-3 bg-card px-3 lg:hidden">
+ <label
+ htmlFor="home-pdf-template"
+ className="text-sm font-medium text-muted-foreground"
+ >
+ Choose template
+ </label>
+ <NativeSelect
+ id="home-pdf-template"
+ size="sm"
+ value={selectedPdfId}
+ onChange={(e) =>
+ handlePdfChange(e.target.value as PdfRecipeId)
+ }
+ className="w-40 min-w-0 sm:w-48"
+ >
+ {homePdfPreviews.map((pdf) => (
+ <NativeSelectOption key={pdf.id} value={pdf.id}>
+ {pdf.name}
+ </NativeSelectOption>
+ ))}
+ </NativeSelect>
+ </div>
+
+ <Separator className="lg:hidden" />
+
+ <div className="flex h-12 shrink-0 items-center justify-between gap-2 bg-card px-4">
+ <TabsList className="h-8 p-0.5">
+ <TabsTrigger
+ value="preview"
+ sound="toggleOn"
+ className="h-7 px-2.5 text-xs"
+ >
+ <EyeIcon className="size-3.5" aria-hidden="true" />
+ Preview
+ </TabsTrigger>
+ <TabsTrigger
+ value="code"
+ sound="toggleOn"
+ className="h-7 px-2.5 text-xs"
+ >
+ <CodeXmlIcon className="size-3.5" aria-hidden="true" />
+ Code
+ </TabsTrigger>
+ </TabsList>
+
+ {workspaceTab === "preview" ? (
+ <div
+ className="hidden rounded-lg bg-muted p-0.5 lg:flex"
+ role="radiogroup"
+ aria-label="PDF preview viewport"
+ >
+ <Toggle
+ size="sm"
+ pressed={viewport === "desktop"}
+ onPressedChange={() => setViewport("desktop")}
+ aria-label="Desktop preview"
+ className="h-7 gap-1.5 px-2.5 text-xs"
+ >
+ <MonitorIcon className="size-3.5" aria-hidden="true" />
+ <span className="hidden xl:inline">Desktop</span>
+ </Toggle>
+ <Toggle
+ size="sm"
+ pressed={viewport === "mobile"}
+ onPressedChange={() => setViewport("mobile")}
+ aria-label="Mobile preview"
+ className="h-7 gap-1.5 px-2.5 text-xs"
+ >
+ <SmartphoneIcon className="size-3.5" aria-hidden="true" />
+ <span className="hidden xl:inline">Mobile</span>
+ </Toggle>
+ </div>
+ ) : null}
+ </div>
+
+ <Separator />
+
+ <TabsContent value="preview" className="min-h-0">
+ <div className="h-[520px] overflow-auto p-2 sm:h-[620px] sm:p-4 lg:h-[672px] lg:p-5">
+ <div
+ className={cn(
+ "mx-auto w-full max-w-[375px] bg-background shadow-xl transition-[width] duration-200",
+ viewport === "desktop"
+ ? "lg:w-[600px] lg:max-w-full"
+ : "lg:w-[375px]"
+ )}
+ >
+ <HomePdfPreview
+ pdfId={selectedPdf.id}
+ selectedId={selectedComponentId}
+ onSelect={setSelectedComponentId}
+ />
+ </div>
+ </div>
+ </TabsContent>
+
+ <TabsContent value="code" className="min-h-0">
+ <CodeViewer
+ availableOutputs={availableCodeOutputs}
+ error={
+ codeRequest.key === codeRequestKey
+ ? codeRequest.error
+ : null
+ }
+ isLoading={
+ codeRequest.key === codeRequestKey && codeRequest.isLoading
+ }
+ output={codeOutput}
+ selectedOutput={selectedCodeOutput}
+ onOutputChange={setCodeOutput}
+ />
+ </TabsContent>
+ </Tabs>
+
+ <aside
+ aria-label="Components used in the selected document"
+ className="no-scrollbar border-t bg-card lg:overflow-y-auto lg:border-t-0 lg:border-l"
+ >
+ <div className="flex h-12 shrink-0 items-center justify-between gap-3 px-4">
+ <CardTitle className="text-sm">Components Used</CardTitle>
+ <Badge
+ variant="outline"
+ className="font-mono text-muted-foreground"
+ >
+ {selectedPdf.componentIds.length}
+ </Badge>
+ </div>
+ <Separator />
+
+ <CardContent className="p-2">
+ <div className="no-scrollbar flex gap-2 overflow-x-auto lg:flex-col lg:gap-1">
+ {selectedPdf.componentIds.map((componentId, index) => {
+ const part = homePdfComponentCatalog[componentId];
+ const isSelected = selectedComponentId === componentId;
+
+ return (
+ <Button
+ key={componentId}
+ type="button"
+ variant="ghost"
+ size="sm"
+ sound="click"
+ aria-pressed={isSelected}
+ className={cn(
+ "h-9 min-w-48 justify-start gap-2.5 border px-2 text-left lg:min-w-0",
+ isSelected
+ ? "border-blue-500/40 bg-blue-500/10 text-blue-700 hover:bg-blue-500/10 hover:text-blue-700 dark:text-blue-300 dark:hover:bg-blue-500/10 dark:hover:text-blue-300"
+ : "border-transparent text-muted-foreground hover:border-blue-500/30 hover:bg-blue-500/10 hover:text-blue-700 dark:hover:bg-blue-500/10 dark:hover:text-blue-300"
+ )}
+ onClick={() => handleComponentChange(componentId)}
+ >
+ <Badge
+ variant="outline"
+ className={cn(
+ "size-6 bg-background px-0 font-mono",
+ isSelected && "border-blue-500/40 text-blue-600"
+ )}
+ >
+ {String(index + 1).padStart(2, "0")}
+ </Badge>
+ <span className="min-w-0 flex-1 truncate font-medium">
+ {part.label}
+ </span>
+ </Button>
+ );
+ })}
+ </div>
+ </CardContent>
+
+ <Separator />
+
+ <CardContent className="p-4" aria-live="polite">
+ <h3 className="text-lg font-semibold tracking-tight">
+ <Link
+ href={`/docs/components/${selectedComponent.docsPath}`}
+ className="group inline-flex items-center gap-1.5 rounded-sm underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
+ transitionTypes={["nav-forward"]}
+ >
+ {selectedComponent.label}
+ <ArrowUpRightIcon
+ className="size-4 text-muted-foreground transition-colors group-hover:text-foreground"
+ aria-hidden="true"
+ />
+ </Link>
+ </h3>
+ <p className="mt-2 text-sm leading-6 text-muted-foreground">
+ {selectedComponent.description}
+ </p>
+
+ <CodeBlockCommand
+ __bun__={`bunx --bun shadcn@latest add ${registryItem}`}
+ __npm__={`npx shadcn@latest add ${registryItem}`}
+ __pnpm__={`pnpm dlx shadcn@latest add ${registryItem}`}
+ __yarn__={`yarn shadcn@latest add ${registryItem}`}
+ className="mt-4 border border-border/70 dark:bg-background/60"
+ />
+ </CardContent>
+ </aside>
+ </CardContent>
+ </Card>
+ </div>
+ </section>
+ );
+};