@ons/design-system 50.0.1 → 51.0.0

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 (164) hide show
  1. package/README.md +35 -13
  2. package/components/access-code/_macro.njk +1 -1
  3. package/components/access-code/_macro.spec.js +162 -0
  4. package/components/access-code/uac.spec.js +26 -0
  5. package/components/accordion/_macro.spec.js +224 -0
  6. package/components/accordion/accordion.spec.js +134 -0
  7. package/components/address-input/_macro.njk +1 -1
  8. package/components/address-input/_macro.spec.js +465 -0
  9. package/components/address-input/autosuggest.address.js +5 -4
  10. package/components/address-input/autosuggest.address.setter.js +3 -1
  11. package/components/address-input/autosuggest.address.spec.js +733 -0
  12. package/components/address-output/_macro.njk +6 -6
  13. package/components/address-output/_macro.spec.js +122 -0
  14. package/components/autosuggest/_macro.njk +1 -1
  15. package/components/autosuggest/_macro.spec.js +229 -0
  16. package/components/autosuggest/autosuggest.helpers.js +2 -3
  17. package/components/autosuggest/autosuggest.helpers.spec.js +85 -0
  18. package/components/autosuggest/autosuggest.js +4 -2
  19. package/components/autosuggest/autosuggest.spec.js +625 -0
  20. package/components/autosuggest/autosuggest.ui.js +6 -2
  21. package/components/breadcrumbs/_macro.spec.js +129 -0
  22. package/components/button/_macro.njk +5 -5
  23. package/components/button/_macro.spec.js +446 -0
  24. package/components/button/button.spec.js +290 -0
  25. package/components/call-to-action/_macro.njk +3 -1
  26. package/components/call-to-action/_macro.spec.js +52 -0
  27. package/components/card/_macro.njk +26 -19
  28. package/components/card/_macro.spec.js +261 -0
  29. package/components/char-check-limit/_macro.spec.js +73 -0
  30. package/components/char-check-limit/character-check.spec.js +196 -0
  31. package/components/char-check-limit/character-limit.js +1 -1
  32. package/components/checkboxes/_checkbox-macro.spec.js +419 -0
  33. package/components/checkboxes/_macro.njk +1 -3
  34. package/components/checkboxes/_macro.spec.js +306 -0
  35. package/components/checkboxes/checkboxes.spec.js +208 -0
  36. package/components/code-highlight/_macro.spec.js +56 -0
  37. package/components/code-highlight/code-highlight.spec.js +18 -0
  38. package/components/collapsible/_macro.spec.js +204 -0
  39. package/components/collapsible/collapsible.js +2 -1
  40. package/components/collapsible/collapsible.spec.js +236 -0
  41. package/components/content-pagination/_macro.spec.js +199 -0
  42. package/components/cookies-banner/_macro.njk +1 -1
  43. package/components/cookies-banner/_macro.spec.js +171 -0
  44. package/components/cookies-banner/cookies-banner.spec.js +90 -0
  45. package/components/date-input/_macro.njk +6 -3
  46. package/components/date-input/_macro.spec.js +286 -0
  47. package/components/document-list/_macro.njk +3 -5
  48. package/components/document-list/_macro.spec.js +491 -0
  49. package/components/download-resources/download-resources.spec.js +540 -0
  50. package/components/duration/_macro.njk +7 -6
  51. package/components/duration/_macro.spec.js +251 -0
  52. package/components/error/_macro.spec.js +97 -0
  53. package/components/external-link/_macro.spec.js +60 -0
  54. package/components/feedback/_macro.njk +5 -3
  55. package/components/feedback/_macro.spec.js +122 -0
  56. package/components/field/_macro.njk +2 -2
  57. package/components/field/_macro.spec.js +97 -0
  58. package/components/fieldset/_macro.njk +3 -3
  59. package/components/fieldset/_macro.spec.js +173 -0
  60. package/components/footer/_macro.njk +11 -48
  61. package/components/footer/_macro.spec.js +549 -0
  62. package/components/header/_macro.njk +2 -2
  63. package/components/header/_macro.spec.js +562 -0
  64. package/components/hero/_hero.scss +0 -3
  65. package/components/hero/_macro.njk +4 -4
  66. package/components/hero/_macro.spec.js +224 -0
  67. package/components/icons/_macro.njk +15 -15
  68. package/components/icons/_macro.spec.js +140 -0
  69. package/components/images/_macro.njk +1 -1
  70. package/components/images/_macro.spec.js +121 -0
  71. package/components/input/_input-type.scss +12 -5
  72. package/components/input/_macro.njk +4 -5
  73. package/components/input/_macro.spec.js +658 -0
  74. package/components/label/_macro.spec.js +189 -0
  75. package/components/language-selector/_macro.spec.js +129 -0
  76. package/components/lists/_list.scss +4 -0
  77. package/components/lists/_macro.njk +4 -7
  78. package/components/lists/_macro.spec.js +618 -0
  79. package/components/message/_macro.spec.js +137 -0
  80. package/components/message-list/_macro.njk +7 -7
  81. package/components/message-list/_macro.spec.js +159 -0
  82. package/components/metadata/_macro.spec.js +167 -0
  83. package/components/modal/_macro.njk +6 -6
  84. package/components/modal/_macro.spec.js +87 -0
  85. package/components/modal/modal.spec.js +59 -0
  86. package/components/mutually-exclusive/_macro.njk +1 -1
  87. package/components/mutually-exclusive/_macro.spec.js +182 -0
  88. package/components/mutually-exclusive/mutually-exclusive.checkboxes.spec.js +203 -0
  89. package/components/mutually-exclusive/mutually-exclusive.date.spec.js +142 -0
  90. package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +141 -0
  91. package/components/mutually-exclusive/mutually-exclusive.email.spec.js +117 -0
  92. package/components/mutually-exclusive/mutually-exclusive.multiple-options.checkboxes.spec.js +213 -0
  93. package/components/mutually-exclusive/mutually-exclusive.number.spec.js +125 -0
  94. package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +131 -0
  95. package/components/navigation/_macro.njk +6 -6
  96. package/components/navigation/_macro.spec.js +327 -0
  97. package/components/navigation/navigation.dom.js +1 -1
  98. package/components/navigation/navigation.spec.js +232 -0
  99. package/components/pagination/_macro.njk +1 -1
  100. package/components/pagination/_macro.spec.js +411 -0
  101. package/components/panel/_macro.njk +6 -6
  102. package/components/panel/_macro.spec.js +423 -0
  103. package/components/password/_macro.spec.js +137 -0
  104. package/components/password/password.spec.js +40 -0
  105. package/components/phase-banner/_macro.spec.js +73 -0
  106. package/components/promotional-banner/_macro.spec.js +97 -0
  107. package/components/question/_macro.njk +25 -33
  108. package/components/question/_macro.spec.js +309 -0
  109. package/components/quote/_macro.spec.js +81 -0
  110. package/components/radios/_macro.njk +3 -6
  111. package/components/radios/_macro.spec.js +575 -0
  112. package/components/radios/radios.spec.js +180 -0
  113. package/components/related-content/_macro.njk +1 -0
  114. package/components/related-content/_macro.spec.js +142 -0
  115. package/components/relationships/_macro.spec.js +108 -0
  116. package/components/relationships/relationships.spec.js +84 -0
  117. package/components/reply/_macro.njk +2 -2
  118. package/components/reply/_macro.spec.js +69 -0
  119. package/components/reply/reply.spec.js +78 -0
  120. package/components/search/_macro.njk +14 -12
  121. package/components/search/_macro.spec.js +44 -0
  122. package/components/search/_search.scss +7 -7
  123. package/components/section-navigation/_macro.njk +7 -2
  124. package/components/section-navigation/_macro.spec.js +206 -0
  125. package/components/select/_macro.njk +3 -3
  126. package/components/select/_macro.spec.js +203 -0
  127. package/components/select/select.spec.js +56 -0
  128. package/components/share-page/_macro.njk +2 -2
  129. package/components/share-page/_macro.spec.js +110 -0
  130. package/components/skip-to-content/_macro.spec.js +57 -0
  131. package/components/skip-to-content/skip-to-content.spec.js +44 -0
  132. package/components/status/_macro.spec.js +77 -0
  133. package/components/summary/_macro.njk +5 -5
  134. package/components/summary/_macro.spec.js +472 -0
  135. package/components/table/_macro.njk +2 -2
  136. package/components/table/_macro.spec.js +557 -0
  137. package/components/table/table.spec.js +155 -0
  138. package/components/table-of-contents/_macro.njk +35 -35
  139. package/components/table-of-contents/_macro.spec.js +178 -0
  140. package/components/table-of-contents/toc.js +29 -25
  141. package/components/table-of-contents/toc.spec.js +61 -0
  142. package/components/tabs/_macro.njk +1 -1
  143. package/components/tabs/_macro.spec.js +79 -0
  144. package/components/tabs/tabs.spec.js +162 -0
  145. package/components/text-indent/_macro.spec.js +52 -0
  146. package/components/textarea/_macro.njk +5 -3
  147. package/components/textarea/_macro.spec.js +300 -0
  148. package/components/textarea/textarea.spec.js +98 -0
  149. package/components/timeline/_macro.njk +3 -3
  150. package/components/timeline/_macro.spec.js +81 -0
  151. package/components/timeout-modal/_macro.spec.js +68 -0
  152. package/components/timeout-modal/timeout-modal.spec.js +226 -0
  153. package/components/timeout-panel/_macro.njk +0 -1
  154. package/components/timeout-panel/_macro.spec.js +54 -0
  155. package/components/timeout-panel/timeout-panel.dom.js +1 -2
  156. package/components/timeout-panel/timeout-panel.spec.js +161 -0
  157. package/components/upload/_macro.spec.js +75 -0
  158. package/components/video/_macro.spec.js +34 -0
  159. package/css/census.css +1 -1
  160. package/css/main.css +1 -1
  161. package/js/cookies-settings.spec.js +154 -0
  162. package/package.json +10 -23
  163. package/scripts/main.es5.js +1 -1
  164. package/scripts/main.js +1 -1
