Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new "grey" hero variant #3450

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f4b1347
add inital changes
precious-onyenaucheya-ons Nov 27, 2024
349573c
approve vr tests
precious-onyenaucheya-ons Nov 27, 2024
52c7272
Merge branch 'main' into feature/189/add-horizontal-description-list
precious-onyenaucheya-ons Nov 27, 2024
22c7b5f
update as per PR comments
precious-onyenaucheya-ons Nov 28, 2024
79f772b
delete test example
precious-onyenaucheya-ons Nov 28, 2024
3555877
fix failing test
precious-onyenaucheya-ons Nov 28, 2024
2d3c0d0
Merge branch 'main' into feature/189/add-horizontal-description-list
precious-onyenaucheya-ons Nov 28, 2024
6b953a8
address div issue
precious-onyenaucheya-ons Nov 29, 2024
c62a87d
approve visual tests
precious-onyenaucheya-ons Nov 29, 2024
5dd8f0e
update breakpoints
precious-onyenaucheya-ons Nov 29, 2024
56775f8
update css
precious-onyenaucheya-ons Nov 29, 2024
0470ee4
fix typo
precious-onyenaucheya-ons Dec 2, 2024
f08e1b6
add initial changes
precious-onyenaucheya-ons Nov 27, 2024
6cec1f9
add icon
precious-onyenaucheya-ons Nov 27, 2024
321221d
update example
precious-onyenaucheya-ons Nov 28, 2024
2040158
update variant
precious-onyenaucheya-ons Nov 29, 2024
db6f29d
update
precious-onyenaucheya-ons Nov 29, 2024
224586e
Merge branch 'main' into feature/189/add-horizontal-description-list
precious-onyenaucheya-ons Dec 2, 2024
83e02d7
add test
precious-onyenaucheya-ons Dec 3, 2024
4fbc009
refactor to fit inline variant with figma design
precious-onyenaucheya-ons Dec 4, 2024
2f21710
approve visual test
precious-onyenaucheya-ons Dec 4, 2024
4ce8321
Merge branch 'main' into feature/189/add-horizontal-description-list
precious-onyenaucheya-ons Dec 4, 2024
f6ab261
fix accessibility issues
precious-onyenaucheya-ons Dec 4, 2024
724349b
fix grid issues
precious-onyenaucheya-ons Dec 5, 2024
0680abb
approve visual test
precious-onyenaucheya-ons Dec 5, 2024
7bc83cd
Merge remote-tracking branch 'origin' into feature/165/analysis-hero
precious-onyenaucheya-ons Dec 5, 2024
eca78b6
Merge branch 'feature/189/add-horizontal-description-list' into featu…
precious-onyenaucheya-ons Dec 5, 2024
1140c34
add minor changes and fix failing test
precious-onyenaucheya-ons Dec 5, 2024
11e71bb
Update src/components/description-list/_description-list.scss
precious-onyenaucheya-ons Dec 5, 2024
5938ce0
Update src/components/description-list/_macro.njk
precious-onyenaucheya-ons Dec 5, 2024
a42b1ce
Update src/components/description-list/_description-list.scss
precious-onyenaucheya-ons Dec 5, 2024
27bd708
revert changes
precious-onyenaucheya-ons Dec 5, 2024
b23bbf1
update column width
precious-onyenaucheya-ons Dec 6, 2024
035b326
update styling
precious-onyenaucheya-ons Dec 6, 2024
ff0de57
remove margin from item
precious-onyenaucheya-ons Dec 6, 2024
a5ba67b
Merge branch 'feature/189/add-horizontal-description-list' into featu…
precious-onyenaucheya-ons Dec 6, 2024
4d43469
Merge branch 'main' into feature/165/analysis-hero
precious-onyenaucheya-ons Dec 9, 2024
d9b3d83
update
precious-onyenaucheya-ons Dec 16, 2024
ba37ef9
revert changes
precious-onyenaucheya-ons Dec 16, 2024
65d5a14
update css and test
precious-onyenaucheya-ons Dec 16, 2024
094b8c9
fix failing test
precious-onyenaucheya-ons Dec 16, 2024
8031227
Merge branch 'main' into feature/165/analysis-hero
SriHV Dec 17, 2024
407d259
Merge branch 'main' into feature/165/analysis-hero
precious-onyenaucheya-ons Dec 18, 2024
12506cb
update as per PR comments
precious-onyenaucheya-ons Dec 19, 2024
32b2240
fix failing test
precious-onyenaucheya-ons Dec 19, 2024
eca6592
update reference
precious-onyenaucheya-ons Dec 19, 2024
a782f5c
update docs
precious-onyenaucheya-ons Dec 19, 2024
f174579
update style and approve test
precious-onyenaucheya-ons Dec 19, 2024
fc29acb
remove magin bottom from topic
precious-onyenaucheya-ons Dec 20, 2024
fa3e2b8
changes as per comments
SriHV Jan 6, 2025
4449d1b
changed grey color name
SriHV Jan 6, 2025
ba0682c
changed badge to officialStatisticsBadge in macro file
SriHV Jan 6, 2025
69e3aeb
fixed macro tests
SriHV Jan 6, 2025
d313493
fixed visual tests
SriHV Jan 6, 2025
c134d76
changes as per comments
SriHV Jan 9, 2025
1d2098e
Merge branch 'main' into feature/165/analysis-hero
SriHV Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may have a slight issue with the description list. One of the requirements is:

