@ons/design-system 72.10.3 → 72.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/components/card/_card.scss +1 -0
  2. package/components/card/example-card-set-with-headline-figures.njk +4 -4
  3. package/components/chart/_macro.njk +34 -34
  4. package/components/chart/_macro.spec.js +0 -49
  5. package/components/chart/chart.js +18 -8
  6. package/components/chart/columnrange-chart.js +3 -0
  7. package/components/chart/common-chart-options.js +1 -13
  8. package/components/chart/example-bar-with-confidence-levels.njk +0 -5
  9. package/components/chart/example-column-with-confidence-levels.njk +1 -4
  10. package/components/chart/example-scatter-chart.njk +4 -8
  11. package/components/chart/specific-chart-options.js +32 -9
  12. package/components/description-list/_description-list.scss +7 -6
  13. package/components/description-list/_macro.njk +1 -1
  14. package/components/details-panel/_details-panel.scss +40 -20
  15. package/components/details-panel/_macro.njk +18 -12
  16. package/components/details-panel/example-details-panel.njk +1 -0
  17. package/components/featured-article/_macro.njk +76 -0
  18. package/components/featured-article/example-featured-article-with-chart.njk +223 -0
  19. package/components/featured-article/example-featured-article-with-image.njk +24 -0
  20. package/components/featured-article/featured-article.scss +33 -0
  21. package/components/featured-article/macro.spec.js +173 -0
  22. package/components/header/_header.scss +34 -1
  23. package/components/header/_macro.njk +140 -132
  24. package/components/hero/_hero.scss +5 -0
  25. package/components/hero/_macro.njk +8 -4
  26. package/components/hero/example-hero-grey.njk +2 -17
  27. package/css/main.css +1 -1
  28. package/css/print.css +1 -1
  29. package/js/details.js +39 -0
  30. package/js/main.js +1 -0
  31. package/package.json +1 -1
  32. package/scripts/main.es5.js +1 -1
  33. package/scripts/main.js +1 -1
  34. package/scss/main.scss +1 -0
  35. package/scss/print.scss +6 -1
  36. package/scss/utilities/_grid.scss +46 -0
@@ -1,6 +1,9 @@
1
1
  {% macro onsDetailsPanel(params) %}
2
- <div class="ons-details-panel ons-js-details" {% if params.open %}{{ ' ' }}data-open="true"{% endif %}>
3
- <div class="ons-details-panel__banner ons-u-pt-s ons-u-pb-s">
2
+ {% set openText = params.openText | default("Show detail") %}
3
+ {% set closeText = params.closeText | default("Hide detail") %}
4
+
5
+ <details class="ons-details-panel" {% if params.open %}{{ ' ' }}data-open{% endif %}>
6
+ <summary class="ons-details-panel__banner ons-u-pt-s ons-u-pb-s">
4
7
  <div class="ons-container ons-details-panel__banner-contents">
5
8
  <span class="ons-details-panel__info-icon ons-u-mr-2xs" aria-hidden="true">i</span>
6
9
  <div class="ons-details-panel__banner-body">
@@ -9,10 +12,11 @@
9
12
  {% set closingTag = "</h" ~ titleTag ~ ">" %}
10
13
  {{ openingTag | safe }}
11
14
  class="ons-details-panel__banner-title ons-u-fs-m ons-u-mb-2xs">{{ params.title }}{{ closingTag | safe }}
12
- <div class="ons-details-panel__banner-detail ons-js-details-heading">
13
- <span class="ons-details-panel__banner-detail-title ons-js-corrections-details-title ons-u-mr-3xs"
14
- >Show detail</span
15
- >
15
+ <div class="ons-details-panel__banner-detail">
16
+ <span class="ons-details-panel__banner-detail-title ons-u-mr-3xs">
17
+ <span class="ons-details-panel__banner-detail-title--open"> {{ openText }} </span>
18
+ <span class="ons-details-panel__banner-detail-title--close"> {{ closeText }} </span>
19
+ </span>
16
20
  <span class="ons-details-panel__banner-detail-icon">
17
21
  {% from "components/icon/_macro.njk" import onsIcon %}