@@ -0,0 +1,173 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as cheerio from 'cheerio';
4
+
5
+ import axe from '../../tests/helpers/axe';
6
+ import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
+
8
+ const EXAMPLE_FIELDSET_BASIC = {
9
+ id: 'example-fieldset',
10
+ legend: 'Fieldset legend',
11
+ description: 'A fieldset description',
12
+ };
13
+
14
+ describe('macro: fieldset', () => {
15
+ it('passes jest-axe checks', async () => {
16
+ const $ = cheerio.load(renderComponent('fieldset', EXAMPLE_FIELDSET_BASIC));
17
+
18
+ const results = await axe($.html());
19
+ expect(results).toHaveNoViolations();
20
+ });
21
+
22
+ it('has the provided `id` attribute', () => {
23
+ const $ = cheerio.load(renderComponent('fieldset', EXAMPLE_FIELDSET_BASIC));
24
+
25
+ expect($('.ons-fieldset').attr('id')).toBe('example-fieldset');
26
+ });
27
+
28
+ it('has the `legend` text', () => {
29
+ const $ = cheerio.load(renderComponent('fieldset', EXAMPLE_FIELDSET_BASIC));
30
+
31
+ const title = $('.ons-fieldset__legend-title').text();
32
+ expect(title).toBe('Fieldset legend');
33
+ });
34
+
35
+ it('has the `description` text', () => {
36
+ const $ = cheerio.load(renderComponent('fieldset', EXAMPLE_FIELDSET_BASIC));
37
+
38
+ const title = $('.ons-fieldset__description')
39
+ .html()
40
+ .trim();
41
+ expect(title).toBe('A fieldset description');
42
+ });
43
+
44
+ it('has additionally provided style classes', () => {
45
+ const $ = cheerio.load(
46
+ renderComponent('fieldset', {
47
+ ...EXAMPLE_FIELDSET_BASIC,
48
+ classes: 'extra-class another-extra-class',
49
+ }),
50
+ );
51
+
52
+ expect($('.ons-fieldset').hasClass('extra-class')).toBe(true);
53
+ expect($('.ons-fieldset').hasClass('another-extra-class')).toBe(true);
54
+ });
55
+
56
+ it('has additionally provided `legendClasses`', () => {
57
+ const $ = cheerio.load(
58
+ renderComponent('fieldset', {
59
+ ...EXAMPLE_FIELDSET_BASIC,
60
+ legendClasses: 'extra-class another-extra-class',
61
+ }),
62
+ );
63
+
64
+ expect($('.ons-fieldset__legend').hasClass('extra-class')).toBe(true);
65
+ expect($('.ons-fieldset__legend').hasClass('another-extra-class')).toBe(true);
66
+ });
67
+
68
+ it('has additionally provided `attributes`', () => {
69
+ const $ = cheerio.load(
70
+ renderComponent('fieldset', {
71
+ ...EXAMPLE_FIELDSET_BASIC,
72
+ attributes: {
73
+ a: 123,
74
+ b: 456,
75
+ },
76
+ }),
77
+ );
78
+
79
+ expect($('.ons-fieldset').attr('a')).toBe('123');
80
+ expect($('.ons-fieldset').attr('b')).toBe('456');
81
+ });
82
+
83
+ it('has the correct element with `dontWrap`', () => {
84
+ const $ = cheerio.load(
85
+ renderComponent('fieldset', {
86
+ ...EXAMPLE_FIELDSET_BASIC,
87
+ dontWrap: true,
88
+ }),
89
+ );
90
+
91
+ expect($('.ons-input-items').length).toBe(1);
92
+ expect($('.ons-fieldset').length).toBe(0);
93
+ });
94
+
95
+ it('calls with content', () => {
96
+ const $ = cheerio.load(renderComponent('fieldset', EXAMPLE_FIELDSET_BASIC, 'Example content...'));
97
+
98
+ const content = $('.ons-fieldset')
99
+ .html()
100
+ .trim();
101
+ expect(content).toEqual(expect.stringContaining('Example content...'));
102
+ });
103
+
104
+ it('calls the error component when `error` is provided', () => {
105
+ const faker = templateFaker();
106
+ const errorSpy = faker.spy('error');
107
+
108
+ faker.renderComponent('fieldset', {
109
+ ...EXAMPLE_FIELDSET_BASIC,
110
+ error: { text: 'There is an error' },
111
+ });
112
+
113
+ expect(errorSpy.occurrences[0]).toEqual({
114
+ text: 'There is an error',
115
+ });
116
+ });
117
+
118
+ describe('with `legendIsQuestionTitle`', () => {
119
+ it('passes jest-axe checks', async () => {
120
+ const $ = cheerio.load(renderComponent('fieldset', { ...EXAMPLE_FIELDSET_BASIC, legendIsQuestionTitle: true }));
121
+
122
+ const results = await axe($.html());
123
+ expect(results).toHaveNoViolations();
124
+ });
125
+
126
+ it('has the correct class', () => {
127
+ const $ = cheerio.load(renderComponent('fieldset', { ...EXAMPLE_FIELDSET_BASIC, legendIsQuestionTitle: true }));
128
+ expect($('.ons-fieldset__legend').hasClass('ons-u-mb-no')).toBe(true);
129
+ });
130
+
131
+ it('renders the legend in a H1', () => {
132
+ const $ = cheerio.load(renderComponent('fieldset', { ...EXAMPLE_FIELDSET_BASIC, legendIsQuestionTitle: true }));
133
+ const titleTag = $('.ons-fieldset__legend-title')[0].tagName;
134
+
135
+ expect(titleTag).toBe('h1');
136
+ });
137
+
138
+ it('has additionally provided `legendTitleClasses`', () => {
139
+ const $ = cheerio.load(
140
+ renderComponent('fieldset', {
141
+ ...EXAMPLE_FIELDSET_BASIC,
142
+ legendTitleClasses: 'extra-class another-extra-class',
143
+ legendIsQuestionTitle: true,
144
+ }),
145
+ );
146
+
147
+ expect($('.ons-fieldset__legend-title').hasClass('extra-class')).toBe(true);
148
+ expect($('.ons-fieldset__legend-title').hasClass('another-extra-class')).toBe(true);
149
+ });
150
+
151
+ it('has the `legend` text', () => {
152
+ const $ = cheerio.load(
153
+ renderComponent('fieldset', {
154
+ ...EXAMPLE_FIELDSET_BASIC,
155
+ legendTitleClasses: 'extra-class another-extra-class',
156
+ legendIsQuestionTitle: true,
157
+ }),
158
+ );
159
+
160
+ const title = $('.ons-fieldset__legend-title')
161
+ .html()
162
+ .trim();
163
+ expect(title).toBe('Fieldset legend');
164
+ });
165
+
166
+ it('has the correct `description` classes', () => {
167
+ const $ = cheerio.load(renderComponent('fieldset', { ...EXAMPLE_FIELDSET_BASIC, legendIsQuestionTitle: true }));
168
+
169
+ expect($('.ons-fieldset__description').hasClass('ons-fieldset__description--title')).toBe(true);
170
+ expect($('.ons-fieldset__description').hasClass('ons-u-mb-m')).toBe(true);
171
+ });
172
+ });
173
+ });
@@ -9,21 +9,13 @@
9
9
  {% set lang = 'en' %}