description list component added horizontally and it can include text or hyperlinks - https://jira.ons.gov.uk/browse/ONSDESYS-189

I don't think we can currently have links in here.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth checking the margin below the topic. It looks like the gap is smaller in the design
image

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 47 additions & 4 deletions src/components/hero/_hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@
}
}

&--grey {
background-color: var(--ons-color-grey-10);
&::before {
content: '';
background-color: var(--ons-color-banner-bg);
border-radius: 0 0 50% 50%;
inset: 0;
left: -40%;
position: absolute;
width: 150%;
@include mq(l) {
border-radius: 0 0 300% 150%;
left: 0;
width: 100%;
}
}
}
&__badge {
@include mq(xs, l) {
margin-top: 2.5rem;
margin-bottom: 1rem;
}
}

&--topic {
color: var(--ons-color-branded);
@extend .ons-u-mb-no;
}

&__container {
align-items: center;
display: flex;
Expand All @@ -43,10 +72,6 @@
height: 100%;
}

&__text:has(+ .ons-btn) {
margin-bottom: 2rem;
}
rmccar marked this conversation as resolved.
Show resolved Hide resolved

&__pre-title {
margin-bottom: 0.5rem;

Expand All @@ -62,6 +87,12 @@
z-index: 5;
}

&--grey & {
&__details {
padding-top: 1rem;
}
}
Comment on lines +90 to +94
Copy link
Contributor

@rmccar rmccar Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed when breadcrumbs are used not when we use the grey variant


&--dark & {
&__details {
color: var(--ons-color-text-inverse) !important;
Expand Down Expand Up @@ -299,4 +330,16 @@
}
}
}

