import * as React from 'react'; import { Text, View } from '@react-pdf/renderer'; import type { DatasheetVoltageTable } from '../../model/types'; import { styles } from '../styles'; function clamp(n: number, min: number, max: number): number { return Math.max(min, Math.min(max, n)); } export function DenseTable(props: { table: Pick; firstColLabel: string; }): React.ReactElement { const cols = props.table.columns; const rows = props.table.rows; const cfgPct = cols.length >= 12 ? 0.28 : 0.32; const dataPct = 1 - cfgPct; const each = cols.length ? dataPct / cols.length : dataPct; const cfgW = `${Math.round(cfgPct * 100)}%`; const dataW = `${Math.round(clamp(each, 0.03, 0.12) * 1000) / 10}%`; return ( {props.firstColLabel} {cols.map(c => ( {c.label} ))} {rows.map((r, ri) => ( {r.configuration} {r.cells.map((cell, ci) => ( {cell} ))} ))} ); }