10
10
  {% endif %}
11
11
 
12
- {% if params.poweredBy is defined and params.poweredBy %}
13
- {% if params.poweredBy.alt is defined and params.poweredBy.alt %}
14
- {% set poweredByAlt = params.poweredBy.alt %}
15
- {% else %}
16
- {% set poweredByAlt = 'Office for National Statistics' %}
17
- {% endif %}
18
- {% endif %}
19
-
20
12
  {% set poweredByLogo %}
21
13
 
22
14
  {% if params.poweredBy is defined and params.poweredBy and params.poweredBy.logo is defined and params.poweredBy.logo %}
23
15
  {{
24
16
  onsIcon({
25
17
  "iconType": params.poweredBy.logo,
26
- "altText": poweredByAlt
18
+ "altText": params.poweredBy.alt | default("Office for National Statistics")
27
19
  })
28
20
  }}
29
21
  {% else %}
@@ -31,14 +23,14 @@
31
23
  {{
32
24
  onsIcon({
33
25
  "iconType": 'ons-logo-cy',
34
- "altText": poweredByAlt | default('Swyddfa Ystadegau Gwladol')
26
+ "altText": params.poweredBy.alt | default('Swyddfa Ystadegau Gwladol')
35
27
  })
36
28
  }}
37
29
  {% else %}
