Skip to content

Commit

Permalink
feat: page component
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Oct 11, 2021
1 parent 1cc3635 commit c577496
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 0 deletions.
29 changes: 29 additions & 0 deletions components/page/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Page component

Component that centers the page. The page maximizes the width of the content for large viewports, to keep the line length of texts readable and avoid large horizontal distances between related components.

Typically the contents of the page component are:

- Page Header component
- Page Content component
- Main content
- Complimentary content
- Page Footer component

## API

- CSS class name: `utrecht-page`
- Web component: `<utrecht-page>`
- Angular/React/Vue.js component: `UtrechtPage`

## CSS implementation

### Margin

To create some transparent space around the page, `margin-inline` CSS variables are provided. However, to automatically horizontally center the page `margin-inline: auto` needs to be used.

Achieving both goals is made possible by implementing the `margin-inline` as `padding-inline` on a transparent container element. The only downside to this approach is that margin collapsing won't work anymore, but that doesn't seem like anyone would ever need for a component that realistically is only used once per document.

### Padding

Padding is not applied directly in the page component itself, but in the child components such as Page Header, Page Content and Page Footer.
6 changes: 6 additions & 0 deletions components/page/bem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

export const Page = ({ innerHTML = '' }) => `<div class="utrecht-page">${innerHTML}</div>`;
22 changes: 22 additions & 0 deletions components/page/bem.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Gemeente Utrecht
* Copyright (c) 2021 Robbert Broersma
*/

.utrecht-page {
margin-inline-end: auto;
margin-inline-start: auto;
max-inline-size: calc(
var(--utrecht-page-max-inline-size) - var(--utrecht-page-margin-inline-start, 0px) -
var(--utrecht-page-margin-inline-end, 0px)
);
padding-inline-end: var(--utrecht-page-margin-inline-end);
padding-inline-start: var(--utrecht-page-margin-inline-start);
}

.utrecht-page__content {
background-color: var(--utrecht-page-background-color);
color: var(--utrecht-page-color);
max-inline-size: var(--utrecht-page-max-inline-size);
}
41 changes: 41 additions & 0 deletions components/page/bem.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
@license EUPL-1.2
Copyright (c) 2021 Robbert Broersma
-->

import { Canvas, Meta, Story } from "@storybook/addon-docs";
import { PageContent } from "../page-content/bem";
import { PageFooter } from "../page-footer/bem";
import { PageHeader } from "../page-header/bem";
import { Page } from "./bem.js";
import "./bem.scss";

<Meta
title="CSS Component/Page"
parameters={{
docs: {
transformSource: (_src, { args }) => Page(args),
},
layout: "fullscreen",
status: {
type: "WORK IN PROGRESS",
},
}}
/>

# Page component

<Canvas>
<Story
name="Page"
args={{
innerHTML: [
PageHeader({ innerHTML: "Header area" }),
PageContent({ innerHTML: "Content area" }),
PageFooter({ innerHTML: "Footer area" }),
].join("\n"),
}}
>
{Page.bind({})}
</Story>
</Canvas>
36 changes: 36 additions & 0 deletions components/page/block.tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"utrecht": {
"page": {
"background-color": {
"css": {
"syntax": "<color>",
"inherits": true
}
},
"color": {
"css": {
"syntax": "<color>",
"inherits": true
}
},
"margin-inline-start": {
"css": {
"syntax": "<length>",
"inherits": true
}
},
"margin-inline-end": {
"css": {
"syntax": "<length>",
"inherits": true
}
},
"max-inline-size": {
"css": {
"syntax": "<length>",
"inherits": true
}
}
}
}
}
12 changes: 12 additions & 0 deletions components/page/readme.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Description, Meta } from "@storybook/addon-docs";
import { ComponentTokensTable } from "../../documentation/components/ComponentTokensTable";
import tokens from "../../proprietary/design-tokens/dist/index.json";
import document from "./README.md";

<Meta title="CSS Component/Page/README" />

<Description>{document}</Description>

## Design Tokens

<ComponentTokensTable tokens={tokens} component="utrecht-page"></ComponentTokensTable>
14 changes: 14 additions & 0 deletions components/page/stencil.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "./bem";

:host {
display: block;
}

:host([hidden]) {
display: none !important;
}
42 changes: 42 additions & 0 deletions components/page/stencil.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
@license EUPL-1.2
Copyright (c) 2021 Robbert Broersma
-->

import { ArgsTable, Canvas, Meta, Story } from "@storybook/addon-docs";

export const Template = ({ contentHTML = "", footerHTML = "", headerHTML = "" }) => `<utrecht-page>
<utrecht-page-header>${headerHTML}</utrecht-page-header>
<utrecht-page-content>${contentHTML}</utrecht-page-content>
<utrecht-page-footer>${footerHTML}</utrecht-page-footer>
</utrecht-page>`;

<Meta
title="Web Component/Page"
argTypes={{}}
parameters={{
docs: {
transformSource: (_src, { args }) => Template(args),
},
status: {
type: "WORK IN PROGRESS",
},
}}
/>

# Page component

<Canvas>
<Story
name="Page"
args={{
contentHTML: "Main content",
footerHTML: "Footer content",
headerHTML: "Header content",
}}
>
{Template.bind({})}
</Story>
</Canvas>

<ArgsTable story="Page" />
23 changes: 23 additions & 0 deletions components/page/stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, h } from "@stencil/core";

/**
* @license EUPL-1.2
* Copyright (c) 2021 Gemeente Utrecht
*/

@Component({
tag: "utrecht-page",
styleUrl: "stencil.scss",
shadow: true,
})
export class Page {
render() {
return (
<div class="utrecht-page">
<div class="utrecht-page__content">
<slot></slot>
</div>
</div>
);
}
}
2 changes: 2 additions & 0 deletions packages/web-component-library-angular/src/index.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
UtrechtIconZoomout,
UtrechtLogo,
UtrechtLogoButton,
UtrechtPage,
UtrechtPageFooter,
UtrechtPagination,
UtrechtParagraph,
Expand Down Expand Up @@ -105,6 +106,7 @@ const components = [
UtrechtIconZoomout,
UtrechtLogo,
UtrechtLogoButton,
UtrechtPage,
UtrechtPageFooter,
UtrechtPagination,
UtrechtParagraph,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"utrecht": {
"page": {
"background-color": { "value": "{utrecht.color.white.value}" },
"color": { "value": "{utrecht.color.grey.10.value}" },
"margin-inline-start": { "value": "2em" },
"margin-inline-end": { "value": "2em" },
"max-inline-size": { "value": "1184px" },
"padding-block-start": { "value": "1.8em" },
"padding-inline-end": { "value": "2.4em" },
"padding-block-end": { "value": "1em" },
"padding-inline-start": { "value": "2em" }
}
}
}

0 comments on commit c577496

Please sign in to comment.