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.

3.3 KB
Raw Blame
{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forme/page-number",
  "title": "Page Number",
  "description": "Page Number PDF component (forme)",
  "dependencies": [
    "@formepdf/react",
    "@formepdf/core"
  ],
  "registryDependencies": [
    "@pdfcn/forme/utils"
  ],
  "files": [
    {
      "path": "registry/bases/forme/components/page-number/page-number.tsx",
      "content": "import {\n  usePdfcnTheme,\n  useSafeMemo,\n} from \"@/components/pdf/theme-provider\";\nimport {\n  Text,\n  StyleSheet,\n  View,\n} from \"@/lib/pdf-primitives\";\nimport type { Style } from \"@/lib/pdf-primitives\";\nimport type { PDFComponentProps } from \"@/types/pdf-components\";\nimport type { PdfcnTheme } from \"@/types/pdf-themes\";\n\nexport type PageNumberAlign = \"left\" | \"center\" | \"right\";\nexport type PageNumberSize = \"xs\" | \"sm\" | \"md\";\n\n/**\n * Auto page number rendered with a configurable format string at a or inline position.\n * Props - `format` | `align` | `size` | `fixed` | `muted` | `style`\n * @see {@link PageNumberProps}\n */\nexport interface PageNumberProps extends Omit<PDFComponentProps, \"children\"> {\n  /**\n   * Format string — use `{page}` for current page and `{total}` for total page count.\n   * @default 'Page {page} of {total}'\n   */\n  format?: string;\n  /**\n   * @default 'center'\n   */\n  align?: PageNumberAlign;\n  /**\n   * @default 'sm'\n   */\n  size?: PageNumberSize;\n  /**\n   * @default false\n   */\n  fixed?: boolean;\n  /**\n   * @default true\n   */\n  muted?: boolean;\n  children?: never;\n}\n\nconst createPageNumberStyles = (t: PdfcnTheme) => {\n  const { typography, colors, primitives } = t;\n  return StyleSheet.create({\n    alignCenter: { textAlign: \"center\" },\n    alignLeft: { textAlign: \"left\" },\n    alignRight: { textAlign: \"right\" },\n    colorForeground: { color: colors.foreground },\n    colorMuted: { color: colors.mutedForeground },\n    container: { width: \"100%\" },\n    sizeMd: { fontSize: primitives.typography.base },\n    sizeSm: { fontSize: primitives.typography.sm },\n    sizeXs: { fontSize: primitives.typography.xs },\n    text: { fontFamily: typography.body.fontFamily },\n  });\n};\n\nexport const PageNumber = ({\n  format = \"Page {page} of {total}\",\n  align = \"center\",\n  size = \"sm\",\n  muted = true,\n  style,\n}: PageNumberProps) => {\n  const theme = usePdfcnTheme();\n  const styles = useSafeMemo(() => createPageNumberStyles(theme), [theme]);\n  const alignMap = {\n    center: styles.alignCenter,\n    left: styles.alignLeft,\n    right: styles.alignRight,\n  } as Record<PageNumberAlign, Style>;\n  const sizeMap = {\n    md: styles.sizeMd,\n    sm: styles.sizeSm,\n    xs: styles.sizeXs,\n  } as Record<PageNumberSize, Style>;\n  const textStyles: Style[] = [\n    styles.text,\n    alignMap[align],\n    sizeMap[size],\n    muted ? styles.colorMuted : styles.colorForeground,\n  ];\n  if (style) {\n    textStyles.push(...[style].flat());\n  }\n  return (\n    <View style={styles.container}>\n      <Text style={textStyles as never}>\n        {format\n          .replace(\"{page}\", \"{{pageNumber}}\")\n          .replace(\"{total}\", \"{{totalPages}}\")}\n      </Text>\n    </View>\n  );\n};\n",
      "type": "registry:component",
      "target": "components/pdf/page-number/page-number.tsx"
    }
  ],
  "type": "registry:ui"
}