18
22
  {{
@@ -24,22 +28,24 @@
24
28
  </div>
25
29
  </div>
26
30
  </div>
27
- </div>
28
- <div class="ons-container ons-details-panel__content ons-js-details-content ons-u-pt-xl ons-u-pb-3xl">
31
+ </summary>
32
+ <div class="ons-container ons-details-panel__content ons-u-pt-xl ons-u-pb-3xl">
29
33
  {% for item in params.detailsItems %}
30
- <div class="ons-details-panel__item">
34
+ <div class="ons-details-panel__item ons-u-pb-xl ons-u-mb-l ons-u-ml-2xs">
31
35
  <div class="ons-details-panel__content-meta ons-u-mb-l@2xs@m">
32
- <h3 class="ons-details-panel__content-heading">{{ item.text }}</h3>
36
+ <h3 class="ons-details-panel__content-heading ons-u-fs-r--b ons-u-mb-no">{{ item.text }}</h3>
33
37
  <time class="ons-details-panel__content-date" datetime="{{ item.date.iso }}">{{ item.date.short }}</time>
34
38
  </div>
35
39
  <div class="ons-details-panel__content-description">
36
40
  <div class="ons-details-panel__content-text ons-u-mb-s">{{ item.description | safe }}</div>
37
41
  {% if item.url or item.text == 'Content' %}
38
- <a class="ons-details-panel__content-url" href="{{ item.url }}"> View superseded version</a>
42
+ <a class="ons-details-panel__content-url" href="{{ item.url }}">
43
+ {{ item.urlText | default("View superseded version") }}
44
+ </a>
39
45
  {% endif %}
40
46
  </div>
41
47
  </div>
42
48
  {% endfor %}
43
49
  </div>
44
- </div>
50
+ </details>
45
51
  {% endmacro %}
@@ -3,6 +3,7 @@
3
3
  {{
4
4
  onsDetailsPanel({
5
5
  "title": "Correction and Notice",
6
+ "headingLevel": 3,
6
7
  "detailsItems": [
7
8
  {
8
9
  "text": 'Correction',
@@ -0,0 +1,76 @@
1
+ {% from "components/chart/_macro.njk" import onsChart %}
2
+ {% from "components/image/_macro.njk" import onsImage %}
3
+
4
+ {% macro onsFeaturedArticle(params) %}
5
+ {% set headingLevel = params.headingLevel | default(2) %}
6
+ {% set openingArticleTitleTag = "<h" ~ headingLevel %}
7
+ {% set closingArticleTitleTag = "</h" ~ headingLevel ~ ">" %}
8
+
9
+ <div class="ons-featured">
10
+ {{ openingArticleTitleTag | safe }} class="ons-featured__title ons-u-fs-m ons-u-mt-no ons-u-mb-2xs">
11
+ <a href="{{ params.title.url }}">{{ params.title.text }}</a>
12
+ {{ closingArticleTitleTag | safe }}
13
+
14
+ {%- if params.metadata -%}
15
+ {% set metadata = params.metadata %}
16
+ <ul class="ons-featured__item-metadata">
17
+ {%- if metadata.date -%}
18
+ <li class="ons-featured__item-attribute">
19
+ {% set prefixClass = "ons-u-fw-b" if metadata.date.showPrefix == true else "ons-u-vh" %}
20
+ <span class="{{ prefixClass }}">{{ metadata.date.prefix | default("Published") }}: </span>
21
+ {%- if metadata.date.iso -%}
22
+ <time datetime="{{ metadata.date.iso }}">{{ metadata.date.short }}</time>
23
+ {%- endif -%}
24
+ </li>
25
+ {% endif %}
26
+
27
+ {%- if metadata.text -%}
28
+ <li class="ons-featured__item-attribute">
29
+ <span {% if metadata.text %}class="ons-featured__attribute-text ons-u-fw-b"{% endif %}>{{ metadata.text }}</span>
30
+ </li>
31
+ {% endif %}
32
+ </ul>
33
+ {% endif %}
34
+
35
+ <div class="ons-featured__media">
36
+ {% if params.chart %}
37
+ {{
38
+ onsChart({
39
+ "chartType": params.chart.chartType,
40
+ "description": params.chart.description,
41
+ "theme": params.chart.theme,
42
+ "title": params.chart.title,
43
+ "id": params.chart.id,
44
+ "headingLevel": headingLevel + 1,
45
+ "legend": params.chart.legend,
46
+ "xAxis": params.chart.xAxis,
47
+ "yAxis": params.chart.yAxis,
48
+ "series": params.chart.series,
49
+ "annotations": params.chart.annotations,
50
+ "rangeAnnotations": params.chart.rangeAnnotations,
51
+ "referenceLineAnnotations": params.chart.referenceLineAnnotations,
52
+ "estimateLineLabel": params.chart.estimateLineLabel,
53
+ "uncertaintyRangeLabel": params.chart.uncertaintyRangeLabel,
54
+ "isChartInverted": params.chart.isChartInverted,
55
+ "useStackedLayout": params.chart.useStackedLayout,
56
+ "percentageHeightDesktop": params.chart.percentageHeightDesktop,
57
+ "percentageHeightMobile": params.chart.percentageHeightMobile
58
+ })
59
+ }}
60
+ {% elif params.image %}
61
+ <div class="ons-featured__image">
62
+ {{
63
+ onsImage({
64
+ "src": params.image.src,
65
+ "alt": params.image.alt
66
+ })
67
+ }}
68
+ </div>
69
+ {% endif %}
70
+ </div>
71
+
72
+ {% if params.description %}
73
+ <div class="ons-featured__description">{{ params.description | safe }}</div>
74
+ {% endif %}
75
+ </div>
76
+ {% endmacro %}
@@ -0,0 +1,223 @@
1
+ {% from "components/featured-article/_macro.njk" import onsFeaturedArticle %}
2
+ {{
3
+ onsFeaturedArticle({
4
+ "title": {
5
+ "text": 'Retail sales, Great Britain: July 2024',
6
+ "url": '#0'
7
+ },
8
+ "metadata": {
9
+ "text": 'Dataset',
10
+ "date": {
11
+ "prefix": 'Released',
12
+ "showPrefix": true,
13
+ "iso": '2021-02-18',
14
+ "short": '18 February 2021'
15
+ }
16
+ },
17
+ "headingLevel": 3,
18
+ "chart": {
19
+ "chartType": "line",
20
+ "description": "Line chart showing the annual rate of inflation for the Consumer Prices Index including owner occupiers’ housing costs (CPIH) and its components.",
21
+ "theme": "alternate",
22
+ "title": "Sales volumes and values saw moderate growth in July 2024",
23
+ "subtitle": "Figure 6: Upward contribution from housing and household services (including energy) saw the annual CPIH inflation rate rise",
24
+ "id": "id",
25
+ "headingLevel": 4,
26
+ "legend": true,
27
+ "xAxis": {
28
+ "title": "Year",
29
+ "type": "linear",
30
+ "categories": [
31
+ 'Oct 2014',
32
+ 'Nov 2014',
33
+ 'Dec 2014',
34
+ 'Jan 2015',
35
+ 'Feb 2015',
36
+ 'Mar 2015',
37
+ 'Apr 2015',
38
+ 'May 2015',
39
+ 'Jun 2015',
40
+ 'Jul 2015',
41
+ 'Aug 2015',
42
+ 'Sep 2015',
43
+ 'Oct 2015',
44
+ 'Nov 2015',
45
+ 'Dec 2015',
46
+ 'Jan 2016',
47
+ 'Feb 2016',
48
+ 'Mar 2016',
49
+ 'Apr 2016',
50
+ 'May 2016',
51
+ 'Jun 2016',
52
+ 'Jul 2016',
53
+ 'Aug 2016',
54
+ 'Sep 2016',
55
+ 'Oct 2016',
56
+ 'Nov 2016',
57
+ 'Dec 2016',
58
+ 'Jan 2017',
59
+ 'Feb 2017',
60
+ 'Mar 2017',
61
+ 'Apr 2017',
62
+ 'May 2017',
63
+ 'Jun 2017',
64
+ 'Jul 2017',
65
+ 'Aug 2017',
66
+ 'Sep 2017',
67
+ 'Oct 2017',
68
+ 'Nov 2017',
69
+ 'Dec 2017',
70
+ 'Jan 2018',
71
+ 'Feb 2018',
72
+ 'Mar 2018',
73
+ 'Apr 2018',
74
+ 'May 2018',
75
+ 'Jun 2018',
76
+ 'Jul 2018',
77
+ 'Aug 2018',
78
+ 'Sep 2018',
79
+ 'Oct 2018',
80
+ 'Nov 2018',
81
+ 'Dec 2018',
82
+ 'Jan 2019',
83
+ 'Feb 2019',
84
+ 'Mar 2019',
85
+ 'Apr 2019',
86
+ 'May 2019',
87
+ 'Jun 2019',
88
+ 'Jul 2019',
89
+ 'Aug 2019',
90
+ 'Sep 2019',
91
+ 'Oct 2019',
92
+ 'Nov 2019',
93
+ 'Dec 2019',
94
+ 'Jan 2020',
95
+ 'Feb 2020',
96
+ 'Mar 2020',
97
+ 'Apr 2020',
98
+ 'May 2020',
99
+ 'Jun 2020',
100
+ 'Jul 2020',
101
+ 'Aug 2020',
102
+ 'Sep 2020',
103
+ 'Oct 2020',
104
+ 'Nov 2020',
105
+ 'Dec 2020',
106
+ 'Jan 2021',
107
+ 'Feb 2021',
108
+ 'Mar 2021',
109
+ 'Apr 2021',
110
+ 'May 2021',
111
+ 'Jun 2021',
112
+ 'Jul 2021',
113
+ 'Aug 2021',
114
+ 'Sep 2021',
115
+ 'Oct 2021',
116
+ 'Nov 2021',
117
+ 'Dec 2021',
118
+ 'Jan 2022',
119
+ 'Feb 2022',
120
+ 'Mar 2022',
121
+ 'Apr 2022',
122
+ 'May 2022',
123
+ 'Jun 2022',
124
+ 'Jul 2022',
125
+ 'Aug 2022',
126
+ 'Sep 2022',
127
+ 'Oct 2022',
128
+ 'Nov 2022',
129
+ 'Dec 2022',
130
+ 'Jan 2023',
131
+ 'Feb 2023',
132
+ 'Mar 2023',
133
+ 'Apr 2023',
134
+ 'May 2023',
135
+ 'Jun 2023',
136
+ 'Jul 2023',
137
+ 'Aug 2023',
138
+ 'Sep 2023',
139
+ 'Oct 2023',
140
+ 'Nov 2023',
141
+ 'Dec 2023',
142
+ 'Jan 2024',
143
+ 'Feb 2024',
144
+ 'Mar 2024',
145
+ 'Apr 2024',
146
+ 'May 2024',
147
+ 'Jun 2024',
148
+ 'Jul 2024',
149
+ 'Aug 2024',
150
+ 'Sep 2024',
151
+ 'Oct 2024'
152
+ ],
153
+ "tickIntervalDesktop": 15,
154
+ "tickIntervalMobile": 30
155
+ },
156
+ "yAxis": {
157
+ "title": "Sales"
158
+ },
159
+ "series": [
160
+ {
161
+ "name": 'CPIH',
162
+ "data": [
163
+ 1.3, 1.1, 0.7, 0.5, 0.4, 0.3, 0.3, 0.4, 0.3, 0.5, 0.4, 0.2, 0.2, 0.4, 0.5, 0.6,
164
+ 0.6, 0.8, 0.7, 0.7, 0.8, 0.9, 1.0, 1.3, 1.3, 1.5, 1.8, 1.9, 2.3, 2.3, 2.6, 2.7,
165
+ 2.6, 2.6, 2.7, 2.8, 2.8, 2.8, 2.7, 2.7, 2.5, 2.3, 2.2, 2.3, 2.3, 2.3, 2.4, 2.2,
166
+ 2.2, 2.2, 2.0, 1.8, 1.8, 1.8, 2.0, 1.9, 1.9, 2.0, 1.7, 1.7, 1.5, 1.5, 1.4, 1.8,
167
+ 1.7, 1.5, 0.9, 0.7, 0.8, 1.1, 0.5, 0.7, 0.9, 0.6, 0.8, 0.9, 0.7, 1.0, 1.6, 2.1,
168
+ 2.4, 2.1, 3.0, 2.9, 3.8, 4.6, 4.8, 4.9, 5.5, 6.2, 7.8, 7.9, 8.2, 8.8, 8.6, 8.8,
169
+ 9.6, 9.3, 9.2, 8.8, 9.2, 8.9, 7.8, 7.9, 7.3, 6.4, 6.3, 6.3, 4.7, 4.2, 4.2, 4.2,
170
+ 3.8, 3.8, 3.0, 2.8, 2.8, 3.1, 3.1, 2.6, 3.2
171
+ ]
172
+ },
173
+ {
174
+ "name": 'Goods',
175
+ "data": [
176
+ 0.3, -0.2, -1.0, -1.5, -2.0, -2.1, -1.9, -1.8, -2.0, -1.8, -2.0, -2.4, -2.1,
177
+ -1.9, -2.1, -1.5, -1.6, -1.7, -1.6, -1.8, -1.7, -1.5, -1.4, -0.5, -0.4, 0.2,
178
+ 0.7, 1.1, 1.9, 2.5, 2.4, 3.0, 2.6, 2.7, 3.1, 3.2, 3.3, 3.3, 3.4, 3.2, 3.0, 2.4,
179
+ 2.6, 2.5, 2.5, 2.6, 2.7, 2.5, 2.3, 2.1, 1.8, 1.2, 1.3, 1.3, 1.4, 1.5, 1.5, 1.7,
180
+ 1.2, 0.9, 0.4, 0.5, 0.6, 1.3, 1.0, 0.6, -0.4, -0.9, -0.5, 0.0, -0.2, -0.3, 0.1,
181
+ -0.7, -0.2, -0.2, -0.5, 0.1, 1.6, 2.3, 2.9, 2.5, 3.3, 3.5, 4.9, 6.5, 6.9, 7.2,
182
+ 8.3, 9.4, 12.4, 12.4, 12.7, 13.6, 13.0, 13.2, 14.8, 14.1, 13.4, 13.3, 13.4,
183
+ 12.7, 10.0, 9.7, 8.5, 6.1, 6.3, 6.2, 2.9, 2.0, 1.9, 1.8, 1.1, 0.9, -0.8, -1.3,
184
+ -1.4, -0.5, -0.9, -1.4, -0.3
185
+ ]
186
+ },
187
+ {
188
+ "name": 'Services',
189
+ "data": [
190
+ 2.2, 2.1, 2.1, 2.1, 2.2, 2.2, 2.0, 2.1, 2.1, 2.2, 2.2, 2.2, 2.1, 2.2, 2.5, 2.2,
191
+ 2.3, 2.6, 2.4, 2.6, 2.7, 2.6, 2.7, 2.6, 2.5, 2.4, 2.5, 2.5, 2.6, 2.2, 2.8, 2.6,
192
+ 2.5, 2.4, 2.5, 2.5, 2.4, 2.4, 2.2, 2.3, 2.1, 2.1, 1.9, 2.1, 2.0, 2.0, 2.2, 2.0,
193
+ 2.1, 2.2, 2.1, 2.2, 2.2, 2.2, 2.5, 2.3, 2.2, 2.2, 2.0, 2.2, 2.2, 2.2, 1.9, 2.1,
194
+ 2.2, 2.2, 1.9, 1.8, 1.7, 2.0, 1.0, 1.5, 1.5, 1.5, 1.6, 1.7, 1.6, 1.6, 1.7, 1.9,
195
+ 2.1, 1.8, 2.7, 2.5, 2.9, 3.0, 3.1, 3.1, 3.2, 3.7, 4.1, 4.3, 4.5, 4.9, 5.1, 5.3,
196
+ 5.3, 5.4, 5.8, 5.2, 5.6, 5.7, 6.0, 6.3, 6.3, 6.5, 6.1, 6.3, 6.2, 6.0, 6.0, 6.1,
197
+ 6.0, 6.0, 6.0, 5.9, 6.0, 5.7, 5.9, 5.6, 5.6
198
+ ]
199
+ },
200
+ {
201
+ "name": 'CPIH excl energy, food, alcohol & tobacco',
202
+ "data": [
203
+ 1.5, 1.3, 1.4, 1.5, 1.4, 1.2, 1.1, 1.2, 1.0, 1.3, 1.2, 1.2, 1.3, 1.4, 1.5, 1.4,
204
+ 1.4, 1.6, 1.5, 1.5, 1.6, 1.6, 1.5, 1.7, 1.6, 1.7, 1.8, 1.8, 2.1, 1.9, 2.4, 2.5,
205
+ 2.4, 2.4, 2.6, 2.5, 2.5, 2.5, 2.3, 2.4, 2.2, 2.1, 2.0, 2.0, 1.8, 1.8, 1.9, 1.8,
206
+ 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.7, 1.7, 1.7, 1.9, 1.5, 1.6, 1.7, 1.7, 1.4, 1.6,
207
+ 1.7, 1.6, 1.5, 1.3, 1.5, 1.8, 1.0, 1.4, 1.5, 1.2, 1.5, 1.5, 1.1, 1.3, 1.5, 2.0,
208
+ 2.3, 1.9, 2.9, 2.7, 3.1, 3.6, 3.8, 4.0, 4.6, 5.1, 5.4, 5.2, 5.2, 5.5, 5.6, 5.8,
209
+ 5.8, 5.7, 5.8, 5.3, 5.7, 5.7, 6.2, 6.5, 6.4, 6.4, 5.9, 5.9, 5.6, 5.2, 5.2, 5.1,
210
+ 4.8, 4.7, 4.4, 4.2, 4.2, 4.1, 4.3, 4.0, 4.1
211
+ ]
212
+ }
213
+ ],
214
+ "percentageHeightDesktop": 35,
215
+ "percentageHeightMobile": 90
216
+ },
217
+ "description": "<ul>
218
+ <li>Retail sales volumes increased by 0.4% in July 2024, following a 0.2% increase in June 2024.</li>
219
+ <li>Retail sales values increased by 0.5% in July 2024, following a 0.3% increase in June 2024.</li>
220
+ <li>The annual rate of inflation for the Consumer Prices Index including owner occupiers’ housing costs (CPIH) was 2.8% in July 2024, up from 2.6% in June 2024.</li>
221
+ </ul>"
222
+ })
223
+ }}
@@ -0,0 +1,24 @@
1
+ {% from "components/featured-article/_macro.njk" import onsFeaturedArticle %}
2
+ {{
3
+ onsFeaturedArticle({
4
+ "title": {
5
+ "text": 'Retail sales, Great Britain: July 2024',
6
+ "url": '#0'
7
+ },
8
+ "metadata": {
9
+ "text": 'Dataset',
10
+ "date": {
11
+ "prefix": 'Released',
12
+ "showPrefix": true,
13
+ "iso": '2021-02-18',
14
+ "short": '18 February 2021'
15
+ }
16
+ },
17
+ "headingLevel": 3,
18
+ "image": {
19
+ "src": '/img/small/census-monuments-lights-featured.jpg',
20
+ "alt": 'census monuments lights featured'
21
+ },
22
+ "description": "Retail sales volumes and values saw moderate growth in July 2024, with the annual rate of inflation for the Consumer Prices Index including owner occupiers’ housing costs (CPIH) rising to 2.8%."
23
+ })
24
+ }}
@@ -0,0 +1,33 @@
1
+ .ons-featured {
2
+ background-color: var(--ons-color-banner-bg);
3
+ padding: 2rem;
4
+ border-bottom: 0;
5
+ display: block;
6
+ outline: 2px solid transparent;
7
+ outline-offset: -2px;
8
+
9
+ &__image {
10
+ .ons-image__img {
11
+ width: 100%;
12
+ max-width: $grid-max-width;
13
+ }
14
+ }
15
+
16
+ &__item-metadata {
17
+ @extend .ons-list--bare;
18
+ }
19
+
20
+ &__item-attribute {
21
+ display: inline-block;
22
+ margin-right: 1rem;
23
+
24
+ @extend .ons-u-fs-s;
25
+ }
26
+
27
+ &__description {
28
+ border-top: 1px solid var(--ons-color-grey-75);
29
+ margin-top: 2rem;
30
+ padding: 2rem 0 0;
31
+ margin-bottom: 0;
32
+ }
33
+ }
@@ -0,0 +1,173 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as cheerio from 'cheerio';
4
+ import axe from '../../tests/helpers/axe';
5
+ import { renderComponent } from '../../tests/helpers/rendering';
6
+ import { EXAMPLE_FEATURED_ARTICLE_WITH_CHART, EXAMPLE_FEATURED_ARTICLE_WITH_IMAGE } from './_test-examples';
7
+
8
+ describe('Macro: Featured Article', () => {
9
+ describe('GIVEN: Params: required', () => {
10
+ describe('WHEN: chart is provided and image is not', () => {
11
+ const $ = cheerio.load(renderComponent('featured-article', EXAMPLE_FEATURED_ARTICLE_WITH_CHART));
12
+
13
+ test('THEN: it passes accessibility checks', async () => {
14
+ const results = await axe($.html());
15
+ expect(results).toHaveNoViolations();
16
+ });
17
+
18
+ test('THEN: it displays the correct title text', () => {
19
+ expect($('.ons-featured__title').text().trim()).toBe('Economic Trends 2024');
20
+ });
21
+
22
+ test('THEN: the title has the correct url link', () => {
23
+ expect($('.ons-featured__title a').attr('href')).toBe('/economy/economic-trends-2024');
24
+ });
25
+
26
+ test('THEN: it renders the onsChart component', () => {
27
+ expect($('[data-highcharts-base-chart]').length).toBe(1);
28
+ });
29
+
30
+ test('THEN: the chart has the correct id', () => {
31
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-id')).toBe('growth-chart');
32
+ });
33
+
34
+ test('THEN: the chart has the correct type', () => {
35
+ expect($('[data-highcharts-base-chart]').attr('data-highcharts-type')).toBe('line');
36
+ });
37
+ });
38
+
39
+ describe('WHEN: image is provided and chart is not', () => {
40
+ const $ = cheerio.load(renderComponent('featured-article', EXAMPLE_FEATURED_ARTICLE_WITH_IMAGE));
41
+
42
+ test('THEN: it passes accessibility checks', async () => {
43
+ const results = await axe($.html());
44
+ expect(results).toHaveNoViolations();
45
+ });
46
+
47
+ test('THEN: it displays the correct title text', () => {
48
+ expect($('.ons-featured__title').text().trim()).toBe('Population Insights');
49
+ });
50
+
51
+ test('THEN: the title has the correct url link', () => {
52
+ expect($('.ons-featured__title a').attr('href')).toBe('/people/population/insights');
53
+ });
54
+
55
+ test('THEN: it renders image with correct src attribute', () => {
56
+ expect($('.ons-image__img').attr('src')).toBe('example.png');
57
+ });
58
+
59
+ test('THEN: it renders image with correct alt text', () => {
60
+ expect($('.ons-image__img').attr('alt')).toBe('Example alt text');
61
+ });
62
+ });
63
+
64
+ describe('WHEN: both chart and image is provided', () => {
65
+ const $ = cheerio.load(renderComponent('featured-article', EXAMPLE_FEATURED_ARTICLE_WITH_CHART));
66
+
67
+ test('THEN: it renders the onsChart component', () => {
68
+ expect($('[data-highcharts-base-chart]').length).toBe(1);
69
+ });
70
+ test('THEN: it does not render the onsImage component', () => {
71
+ expect($('.ons-image__img').length).toBe(0);
72
+ });
73
+ });
74
+ });
75
+
76
+ describe('GIVEN: Param: metadata', () => {
77
+ describe('WHEN: chart is provided', () => {
78
+ const $ = cheerio.load(
79
+ renderComponent('featured-article', {
80
+ ...EXAMPLE_FEATURED_ARTICLE_WITH_CHART,
81
+ metadata: {
82
+ date: {
83
+ prefix: 'Released',
84
+ showPrefix: true,
85
+ iso: '2024-05-01',
86
+ short: '1 May 2024',
87
+ },
88
+ text: 'Bulletin',
89
+ },
90
+ }),
91
+ );
92
+
93
+ test('THEN: it renders ISO date value correctly', () => {
94
+ expect($('time').attr('datetime')).toBe('2024-05-01');
95
+ });
96
+
97
+ test('THEN: it renders short date label correctly', () => {
98
+ expect($('time').text()).toBe('1 May 2024');
99
+ });
100
+
101
+ test('THEN: it displays metadata text', () => {
102
+ expect($('.ons-featured__item-attribute span').text()).toContain('Bulletin');
103
+ });
104
+ });
105
+
106
+ describe('WHEN: image is provided', () => {
107
+ const $ = cheerio.load(
108
+ renderComponent('featured-article', {
109
+ ...EXAMPLE_FEATURED_ARTICLE_WITH_IMAGE,
110
+ metadata: {
111
+ date: {
112
+ prefix: 'Released',
113
+ showPrefix: true,
114
+ iso: '2024-05-01',
115
+ short: '1 May 2024',
116
+ },
117
+ text: 'Bulletin',
118
+ },
119
+ }),
120
+ );
121
+
122
+ test('THEN: it renders ISO date value correctly', () => {
123
+ expect($('time').attr('datetime')).toBe('2024-05-01');
124
+ });
125
+
126
+ test('THEN: it renders short date label correctly', () => {
127
+ expect($('time').text()).toBe('1 May 2024');
128
+ });
129
+
130
+ test('THEN: it displays metadata text', () => {
131
+ expect($('.ons-featured__item-attribute span').text()).toContain('Bulletin');
132
+ });
133
+ });
134
+
135
+ describe('WHEN: metadata is not provided', () => {
136
+ const articleWithoutMetadata = {
137
+ ...EXAMPLE_FEATURED_ARTICLE_WITH_CHART,
138
+ };
139
+ const $ = cheerio.load(renderComponent('featured-article', articleWithoutMetadata));
140
+
141
+ test('THEN: metadata section is not rendered', () => {
142
+ expect($('.ons-featured__item-metadata').length).toBe(0);
143
+ });
144
+ });
145
+ });
146
+
147
+ describe('GIVEN: Params: description', () => {
148
+ describe('WHEN: description is provided', () => {
149
+ test('THEN: has expected description', () => {
150
+ const $ = cheerio.load(
151
+ renderComponent('featured-article', { ...EXAMPLE_FEATURED_ARTICLE_WITH_CHART, description: 'Some description' }),
152
+ );
153
+ const title = $('.ons-featured__description').html().trim();
154
+ expect(title).toBe('Some description');
155
+ });
156
+ });
157
+ });
158
+
159
+ describe('GIVEN: Param: headingLevel', () => {
160
+ describe('WHEN: heading level is provided', () => {
161
+ const $ = cheerio.load(
162
+ renderComponent('featured-article', {
163
+ ...EXAMPLE_FEATURED_ARTICLE_WITH_CHART,
164
+ headingLevel: 3,
165
+ }),
166
+ );
167
+
168
+ test('THEN: title is rendered using correct heading tag', () => {
169
+ expect($('.ons-featured__title')[0].tagName).toBe('h3');
170
+ });
171
+ });
172
+ });
173
+ });
@@ -1,5 +1,6 @@
1
1
  // Block
2
2
  .ons-header {
3
+ $root: &;
3
4
  @include font-smoothing;
4
5
 
5
6
  display: block;
@@ -239,6 +240,22 @@
239
240
  &--basic & {
240
241
  &__grid-top {
241
242
  padding: 0;
243
+ flex-direction: column;
244
+ align-items: flex-start;
245
+
246
+ #{$root}__menu-links {
247
+ width: 100%;
248
+ }
249
+
250
+ // When JS is enabled, revert the no-js styles
251
+ .ons-js-enabled & {
252
+ flex-direction: inherit;
253
+ align-items: center;
254
+
255
+ #{$root}__menu-links {
256
+ width: auto;
257
+ }
258
+ }
242
259
  }
243
260
  }
244
261
 
@@ -246,15 +263,21 @@
246
263
  // applies styles for non-js variant
247
264
  background-color: var(--ons-color-branded-tint);
248
265
  border-bottom: 1px solid var(--ons-color-ocean-blue);
249
- width: 100%;
250
266
  margin-bottom: 0;
251
267
  padding-bottom: 1rem;
268
+ position: relative;
269
+ width: 100%;
252
270
 
253
271
  // updates styles when js is enabled
254
272
  .ons-js-enabled & {
255
273
  border-bottom: 0;
256
274
  margin-bottom: 1rem;
257
275
  padding-bottom: 0;
276
+ position: absolute;
277
+ top: 100%;
278
+ left: 50%;
279
+ width: 100vw;
280
+ transform: translateX(-50%);
258
281
  }
259
282
 
260
283
  &__key-list {
@@ -295,7 +318,17 @@
295
318
  @extend .ons-u-pt-2xl;
296
319
  @extend .ons-u-pb-2xl;
297
320
 
321
+ position: relative;
298
322
  width: 100%;
323
+
324
+ // updates styles when js is enabled
325
+ .ons-js-enabled & {
326
+ position: absolute;
327
+ top: 100%;
328
+ left: 50%;
329
+ width: 100vw;
330
+ transform: translateX(-50%);
331
+ }
299
332
  &__input {
300
333
  border-bottom: 1px solid var(--ons-color-ocean-blue);
301
334
  @extend .ons-u-mb-2xl;