@ons/design-system 73.7.0 → 73.9.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.
package/README.md CHANGED
@@ -143,6 +143,8 @@ Checkout the branch locally and run:
143
143
 
144
144
  `yarn test-visual` - This will run the same tests locally as were run in Github Actions. After they have completed the report will open in your default browser.
145
145
 
146
+ `VR_SHARD_INDEX=0 VR_SHARD_COUNT=4 yarn test-visual` - This runs only one shard of the visual tests locally. Useful when one shard fails in CI.
147
+
146
148
  `yarn test-visual:approve` - This will approve the failures/diff caught by the tests.
147
149
 
148
150
  `git lfs push --all origin` - First commit the files in the normal way then run the command. This will push the new reference images to Git LFS.
@@ -176,7 +178,7 @@ yarn add @ons/design-system@next
176
178
 
177
179
  ### Publishing the stable major
178
180
 
179
- 1. Merge `next` into `main`.
181
+ 1. Merge `next` into `main`. **Do not squash; use a regular merge commit to preserve history.**
180
182
  2. Create a normal release tag, for example: `74.0.0`.
181
183
  3. Publish the GitHub Release (not marked as a pre-release).
182
184
 
@@ -363,9 +363,7 @@
363
363
  // updates styles when js is enabled
364
364
  .ons-js-enabled & {
365
365
  position: relative;
366
- left: 50%;
367
- width: 100vw;
368
- transform: translateX(-50%);
366
+ width: 100%;
369
367
  border-top: 0;
370
368
  }
371
369
  }
@@ -368,7 +368,7 @@
368
368
  "name": params.search.form.inputName | default('q'),
369
369
  "width": 'full',
370
370
  "label": {
371
- "text": (params.search.form.inputLabel if params.search.form else params.searchLinks.searchNavigationInputLabel) | default('Search the ONS'),
371
+ "text": (params.search.form.inputLabel if params.search.form else params.searchLinks.searchNavigationInputLabel) | default('Chwilio’r SYG' if params.lang == 'cy' else 'Search the ONS'),
372
372
  "id": "header-search-input-label"
373
373
  },