38
30
  {{
39
31
  onsIcon({
40
32
  "iconType": 'ons-logo-en',
41
- "altText": poweredByAlt | default('Office for National Statistics')
33
+ "altText": params.poweredBy.alt | default('Office for National Statistics')
42
34
  })
43
35
  }}
44
36
  {% endif %}
@@ -46,14 +38,6 @@
46
38
 
47
39
  {% endset %}
48
40
 
49
- {% set crestLogo %}
50
- {{
51
- onsIcon({
52
- "iconType": 'crest'
53
- })
54
- }}
55
- {% endset %}
56
-
57
41
  <footer class="ons-footer">
58
42
 
59
43
  {% if params.footerWarning is defined and params.footerWarning %}
@@ -103,34 +87,9 @@
103
87
  </div>
104
88
  {% endif %}
105
89
 
106
- {% if params.language is defined and params.language %}
107
- {% set currentLanguage = params.language.languages | selectattr("current") | first %}
108
- {% set languageNumber = params.language.languages | length %}
109
- <div class="ons-grid__col {% if languageNumber and languageNumber != 2 %} ons-u-d-no@m{% elif languageNumber %} ons-u-d-no{% endif %}">
110
- {% set languageItems = params.language.languages | rejectattr("current") | list %}
111
- {% if currentLanguage.allLanguages is defined and currentLanguage.allLanguages and params.language.allLanguagesUrl is defined and params.language.allLanguagesUrl %}
112
- {% set languageItems = (languageItems.push({
113
- "url": params.language.allLanguagesUrl,
114
- "text": currentLanguage.allLanguages,
115
- "lang": currentLanguage.ISOCode
116
- }), languageItems) %}
117
- {% endif %}
118
- {{
119
- onsList({
120
- "classes": 'ons-u-mb-no',
121
- "variants": ['bare', 'inline@m'],
122
- "itemsList": languageItems
123
- })
124
- }}
125
- </div>
126
- <div class="ons-grid__col {% if languageNumber and languageNumber != 2 %} ons-u-d-no@m{% elif languageNumber %} ons-u-d-no{% endif %} ons-u-mb-m">
127
- <hr class="ons-footer__hr">
128
- </div>
129
- {% endif %}
130
-
131
90
  {% if params.newTabWarning is defined and params.newTabWarning %}
