generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
447 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@utrecht/component-library-react": minor | ||
"@utrecht/component-library-pdf": minor | ||
"@utrecht/table-of-contents-css": minor | ||
"@utrecht/components": minor | ||
"@utrecht/component-library-css": minor | ||
--- | ||
|
||
Add Table of Contents component for the PDF component library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# Table of Contents | ||
|
||
Lijst met de koppenstructuur van een document. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
|
||
Table of Contents moet opgebouwd worden met de volgende tags: | ||
|
||
- `<TOC>` voor de lijst met Table of Contents. | ||
- `<TOCI>` voor de items in de lijst met Table of Contents. | ||
- `<Reference>` als wrapper om de link. | ||
- `<Link>` voor de link. | ||
- `<Lbl>` voor het hoofdstuknummer. | ||
- `<Span>` voor koptekst. | ||
|
||
Als de Table of Contents een heading of extra content heeft, dan moet die buiten de `<TOC>` tag staan. Je kunt de hele table of contents in een `<Sect>` tag plaatsen. | ||
|
||
```text | ||
<TOC> { | ||
<TOCI> { | ||
<Reference> { | ||
<Link> { | ||
<Lbl> { | ||
"1.0.0" | ||
} | ||
<Span> { | ||
"The quick brown fox jumps over the lazy dog" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"version": "0.0.0", | ||
"author": "Community for NL Design System", | ||
"description": "Table of Contents component for the Municipality of Utrecht based on the NL Design System architecture", | ||
"license": "EUPL-1.2", | ||
"name": "@utrecht/table-of-contents-css", | ||
"files": [ | ||
"dist/", | ||
"docs/", | ||
"src/", | ||
"*.md" | ||
], | ||
"main": "dist/index.css", | ||
"scripts": { | ||
"build": "rollup -c ../rollup.config.mjs", | ||
"clean": "rimraf dist" | ||
}, | ||
"devDependencies": { | ||
"rollup": "4.18.0" | ||
}, | ||
"keywords": [ | ||
"nl-design-system" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git+ssh", | ||
"url": "git@github.com:nl-design-system/utrecht.git", | ||
"directory": "components/table-of-contents" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
$utrecht-support-prince-xml: false !default; | ||
|
||
/* stylelint-disable order/properties-alphabetical-order */ | ||
@mixin utrecht-table-of-contents { | ||
page-break-inside: avoid; | ||
} | ||
|
||
@mixin utrecht-table-of-contents__list { | ||
list-style-type: none; | ||
padding-inline-start: 0; | ||
page-break-inside: avoid; | ||
|
||
@if $utrecht-support-prince-xml { | ||
-prince-pdf-tag-type: TOC; | ||
|
||
/* reset Prince XML default styling of <ul> */ | ||
/* stylelint-disable-next-line property-disallowed-list */ | ||
margin-left: 0; | ||
/* stylelint-disable-next-line property-disallowed-list */ | ||
margin-top: 0; | ||
/* stylelint-disable-next-line property-disallowed-list */ | ||
margin-right: 0; | ||
} | ||
} | ||
|
||
@mixin utrecht-table-of-contents__list-item { | ||
margin-block-end: var(--utrecht-unordered-list-item-margin-block-end); | ||
margin-block-start: var(--utrecht-unordered-list-item-margin-block-start); | ||
|
||
@if $utrecht-support-prince-xml { | ||
-prince-pdf-tag-type: TOCI; | ||
} | ||
} | ||
|
||
@mixin utrecht-table-of-contents__list-item-body { | ||
@if $utrecht-support-prince-xml { | ||
-prince-pdf-tag-type: P; | ||
} | ||
} | ||
|
||
@mixin utrecht-table-of-contents__list-item-label { | ||
font-variant-numeric: lining-nums tabular-nums; | ||
@if $utrecht-support-prince-xml { | ||
-prince-pdf-tag-type: Lbl; | ||
} | ||
} | ||
|
||
@mixin utrecht-table-of-contents__list-item-title { | ||
@if $utrecht-support-prince-xml { | ||
-prince-pdf-tag-type: Span; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
@import "./mixin"; | ||
|
||
.utrecht-table-of-contents { | ||
@include utrecht-table-of-contents; | ||
} | ||
|
||
.utrecht-table-of-contents__list { | ||
@include utrecht-table-of-contents__list; | ||
} | ||
|
||
.utrecht-table-of-contents__list-item { | ||
@include utrecht-table-of-contents__list-item; | ||
} | ||
|
||
.utrecht-table-of-contents__list-item::before { | ||
content: ""; | ||
} | ||
|
||
.utrecht-table-of-contents__list-item-body { | ||
@include utrecht-table-of-contents__list-item-body; | ||
} | ||
|
||
.utrecht-table-of-contents__list-item-label { | ||
@include utrecht-table-of-contents__list-item-label; | ||
} | ||
|
||
.utrecht-table-of-contents__list-item-title { | ||
@include utrecht-table-of-contents__list-item-title; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"utrecht": { | ||
"table-of-contents": {} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/component-library-pdf/src/TableOfContents.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-env jest */ | ||
|
||
import { beforeAll, describe, expect, it } from '@jest/globals'; | ||
import { | ||
Heading1, | ||
Heading2, | ||
TableOfContents, | ||
TableOfContentsLink, | ||
TableOfContentsList, | ||
TableOfContentsListItem, | ||
} from '@utrecht/component-library-react/src/index'; | ||
import React from 'react'; | ||
import { renderPdf } from './lib'; | ||
|
||
describe('Table of Contents', () => { | ||
let sha256: string; | ||
|
||
beforeAll(async () => { | ||
({ sha256 } = await renderPdf({ | ||
id: 'pdf-table-of-contents', | ||
render: () => ( | ||
<> | ||
<Heading1>Document Title</Heading1> | ||
<TableOfContents> | ||
<Heading2>Table of Contents</Heading2> | ||
<TableOfContentsList> | ||
<TableOfContentsListItem> | ||
<TableOfContentsLink href="#chapter-1" label="1. "> | ||
The quick brown fox jumps over the lazy dog | ||
</TableOfContentsLink> | ||
</TableOfContentsListItem> | ||
</TableOfContentsList> | ||
</TableOfContents> | ||
<Heading2 id="chapter-1">The quick brown fox jumps over the lazy dog</Heading2> | ||
</> | ||
), | ||
})); | ||
}); | ||
|
||
it('renders a <TOC> tag', async () => { | ||
expect(sha256).toBe('bd73ea7ffb47470d26b64dae2336118acc8b7448190b63c399de448bb09a14c2'); | ||
}); | ||
|
||
describe('list item', () => { | ||
it('renders a <TOCI> tag', async () => { | ||
expect(sha256).toBe('bd73ea7ffb47470d26b64dae2336118acc8b7448190b63c399de448bb09a14c2'); | ||
}); | ||
|
||
it('renders a <Reference> tag', async () => { | ||
expect(sha256).toBe('bd73ea7ffb47470d26b64dae2336118acc8b7448190b63c399de448bb09a14c2'); | ||
}); | ||
|
||
it('renders a <Link> tag', async () => { | ||
expect(sha256).toBe('bd73ea7ffb47470d26b64dae2336118acc8b7448190b63c399de448bb09a14c2'); | ||
}); | ||
|
||
it('renders a <Lbl> tag with chapter number', async () => { | ||
expect(sha256).toBe('bd73ea7ffb47470d26b64dae2336118acc8b7448190b63c399de448bb09a14c2'); | ||
}); | ||
|
||
it('renders a <Span> tag with the text content', async () => { | ||
expect(sha256).toBe('bd73ea7ffb47470d26b64dae2336118acc8b7448190b63c399de448bb09a14c2'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2022 Robbert Broersma | ||
*/ | ||
|
||
import { clsx } from 'clsx'; | ||
import { HTMLAttributes, LiHTMLAttributes, type PropsWithChildren } from 'react'; | ||
import { Link, LinkProps } from './Link'; | ||
|
||
export type TableOfContentsProps = HTMLAttributes<HTMLElement>; | ||
|
||
export const TableOfContents = ({ children, className, ...restProps }: PropsWithChildren<TableOfContentsProps>) => ( | ||
<section className={clsx('utrecht-table-of-contents', className)} {...restProps}> | ||
{children} | ||
</section> | ||
); | ||
|
||
export type TableOfContentsListProps = HTMLAttributes<HTMLElement>; | ||
|
||
export const TableOfContentsList = ({ | ||
children, | ||
className, | ||
...restProps | ||
}: PropsWithChildren<TableOfContentsListProps>) => ( | ||
<ul className={clsx('utrecht-table-of-contents__list', className)} {...restProps}> | ||
{children} | ||
</ul> | ||
); | ||
|
||
export type TableOfContentsListItemProps = LiHTMLAttributes<HTMLLIElement>; | ||
|
||
export const TableOfContentsListItem = ({ | ||
children, | ||
className, | ||
...restProps | ||
}: PropsWithChildren<TableOfContentsListItemProps>) => ( | ||
<li className={clsx('utrecht-table-of-contents__list-item', className)} {...restProps}> | ||
<span className="utrecht-table-of-contents__list-item-body">{children}</span> | ||
</li> | ||
); | ||
|
||
export interface TableOfContentsLinkProps extends LinkProps { | ||
href: string; | ||
label?: string; | ||
} | ||
|
||
export const TableOfContentsLink = ({ | ||
children, | ||
className, | ||
label, | ||
...restProps | ||
}: PropsWithChildren<TableOfContentsLinkProps>) => ( | ||
<Link className={clsx('utrecht-table-of-contents__link', className)} {...restProps}> | ||
{label && <span className="utrecht-table-of-contents__list-item-label">{label}</span>} | ||
<span className="utrecht-table-of-contents__list-item-title">{children}</span> | ||
</Link> | ||
); |
8 changes: 8 additions & 0 deletions
8
packages/component-library-react/src/css-module/TableOfContents.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
import '@utrecht/table-of-contents-css/src/index.scss'; | ||
|
||
export * from '../TableOfContents'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.