374
374
  "searchButton": {
@@ -8,7 +8,7 @@
8
8
  class="ons-table-scrollable__content"
9
9
  tabindex="0"
10
10
  role="region"
11
- aria-label="{{ params.caption }}. {{ params.ariaLabel | default('Scrollable table') }}"
11
+ {% if params.ariaLabel %}aria-label="{{ params.ariaLabel }}"{% endif %}
12
12
  >
13
13
  {# Uses multiple loops to set the rowspan class so that it can work in both nunjucks and jinja2 environments due to the scoping rules of each language #}
14
14
  <table
@@ -7,6 +7,7 @@ import { mapAll } from '../../tests/helpers/cheerio';
7
7
  import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
8
8
 
9
9
  const EXAMPLE_TABLE_MINIMAL = {
10
+ ariaLabel: 'Example table',
10
11
  ths: [],
11
12
  trs: [],
12
13
  };
@@ -67,27 +68,15 @@ describe('macro: table', () => {
67
68
  expect($('.ons-table-scrollable__content').length).toBe(1);
68
69
  });
69
70
 
70
- it('renders an appropriate `aria-label` attribute on the "content" container element', () => {
71
+ it('renders the `aria-label` attribute on the "content" container element', () => {
71
72
  const $ = cheerio.load(
72
73
  renderComponent('table', {
73
74
  ...EXAMPLE_TABLE,
74
- caption: 'Example table caption',
75
- }),
76
- );
77
-
78
- expect($('.ons-table-scrollable__content').attr('aria-label')).toBe('Example table caption. Scrollable table');
79
- });
80
-
81
- it('renders a custom `aria-label` attribute on the "content" container element', () => {
82
- const $ = cheerio.load(
83
- renderComponent('table', {
84
- ...EXAMPLE_TABLE,
85
- caption: 'Example table caption',
86
75
  ariaLabel: 'Special table',
87
76
  }),
88
77
  );
89
78
 
90
- expect($('.ons-table-scrollable__content').attr('aria-label')).toBe('Example table caption. Special table');
79
+ expect($('.ons-table-scrollable__content').attr('aria-label')).toBe('Special table');
91
80
  });
92
81
 
93
82
  describe('Vertical Alignment', () => {
@@ -0,0 +1,46 @@
1
+ {% from "components/table/_macro.njk" import onsTable %}
2
+ {{
3
+ onsTable({
4
+ "ariaLabel": "Basic table example",
5
+ "id": "basic-table",
6
+ "ths": [
7
+ {
8
+ "value": "Column A"
9
+ },
10
+ {
11
+ "value": "Column B"
12
+ },
13
+ {
14
+ "value": "Column C"
15
+ }
16
+ ],
17
+ "trs": [
18
+ {
19
+ "tds": [
20
+ {
21
+ "value": "Cell A1"
22
+ },
23
+ {
24
+ "value": "Cell B1"
25
+ },
26
+ {
27
+ "value": "Cell C1"
28
+ }
29
+ ]
30
+ },
31
+ {
32
+ "tds": [
33
+ {
34
+ "value": "Cell A2"
35
+ },
36
+ {
37
+ "value": "Cell B2"
38
+ },
39
+ {
40
+ "value": "Cell C2"
41
+ }
42
+ ]
43
+ }
44
+ ]
45
+ })
46
+ }}
@@ -0,0 +1,47 @@
1
+ {% from "components/table/_macro.njk" import onsTable %}
2
+ {{
3
+ onsTable({
4
+ "caption": "A basic table with a visually hidden caption",
5
+ "hideCaption": true,
6
+ "id": "basic-table",
7
+ "ths": [
8
+ {
9
+ "value": "Column A"
10
+ },
11
+ {
12
+ "value": "Column B"
13
+ },
14
+ {
15
+ "value": "Column C"
16
+ }
17
+ ],
18
+ "trs": [
19
+ {
20
+ "tds": [
21
+ {
22
+ "value": "Cell A1"
23
+ },
24
+ {
25
+ "value": "Cell B1"
26
+ },
27
+ {
28
+ "value": "Cell C1"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "tds": [
34
+ {
35
+ "value": "Cell A2"
36
+ },
37
+ {
38
+ "value": "Cell B2"
39
+ },
40
+ {
41
+ "value": "Cell C2"
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ })
47
+ }}
@@ -5,6 +5,7 @@ describe('script: table', () => {
5
5
  // Construct a table with 15 columns and 15 rows with long labels.
6
6
  const params = {
7
7
  variants: ['scrollable'],
8
+ ariaLabel: 'Example table',
8
9
  ths: Array.from({ length: 15 }, (_, i) => ({ value: `Column ${i + 1}` })),
9
10
  trs: [
10
11
  {
@@ -44,6 +45,7 @@ describe('script: table', () => {
44
45
  describe('variant: sortable', () => {
45
46
  const params = {
46
47
  variants: ['sortable'],
48
+ ariaLabel: 'Example table',
47
49
  sortBy: 'Sort by',
48
50
  ariaAsc: 'ascending',
49
51
  ariaDesc: 'descending',
@@ -15,6 +15,8 @@
15
15
 
16
16
  <nav class="ons-table-of-contents" aria-label="{{ params.ariaLabel | default('Table of contents') }}">
17
17
  <h2 class="ons-table-of-contents__title ons-u-fs-r--b ons-u-mb-s">{{ params.title }}</h2>
18
+ {% set element = 'ol' if params.ordered else 'ul' %}
19
+ {% set variant = null if params.ordered else 'dashed' %}
18
20
  {% if params.lists %}
19
21
  {% for list in params.lists %}
20
22
  {% if list.listHeading %}
@@ -24,9 +26,9 @@
24
26
  {% endif %}
25
27
  {{
26
28
  onsList({
27
- "element": 'ol',
29
+ "element": element,
28
30
  "classes": 'ons-u-mb-l',
29
- "variants": 'dashed',
31
+ "variants": variant,
30
32
  "itemsList": list.itemsList
31
33
  })
32
34
  }}
@@ -34,9 +36,9 @@
34
36
  {% elif params.itemsList %}
35
37
  {{
36
38
  onsList({
37
- "element": 'ol',
39
+ "element": element,
38
40
  "classes": 'ons-u-mb-l',
39
- "variants": 'dashed',
41
+ "variants": variant,
40
42
  "itemsList": params.itemsList
41
43
  })
42
44
  }}
@@ -160,12 +160,29 @@ describe('macro: table-of-contents', () => {
160
160
  faker.renderComponent('table-of-contents', EXAMPLE_TABLE_OF_CONTENTS_SINGLE);
161
161
 
162
162
  expect(listsSpy.occurrences[0]).toEqual({
163
- element: 'ol',
163
+ element: 'ul',
164
164
  classes: 'ons-u-mb-l',
165
165
  variants: 'dashed',
166
166
  itemsList: EXAMPLE_TABLE_OF_CONTENTS_SINGLE.itemsList,
167
167
  });
168
168
  });
169
+
170
+ it('outputs `lists` component as an ordered list when `ordered` is `true`', () => {
171
+ const faker = templateFaker();
172
+ const listsSpy = faker.spy('list');
173
+
174
+ faker.renderComponent('table-of-contents', {
175
+ ...EXAMPLE_TABLE_OF_CONTENTS_SINGLE,
176
+ ordered: true,
177
+ });
178
+
179
+ expect(listsSpy.occurrences[0]).toEqual({
180
+ element: 'ol',
181
+ classes: 'ons-u-mb-l',
182
+ variants: null,
183
+ itemsList: EXAMPLE_TABLE_OF_CONTENTS_SINGLE.itemsList,
184
+ });
185
+ });
169
186
  });
170
187
 
171
188
  describe('multiple lists', () => {
@@ -199,18 +216,41 @@ describe('macro: table-of-contents', () => {
199
216
  faker.renderComponent('table-of-contents', EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE);
200
217
 
201
218
  expect(listsSpy.occurrences[0]).toEqual({
202
- element: 'ol',
219
+ element: 'ul',
203
220
  classes: 'ons-u-mb-l',
204
221
  variants: 'dashed',
205
222
  itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[0].itemsList,
206
223
  });
207
224
  expect(listsSpy.occurrences[1]).toEqual({
208
- element: 'ol',
225
+ element: 'ul',
209
226
  classes: 'ons-u-mb-l',
210
227
  variants: 'dashed',
211
228
  itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[1].itemsList,
212
229
  });
213
230
  });
231
+
232
+ it('outputs `lists` component for each list as ordered lists when `ordered` is `true`', () => {
233
+ const faker = templateFaker();
234
+ const listsSpy = faker.spy('list');
235
+
236
+ faker.renderComponent('table-of-contents', {
237
+ ...EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE,
238
+ ordered: true,
239
+ });
240
+
241
+ expect(listsSpy.occurrences[0]).toEqual({
242
+ element: 'ol',
243
+ classes: 'ons-u-mb-l',
244
+ variants: null,
245
+ itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[0].itemsList,
246
+ });
247
+ expect(listsSpy.occurrences[1]).toEqual({
248
+ element: 'ol',
249
+ classes: 'ons-u-mb-l',
250
+ variants: null,
251
+ itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[1].itemsList,
252
+ });
253
+ });
214
254
  });
215
255
 
216
256
  describe('related links and button', () => {
@@ -0,0 +1,64 @@
1
+ {% from "components/table-of-contents/_macro.njk" import onsTableOfContents %}
2
+
3
+ {{-
4
+ onsTableOfContents({
5
+ "title": 'Contents',
6
+ "ariaLabel": 'Pages in this guide',
7
+ "skipLink": {
8
+ "url": "#0",
9
+ "text": 'Skip to guide content'
10
+ },
11
+ "ordered": true,
12
+ "lists": [
13
+ {
14
+ "itemsList": [
15
+ {
16
+ "url": '#0',
17
+ "text": 'Overview',
18
+ "current": true
19
+ },
20
+ {
21
+ "url": '#0',
22
+ "text": 'Who should take part and why'
23
+ },
24
+ {
25
+ "url": '#0',
26
+ "text": 'How your information is used'
27
+ },
28
+ {
29
+ "url": '#0',
30
+ "text": 'The 2019 Census Rehearsal'
31
+ },
32
+ {
33
+ "url": '#0',
34
+ "text": 'Further information'
35
+ },
36
+ {
37
+ "url": '#0',
38
+ "text": 'Online census'
39
+ },
40
+ {
41
+ "url": '#0',
42
+ "text": 'Who should take part and why'
43
+ },
44
+ {
45
+ "url": '#0',
46
+ "text": 'How your information is used'
47
+ },
48
+ {
49
+ "url": '#0',
50
+ "text": 'The 2019 Census Rehearsal'
51
+ },
52
+ {
53
+ "url": '#0',
54
+ "text": 'Further information'
55
+ },
56
+ {
57
+ "url": '#0',
58
+ "text": 'Online census'
59
+ }
60
+ ]
61
+ }
62
+ ]
63
+ })
64
+ -}}
@@ -0,0 +1,156 @@
1
+ ---
2
+ title: 'Example: Table of contents on full page'
3
+ layout: ~
4
+ ---
5
+
6
+ {% from "components/table-of-contents/_macro.njk" import onsTableOfContents %}
7
+ {% extends "layout/_template.njk" %}
8
+ {%
9
+ set pageConfig = {
10
+ "header": {
11
+ "title": "What is the census?"
12
+ },
13
+ "breadcrumbs": {
14
+ "ariaLabel": 'Back',
15
+ "itemsList": [
16
+ {
17
+ "url": '/',
18
+ "id": "back-example-feedback-form-error",
19
+ "text": 'Back',
20
+ "attributes": {
21
+ "data-attribute": "Example attribute"
22
+ }
23
+ }
24
+ ]
25
+ },
26
+ "footer": {
27
+ "oglLink": {
28
+ "pre": 'All content is available under the',
29
+ "link": 'Open Government Licence v3.0',
30
+ "url": 'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/',
31
+ "post": ', except where otherwise stated'
32
+ }
33
+ }
34
+ }
35
+ %}
36
+
37
+ {% block main %}
38
+ <div class="ons-page__container ons-container">
39
+ <div class="ons-grid ons-js-table-of-contents-container">
40
+ <div class="ons-grid__col ons-grid__col--sticky@m ons-col-4@m">
41
+ {{
42
+ onsTableOfContents({
43
+ "title": 'Contents',
44
+ "ariaLabel": 'Sections in this page',
45
+ "ordered": true,
46
+ "itemsList": [
47
+ {
48
+ "url": '#section1',
49
+ "text": 'What is the census?'
50
+ },
51
+ {
52
+ "url": '#section2',
53
+ "text": 'The online census has now closed'
54
+ },
55
+ {
56
+ "url": '#section3',
57
+ "text": 'What happens after Census Day'
58
+ },
59
+ {
60
+ "url": '#section4',
61
+ "text": 'The census in Northern Ireland and Scotland'
62
+ },
63
+ {
64
+ "url": '#section5',
65
+ "text": 'The last census'
66
+ }
67
+ ]
68
+ })
69
+ }}
70
+ </div>
71
+ <div class="ons-grid__col ons-col-7@m ons-push-1@m">
72
+ <section id="section1">
73
+ <h2>1. What is the census?</h2>
74
+ <p>
75
+ The census is a survey that happens every 10 years and gives us a picture of all the people and households in
76
+ England and Wales.
77
+ </p>
78
+
79
+ <p>
80
+ Your answers to the census questions will help organisations make decisions on planning and funding public services
81
+ in your area, including transport, education and healthcare.
82
+ </p>
83
+ </section>
84
+ <section id="section2">
85
+ <h2>2. The online census has now closed</h2>
86
+ <p>Census Day was on Sunday 21 March 2021.</p>
87
+
88
+ <p>
89
+ If you still have a paper census questionnaire, fill it in as soon as you can and return it to FREEPOST, Census
90
+ 2021.
91
+ </p>
92
+ </section>
93
+ <section id="section3">
94
+ <h2>3. What happens after Census Day</h2>
95
+ <p>
96
+ Two follow-up surveys, the <a href="#0">Census Coverage Survey</a> and the <a href="#0">Census Quality Survey</a>,
97
+ help to improve the quality and accuracy of the census results.
98
+ </p>
99
+
100
+ <p>
101
+ Over the next year, we work hard to process the answers from all the census questionnaires. This is so that we can
102
+ publish the initial Census 2021 findings one year after the census and the main releases two years after the census.
103
+ </p>
104
+
105
+ <p>
106
+ To make sure the Census 2021 statistics we publish meet the needs of those who use them, we also run an outputs
107
+ consultation.
108
+ </p>
109
+ </section>
110
+ <section id="section4">
111
+ <h2>4. The census in Northern Ireland and Scotland</h2>
112
+ <p>The Office for National Statistics (ONS) runs the census in England and Wales.</p>
113
+
114
+ <p>
115
+ If you live in Northern Ireland, visit the Northern Ireland Statistics Agency (NISRA) census website to find out
116
+ about the census for Northern Ireland.
117
+ </p>
118
+
119
+ <p>
120
+ If you live in Scotland, visit the National Records of Scotland census website to find out how to take part in the
121
+ census for Scotland.
122
+ </p>
123
+ </section>
124
+ <section id="section5">
125
+ <h2>5. The last census</h2>
126
+ <p>
127
+ The last census took place in 2011. Many people and organisations used information from the 2011 Census in a variety
128
+ of ways.
129
+ </p>
130
+
131
+ <p>
132
+ For example, Bristol City Council used it to inform decisions on how to fund local housing improvements. It was also
133
+ essential for the charity Redbridge Council for Voluntary Services to help people from ethnic minority groups learn
134
+ more about dementia.
135
+ </p>
136
+
137
+ <p>
138
+ To read more about the benefits that information from the 2011 Census helped to create, visit the Office for
139
+ National Statistics (ONS) website.
140
+ </p>
141
+ <p>
142
+ The Census Coverage Survey (CCS) was a short, separate survey that we at the Office for National Statistics (ONS)
143
+ started six to eight weeks after Census Day.
144
+ </p>
145
+
146
+ <p>
147
+ The CCS helps make sure everyone is counted and our census results are as accurate as possible. It asked similar
148
+ questions to the main census, just fewer of them, at addresses in a selection of postcodes across England and Wales.
149
+ </p>
150
+
151
+ <p>The CCS has now closed.</p>
152
+ </section>
153
+ </div>
154
+ </div>
155
+ </div>
156
+ {% endblock %}