From 17d9813e7d1176710c42971130354fbcca31dba4 Mon Sep 17 00:00:00 2001 From: Robbert Broersma Date: Sat, 12 Oct 2024 14:30:49 +0200 Subject: [PATCH] feat: add Column Layout to PDF component library --- .changeset/rare-numbers-explode.md | 5 ++ .../column-layout/docs/technology-pdf.nl.md | 5 ++ .../src/ColumnLayout.test.tsx | 54 +++++++++++++++++++ .../src/ColumnLayout.stories.tsx | 53 ++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 .changeset/rare-numbers-explode.md create mode 100644 components/column-layout/docs/technology-pdf.nl.md create mode 100644 packages/component-library-pdf/src/ColumnLayout.test.tsx create mode 100644 packages/storybook-pdf/src/ColumnLayout.stories.tsx diff --git a/.changeset/rare-numbers-explode.md b/.changeset/rare-numbers-explode.md new file mode 100644 index 00000000000..9e101f3b46c --- /dev/null +++ b/.changeset/rare-numbers-explode.md @@ -0,0 +1,5 @@ +--- +"@utrecht/component-library-pdf": minor +--- + +Add Column Layout to the PDF component library. diff --git a/components/column-layout/docs/technology-pdf.nl.md b/components/column-layout/docs/technology-pdf.nl.md new file mode 100644 index 00000000000..de0122eed9c --- /dev/null +++ b/components/column-layout/docs/technology-pdf.nl.md @@ -0,0 +1,5 @@ + + +# PDF + +De inhoud van een Column Layout in PDF moet doorlopen, net als wanneer er geen kolommen zouden zijn. Een alinea tekst die over meerdere kolommen verdeeld is, moet 1 `

` tag hebben. De tekst binnen de `

` moet een logische leesvolgorde hebben. diff --git a/packages/component-library-pdf/src/ColumnLayout.test.tsx b/packages/component-library-pdf/src/ColumnLayout.test.tsx new file mode 100644 index 00000000000..2d27933ceec --- /dev/null +++ b/packages/component-library-pdf/src/ColumnLayout.test.tsx @@ -0,0 +1,54 @@ +/* eslint-env jest */ + +import { beforeAll, describe, expect, it } from '@jest/globals'; +import { ColumnLayout, Paragraph } from '@utrecht/component-library-react/src/index'; +import React from 'react'; +import { renderPdf } from './lib'; + +describe('Column Layout', () => { + describe('with one paragraph spanning multiple columns and multiple pages', () => { + describe('default configuration', () => { + let sha256: string; + + beforeAll(async () => { + ({ sha256 } = await renderPdf({ + id: 'pdf-column-layout', + render: () => ( + + {'The quick brown fox jumps over the lazy dog. '.repeat(100)} + + ), + })); + }); + + it('the file must contain one `

` tag, containing all text spanning multiple columns', async () => { + expect(sha256).toBe('c3e93b12aaf33634b4951c337efc4e802640e156961d69edd2875f929efa68cc'); + }); + + it('renders 2 columns', async () => { + expect(sha256).toBe('c3e93b12aaf33634b4951c337efc4e802640e156961d69edd2875f929efa68cc'); + }); + }); + + describe('configured for 3 columns in print', () => { + it('renders 3 columns', async () => { + const { sha256 } = await renderPdf({ + id: 'pdf-column-layout-column-count-3', + render: () => ( + + {'The quick brown fox jumps over the lazy dog. '.repeat(100)} + + ), + }); + + expect(sha256).toBe('70e639763a526bca6a335629ace1d4e1c70ed2cb58be618456448be6cc4d7b7a'); + }); + }); + }); +}); diff --git a/packages/storybook-pdf/src/ColumnLayout.stories.tsx b/packages/storybook-pdf/src/ColumnLayout.stories.tsx new file mode 100644 index 00000000000..7b6ab9daa02 --- /dev/null +++ b/packages/storybook-pdf/src/ColumnLayout.stories.tsx @@ -0,0 +1,53 @@ +/* @license CC0-1.0 */ + +import { Meta, StoryObj } from '@storybook/react'; +import readme from '@utrecht/column-layout-css/README.md?raw'; +import pdfDocs from '@utrecht/column-layout-css/docs/technology-pdf.nl.md?raw'; +import { ColumnLayout } from '@utrecht/component-library-react'; +import { mergeMarkdown } from '@utrecht/storybook-helpers/src/markdown'; +import React from 'react'; +import { PdfPreview } from './PdfPreview'; + +const meta = { + title: 'PDF Component/Column Layout', + id: 'pdf-column-layout', + component: ColumnLayout, + argTypes: { + children: { + description: 'Content of the columns.', + control: 'text', + }, + }, + args: { + children: [], + }, + parameters: { + bugs: 'https://github.com/nl-design-system/utrecht/issues?q=is%3Aissue+is%3Aopen+label%3Acomponent%2Fcolumn-layout', + status: { + type: 'WORK IN PROGRESS', + }, + docs: { + description: { + component: mergeMarkdown([readme, pdfDocs]), + }, + }, + }, + render: () => , +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = {}; + +export const ThreeColumns: Story = { + name: '3 columns', + render: () => ( + + ), +};