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.

9.5 KB
Raw Blame
{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forme/invoice-modern",
  "title": "Invoice Modern",
  "description": "Invoice Modern PDF block (forme)",
  "dependencies": [
    "@formepdf/react",
    "@formepdf/core"
  ],
  "registryDependencies": [
    "@pdfcn/forme/utils",
    "@pdfcn/forme/key-value",
    "@pdfcn/forme/page-footer",
    "@pdfcn/forme/page-header",
    "@pdfcn/forme/section",
    "@pdfcn/forme/table",
    "@pdfcn/forme/text"
  ],
  "files": [
    {
      "path": "registry/bases/forme/blocks/invoice-modern/invoice-modern.tsx",
      "content": "import { Document, Page, StyleSheet, View } from \"@formepdf/react\";\n\nimport { KeyValue } from \"@/components/pdf/key-value/key-value\";\nimport { PageFooter } from \"@/components/pdf/page-footer/page-footer\";\nimport { PageHeader } from \"@/components/pdf/page-header/page-header\";\nimport { Section } from \"@/components/pdf/section/section\";\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHeader,\n  TableRow,\n} from \"@/components/pdf/table/table\";\nimport { Text } from \"@/components/pdf/text/text\";\nimport {\n  PdfcnThemeProvider,\n  usePdfcnTheme,\n} from \"@/components/pdf/theme-provider\";\nimport type { PdfcnTheme } from \"@/types/pdf-themes\";\n\nimport type { InvoiceModernData } from \"./invoice-modern.types\";\n\n// Sample data — replace with your own props or data source\nconst sampleData: InvoiceModernData = {\n  billTo: {\n    address: \"789 Innovation Blvd, Floor 3\",\n    email: \"[email protected]\",\n    name: \"TechStart Solutions\",\n    phone: \"+1 (555) 987-6543\",\n  },\n  companyAddress: \"Nagpur, IN\",\n  companyEmail: \"[email protected]\",\n  companyName: \"pdfcn\",\n  dueDate: \"March 20, 2026\",\n  invoiceDate: \"February 18, 2026\",\n  invoiceNumber: \"INV-2026-002\",\n  items: [\n    { description: \"API Integration\", quantity: 1, unitPrice: 15_000 },\n    { description: \"SEO\", quantity: 2, unitPrice: 5500 },\n    { description: \"Security Audit\", quantity: 1, unitPrice: 7200 },\n  ],\n  notes: \"Payment terms: Net 30 days. Thank you for your business!\",\n  paymentTerms: {\n    dueDate: \"March 20, 2026\",\n    gst: \"GSTIN 123456789\",\n    method: \"Wire Transfer / Bank Account\",\n  },\n  subtitle: \"Innovative PDF Solutions\",\n  summary: {\n    subtotal: 33_200,\n    tax: 2324,\n    total: 35_524,\n  },\n};\n\nconst InvoiceModernContent = ({ data }: { data: InvoiceModernData }) => {\n  const theme = usePdfcnTheme();\n\n  const styles = StyleSheet.create({\n    dividerCol: {\n      backgroundColor: theme.colors.border,\n      marginRight: 12,\n      width: 1,\n    },\n    metaCol: {\n      flex: 1,\n      paddingRight: 12,\n    },\n    metaLabel: {\n      color: theme.colors.mutedForeground,\n      fontSize: 8,\n      fontWeight: \"bold\",\n      letterSpacing: 0.5,\n      marginBottom: 3,\n      textTransform: \"uppercase\",\n    },\n    metaRow: {\n      flexDirection: \"row\",\n      marginBottom: theme.spacing.sectionGap,\n    },\n    metaValue: {\n      color: theme.colors.foreground,\n      fontSize: 9,\n    },\n    page: {\n      backgroundColor: theme.colors.background,\n    },\n  });\n\n  return (\n    <Document title={`Invoice ${data.invoiceNumber}`}>\n      <Page size=\"A4\" margin={{ bottom: 25, left: 56, right: 56, top: 56 }}>\n        <PageFooter\n          leftText={data.notes}\n          rightText=\"Page 1 of 1\"\n          sticky\n          pagePadding={25}\n        />\n        <View style={styles.page as never}>\n          <PageHeader\n            variant=\"branded\"\n            title={data.companyName}\n            subtitle={`${data.subtitle}  ·  ${data.companyAddress}  ·  ${data.companyEmail}`}\n          />\n          <View style={styles.metaRow}>\n            <View style={styles.metaCol}>\n              <Text style={styles.metaLabel} noMargin>\n                Invoice Number\n              </Text>\n              <Text\n                style={{\n                  ...styles.metaValue,\n                  fontSize: 11,\n                  fontWeight: \"bold\",\n                }}\n                noMargin\n              >\n                {data.invoiceNumber}\n              </Text>\n            </View>\n            <View style={styles.metaCol}>\n              <Text style={styles.metaLabel} noMargin>\n                Invoice Date\n              </Text>\n              <Text style={styles.metaValue} noMargin>\n                {data.invoiceDate}\n              </Text>\n            </View>\n            <View style={styles.metaCol}>\n              <Text style={styles.metaLabel} noMargin>\n                Due Date\n              </Text>\n              <Text style={styles.metaValue} noMargin>\n                {data.dueDate}\n              </Text>\n            </View>\n            <View style={styles.dividerCol} />\n            <View style={{ flex: 2 }}>\n              <Text style={styles.metaLabel} noMargin>\n                Billed To\n              </Text>\n              <Text\n                style={{ ...styles.metaValue, fontWeight: \"bold\" }}\n                noMargin\n              >\n                {data.billTo.name}\n              </Text>\n              <Text\n                style={{\n                  ...styles.metaValue,\n                  color: theme.colors.mutedForeground,\n                }}\n                noMargin\n              >\n                {data.billTo.address}\n              </Text>\n              <Text\n                style={{\n                  ...styles.metaValue,\n                  color: theme.colors.mutedForeground,\n                }}\n                noMargin\n              >\n                {data.billTo.email}\n              </Text>\n              <Text\n                style={{\n                  ...styles.metaValue,\n                  color: theme.colors.mutedForeground,\n                }}\n                noMargin\n              >\n                {data.billTo.phone}\n              </Text>\n            </View>\n          </View>\n          <Table variant=\"primary-header\">\n            <TableHeader>\n              <TableRow header>\n                <TableCell>Description</TableCell>\n                <TableCell align=\"center\">Qty</TableCell>\n                <TableCell align=\"right\">Unit Price</TableCell>\n                <TableCell align=\"right\">Amount</TableCell>\n              </TableRow>\n            </TableHeader>\n            <TableBody>\n              {data.items.map((item, index) => (\n                // biome-ignore lint/suspicious/noArrayIndexKey: invoice items have no stable id\n                <TableRow key={index}>\n                  <TableCell>{item.description}</TableCell>\n                  <TableCell align=\"center\">{`${item.quantity}`}</TableCell>\n                  <TableCell align=\"right\">{`$${item.unitPrice.toLocaleString()}`}</TableCell>\n                  <TableCell align=\"right\">{`$${(item.quantity * item.unitPrice).toFixed(2)}`}</TableCell>\n                </TableRow>\n              ))}\n            </TableBody>\n          </Table>\n          <Section noWrap style={{ flexDirection: \"row\", marginTop: 16 }}>\n            <View style={{ flex: 1, paddingRight: 20 }}>\n              <Text style={styles.metaLabel} noMargin>\n                Payment Method\n              </Text>\n              <Text variant=\"xs\" noMargin>\n                {data.paymentTerms.method}\n              </Text>\n              <Text variant=\"xs\" noMargin color=\"mutedForeground\">\n                {data.paymentTerms.gst}\n              </Text>\n            </View>\n            <View style={{ width: 220 }}>\n              <KeyValue\n                size=\"sm\"\n                dividerThickness={1}\n                items={[\n                  {\n                    key: \"Subtotal\",\n                    value: `$${data.summary.subtotal.toFixed(2)}`,\n                  },\n                  { key: \"Tax (7%)\", value: `$${data.summary.tax.toFixed(2)}` },\n                  {\n                    key: \"Total Due\",\n                    keyStyle: { fontSize: 12, fontWeight: \"bold\" },\n                    value: `$${data.summary.total.toFixed(2)}`,\n                    valueStyle: { fontSize: 12, fontWeight: \"bold\" },\n                  },\n                ]}\n                divided\n              />\n            </View>\n          </Section>\n        </View>\n      </Page>\n    </Document>\n  );\n};\n\nexport const InvoiceModernDocument = ({\n  theme,\n  data = sampleData,\n}: {\n  theme?: PdfcnTheme;\n  data?: InvoiceModernData;\n}) => (\n  <PdfcnThemeProvider theme={theme}>\n    <InvoiceModernContent data={data} />\n  </PdfcnThemeProvider>\n);\n",
      "type": "registry:block",
      "target": "components/pdf/blocks/invoice-modern/invoice-modern.tsx"
    },
    {
      "path": "registry/bases/forme/blocks/invoice-modern/invoice-modern.types.ts",
      "content": "export interface InvoiceModernData {\n  invoiceNumber: string;\n  invoiceDate: string;\n  dueDate: string;\n  companyName: string;\n  subtitle: string;\n  companyAddress: string;\n  companyEmail: string;\n  billTo: {\n    name: string;\n    address: string;\n    email: string;\n    phone: string;\n  };\n  items: {\n    description: string;\n    quantity: number;\n    unitPrice: number;\n  }[];\n  summary: {\n    subtotal: number;\n    tax: number;\n    total: number;\n  };\n  paymentTerms: {\n    dueDate: string;\n    method: string;\n    gst: string;\n  };\n  notes?: string;\n}\n",
      "type": "registry:block",
      "target": "components/pdf/blocks/invoice-modern/invoice-modern.types.ts"
    }
  ],
  "type": "registry:block"
}