Skip to content

Commit fe7a95f

Browse files
Add Alert block to Page object (#1921)
1 parent da3c096 commit fe7a95f

File tree

7 files changed

+98
-11
lines changed

7 files changed

+98
-11
lines changed

.changeset/dirty-snails-impress.md

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+
Adds an optional Alert block to the Page object

src/components/alert/alert.stories.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,7 @@ When more contrast is desired, you may also attach a theme class to the the floa
185185
## Template Blocks
186186

187187
- `content`
188+
189+
## Alert within a Page object
190+
191+
The Page object has an `alert` block that was designed to accept an Alert component. See the [Page with Alert example](/?path=/docs/objects-page--example-with-alert) for more details.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% embed '@cloudfour/objects/page/page.twig' only %}
2+
{% block alert %}
3+
{% include '@cloudfour/components/alert/alert.twig' with {
4+
dismissable: true,
5+
floating: true,
6+
icon: 'cloud-slash',
7+
message: 'You appear to be offline, some content may be unavailable.'
8+
} only %}
9+
{% endblock %}
10+
{% block header %}
11+
<p class="u-pad-1 t-dark">
12+
Header content.
13+
</p>
14+
{% endblock %}
15+
{% block content %}
16+
<p class="u-pad-1">
17+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu ex
18+
enim. Nunc efficitur scelerisque dolor et sollicitudin. Donec finibus
19+
lorem elit, eu consectetur quam pellentesque sed. Pellentesque habitant
20+
morbi tristique senectus et netus et malesuada fames ac turpis egestas.
21+
</p>
22+
{% endblock %}
23+
{% block footer %}
24+
<p class="u-pad-1 t-dark">
25+
Footer content.
26+
</p>
27+
{% endblock %}
28+
{% endembed %}

src/objects/page/page.scss

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
@use '../../compiled/tokens/scss/size';
2+
@use '../../mixins/spacing';
3+
14
/**
25
* Page container
36
*
@@ -11,7 +14,7 @@
1114
.o-page {
1215
display: grid;
1316
grid-template-columns: minmax(0, 1fr); // 1
14-
grid-template-rows: minmax(0, auto) minmax(0, 1fr) minmax(0, auto); // 2
17+
grid-template-rows: minmax(0, auto) 0 minmax(0, 1fr) minmax(0, auto); // 2
1518
min-block-size: 100%;
1619
}
1720

@@ -25,10 +28,25 @@
2528
grid-row: 1;
2629
}
2730

28-
.o-page__content {
31+
/**
32+
* An optional `alert` block can be used to pass an Alert component
33+
*
34+
* 1. The alert should overlap the content above slightly
35+
*/
36+
37+
.o-page__alert {
38+
@include spacing.fluid-padding-inline;
39+
display: grid;
2940
grid-row: 2;
41+
inset-block-start: calc(size.$overlap-large * -1); // 1
42+
justify-content: center;
43+
position: relative;
3044
}
3145

32-
.o-page__footer {
46+
.o-page__content {
3347
grid-row: 3;
3448
}
49+
50+
.o-page__footer {
51+
grid-row: 4;
52+
}

src/objects/page/page.stories.mdx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@ import { useEffect } from '@storybook/client-api';
1111
// eslint-disable-next-line @cloudfour/import/no-webpack-loader-syntax
1212
import exampleDemoSource from '!!raw-loader!./demo/example.twig';
1313
import exampleDemo from './demo/example.twig';
14+
// eslint-disable-next-line @cloudfour/import/no-webpack-loader-syntax
15+
import exampleDemoWithAlertSource from '!!raw-loader!./demo/example-with-alert.twig';
16+
import exampleDemoWithAlert from './demo/example-with-alert.twig';
1417

1518
<Meta
1619
title="Objects/Page"
1720
parameters={{ docs: { inlineStories: false }, layout: 'fullscreen' }}
21+
decorators={[
22+
(story) => {
23+
useEffect(() => {
24+
// Set this story's `body` element to full-height
25+
document.body.style.height = '100%';
26+
// Prevent Storybook's container from affecting this layout
27+
document.querySelector('#root').style.display = 'contents';
28+
});
29+
return story();
30+
},
31+
]}
1832
/>
1933

2034
# Page
@@ -34,14 +48,23 @@ The header block is optional.
3448
docs: { source: { code: exampleDemoSource } },
3549
}}
3650
>
37-
{() => {
38-
useEffect(() => {
39-
// Set this story's `body` element to full-height
40-
document.body.style.height = '100%';
41-
// Prevent Storybook's container from affecting this layout
42-
document.querySelector('#root').style.display = 'contents';
43-
});
44-
return exampleDemo();
51+
{exampleDemo()}
52+
</Story>
53+
</Canvas>
54+
55+
## Page with Alert
56+
57+
The Page object also has an optional `alert` block that can be used to pass an [Alert component](/?path=/docs/components-alert--basic).
58+
59+
<Canvas>
60+
<Story
61+
name="Example with Alert"
62+
height="400px"
63+
parameters={{
64+
layout: 'fullscreen',
65+
docs: { source: { code: exampleDemoWithAlertSource } },
4566
}}
67+
>
68+
{exampleDemoWithAlert()}
4669
</Story>
4770
</Canvas>

src/objects/page/page.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
{% block header %}{% endblock %}
55
</div>
66
{% endif %}
7+
{% if block('alert') %}
8+
<div class="o-page__alert">
9+
{% block alert %}{% endblock %}
10+
</div>
11+
{% endif %}
712
<div class="o-page__content{% if content_class %} {{ content_class }}{% endif %}">
813
{% block content %}{% endblock %}
914
</div>

src/tokens/size/sizing.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ module.exports = {
5959
comment:
6060
'Small amount of overlap between adjacent items organized in a visual bunch.',
6161
},
62+
large: {
63+
value: modularEm(1),
64+
comment: 'Larger amount of overlap between adjacent items.',
65+
},
6266
},
6367
},
6468
};

0 commit comments

Comments
 (0)