From 95a1f652f9df864f52467b84fb5a85e62936e2fb Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Thu, 15 May 2025 13:24:10 +0200 Subject: [PATCH] Better print layouts: wrap code blocks & force table column auto-sizing (#3236) --- .changeset/rare-radios-thank.md | 5 +++++ .../components/DocumentView/CodeBlock/CodeBlockRenderer.tsx | 2 +- .../gitbook/src/components/DocumentView/Table/RecordRow.tsx | 4 ++-- .../gitbook/src/components/DocumentView/Table/ViewGrid.tsx | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/rare-radios-thank.md diff --git a/.changeset/rare-radios-thank.md b/.changeset/rare-radios-thank.md new file mode 100644 index 000000000..0fb143ce4 --- /dev/null +++ b/.changeset/rare-radios-thank.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Better print layouts: wrap code blocks & force table column auto-sizing diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlockRenderer.tsx b/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlockRenderer.tsx index d8f35d90b..0ad885a44 100644 --- a/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlockRenderer.tsx +++ b/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlockRenderer.tsx @@ -58,7 +58,7 @@ export const CodeBlockRenderer = forwardRef(function CodeBlockRenderer( diff --git a/packages/gitbook/src/components/DocumentView/Table/RecordRow.tsx b/packages/gitbook/src/components/DocumentView/Table/RecordRow.tsx index e39f386cc..b09760ceb 100644 --- a/packages/gitbook/src/components/DocumentView/Table/RecordRow.tsx +++ b/packages/gitbook/src/components/DocumentView/Table/RecordRow.tsx @@ -15,14 +15,14 @@ export function RecordRow( fixedColumns: string[]; } ) { - const { view, autoSizedColumns, fixedColumns, block } = props; + const { view, autoSizedColumns, fixedColumns, block, context } = props; return (
{view.columns.map((column) => { const columnWidth = getColumnWidth({ column, - columnWidths: view.columnWidths, + columnWidths: context.mode === 'print' ? undefined : view.columnWidths, autoSizedColumns, fixedColumns, }); diff --git a/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx b/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx index 50aa13565..9f2b98ba4 100644 --- a/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx +++ b/packages/gitbook/src/components/DocumentView/Table/ViewGrid.tsx @@ -13,10 +13,10 @@ import { getColumnAlignment } from './utils'; 3. Auto-size is turned off without setting a width, we then default to a fixed width of 100px */ export function ViewGrid(props: TableViewProps) { - const { block, view, records, style } = props; + const { block, view, records, style, context } = props; /* Calculate how many columns are auto-sized vs fixed width */ - const columnWidths = view.columnWidths; + const columnWidths = context.mode === 'print' ? undefined : view.columnWidths; const autoSizedColumns = view.columns.filter((column) => !columnWidths?.[column]); const fixedColumns = view.columns.filter((column) => columnWidths?.[column]);