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.

fix: use border-box sizing on shipping label page style

Lalit Madana74771adce3e
diff --git a/apps/web/public/r/takumi/shipping-label.json b/apps/web/public/r/takumi/shipping-label.json
index eedc70a..ad6945e 100644
--- a/apps/web/public/r/takumi/shipping-label.json
+++ b/apps/web/public/r/takumi/shipping-label.json
@@ -17,7 +17,7 @@
"files": [
{
"path": "registry/bases/takumi/blocks/shipping-label/shipping-label.tsx",
- "content": "import { PdfImage } from \"@/registry/bases/takumi/components/pdf-image/pdf-image\";\nimport { PdfQRCode } from \"@/registry/bases/takumi/components/qrcode/qrcode\";\nimport { Text } from \"@/registry/bases/takumi/components/text/text\";\nimport {\n PdfcnThemeProvider,\n usePdfcnTheme,\n} from \"@/registry/bases/takumi/components/theme-provider\";\nimport {\n View,\n StyleSheet,\n Document,\n Page,\n} from \"@/registry/bases/takumi/lib/pdf-primitives\";\nimport { resolveColor } from \"@/registry/bases/takumi/lib/resolve-color\";\nimport type { PdfcnTheme } from \"@/registry/types/pdf-themes\";\n\nimport type {\n ShippingLabelAddress,\n ShippingLabelData,\n} from \"./shipping-label.types\";\n\n// Sample data — replace with your own props or data source\nconst sampleData: ShippingLabelData = {\n carrier: \"UPS\",\n dimensions: '12\" x 8\" x 6\"',\n from: {\n address: \"456 Industrial Blvd\",\n city: \"Los Angeles\",\n country: \"USA\",\n name: \"ACME Corporation\",\n state: \"CA\",\n zip: \"90001\",\n },\n handlingLabels: [\"FRAGILE\", \"THIS SIDE UP\"],\n packageCount: 1,\n postage: \"$18.40\",\n serviceLevel: \"Ground\",\n to: {\n address: \"123 Main Street, Apt 4B\",\n city: \"New York\",\n country: \"USA\",\n name: \"John Doe\",\n phone: \"(503) 555-0142\",\n state: \"NY\",\n zip: \"10001\",\n },\n trackingNumber: \"TRACK123456789US\",\n weight: \"2.5 kg\",\n};\n\n// Standard 4\" x 6\" shipping label, expressed in PDF points (72 dpi)\nconst LABEL_SIZE = { height: 432, width: 288 };\n\nconst formatCityLine = (party: ShippingLabelAddress) => {\n const cityStateZip = `${party.city}, ${party.state} ${party.zip}`;\n return party.country ? `${cityStateZip}, ${party.country}` : cityStateZip;\n};\n\nconst formatStreetLine = (party: ShippingLabelAddress) => party.address;\n\n// Shared address block — same treatment for both parties (10pt, bold name)\nconst AddressLines = ({\n party,\n}: {\n party: ShippingLabelAddress & { phone?: string };\n}) => (\n <>\n <Text noMargin variant=\"xs\" weight=\"bold\">\n {party.name}\n </Text>\n <Text noMargin variant=\"xs\">\n {formatStreetLine(party)}\n </Text>\n <Text noMargin variant=\"xs\">\n {formatCityLine(party)}\n </Text>\n {party.phone && (\n <Text noMargin variant=\"xs\" color=\"mutedForeground\">\n {party.phone}\n </Text>\n )}\n </>\n);\n\nconst ShippingLabelContent = ({ data }: { data: ShippingLabelData }) => {\n const theme = usePdfcnTheme();\n\n const accent = resolveColor(\n data.accentColor ?? theme.colors.primary,\n theme.colors\n );\n\n const detailRows = [\n ...(data.weight ? [{ key: \"Weight\", value: data.weight }] : []),\n ...(data.dimensions ? [{ key: \"Dimensions\", value: data.dimensions }] : []),\n ...(typeof data.packageCount === \"number\"\n ? [{ key: \"Packages\", value: `${data.packageCount}` }]\n : []),\n { key: \"Postage\", value: data.postage ?? \"PAID\" },\n ];\n\n const styles = StyleSheet.create({\n addresses: { flex: 1, flexDirection: \"row\" },\n badgesRow: {\n flexDirection: \"row\",\n flexWrap: \"wrap\",\n gap: 6,\n marginTop: 8,\n },\n barcodeArea: { alignItems: \"center\", marginTop: 10 },\n carrierName: { fontSize: 16, fontWeight: \"bold\" },\n fromColumn: { flex: 1, paddingLeft: 12 },\n handlingTag: {\n alignItems: \"center\",\n backgroundColor: theme.colors.foreground,\n justifyContent: \"center\",\n paddingHorizontal: 8,\n paddingVertical: 4,\n },\n handlingTagText: {\n color: theme.colors.background,\n fontSize: 8,\n fontWeight: \"bold\",\n letterSpacing: 1,\n textTransform: \"uppercase\",\n },\n headerRow: {\n alignItems: \"center\",\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n },\n label: {\n borderColor: theme.colors.foreground,\n borderStyle: \"solid\",\n borderWidth: 2,\n flex: 1,\n padding: 10,\n },\n page: {\n backgroundColor: theme.colors.background,\n flexDirection: \"column\",\n height: LABEL_SIZE.height,\n overflow: \"hidden\",\n padding: 8,\n width: LABEL_SIZE.width,\n },\n rule: {\n backgroundColor: theme.colors.foreground,\n height: 2,\n marginVertical: 6,\n },\n sectionLabel: {\n color: accent,\n fontSize: 8,\n fontWeight: \"bold\",\n letterSpacing: 1,\n marginBottom: 4,\n textTransform: \"uppercase\",\n },\n serviceRight: { alignItems: \"flex-end\" },\n shipToColumn: {\n borderRightColor: theme.colors.foreground,\n borderRightStyle: \"solid\",\n borderRightWidth: 2,\n flex: 1.4,\n paddingRight: 12,\n },\n table: {\n borderColor: theme.colors.foreground,\n borderStyle: \"solid\",\n borderWidth: 2,\n },\n tableKey: {\n color: theme.colors.mutedForeground,\n fontSize: 8,\n fontWeight: \"bold\",\n letterSpacing: 0.5,\n textTransform: \"uppercase\",\n width: 84,\n },\n tableRow: {\n alignItems: \"center\",\n borderBottomColor: theme.colors.border,\n borderBottomStyle: \"solid\",\n borderBottomWidth: 1,\n flexDirection: \"row\",\n paddingHorizontal: 8,\n paddingVertical: 3,\n },\n tableRowLast: {\n alignItems: \"center\",\n flexDirection: \"row\",\n paddingHorizontal: 8,\n paddingVertical: 3,\n },\n tableValue: { flex: 1 },\n trackingText: {\n fontWeight: \"bold\",\n letterSpacing: 2,\n marginTop: 6,\n textTransform: \"uppercase\",\n },\n });\n\n return (\n <Document title={`Shipping Label ${data.trackingNumber}`}>\n <Page size={LABEL_SIZE} style={styles.page}>\n <View style={styles.label}>\n <View style={styles.headerRow}>\n <Text noMargin style={styles.carrierName}>\n {data.carrier}\n </Text>\n <View style={styles.serviceRight}>\n <Text noMargin style={styles.sectionLabel}>\n {data.serviceLevel}\n </Text>\n </View>\n </View>\n\n <View style={styles.rule} />\n\n <View style={styles.addresses}>\n <View style={styles.shipToColumn}>\n <Text noMargin style={styles.sectionLabel}>\n Ship To\n </Text>\n <AddressLines party={data.to} />\n </View>\n <View style={styles.fromColumn}>\n <Text noMargin style={styles.sectionLabel}>\n From\n </Text>\n <AddressLines party={data.from} />\n </View>\n </View>\n\n <View style={styles.rule} />\n\n <View style={styles.table}>\n {detailRows.map((row, index) => (\n <View\n key={row.key}\n style={\n index === detailRows.length - 1\n ? styles.tableRowLast\n : styles.tableRow\n }\n >\n <Text noMargin style={styles.tableKey}>\n {row.key}\n </Text>\n <Text noMargin style={styles.tableValue} variant=\"xs\">\n {row.value}\n </Text>\n </View>\n ))}\n </View>\n\n {data.handlingLabels && data.handlingLabels.length > 0 && (\n <View style={styles.badgesRow}>\n {data.handlingLabels.map((label, index) => (\n <View key={`${label}-${index}`} style={styles.handlingTag}>\n <Text noMargin style={styles.handlingTagText}>\n {label}\n </Text>\n </View>\n ))}\n </View>\n )}\n\n <View style={styles.barcodeArea}>\n {data.barcodeUrl ? (\n <PdfImage\n fit=\"contain\"\n height={72}\n src={data.barcodeUrl}\n width=\"100%\"\n />\n ) : (\n <PdfQRCode\n backgroundColor=\"#ffffff\"\n color=\"#000000\"\n size={80}\n value={data.trackingNumber}\n />\n )}\n <Text\n noMargin\n style={styles.trackingText}\n variant=\"xs\"\n weight=\"bold\"\n >\n {data.trackingNumber}\n </Text>\n </View>\n </View>\n </Page>\n </Document>\n );\n};\n\nexport const ShippingLabelDocument = ({\n theme,\n data = sampleData,\n}: {\n theme?: PdfcnTheme;\n data?: ShippingLabelData;\n}) => (\n <PdfcnThemeProvider theme={theme}>\n <ShippingLabelContent data={data} />\n </PdfcnThemeProvider>\n);\n",
+ "content": "import { PdfImage } from \"@/registry/bases/takumi/components/pdf-image/pdf-image\";\nimport { PdfQRCode } from \"@/registry/bases/takumi/components/qrcode/qrcode\";\nimport { Text } from \"@/registry/bases/takumi/components/text/text\";\nimport {\n PdfcnThemeProvider,\n usePdfcnTheme,\n} from \"@/registry/bases/takumi/components/theme-provider\";\nimport {\n View,\n StyleSheet,\n Document,\n Page,\n} from \"@/registry/bases/takumi/lib/pdf-primitives\";\nimport { resolveColor } from \"@/registry/bases/takumi/lib/resolve-color\";\nimport type { PdfcnTheme } from \"@/registry/types/pdf-themes\";\n\nimport type {\n ShippingLabelAddress,\n ShippingLabelData,\n} from \"./shipping-label.types\";\n\n// Sample data — replace with your own props or data source\nconst sampleData: ShippingLabelData = {\n carrier: \"UPS\",\n dimensions: '12\" x 8\" x 6\"',\n from: {\n address: \"456 Industrial Blvd\",\n city: \"Los Angeles\",\n country: \"USA\",\n name: \"ACME Corporation\",\n state: \"CA\",\n zip: \"90001\",\n },\n handlingLabels: [\"FRAGILE\", \"THIS SIDE UP\"],\n packageCount: 1,\n postage: \"$18.40\",\n serviceLevel: \"Ground\",\n to: {\n address: \"123 Main Street, Apt 4B\",\n city: \"New York\",\n country: \"USA\",\n name: \"John Doe\",\n phone: \"(503) 555-0142\",\n state: \"NY\",\n zip: \"10001\",\n },\n trackingNumber: \"TRACK123456789US\",\n weight: \"2.5 kg\",\n};\n\n// Standard 4\" x 6\" shipping label, expressed in PDF points (72 dpi)\nconst LABEL_SIZE = { height: 432, width: 288 };\n\nconst formatCityLine = (party: ShippingLabelAddress) => {\n const cityStateZip = `${party.city}, ${party.state} ${party.zip}`;\n return party.country ? `${cityStateZip}, ${party.country}` : cityStateZip;\n};\n\nconst formatStreetLine = (party: ShippingLabelAddress) => party.address;\n\n// Shared address block — same treatment for both parties (10pt, bold name)\nconst AddressLines = ({\n party,\n}: {\n party: ShippingLabelAddress & { phone?: string };\n}) => (\n <>\n <Text noMargin variant=\"xs\" weight=\"bold\">\n {party.name}\n </Text>\n <Text noMargin variant=\"xs\">\n {formatStreetLine(party)}\n </Text>\n <Text noMargin variant=\"xs\">\n {formatCityLine(party)}\n </Text>\n {party.phone && (\n <Text noMargin variant=\"xs\" color=\"mutedForeground\">\n {party.phone}\n </Text>\n )}\n </>\n);\n\nconst ShippingLabelContent = ({ data }: { data: ShippingLabelData }) => {\n const theme = usePdfcnTheme();\n\n const accent = resolveColor(\n data.accentColor ?? theme.colors.primary,\n theme.colors\n );\n\n const detailRows = [\n ...(data.weight ? [{ key: \"Weight\", value: data.weight }] : []),\n ...(data.dimensions ? [{ key: \"Dimensions\", value: data.dimensions }] : []),\n ...(typeof data.packageCount === \"number\"\n ? [{ key: \"Packages\", value: `${data.packageCount}` }]\n : []),\n { key: \"Postage\", value: data.postage ?? \"PAID\" },\n ];\n\n const styles = StyleSheet.create({\n addresses: { flex: 1, flexDirection: \"row\" },\n badgesRow: {\n flexDirection: \"row\",\n flexWrap: \"wrap\",\n gap: 6,\n marginTop: 8,\n },\n barcodeArea: { alignItems: \"center\", marginTop: 10 },\n carrierName: { fontSize: 16, fontWeight: \"bold\" },\n fromColumn: { flex: 1, paddingLeft: 12 },\n handlingTag: {\n alignItems: \"center\",\n backgroundColor: theme.colors.foreground,\n justifyContent: \"center\",\n paddingHorizontal: 8,\n paddingVertical: 4,\n },\n handlingTagText: {\n color: theme.colors.background,\n fontSize: 8,\n fontWeight: \"bold\",\n letterSpacing: 1,\n textTransform: \"uppercase\",\n },\n headerRow: {\n alignItems: \"center\",\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n },\n label: {\n borderColor: theme.colors.foreground,\n borderStyle: \"solid\",\n borderWidth: 2,\n flex: 1,\n padding: 10,\n },\n page: {\n backgroundColor: theme.colors.background,\n boxSizing: \"border-box\",\n flexDirection: \"column\",\n height: LABEL_SIZE.height,\n overflow: \"hidden\",\n padding: 8,\n width: LABEL_SIZE.width,\n },\n rule: {\n backgroundColor: theme.colors.foreground,\n height: 2,\n marginVertical: 6,\n },\n sectionLabel: {\n color: accent,\n fontSize: 8,\n fontWeight: \"bold\",\n letterSpacing: 1,\n marginBottom: 4,\n textTransform: \"uppercase\",\n },\n serviceRight: { alignItems: \"flex-end\" },\n shipToColumn: {\n borderRightColor: theme.colors.foreground,\n borderRightStyle: \"solid\",\n borderRightWidth: 2,\n flex: 1.4,\n paddingRight: 12,\n },\n table: {\n borderColor: theme.colors.foreground,\n borderStyle: \"solid\",\n borderWidth: 2,\n },\n tableKey: {\n color: theme.colors.mutedForeground,\n fontSize: 8,\n fontWeight: \"bold\",\n letterSpacing: 0.5,\n textTransform: \"uppercase\",\n width: 84,\n },\n tableRow: {\n alignItems: \"center\",\n borderBottomColor: theme.colors.border,\n borderBottomStyle: \"solid\",\n borderBottomWidth: 1,\n flexDirection: \"row\",\n paddingHorizontal: 8,\n paddingVertical: 3,\n },\n tableRowLast: {\n alignItems: \"center\",\n flexDirection: \"row\",\n paddingHorizontal: 8,\n paddingVertical: 3,\n },\n tableValue: { flex: 1 },\n trackingText: {\n fontWeight: \"bold\",\n letterSpacing: 2,\n marginTop: 6,\n textTransform: \"uppercase\",\n },\n });\n\n return (\n <Document title={`Shipping Label ${data.trackingNumber}`}>\n <Page size={LABEL_SIZE} style={styles.page}>\n <View style={styles.label}>\n <View style={styles.headerRow}>\n <Text noMargin style={styles.carrierName}>\n {data.carrier}\n </Text>\n <View style={styles.serviceRight}>\n <Text noMargin style={styles.sectionLabel}>\n {data.serviceLevel}\n </Text>\n </View>\n </View>\n\n <View style={styles.rule} />\n\n <View style={styles.addresses}>\n <View style={styles.shipToColumn}>\n <Text noMargin style={styles.sectionLabel}>\n Ship To\n </Text>\n <AddressLines party={data.to} />\n </View>\n <View style={styles.fromColumn}>\n <Text noMargin style={styles.sectionLabel}>\n From\n </Text>\n <AddressLines party={data.from} />\n </View>\n </View>\n\n <View style={styles.rule} />\n\n <View style={styles.table}>\n {detailRows.map((row, index) => (\n <View\n key={row.key}\n style={\n index === detailRows.length - 1\n ? styles.tableRowLast\n : styles.tableRow\n }\n >\n <Text noMargin style={styles.tableKey}>\n {row.key}\n </Text>\n <Text noMargin style={styles.tableValue} variant=\"xs\">\n {row.value}\n </Text>\n </View>\n ))}\n </View>\n\n {data.handlingLabels && data.handlingLabels.length > 0 && (\n <View style={styles.badgesRow}>\n {data.handlingLabels.map((label, index) => (\n <View key={`${label}-${index}`} style={styles.handlingTag}>\n <Text noMargin style={styles.handlingTagText}>\n {label}\n </Text>\n </View>\n ))}\n </View>\n )}\n\n <View style={styles.barcodeArea}>\n {data.barcodeUrl ? (\n <PdfImage\n fit=\"contain\"\n height={72}\n src={data.barcodeUrl}\n width=\"100%\"\n />\n ) : (\n <PdfQRCode\n backgroundColor=\"#ffffff\"\n color=\"#000000\"\n size={80}\n value={data.trackingNumber}\n />\n )}\n <Text\n noMargin\n style={styles.trackingText}\n variant=\"xs\"\n weight=\"bold\"\n >\n {data.trackingNumber}\n </Text>\n </View>\n </View>\n </Page>\n </Document>\n );\n};\n\nexport const ShippingLabelDocument = ({\n theme,\n data = sampleData,\n}: {\n theme?: PdfcnTheme;\n data?: ShippingLabelData;\n}) => (\n <PdfcnThemeProvider theme={theme}>\n <ShippingLabelContent data={data} />\n </PdfcnThemeProvider>\n);\n",
"type": "registry:block",
"target": "components/pdf/blocks/shipping-label/shipping-label.tsx"
},
diff --git a/apps/web/registry/bases/takumi/blocks/shipping-label/shipping-label.tsx b/apps/web/registry/bases/takumi/blocks/shipping-label/shipping-label.tsx
index 1dc69c0..fd68713 100644
--- a/apps/web/registry/bases/takumi/blocks/shipping-label/shipping-label.tsx
+++ b/apps/web/registry/bases/takumi/blocks/shipping-label/shipping-label.tsx
@@ -138,6 +138,7 @@ const ShippingLabelContent = ({ data }: { data: ShippingLabelData }) => {
},
page: {
backgroundColor: theme.colors.background,
+ boxSizing: "border-box",
flexDirection: "column",
height: LABEL_SIZE.height,
overflow: "hidden",