&__title-container {
@include mq(l) {
display: grid;
align-items: start;
justify-content: space-between;

&.ons-hero__title-badge {
grid-template-columns: 1fr auto;
}
}
}
}
24 changes: 14 additions & 10 deletions src/components/hero/_macro-options.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
| Name | Type | Required | Description |
| -------------- | ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------- |
| variants | array or string | false | An array of values or single value (string) to adjust the component using available variants, “dark” and "navy-blue" |
| wide | boolean | false | Set to “true” when using the `wide` page layout container |
| title | string | true | Text for the hero title |
| subtitle | string | false | Text for the hero subtitle |
| text | string | false | Text to follow the hero title and subtitle |
| button | `Object<Button>` | false | Settings for the hero [call to action button](#button) |
| html | string | false | Allows arbitrary HTML for additional content to be added to the component |
| detailsColumns | integer | false | Number of grid columns for the hero to span on screens larger than the medium breakpoint, defaults to 8 |
| Name | Type | Required | Description |
| ----------------------- | --------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------- |
| variants | array or string | false | An array of values or single value (string) to adjust the component using available variant, “dark, navy-blue and grey” |
| wide | boolean | false | Set to “true” when using the `wide` page layout container |
| title | string | true | Text for the hero title |
| subtitle | string | false | Text for the hero subtitle |
| text | string | false | Text to follow the hero title and subtitle |
| button | `Object<Button>` | false | Settings for the hero [call to action button](#button) |
| html | string | false | Allows arbitrary HTML for additional content to be added to the component |
| detailsColumns | integer | false | Number of grid columns for the hero to span on screens larger than the medium breakpoint, defaults to 8 |
| descriptionList | `DescriptionList` [_(ref)_](/components/description-list) | false | Settings to set the DescriptionList component within the HTML `<hero>` element |
| officialStatisticsBadge | boolean | false | Set to “true” display the official statistics badge in the hero |
| topic | string | false | Topic for the hero |
| breadcrumbs | `Breadcrumbs` [_(ref)_](/components/breadcrumbs) | false | Settings to set the Breadcrumbs component within the HTML `<hero>` element |

## Button

Expand Down
59 changes: 49 additions & 10 deletions src/components/hero/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,41 @@
{% endif %}
<div class="ons-hero__container ons-container{{ ' ons-container--wide' if params.wide }}">
<div class="ons-hero__details ons-grid__col ons-col-{{ detailsColumns }}@m ons-col-10@s@m">
<header>
<h1 class="ons-hero__title ons-u-fs-3xl">{{ params.title }}</h1>
{% if params.subtitle %}
<h2 class="ons-hero__subtitle ons-u-fs-r--b">{{ params.subtitle }}</h2>
{% endif %}
</header>

{% if params.text %}
<p class="ons-hero__text">{{ params.text | safe }}</p>
{% if params.breadcrumbs %}
{% from "components/breadcrumbs/_macro.njk" import onsBreadcrumbs %}
{{
onsBreadcrumbs({
"itemsList": params.breadcrumbs.itemsList,
"ariaLabel": params.breadcrumbs.ariaLabel,
"id": params.breadcrumbs.id,
"classes": 'ons-u-pt-no ' ~ params.breadcrumbs.classes
})
}}
{% endif %}
{% if params.topic %}
<h2 class="ons-hero--topic">{{ params.topic | safe }}</h2>
rmccar marked this conversation as resolved.
Show resolved Hide resolved
admilne marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}
<div class="ons-hero__title-container {% if params.officialStatisticsBadge %}ons-hero__title-badge{% endif %}">
<header>
<h1 class="ons-hero__title ons-u-fs-3xl">{{ params.title }}</h1>
{% if params.subtitle %}
<h2 class="ons-hero__subtitle ons-u-fs-r--b">{{ params.subtitle }}</h2>
{% endif %}
</header>
{% if params.officialStatisticsBadge == true %}
{% from "components/icon/_macro.njk" import onsIcon %}
<div class="ons-hero__badge">
{{-
onsIcon({
"iconType": 'official-statistics'
})
-}}
</div>
{% endif %}
{% if params.text %}
<p class="ons-hero__text">{{ params.text | safe }}</p>
{% endif %}
</div>

{% if params.button %}
{% from "components/button/_macro.njk" import onsButton %}
Expand All @@ -34,7 +59,7 @@
{% endif %}
{{
onsButton({
"classes": btnClasses,
"classes": 'ons-u-mt-s' + btnClasses,
"type": 'button',
"text": params.button.text,
"url": params.button.url
Expand All @@ -44,7 +69,21 @@
{% if caller %}
<div class="ons-hero__additional-content">{{- caller() -}}</div>
{% endif %}

{% if params.descriptionList %}
{% from "components/description-list/_macro.njk" import onsDescriptionList %}
{{
onsDescriptionList({
"classes": "ons-u-mb-no",
"variant": 'inline',
"termCol": params.descriptionList.termCol,
"descriptionCol": params.descriptionList.descriptionCol,
"itemsList": params.descriptionList.itemsList
})
}}
{% endif %}
</div>

{% if params.html %}
<div class="ons-hero__additional-html">{{- params.html | safe -}}</div>
{% endif %}
Expand Down
85 changes: 84 additions & 1 deletion src/components/hero/_macro.spec.js
rmccar marked this conversation as resolved.
Show resolved Hide resolved
admilne marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('macro: hero', () => {

faker.renderComponent('hero', { ...EXAMPLE_HERO, variants: 'dark' });

expect(buttonSpy.occurrences[0]).toHaveProperty('classes', ' ons-btn--ghost');
expect(buttonSpy.occurrences[0]).toHaveProperty('classes', 'ons-u-mt-s ons-btn--ghost');
});

it('calls with content', () => {
Expand All @@ -92,4 +92,87 @@ describe('macro: hero', () => {
const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, variants: 'navy-blue' }));
expect($('.ons-hero--navy-blue .ons-hero__circles').length).toBe(1);
});

it('outputs the correct topic when set', () => {
const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, topic: 'Topic Text' }));

const content = $('.ons-hero--topic').text().trim();
expect(content).toBe('Topic Text');
});

it('outputs the official statistics badge when officialStatisticsBadge is set to true', () => {
const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, officialStatisticsBadge: true }));