132
91
  <div class="ons-grid__col">
133
- <p class="ons-u-fs-s ons-u-mb-m">{{ params.newTabWarning | safe }}</p>
92
+ <p class="ons-u-fs-s ons-u-mb-m ons-footer__new-tab-warning">{{ params.newTabWarning | safe }}</p>
134
93
  </div>
135
94
  {% endif %}
136
95
 
@@ -242,8 +201,12 @@
242
201
 
243
202
  {% if params.crest is defined and params.crest %}
244
203
  <!-- Crest -->
245
- <div class="ons-grid__col">
246
- {{ crestLogo | safe }}
204
+ <div class="ons-grid__col ons-footer__crest">
205
+ {{
206
+ onsIcon({
207
+ "iconType": 'crest'
208
+ })
209
+ }}
247
210
  </div>
248
211
  {% elif params.legal is defined and params.legal %}
249
212
  <!-- Powered by -->
@@ -259,7 +222,7 @@
259
222
  <!-- Copyright -->
260
223
  <div class="ons-grid">
261
224
  <div class="ons-grid__col ons-u-mt-s">
262
- <p class="ons-u-fs-s ons-u-mb-no">&copy; {{ params.copyrightDeclaration.copyright }} <br> {{ params.copyrightDeclaration.text }}</p>
225
+ <p class="ons-u-fs-s ons-u-mb-no ons-footer__copyright">&copy; {{ params.copyrightDeclaration.copyright }} <br> {{ params.copyrightDeclaration.text }}</p>
263
226
  </div>
264
227
  </div>
265
228
  {% endif %}