Skip to content

Commit 8aef4fe

Browse files
authored
Page object (#1043)
1 parent 28ff9c1 commit 8aef4fe

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add Page object for "sticky" page footers

src/base/_defaults.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ ul {
4545
margin: 0;
4646
}
4747

48+
/**
49+
* Forces the viewport to be filled. Necessary for the footer to "stick" to the
50+
* bottom of short pages.
51+
*
52+
* @see https://css-tricks.com/couple-takes-sticky-footer/#there-is-grid
53+
*/
54+
55+
html,
56+
body {
57+
height: 100%;
58+
}
59+
4860
/**
4961
* 1. Prevents custom background colors, iframes, etc. from making page content
5062
* unreadable.

src/objects/page/demo/example.twig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% embed '@cloudfour/objects/page/page.twig' %}
2+
{% block content %}
3+
<p class="u-pad-1">
4+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu ex
5+
enim. Nunc efficitur scelerisque dolor et sollicitudin. Donec finibus
6+
lorem elit, eu consectetur quam pellentesque sed. Pellentesque habitant
7+
morbi tristique senectus et netus et malesuada fames ac turpis egestas.
8+
</p>
9+
{% endblock %}
10+
{% block footer %}
11+
<p class="u-pad-1 t-dark">
12+
Footer content.
13+
</p>
14+
{% endblock %}
15+
{% endembed %}

src/objects/page/page.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Page container
3+
*
4+
* Attempts to fill the available area (assuming `height: 100%` is correctly
5+
* applied to all parent elements) and keeps the footer at the bottom of that
6+
* area.
7+
*
8+
* @see https://css-tricks.com/couple-takes-sticky-footer/#there-is-grid
9+
*/
10+
11+
.o-page {
12+
display: grid;
13+
grid-template-rows: 1fr auto;
14+
min-height: 100%;
15+
}
16+
17+
/**
18+
* These classes aren't strictly required, but they keep the HTML source a
19+
* little easier to read while also supporting swapping of source order if
20+
* that's ever something that content calls for.
21+
*/
22+
23+
.o-page__content {
24+
grid-row: 1;
25+
}
26+
27+
.o-page__footer {
28+
grid-row: 2;
29+
}

src/objects/page/page.stories.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';
2+
import { useEffect } from '@storybook/client-api';
3+
import exampleDemo from './demo/example.twig';
4+
5+
<Meta
6+
title="Objects/Page"
7+
parameters={{ docs: { inlineStories: false }, paddings: { disabled: true } }}
8+
/>
9+
10+
# Page
11+
12+
A wrapper for page body and footer content that keeps the footer at the bottom of the viewport even if the page is too short to push it down.
13+
14+
For this to work correctly, each parent element needs to fill its container height. For best results, apply this to the `body` element directly or nested immediately within.
15+
16+
<Canvas>
17+
<Story name="Example" height="400px">
18+
{() => {
19+
useEffect(() => {
20+
// Override Storybook's `min-height` in the preview
21+
document.body.style.minHeight = '';
22+
// Prevent Storybook's container from affecting this layout
23+
document.querySelector('#root').style.display = 'contents';
24+
});
25+
return exampleDemo();
26+
}}
27+
</Story>
28+
</Canvas>

src/objects/page/page.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="o-page{% if class %} {{class}}{% endif %}">
2+
<div class="o-page__footer">
3+
{% block footer %}{% endblock %}
4+
</div>
5+
<div class="o-page__content">
6+
{% block content %}{% endblock %}
7+
</div>
8+
</div>

0 commit comments

Comments
 (0)