Skip to content

Commit

Permalink
feat: add Image to component-library-pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert authored and Yolijn committed Oct 12, 2024
1 parent 00757ea commit 174828c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 0 deletions.
10 changes: 10 additions & 0 deletions components/img/docs/technology-pdf.nl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- @license CC0-1.0 -->

# PDF

Image moet opgebouwd worden met de `<Figure>` tag, met een tekst-alternatief in de `Alt` property.

```text
<Figure Alt="logo gemeente Utrecht"> {
}
```
43 changes: 43 additions & 0 deletions packages/component-library-pdf/src/Image.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-env jest */

import { beforeAll, describe, expect, it } from '@jest/globals';
import { Image } from '@utrecht/component-library-react/src/index';
import { readFile } from 'fs/promises';
import React from 'react';
import { renderPdf } from './lib';

describe('Image', () => {
let dataURL = '';

beforeAll(async () => {
const file = await readFile('./src/image.png');
dataURL = `data:image/png;base64,${file.toString('base64')}`;
});

it('renders a <Figure> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-image',
render: () => <Image src={dataURL} alt="" />,
});

expect(sha256).toBe('TODO');
});

it('renders a text alternative for `<img alt="Colorful gradients">`', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-image-alt',
render: () => <Image src={dataURL} alt="Colorful gradients" />,
});

expect(sha256).toBe('TODO');
});

it('renders a visible text alternative for `<img alt="Text alternative">`', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-image-actual-text',
render: () => <Image src="about:blank" alt="Text alternative for an image that is unavailable" />,
});

expect(sha256).toBe('TODO');
});
});
Binary file added packages/component-library-pdf/src/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/storybook-pdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@utrecht/heading-4-css": "workspace:*",
"@utrecht/heading-5-css": "workspace:*",
"@utrecht/heading-6-css": "workspace:*",
"@utrecht/img-css": "workspace:*",
"@utrecht/link-css": "workspace:*",
"@utrecht/ordered-list-css": "workspace:*",
"@utrecht/page-css": "workspace:*",
Expand Down
40 changes: 40 additions & 0 deletions packages/storybook-pdf/src/Image.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* @license CC0-1.0 */

import { Meta, StoryObj } from '@storybook/react';
import { Image } from '@utrecht/component-library-react/src/Image';
import readme from '@utrecht/img-css/README.md?raw';
import pdfDocs from '@utrecht/img-css/docs/technology-pdf.nl.md?raw';
import { mergeMarkdown } from '@utrecht/storybook-helpers/src/markdown';
import React from 'react';
import { PdfPreview } from './PdfPreview';

const meta = {
title: 'PDF Component/Image',
id: 'pdf-image',
component: Image,
argTypes: {},
args: {},
parameters: {
bugs: 'https://github.com/nl-design-system/utrecht/issues?q=is%3Aissue+is%3Aopen+label%3Acomponent%2Fimage',
nldesignsystem: 'https://nldesignsystem.nl/image',
status: {
type: 'ALPHA',
},
docs: {
description: {
component: mergeMarkdown([readme, pdfDocs]),
},
},
},
render: () => <PdfPreview component="Link" src="pdf-image-alt-1.png" download="pdf-image-alt.pdf" />,
} satisfies Meta<typeof Image>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};

export const ImageNotFound: Story = {
render: () => <PdfPreview component="Link" src="pdf-image-actual-text-1.png" download="pdf-image-actual-text.pdf" />,
};
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 174828c

Please sign in to comment.