expect($('.ons-hero__badge').length).toBe(1);
expect($('.ons-hero__badge svg title').text().trim()).toBe('Offical Statistics Badge');
});

it('renders curved gradient when variant is `grey`', () => {
const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, variants: 'grey' }));
expect($('.ons-hero--grey').length).toBe(1);
});

it('outputs the correct breadcrumbs', () => {
const $ = cheerio.load(
renderComponent('hero', {
...EXAMPLE_HERO,
variants: 'grey',
breadcrumbs: {
ariaLabel: 'Breadcrumbs',
itemsList: [
{
url: '/breadcrumb-1',
text: 'Breadcrumbs 1',
},
{
url: '/breadcrumb-2',
text: 'Breadcrumbs 2',
},
],
},
}),
);

const breadcrumbs = $('.ons-breadcrumbs__link');
expect($(breadcrumbs).length).toBe(2);
expect($(breadcrumbs[0]).attr('href')).toBe('/breadcrumb-1');
expect($(breadcrumbs[0]).text().trim()).toBe('Breadcrumbs 1');
expect($(breadcrumbs[1]).attr('href')).toBe('/breadcrumb-2');
expect($(breadcrumbs[1]).text().trim()).toBe('Breadcrumbs 2');
});

it('outputs the correct description list value', () => {
const $ = cheerio.load(
renderComponent('hero', {
...EXAMPLE_HERO,
variants: 'grey',
descriptionList: {
termCol: '4',
descriptionCol: '8',
itemsList: [
{
term: 'term1:',
descriptions: [
{
description: 'description1',
},
],
},
{
term: 'term2:',
descriptions: [
{
description: 'description2',
},
],
},
],
},
}),
);

const descriptionText = $('.ons-description-list__value');
expect($(descriptionText[0]).text().trim()).toBe('description1');
expect($(descriptionText[1]).text().trim()).toBe('description2');
});
});
78 changes: 78 additions & 0 deletions src/components/hero/example-hero-grey.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
'fullWidth': true
---

{% from "components/hero/_macro.njk" import onsHero %}
{{
onsHero({
"variants": 'grey',
"detailsColumns": '12',
"officialStatisticsBadge": true,
"topic": 'Statistical article',
"title": 'Retail sales rise amid summer discounts and sporting events, according to a first estimate',
"text": 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id mattis ligula, nec sollicitudin arcu. Donec non tristique tellus. Donec eget malesuada lorem.',
"breadcrumbs": {
"ariaLabel": 'Breadcrumbs',
"itemsList": [
{
"url": '/',
"text": 'Home'
},
{
"url": '/',
"text": 'Business, industry and trade'
},
{
"url": '/',
"text": 'Retail industry'
}
]
},
"descriptionList": {
"termCol": "5",
"descriptionCol": "7",
"itemsList": [
{
"term": "Release date:",
"descriptions": [
{
"description": "16 August 2024"
}
]
},
{
"term": "Edition:",
"descriptions": [
{
"description": "Latest"
}
]
},
{
"term": "Contact:",
"descriptions": [
{
"description": "Retail Sales team"
}
]
},
{
"term": "Next release:",
"descriptions": [
{
"description": "20 September 2024"
}
]
},
{
"term": "Releases:",
"descriptions": [
{
"description": "View previous releases"
}
]
}
]
}
})
}}
Loading
Loading