@ons/design-system 73.12.0 → 74.0.0-next.10

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 (34) hide show
  1. package/README.md +12 -2
  2. package/components/access-code/example-access-code-error.njk +1 -1
  3. package/components/access-code/example-access-code.njk +1 -1
  4. package/components/back-to-top/example-full-page-back-to-top.njk +1 -1
  5. package/components/breadcrumbs/_breadcrumbs.scss +4 -7
  6. package/components/breadcrumbs/_macro.njk +29 -25
  7. package/components/breadcrumbs/_macro.spec.js +39 -0
  8. package/components/breadcrumbs/example-breadcrumbs-wide.njk +52 -0
  9. package/components/header/_macro.njk +7 -3
  10. package/components/header/_macro.spec.js +27 -0
  11. package/components/hero/_macro.njk +3 -2
  12. package/components/hero/_macro.spec.js +36 -0
  13. package/components/hero/example-hero-dark-wide.njk +17 -0
  14. package/components/hero/example-hero-dark-with-external-breadcrumbs.njk +17 -21
  15. package/components/hero/example-hero-default-full-width.njk +16 -0
  16. package/components/hero/example-hero-default-with-external-breadcrumbs.njk +165 -169
  17. package/components/hero/example-hero-grey-with-external-breadcrumbs.njk +207 -211
  18. package/components/hero/example-hero-navy-blue-with-external-breadcrumbs.njk +163 -167
  19. package/components/hero/example-hero-pale-blue-with-external-breadcrumbs.njk +165 -169
  20. package/components/question/example-question-ccs.njk +1 -1
  21. package/components/question/example-question-fieldset.njk +1 -1
  22. package/components/question/example-question-interviewer-note.njk +1 -1
  23. package/components/question/example-question-no-fieldset.njk +1 -1
  24. package/components/relationships/example-relationships-error.njk +1 -1
  25. package/components/relationships/example-relationships-you.njk +1 -1
  26. package/components/relationships/example-relationships.njk +1 -1
  27. package/components/table-of-contents/example-table-of-contents-sticky-full-page-ordered.njk +1 -1
  28. package/components/table-of-contents/example-table-of-contents-sticky-full-page.njk +1 -1
  29. package/components/table-of-contents/table-of-contents.spec.js +4 -5
  30. package/css/main.css +1 -1
  31. package/layout/_template.njk +60 -47
  32. package/package.json +1 -1
  33. package/scss/objects/_page.scss +1 -1
  34. package/scss/objects/_spacing.scss +0 -4
package/README.md CHANGED
@@ -145,11 +145,21 @@ Checkout the branch locally and run:
145
145
 
146
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
147
 
148
+ ### Handling VR test failures
149
+
150
+ If the VR tests fail locally, you'll see an error starting with `Error: docker run --rm -i --add-host=host.docker.internal:host-gateway...`
151
+
152
+ `npx http-server backstop_data -p 8008 -o /html_report/` - View the report in your browser.
153
+
154
+ ### Approving VR test reference image changes
155
+
148
156
  `yarn test-visual:approve` - This will approve the failures/diff caught by the tests.
149
157
 
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.
158
+ Commit and approve the file changes in the normal way.
159
+
160
+ `git lfs push --all origin` - This will push the new reference images to Git LFS.
151
161
 
152
- You can then commit and push the updated references and your changes to your branch. The test images that would have been created when you ran `yarn test-visual` are gitignored and the new references images will be pushed to Git LFS.
162
+ You can then push the updated references and your changes to your branch. The test images that would have been created when you ran `yarn test-visual` are gitignored and the new references images will be pushed to Git LFS.
153
163
 
154
164
  If your local tests are failing but you have approved them, run `yarn test-visual:reference`. This will update the reference images locally on your machine.
155
165
 
@@ -14,7 +14,7 @@ layout: ~
14
14
  }
15
15
  %}
16
16
 
