Skip to content

Commit ec2c142

Browse files
Merge pull request #1201 from nhsuk/add-html-param-to-hero
Add missing params to hero component
2 parents 953118b + c1debde commit ec2c142

13 files changed

+73
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ You can now add `classes` and `attributes` to table cells, for example using the
6161

6262
This was added in [pull request #1172: Add table cell `classes` and `attributes` param support](https://github.com/nhsuk/nhsuk-frontend/pull/1172).
6363

64+
#### Add html content and heading attributes to hero
65+
66+
You can now use `caller`, `html`, `headingClasses` and `headingLevel` in the hero component.
67+
68+
This was added in [pull request #1201: Add missing params to hero component](https://github.com/nhsuk/nhsuk-frontend/pull/1201).
69+
6470
#### Default bottom margin on tables
6571

6672
This was added in [pull request #1005: Update table styles so nhsuk-table has bottom margin](https://github.com/nhsuk/nhsuk-frontend/pull/1005).

app/_templates/layout.njk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% extends 'template.njk' %}
22
{% block pageTitle %}{{ title }} - NHS.UK Frontend{% endblock %}
33

4-
{% set assetPath = "/nhsuk-frontend/assets" %}
5-
64
{% block head %}
75
<link href="https://www.nhs.uk/" rel="preconnect">
86
<link href="https://assets.nhs.uk/" rel="preconnect" crossorigin>

app/components/button/link.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="nhsuk-grid-column-two-thirds">
88
{{ button({
99
"text": "Link button",
10-
"href": "/nhsuk-frontend/"
10+
"href": baseUrl
1111
}) }}
1212
</div>
1313
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% set title = 'Hero' %}
2+
{% from 'components/hero/macro.njk' import hero %}
3+
{% from 'components/button/macro.njk' import button %}
4+
5+
{% extends 'example.njk' %}
6+
7+
{% block main %}
8+
{% call hero({
9+
heading: "This is a header for the product or service",
10+
headingClasses: "nhsuk-heading-l nhsuk-u-margin-top-5"
11+
}) %}
12+
<p class="nhsuk-body-l">This is some more content which explains a bit more about the product or service.</p>
13+
14+
{{ button({
15+
text: "Sign up",
16+
classes: "nhsuk-button--reverse"
17+
}) }}
18+
{% endcall %}
19+
{% endblock %}

app/pages/examples.njk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
<li><a href="../components/header/header-org-white-nav.html">Header organisational with white header and navigation</a></li>
8989
<li><a href="../components/hero/index.html">Hero</a></li>
9090
<li><a href="../components/hero/hero-image.html">Hero with image</a></li>
91-
<li><a href="../components/hero/hero-image-content.html">Hero with image with content</a></li>
91+
<li><a href="../components/hero/hero-image-content.html">Hero with image, text content</a></li>
92+
<li><a href="../components/hero/hero-with-html.html">Hero with HTML content</a></li>
9293
<li><a href="../components/hint/index.html">Hint</a></li>
9394
<li><a href="../components/images/index.html">Images</a></li>
9495
<li><a href="../components/input/index.html">Input</a></li>

packages/components/hero/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,16 @@
103103

104104
The hero macro takes the following arguments:
105105

106-
| Name | Type | Required | Description |
107-
| -------------- | ------ | -------- | ------------------------------------------------------------------------------------------- |
108-
| **heading** | string | No | Text heading of the hero component. |
109-
| **text** | string | No | Text content of the hero component. |
110-
| **imageURL** | string | No | URL of the image of the hero component. |
111-
| **classes** | string | No | Optional additional classes to add to the hero container. Separate each class with a space. |
112-
| **attributes** | object | No | Any extra HTML attributes (for example data attributes) to add to the hero container. |
106+
| Name | Type | Required | Description |
107+
| ------------------ | -------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
108+
| **heading** | string | No | Text heading of the hero component |
109+
| **headingClasses** | string | No | Optional additional classes to add to heading. Separate each class with a space. |
110+
| **headingLevel** | integer | No | Optional heading level for the heading. Default: `1` |
111+
| **text** | string | No | Text content of the hero component. If `html` is provided, the `text` argument will be ignored. |
112+
| **html** | string | No | HTML content of the hero component. If `html` is provided, the `text` argument will be ignored. |
113+
| **caller** | nunjucks-block | No | Not strictly a parameter but [Nunjucks code convention](https://mozilla.github.io/nunjucks/templating.html#call). Using a `call` block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire hero component in a `call` block. |
114+
| **imageURL** | string | No | URL of the image of the hero component. |
115+
| **classes** | string | No | Optional additional classes to add to the hero container. Separate each class with a space. |
116+
| **attributes** | object | No | Any extra HTML attributes (for example data attributes) to add to the hero container. |
113117

114118
If you are using Nunjucks macros in production be aware that using `html` arguments, or ones ending with `html` can be a [security risk](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Read more about this in the [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#user-defined-templates-warning).

packages/components/hero/_hero.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
color: $color_nhsuk-white;
1616
position: relative; // [1]
1717

18+
a {
19+
@include nhsuk-link-style-white;
20+
}
21+
1822
.nhsuk-hero--border {
1923
// [2]
2024
border-top: $nhsuk-hero-border solid $nhsuk-secondary-border-color;
@@ -26,6 +30,10 @@
2630
@include nhsuk-responsive-padding(8, bottom);
2731
}
2832

33+
.nhsuk-hero__heading {
34+
@include nhsuk-responsive-margin(3, bottom);
35+
}
36+
2937
/// Hero component image styles
3038
///
3139
/// 3. Center the background image.
@@ -84,8 +92,15 @@
8492
/// 13. Remove the arrow in Windows high contrast mode.
8593
/// 14. Reduce spacing and change positioning for Windows high contrast mode.
8694
/// 15. Prevent text breaking out of box on smaller sizes
95+
/// 16. Prevent overlap using safe area: box offset + arrow height + spacing
8796

8897
.nhsuk-hero--image-description {
98+
margin-bottom: calc(70px + 20px + nhsuk-spacing(3)); // [16]
99+
100+
@include mq($from: tablet) {
101+
margin-bottom: calc(48px + 20px + nhsuk-spacing(4)); // [16]
102+
}
103+
89104
.nhsuk-hero-content {
90105
background-color: $color_nhsuk-blue;
91106
color: $color_nhsuk-white;

packages/components/hero/template.njk

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
{% from "../../macros/attributes.njk" import nhsukAttributes %}
22

3+
{% set headingLevel = params.headingLevel if params.headingLevel else 1 -%}
4+
35
<section class="nhsuk-hero
46
{%- if params.imageURL and params.heading %} nhsuk-hero--image nhsuk-hero--image-description
57
{%- elif params.imageURL %} nhsuk-hero--image{% endif %}
68
{%- if params.classes %} {{ params.classes }}{% endif %}"
79
{%- if params.imageURL %} style="background-image: url('{{ params.imageURL }}');"{% endif %}
810
{{- nhsukAttributes(params.attributes) }}>
911
{% if params.imageURL %}<div class="nhsuk-hero__overlay">{% endif %}
10-
{%- if params.heading %}
12+
{%- if caller or params.heading or params.text or params.html %}
1113
<div class="nhsuk-width-container{% if not params.imageURL %} nhsuk-hero--border{% endif %}">
1214
<div class="nhsuk-grid-row">
1315
<div class="nhsuk-grid-column-two-thirds">
1416
<div class="{% if params.imageURL %}nhsuk-hero-content{% else %}nhsuk-hero__wrapper{% endif %}">
15-
<h1 {% if params.text %}class="nhsuk-u-margin-bottom-3"{% endif %}>{{ params.heading }}</h1>
16-
{% if params.text %}<p class="nhsuk-body-l nhsuk-u-margin-bottom-0">{{ params.text }}</p>{% endif %}
17-
{% if params.imageURL %}<span class="nhsuk-hero__arrow" aria-hidden="true"></span>{% endif %}
17+
{%- if params.heading -%}
18+
<h{{ headingLevel }} class="nhsuk-hero__heading
19+
{%- if params.headingClasses %} {{ params.headingClasses }}{% endif %}
20+
{%- if not (caller or params.text or params.html) %} nhsuk-u-margin-bottom-0{% endif %}">
21+
{{- params.heading -}}
22+
</h{{ headingLevel }}>
23+
{%- endif %}
24+
{% if caller or params.html -%}
25+
{{ caller() if caller else params.html | safe }}
26+
{%- elif params.text -%}
27+
<p class="nhsuk-body-l nhsuk-u-margin-bottom-0">{{ params.text }}</p>
28+
{%- endif %}
29+
{% if params.imageURL -%}
30+
<span class="nhsuk-hero__arrow" aria-hidden="true"></span>
31+
{%- endif %}
1832
</div>
1933
</div>
2034
</div>

tasks/docs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async function buildHTML() {
3232
const { name, dir } = parse(path)
3333

3434
const html = env.render(path, {
35+
assetPath: `/nhsuk-frontend/assets`,
3536
baseUrl: '/nhsuk-frontend/',
3637
version
3738
})
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)