- "content": "import { StyleSheet } from '@react-pdf/renderer';\nimport { usePdfxTheme } from '../lib/pdfx-theme-context';\ntype PdfxTheme = ReturnType<typeof usePdfxTheme>;\n\n/**\n * Creates all table styles derived from the active theme.\n * @param t - The resolved PdfxTheme instance.\n */\nexport function createTableStyles(t: PdfxTheme) {\n const { spacing, borderRadius, fontWeights, typography } = t.primitives;\n const borderColor = t.colors.border;\n\n const hairline = 0.5;\n const rule = 1;\n const thick = 1.5;\n\n const cellPadV = spacing[2] - 2;\n const cellPadH = spacing[2] + 2;\n const cellPadVCompact = spacing[0.5];\n const cellPadHCompact = spacing[2];\n\n const rowDivider = {\n borderBottomWidth: hairline,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid' as const,\n };\n\n return StyleSheet.create({\n table: {\n display: 'flex',\n flexDirection: 'column',\n width: '100%',\n marginBottom: t.spacing.componentGap,\n },\n\n tableGrid: {\n borderWidth: thick,\n borderColor: borderColor,\n borderStyle: 'solid',\n borderTopLeftRadius: borderRadius.md,\n borderTopRightRadius: borderRadius.md,\n borderBottomLeftRadius: borderRadius.md,\n borderBottomRightRadius: borderRadius.md,\n overflow: 'hidden' as const,\n },\n\n tableLine: {\n borderBottomWidth: hairline,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n\n tableMinimal: {\n paddingVertical: spacing[2],\n },\n\n tableStriped: {\n borderTopWidth: hairline,\n borderTopColor: borderColor,\n borderTopStyle: 'solid',\n borderBottomWidth: hairline,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n\n tableCompact: {\n borderBottomWidth: hairline,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n\n tableBordered: {\n borderWidth: rule,\n borderColor: borderColor,\n borderStyle: 'solid',\n borderTopLeftRadius: borderRadius.sm,\n borderTopRightRadius: borderRadius.sm,\n borderBottomLeftRadius: borderRadius.sm,\n borderBottomRightRadius: borderRadius.sm,\n overflow: 'hidden' as const,\n },\n\n tablePrimaryHeader: {\n borderBottomWidth: hairline,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n\n row: {\n flexDirection: 'row',\n display: 'flex',\n },\n\n rowGrid: rowDivider,\n rowLine: rowDivider,\n rowMinimal: rowDivider,\n rowStriped: {},\n rowCompact: rowDivider,\n rowBordered: rowDivider,\n rowPrimaryHeader: rowDivider,\n\n rowHeaderGrid: {\n backgroundColor: t.colors.muted,\n borderBottomWidth: rule,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n rowHeaderLine: {\n borderBottomWidth: rule,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n rowHeaderMinimal: {\n borderBottomWidth: rule,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n rowHeaderStriped: {\n backgroundColor: t.colors.muted,\n borderBottomWidth: rule,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n rowHeaderCompact: {\n backgroundColor: t.colors.muted,\n borderBottomWidth: rule,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n rowHeaderBordered: {\n backgroundColor: t.colors.muted,\n borderBottomWidth: hairline,\n borderBottomColor: borderColor,\n borderBottomStyle: 'solid',\n },\n rowHeaderPrimaryHeader: {\n backgroundColor: t.colors.primary,\n },\n\n rowFooter: {\n borderTopWidth: rule,\n borderTopColor: borderColor,\n borderTopStyle: 'solid',\n },\n rowFooterStriped: {\n borderTopWidth: rule,\n borderTopColor: borderColor,\n borderTopStyle: 'solid',\n backgroundColor: t.colors.muted,\n },\n\n rowStripe: {\n backgroundColor: t.colors.muted,\n },\n\n cell: {\n flex: 1,\n paddingVertical: cellPadV,\n paddingHorizontal: cellPadH,\n justifyContent: 'center',\n },\n cellFixed: {\n flex: 0,\n flexGrow: 0,\n flexShrink: 0,\n paddingVertical: cellPadV,\n paddingHorizontal: cellPadH,\n justifyContent: 'center',\n },\n\n cellMinimal: {\n paddingVertical: spacing[1] + 1,\n paddingHorizontal: spacing[2] - 2,\n },\n cellStriped: {\n paddingVertical: cellPadV,\n paddingHorizontal: cellPadH,\n },\n cellCompact: {\n paddingVertical: cellPadVCompact,\n paddingHorizontal: cellPadHCompact,\n },\n cellBordered: {\n paddingVertical: cellPadV,\n paddingHorizontal: cellPadH,\n },\n cellPrimaryHeader: {\n paddingVertical: cellPadV,\n paddingHorizontal: cellPadH,\n },\n\n cellGridBorder: {\n borderRightWidth: hairline,\n borderRightColor: borderColor,\n borderRightStyle: 'solid',\n },\n cellBorderedBorder: {\n borderRightWidth: hairline,\n borderRightColor: borderColor,\n borderRightStyle: 'solid',\n },\n\n cellText: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.foreground,\n },\n\n cellTextHeaderGrid: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.foreground,\n fontWeight: fontWeights.semibold,\n },\n cellTextHeaderLine: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.foreground,\n fontWeight: fontWeights.semibold,\n },\n cellTextHeaderMinimal: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.mutedForeground,\n fontWeight: fontWeights.medium,\n },\n cellTextHeaderStriped: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.foreground,\n fontWeight: fontWeights.semibold,\n },\n cellTextHeaderCompact: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: typography.xs,\n lineHeight: 1.2,\n color: t.colors.foreground,\n fontWeight: fontWeights.semibold,\n textTransform: 'uppercase',\n letterSpacing: 0.6,\n },\n cellTextHeaderBordered: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.foreground,\n fontWeight: fontWeights.bold,\n },\n cellTextHeaderPrimaryHeader: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: typography.xs,\n lineHeight: 1.2,\n color: t.colors.primaryForeground,\n fontWeight: fontWeights.semibold,\n textTransform: 'uppercase',\n letterSpacing: 0.6,\n },\n\n cellTextFooter: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: t.typography.body.fontSize,\n lineHeight: 1.2,\n color: t.colors.foreground,\n fontWeight: fontWeights.semibold,\n },\n\n cellTextCompact: {\n fontFamily: t.typography.body.fontFamily,\n fontSize: typography.xs,\n lineHeight: 1.2,\n color: t.colors.foreground,\n },\n });\n}\n",
0 commit comments