17
- {% block main %}
17
+ {% block mainContent %}
18
18
  {%
19
19
  call onsPanel({
20
20
  "title": "There is a problem with this page",
@@ -16,7 +16,7 @@ layout: ~
16
16
  }
17
17
  %}
18
18
 
19
- {% block main %}
19
+ {% block mainContent %}
20
20
  <h1 class="ons-u-mt-2xl">Start study</h1>
21
21
 
22
22
  {{
@@ -30,7 +30,7 @@ layout: ~
30
30
  }
31
31
  %}
32
32
 
33
- {% block main %}
33
+ {% block mainContent %}
34
34
  <h1 class="ons-u-fs-2xl">
35
35
  <span class="ons-u-fs-m ons-u-db ons-u-mb-2xs ons-u-lighter">Press releases</span>
36
36
  <span class="ons-u-vh">: </span>
@@ -3,7 +3,7 @@ $breadcrumb-chevron-height: 0.65rem;
3
3
  .ons-breadcrumbs-wrapper {
4
4
  position: relative;
5
5
  z-index: 10;
6
- margin-bottom: -2rem;
6
+ margin-bottom: -1rem;
7
7
  &--grey {
8
8
  background-color: var(--ons-color-banner-bg);
9
9
  }
@@ -14,9 +14,9 @@ $breadcrumb-chevron-height: 0.65rem;
14
14
 
15
15
  &--navy-blue {
16
16
  background-color: var(--ons-color-navy-blue-light);
17
- margin-bottom: -1.75rem;
17
+ margin-bottom: -0.75rem;
18
18
  @include mq(l) {
19
- margin-bottom: -3.25rem;
19
+ margin-bottom: -2.25rem;
20
20
  }
21
21
  }
22
22
 
@@ -48,15 +48,12 @@ $breadcrumb-chevron-height: 0.65rem;
48
48
  &--pale-blue {
49
49
  background-color: var(--ons-color-pale-blue);
50
50
  }
51
- .ons-breadcrumbs {
52
- padding: 1rem;
53
- }
54
51
  }
55
52
 
56
53
  .ons-breadcrumbs {
57
54
  align-items: center;
58
55
  display: flex;
59
- padding: 1rem 0;
56
+ padding: 1rem 0 0;
60
57
 
61
58
  &__items {
62
59
  margin: 0;
@@ -1,33 +1,37 @@
1
1
  {% from "components/icon/_macro.njk" import onsIcon %}
2
2
  {% macro onsBreadcrumbs(params) %}
3
3
  {% set breadcrumbs %}
4
- <nav
5
- class="ons-breadcrumbs{{ ' ons-container' if params.variant }}{{ ' ' + params.classes if params.classes else '' }}"
6
- aria-label="{{ params.ariaLabel | default('Breadcrumbs') }}"
7
- {% if params.id %}id="{{ params.id }}"{% endif %}
4
+ <div
5
+ class="ons-container{{ ' ons-container--full-width' if params.fullWidth else "" }}{{ ' ons-container--wide' if params.wide else "" }}"
8
6
  >
9
- <ol class="ons-breadcrumbs__items ons-u-fs-s">
10
- {%- for item in params.itemsList -%}
11
- <li
12
- class="ons-breadcrumbs__item{{ ' ' + item.itemClasses if item.itemClasses else '' }}"
13
- id="breadcrumb-{{ loop.index }}"
14
- >
15
- <a
16
- class="ons-breadcrumbs__link{{ ' ' + item.linkClasses if item.linkClasses else '' }}"
17
- href="{% if not isDesignSystemExample %}{{ item.url }}{% else %}#0{% endif %}"
18
- {% if item.id %}{{ ' ' }}id='{{ item.id }}'{% endif %}
19
- {% if item.attributes %}{% for attribute, value in (item.attributes.items() if item.attributes is mapping and item.attributes.items else item.attributes) %}{{ ' ' }}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
20
- >{{ item.text }}</a
7
+ <nav
8
+ class="ons-breadcrumbs{{ ' ' + params.classes if params.classes else '' }}"
9
+ aria-label="{{ params.ariaLabel | default('Breadcrumbs') }}"
10
+ {% if params.id %}id="{{ params.id }}"{% endif %}
11
+ >
12
+ <ol class="ons-breadcrumbs__items ons-u-fs-s">
13
+ {%- for item in params.itemsList -%}
14
+ <li
15
+ class="ons-breadcrumbs__item{{ ' ' + item.itemClasses if item.itemClasses else '' }}"
16
+ id="breadcrumb-{{ loop.index }}"
21
17
  >
22
- {{-
23
- onsIcon({
24
- "iconType": "chevron"
25
- })
26
- -}}
27
- </li>
28
- {%- endfor -%}
29
- </ol>
30
- </nav>
18
+ <a
19
+ class="ons-breadcrumbs__link{{ ' ' + item.linkClasses if item.linkClasses else '' }}"
20
+ href="{% if not isDesignSystemExample %}{{ item.url }}{% else %}#0{% endif %}"
21
+ {% if item.id %}{{ ' ' }}id='{{ item.id }}'{% endif %}
22
+ {% if item.attributes %}{% for attribute, value in (item.attributes.items() if item.attributes is mapping and item.attributes.items else item.attributes) %}{{ ' ' }}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
23
+ >{{ item.text }}</a
24
+ >
25
+ {{-
26
+ onsIcon({
27
+ "iconType": "chevron"
28
+ })
29
+ -}}
30
+ </li>
31
+ {%- endfor -%}
32
+ </ol>
33
+ </nav>
34
+ </div>
31
35
  {% endset %}
32
36
  {% if params.variant %}
33
37
  <div class="ons-breadcrumbs-wrapper ons-breadcrumbs-wrapper--{{ params.variant }}">{{ breadcrumbs | safe }}</div>
@@ -133,6 +133,45 @@ describe('FOR: Macro: Breadcrumbs', () => {
133
133
  });
134
134
  });
135
135
 
136
+ describe('GIVEN: Params: fullWidth', () => {
137
+ describe('WHEN: fullWidth is not provided', () => {
138
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS_REQUIRED_PARAMS));
139
+ test('THEN: renders container without full-width class', () => {
140
+ expect($('.ons-container').hasClass('ons-container--full-width')).toBe(false);
141
+ });
142
+ });
143
+ describe('WHEN: fullWidth is set to true', () => {
144
+ const $ = cheerio.load(
145
+ renderComponent('breadcrumbs', {
146
+ ...EXAMPLE_BREADCRUMBS_REQUIRED_PARAMS,
147
+ fullWidth: true,
148
+ }),
149
+ );
150
+ test('THEN: renders container with full-width class', () => {
151
+ expect($('.ons-container').hasClass('ons-container--full-width')).toBe(true);
152
+ });
153
+ });
154
+ });
155
+ describe('GIVEN: Params: wide', () => {
156
+ describe('WHEN: wide is not provided', () => {
157
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS_REQUIRED_PARAMS));
158
+ test('THEN: renders container without wide class', () => {
159
+ expect($('.ons-container').hasClass('ons-container--wide')).toBe(false);
160
+ });
161
+ });
162
+ describe('WHEN: wide is set to true', () => {
163
+ const $ = cheerio.load(
164
+ renderComponent('breadcrumbs', {
165
+ ...EXAMPLE_BREADCRUMBS_REQUIRED_PARAMS,
166
+ wide: true,
167
+ }),
168
+ );
169
+ test('THEN: renders container with wide class', () => {
170
+ expect($('.ons-container').hasClass('ons-container--wide')).toBe(true);
171
+ });
172
+ });
173
+ });
174
+
136
175
  describe('GIVEN: Params: variant', () => {
137
176
  describe('WHEN: variant is provided', () => {
138
177
  const $ = cheerio.load(
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: 'Example: Breadcrumbs override wide'
3
+ layout: ~
4
+ ---
5
+
6
+ {% from "components/hero/_macro.njk" import onsHero %}
7
+ {% from "components/breadcrumbs/_macro.njk" import onsBreadcrumbs %}
8
+ {% extends "layout/_template.njk" %}
9
+ {%
10
+ set pageConfig = {
11
+ "header": {
12
+ "title": 'Service title',
13
+ "mastheadLogoUrl": '#0',
14
+ "titleUrl": '#0',
15
+ "serviceLinks": {
16
+ "id": "service-links-internal",
17
+ "ariaLabel": 'Services menu',
18
+ "ariaListLabel": 'Menu',
19
+ "toggleServicesButton": {
20
+ "text": 'Account',
21
+ "ariaLabel": 'Toggle services menu'
22
+ },
23
+ "itemsList": [
24
+ {
25
+ "text": "Jacky Turner",
26
+ "iconType": 'person'
27
+ },
28
+ {
29
+ "text": "Sign out",
30
+ "url": "#0"
31
+ }
32
+ ]
33
+ }
34
+ },
35
+ "wide": true
36
+ }
37
+ %}
38
+
39
+ {% block breadcrumbs %}
40
+ {{
41
+ onsBreadcrumbs({
42
+ "wide": true,
43
+ "ariaLabel": 'Breadcrumbs',
44
+ "itemsList": [
45
+ {
46
+ "url": '/',
47
+ "text": 'Home'
48
+ }
49
+ ]
50
+ })
51
+ }}
52
+ {% endblock %}
@@ -6,6 +6,7 @@
6
6
  {% set titleTag = "h1" if params.titleAsH1 else "div" %}
7
7
  {% set openingTag = "<" + titleTag %}
8
8
  {% set closingTag = "</" + titleTag + ">" %}
9
+ {% set rootElementTag = "div" if params.useDivForRootElement else "header" %}
9
10
  {% set currentLanguageIsoCode = "en" %}
10
11
  {% set logoAltText = params.mastheadLogoAltText or params.mastheadLogo.altText %}
11
12
 
@@ -13,10 +14,11 @@
13
14
  {% set currentLanguage = params.language.languages | selectattr("current") | first %}
14
15
  {% set currentLanguageIsoCode = currentLanguage.isoCode %}
15
16
  {% endif %}
16
-
17
- <header
17
+ <!-- prettier-ignore-start -->
18
+ <{{ rootElementTag | safe }}
18
19
  class="ons-header{{ ' '+ params.classes if params.classes }}{% if params.variants is not string %}{% for variant in params.variants %}{{ ' ' }}ons-header--{{ variant }}{% endfor %}{% else %}{{ ' ' }}ons-header--{{ params.variants }}{% endif %}"
19
20
  >
21
+ <!-- prettier-ignore-end -->
20
22
  {{
21
23
  onsBrowserBanner({
22
24
  "lang": currentLanguageIsoCode,
@@ -535,5 +537,7 @@
535
537
  {% if params.navigation %}
536
538
  {{ onsNavigation(params) }}
537
539
  {% endif %}
538
- </header>
540
+ <!-- prettier-ignore-start -->
541
+ </{{ rootElementTag | safe }}>
542
+ <!-- prettier-ignore-end -->
539
543
  {% endmacro %}
@@ -36,6 +36,33 @@ describe('FOR: Macro: Header', () => {
36
36
  });
37
37
  });
38
38
 
39
+ describe('GIVEN: Params: useDivForRootElement', () => {
40
+ describe('WHEN: useDivForRootElement is not set', () => {
41
+ const $ = cheerio.load(
42
+ renderComponent('header', {
43
+ ...EXAMPLE_HEADER_BASIC,
44
+ }),
45
+ );
46
+ test('THEN: renders the root element as a header tag', () => {
47
+ expect($('header.ons-header').length).toBe(1);
48
+ });
49
+ });
50
+ describe('WHEN: useDivForRootElement is set to true', () => {
51
+ const $ = cheerio.load(
52
+ renderComponent('header', {
53
+ ...EXAMPLE_HEADER_BASIC,
54
+ useDivForRootElement: true,
55
+ }),
56
+ );
57
+ test('THEN: renders the root element as a div tag', () => {
58
+ expect($('div.ons-header').length).toBe(1);
59
+ });
60
+ test('THEN: does not render a header tag as the root element', () => {
61
+ expect($('header.ons-header').length).toBe(0);
62
+ });
63
+ });
64
+ });
65
+
39
66
  describe('Accessibility: search heading', () => {
40
67
  test('THEN: axe passes when search heading is present (params.search.links.heading)', async () => {
41
68
  const params = {
@@ -21,7 +21,9 @@
21
21
  {% endfor %}
22
22
  </div>
23
23
  {% endif %}
24
- <div class="ons-hero__container ons-container{{ ' ons-container--wide' if params.wide }}">
24
+ <div
25
+ class="ons-hero__container ons-container{{ ' ons-container--wide' if params.wide }}{{ ' ons-container--full-width' if params.fullWidth }}"
26
+ >
25
27
  <div class="ons-hero__details ons-grid__col ons-col-{{ detailsColumns }}@m col-10@s@m">
26
28
  <div class="ons-hero__content">
27
29
  <div class="ons-hero__title-container">
@@ -44,7 +46,6 @@
44
46
  {% elif params.richText %}
45
47
  <div class="ons-hero__richtext">{{ params.richText | safe }}</div>
46
48
  {% endif %}
47
-
48
49
  </div>
49
50
 
50
51
  {% if params.variants == "grey" and params.officialStatisticsBadge == true %}
@@ -34,6 +34,42 @@ describe('macro: hero', () => {
34
34
  expect($('.ons-hero--variant-b').length).toBe(1);
35
35
  });
36
36
 
37
+ it('has the `ons-container--wide` class on the container when `wide` is true', () => {
38
+ const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, wide: true }));
39
+
40
+ expect($('.ons-hero__container').hasClass('ons-container--wide')).toBe(true);
41
+ });
42
+
43
+ it('does not have the `ons-container--wide` class on the container when `wide` is false', () => {
44
+ const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, wide: false }));
45
+
46
+ expect($('.ons-hero__container').hasClass('ons-container--wide')).toBe(false);
47
+ });
48
+
49
+ it('does not have the `ons-container--wide` class on the container when `wide` is not set', () => {
50
+ const $ = cheerio.load(renderComponent('hero', EXAMPLE_HERO));
51
+
52
+ expect($('.ons-hero__container').hasClass('ons-container--wide')).toBe(false);
53
+ });
54
+
55
+ it('has the `ons-container--full-width` class on the container when `fullWidth` is true', () => {
56
+ const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, fullWidth: true }));
57
+
58
+ expect($('.ons-hero__container').hasClass('ons-container--full-width')).toBe(true);
59
+ });
60
+
61
+ it('does not have the `ons-container--full-width` class on the container when `fullWidth` is false', () => {
62
+ const $ = cheerio.load(renderComponent('hero', { ...EXAMPLE_HERO, fullWidth: false }));
63
+
64
+ expect($('.ons-hero__container').hasClass('ons-container--full-width')).toBe(false);
65
+ });
66
+
67
+ it('does not have the `ons-container--full-width` class on the container when `fullWidth` is not set', () => {
68
+ const $ = cheerio.load(renderComponent('hero', EXAMPLE_HERO));
69
+
70
+ expect($('.ons-hero__container').hasClass('ons-container--full-width')).toBe(false);
71
+ });
72
+
37
73
  it('has expected `title`', () => {
38
74
  const $ = cheerio.load(renderComponent('hero', EXAMPLE_HERO));
39
75
 
@@ -0,0 +1,17 @@
1
+ ---
2
+ 'fullWidth': true
3
+ ---
4
+
5
+ {% from "components/hero/_macro.njk" import onsHero %}
6
+ {{
7
+ onsHero({
8
+ "title": 'Design and build digital services for the ONS',
9
+ "text": 'Everything you need to make accessible, consistent digital products',
10
+ "button": {
11
+ "url": '#0',
12
+ "text": 'Get started'
13
+ },
14
+ "variants": 'dark',
15
+ "wide": true
16
+ })
17
+ }}
@@ -4,7 +4,6 @@ layout: ~
4
4
  ---
5
5
 
6
6
  {% from "components/hero/_macro.njk" import onsHero %}
7
- {% from "components/breadcrumbs/_macro.njk" import onsBreadcrumbs %}
8
7
  {% extends "layout/_template.njk" %}
9
8
  {%
10
9
  set pageConfig = {
@@ -162,12 +161,8 @@ layout: ~
162
161
  }
163
162
  ]
164
163
  }
165
- }
166
- }
167
- %}
168
- {% block pageContent %}
169
- {{
170
- onsBreadcrumbs({
164
+ },
165
+ "breadcrumbs": {
171
166
  "ariaLabel": 'Breadcrumbs',
172
167
  "variant": "dark",
173
168
  "itemsList": [
@@ -175,20 +170,21 @@ layout: ~
175
170
  "url": '/',
176
171
  "text": 'Home'
177
172
  }
178
- ]
173
+ ]
174
+ }
175
+ }
176
+ %}
177
+
178
+ {% block hero %}
179
+ {{
180
+ onsHero({
181
+ "title": 'Design and build digital services for the ONS',
182
+ "text": 'Everything you need to make accessible, consistent digital products',
183
+ "button": {
184
+ "url": '#0',
185
+ "text": 'Get started'
186
+ },
187
+ "variants": 'dark'
179
188
  })
180
189
  }}
181
- <main id="main-content">
182
- {{
183
- onsHero({
184
- "title": 'Design and build digital services for the ONS',
185
- "text": 'Everything you need to make accessible, consistent digital products',
186
- "button": {
187
- "url": '#0',
188
- "text": 'Get started'
189
- },
190
- "variants": 'dark'
191
- })
192
- }}
193
- </main>
194
190
  {% endblock %}
@@ -0,0 +1,16 @@
1
+ ---
2
+ 'fullWidth': true
3
+ ---
4
+
5
+ {% from "components/hero/_macro.njk" import onsHero %}
6
+ {{
7
+ onsHero({
8
+ "title": 'Design and build digital services for the ONS',
9
+ "text": 'Everything you need to make accessible, consistent digital products',
10
+ "button": {
11
+ "url": '#0',
12
+ "text": 'Get started'
13
+ },
14
+ "fullWidth": true
15
+ })
16
+ }}