@ons/design-system 72.1.0 → 72.1.2

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 (53) hide show
  1. package/README.md +1 -1
  2. package/components/accordion/_macro.spec.js +2 -2
  3. package/components/address-input/_macro.spec.js +245 -322
  4. package/components/address-input/autosuggest.address.spec.js +16 -14
  5. package/components/address-output/_macro.spec.js +121 -74
  6. package/components/address-output/_test_examples.js +8 -0
  7. package/components/autosuggest/_macro.spec.js +373 -184
  8. package/components/back-to-top/back-to-top.dom.js +4 -4
  9. package/components/back-to-top/back-to-top.js +1 -1
  10. package/components/browser-banner/_macro.spec.js +11 -11
  11. package/components/button/_button.scss +1 -1
  12. package/components/button/_macro.njk +1 -1
  13. package/components/button/_macro.spec.js +405 -351
  14. package/components/button/example-button-group.njk +1 -0
  15. package/components/checkboxes/_checkbox.scss +3 -3
  16. package/components/description-list/_description-list.scss +40 -9
  17. package/components/description-list/_macro.njk +20 -12
  18. package/components/description-list/_macro.spec.js +11 -1
  19. package/components/description-list/example-inline-description-list.njk +58 -0
  20. package/components/details/_details.scss +1 -2
  21. package/components/details/example-details-open.njk +10 -0
  22. package/components/external-link/_macro.spec.js +66 -69
  23. package/components/external-link/_test_examples.js +4 -0
  24. package/components/feedback/_macro.spec.js +109 -80
  25. package/components/feedback/_test_examples.js +17 -0
  26. package/components/field/_macro.spec.js +106 -69
  27. package/components/header/_macro.njk +92 -90
  28. package/components/header/_macro.spec.js +10 -0
  29. package/components/header/example-header-basic.njk +11 -0
  30. package/components/hero/_hero.scss +239 -2
  31. package/components/hero/_macro.njk +7 -0
  32. package/components/hero/_macro.spec.js +5 -0
  33. package/components/hero/example-hero-navy-blue.njk +14 -0
  34. package/components/section-navigation/_macro.njk +9 -6
  35. package/components/table-of-contents/_macro.njk +3 -3
  36. package/components/table-of-contents/_macro.spec.js +3 -3
  37. package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
  38. package/components/table-of-contents/table-of-contents.dom.js +13 -0
  39. package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
  40. package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
  41. package/components/tabs/_tabs.scss +10 -11
  42. package/components/tabs/tabs.js +3 -3
  43. package/components/timeout-modal/timeout-modal.spec.js +1 -1
  44. package/css/main.css +1 -1
  45. package/js/main.js +1 -1
  46. package/package.json +1 -1
  47. package/scripts/main.es5.js +1 -1
  48. package/scripts/main.js +1 -1
  49. package/scss/main.scss +1 -1
  50. package/scss/utilities/_margin.scss +4 -0
  51. package/scss/utilities/_padding.scss +4 -0
  52. package/scss/vars/_colors.scss +2 -0
  53. package/components/table-of-contents/toc.dom.js +0 -13
@@ -5,91 +5,128 @@ import * as cheerio from 'cheerio';
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
7
 
8
- const EXAMPLE_FIELD_BASIC = {
9
- id: 'example-field',
10
- };
11
-
12
- describe('macro: field', () => {
13
- it('passes jest-axe checks', async () => {
14
- const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC));
15
-
16
- const results = await axe($.html());
17
- expect(results).toHaveNoViolations();
8
+ describe('FOR: Macro: Field', () => {
9
+ describe('GIVEN: Params: none', () => {
10
+ describe('WHEN: no params are provided', () => {
11
+ const $ = cheerio.load(renderComponent('field'));
12
+ test('THEN: passes jest-axe checks', async () => {
13
+ const results = await axe($.html());
14
+ expect(results).toHaveNoViolations();
15
+ });
16
+ });
18
17
  });
19
18
 
20
- it('has the provided `id` attribute', () => {
21
- const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC));
22
-
23
- expect($('.ons-field').attr('id')).toBe('example-field');
19
+ describe('GIVEN: Params: id', () => {
20
+ describe('WHEN: id is provided', () => {
21
+ const $ = cheerio.load(
22
+ renderComponent('field', {
23
+ id: 'example-field',
24
+ }),
25
+ );
26
+ test('THEN: renders with the provided id', () => {
27
+ expect($('.ons-field').attr('id')).toBe('example-field');
28
+ });
29
+ });
24
30
  });
25
31
 
26
- it('has additionally provided style classes', () => {
27
- const $ = cheerio.load(
28
- renderComponent('field', {
29
- ...EXAMPLE_FIELD_BASIC,
30
- classes: 'extra-class another-extra-class',
31
- }),
32
- );
33
-
34
- expect($('.ons-field').hasClass('extra-class')).toBe(true);
35
- expect($('.ons-field').hasClass('another-extra-class')).toBe(true);
32
+ describe('GIVEN: Params: classes', () => {
33
+ describe('WHEN: additional style classes are provided', () => {
34
+ const $ = cheerio.load(
35
+ renderComponent('field', {
36
+ classes: 'extra-class another-extra-class',
37
+ }),
38
+ );
39
+ test('THEN: renders with provided classes', () => {
40
+ expect($('.ons-field').hasClass('extra-class')).toBe(true);
41
+ expect($('.ons-field').hasClass('another-extra-class')).toBe(true);
42
+ });
43
+ });
36
44
  });
37
45
 
38
- it('has correct class when `inline` is provided', () => {
39
- const $ = cheerio.load(
40
- renderComponent('field', {
41
- ...EXAMPLE_FIELD_BASIC,
42
- inline: true,
43
- }),
44
- );
45
-
46
- expect($('.ons-field').hasClass('ons-field--inline')).toBe(true);
46
+ describe('GIVEN: Params: inline', () => {
47
+ describe('WHEN: inline is provided', () => {
48
+ const $ = cheerio.load(
49
+ renderComponent('field', {
50
+ inline: true,
51
+ }),
52
+ );
53
+ test('THEN: renders with the inline class', () => {
54
+ expect($('.ons-field').hasClass('ons-field--inline')).toBe(true);
55
+ });
56
+ });
47
57
  });
48
58
 
49
- it('has additionally provided `attributes`', () => {
50
- const $ = cheerio.load(
51
- renderComponent('field', {
52
- ...EXAMPLE_FIELD_BASIC,
53
- attributes: {
54
- a: 123,
55
- b: 456,
56
- },
57
- }),
58
- );
59
-
60
- expect($('.ons-field').attr('a')).toBe('123');
61
- expect($('.ons-field').attr('b')).toBe('456');
59
+ describe('GIVEN: Params: attributes', () => {
60
+ describe('WHEN: custom attributes are provided', () => {
61
+ const $ = cheerio.load(
62
+ renderComponent('field', {
63
+ attributes: {
64
+ a: 123,
65
+ b: 456,
66
+ },
67
+ }),
68
+ );
69
+ test('THEN: renders with additionally provided attributes', () => {
70
+ expect($('.ons-field').attr('a')).toBe('123');
71
+ expect($('.ons-field').attr('b')).toBe('456');
72
+ });
73
+ });
62
74
  });
63
75
 
64
- it('has the correct element with `dontWrap`', () => {
65
- const $ = cheerio.load(
66
- renderComponent('field', {
67
- ...EXAMPLE_FIELD_BASIC,
68
- dontWrap: true,
69
- }),
70
- );
71
-
72
- expect($('.ons-field').length).toBe(0);
73
- });
76
+ describe('GIVEN: Params: dontWrap', () => {
77
+ describe('WHEN: dontWrap is set to true', () => {
78
+ const $ = cheerio.load(
79
+ renderComponent('field', {
80
+ dontWrap: true,
81
+ }),
82
+ );
83
+ test('THEN: renders the content without being wrapped in a field div', () => {
84
+ expect($('.ons-field').length).toBe(0);
85
+ });
86
+ });
74
87
 
75
- it('calls with content', () => {
76
- const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC, 'Example content...'));
88
+ describe('WHEN: dontWrap is set to false', () => {
89
+ const $ = cheerio.load(
90
+ renderComponent('field', {
91
+ dontWrap: false,
92
+ }),
93
+ );
94
+ test('THEN: renders the content wrapped in a field div', () => {
95
+ expect($('.ons-field').length).toBe(1);
96
+ });
97
+ });
77
98
 
78
- const content = $('.ons-field').html().trim();
79
- expect(content).toEqual(expect.stringContaining('Example content...'));
99
+ describe('WHEN: dontWrap is not provided', () => {
100
+ const $ = cheerio.load(renderComponent('field', {}));
101
+ test('THEN: renders the content wrapped in a field div', () => {
102
+ expect($('.ons-field').length).toBe(1);
103
+ });
104
+ });
80
105
  });
81
106
 
82
- it('calls the error component when `error` is provided', () => {
83
- const faker = templateFaker();
84
- const errorSpy = faker.spy('error');
85
-
86
- faker.renderComponent('field', {
87
- ...EXAMPLE_FIELD_BASIC,
88
- error: { text: 'There is an error' },
107
+ describe('GIVEN: Params: error', () => {
108
+ describe('WHEN: error is provided', () => {
109
+ const faker = templateFaker();
110
+ const errorSpy = faker.spy('error');
111
+
112
+ faker.renderComponent('field', {
113
+ error: { text: 'There is an error' },
114
+ });
115
+ test('THEN" calls the error component', () => {
116
+ expect(errorSpy.occurrences[0]).toEqual({
117
+ text: 'There is an error',
118
+ });
119
+ });
89
120
  });
121
+ });
90
122
 
91
- expect(errorSpy.occurrences[0]).toEqual({
92
- text: 'There is an error',
123
+ describe('GIVEN: Content', () => {
124
+ describe('WHEN: field is called with content provided', () => {
125
+ const $ = cheerio.load(renderComponent('field', {}, 'Example content...'));
126
+ const content = $('.ons-field').html().trim();
127
+ test('THEN: renders the field with the provided content', () => {
128
+ expect(content).toEqual(expect.stringContaining('Example content...'));
129
+ });
93
130
  });
94
131
  });
95
132
  });
@@ -218,118 +218,120 @@
218
218
  </nav>
219
219
  {% endif %}
220
220
  </div>
221
- <div class="ons-header__main">
222
- <div class="ons-container{{ ' ons-container--full-width' if params.fullWidth }}{{ ' ons-container--wide' if params.wide }}">
223
- <div
224
- class="ons-grid ons-grid-flex ons-grid-flex--between ons-grid-flex--vertical-center ons-grid-flex--no-wrap{{ ' ons-grid--gutterless' if not params.button }}"
225
- >
226
- <div class="ons-grid__col ons-col-auto ons-u-flex-shrink">
227
- {% if params.titleLogo.large %}
221
+ {% if params.variants != "basic" %}
222
+ <div class="ons-header__main">
223
+ <div class="ons-container{{ ' ons-container--full-width' if params.fullWidth }}{{ ' ons-container--wide' if params.wide }}">
224
+ <div
225
+ class="ons-grid ons-grid-flex ons-grid-flex--between ons-grid-flex--vertical-center ons-grid-flex--no-wrap{{ ' ons-grid--gutterless' if not params.button }}"
226
+ >
227
+ <div class="ons-grid__col ons-col-auto ons-u-flex-shrink">
228
+ {% if params.titleLogo.large %}
228
229
 
229
- {% set title %}
230
- <div
231
- class="ons-header__title-logo ons-header__title-logo--large{{ ' ' + params.titleLogo.classes if params.titleLogo.classes else '' }}{{ ' ons-u-d-no@2xs@s' if params.titleLogo.small }}"
232
- >
233
- {{ params.titleLogo.large | safe }}
234
- </div>
235
- {% if params.titleLogo.small %}
230
+ {% set title %}
236
231
  <div
237
- class="ons-header__title-logo ons-header__title-logo--small ons-u-d-no@s{{ ' ' + params.titleLogo.classes if params.titleLogo.classes else '' }}"
232
+ class="ons-header__title-logo ons-header__title-logo--large{{ ' ' + params.titleLogo.classes if params.titleLogo.classes else '' }}{{ ' ons-u-d-no@2xs@s' if params.titleLogo.small }}"
238
233
  >
239
- {{ params.titleLogo.small | safe }}
234
+ {{ params.titleLogo.large | safe }}
240
235
  </div>
241
- {% endif %}
242
- {% endset %}
236
+ {% if params.titleLogo.small %}
237
+ <div
238
+ class="ons-header__title-logo ons-header__title-logo--small ons-u-d-no@s{{ ' ' + params.titleLogo.classes if params.titleLogo.classes else '' }}"
239
+ >
240
+ {{ params.titleLogo.small | safe }}
241
+ </div>
242
+ {% endif %}
243
+ {% endset %}
243
244
 
244
- {% if params.titleUrl %}
245
- <a class="ons-header__title-logo-link" href="{{ params.titleUrl }}">{{ title | safe }}</a>
245
+ {% if params.titleUrl %}
246
+ <a class="ons-header__title-logo-link" href="{{ params.titleUrl }}">{{ title | safe }}</a>
247
+ {% else %}
248
+ {{ title | safe }}
249
+ {% endif %}
246
250
  {% else %}
247
- {{ title | safe }}
248
- {% endif %}
249
- {% else %}
250
251
 
251
- {% set title %}
252
- {{ openingTag | safe }}
253
- class="ons-header__title">{{ params.title }}{{ closingTag | safe }}
254
- {% endset %}
252
+ {% set title %}
253
+ {{ openingTag | safe }}
254
+ class="ons-header__title">{{ params.title }}{{ closingTag | safe }}
255
+ {% endset %}
255
256
 
256
- {% if params.titleUrl %}
257
- <a class="ons-header__title-link" href="{{ params.titleUrl }}">{{ title | safe }}</a>
258
- {% else %}
259
- {{ title | safe }}
257
+ {% if params.titleUrl %}
258
+ <a class="ons-header__title-link" href="{{ params.titleUrl }}">{{ title | safe }}</a>
259
+ {% else %}
260
+ {{ title | safe }}
261
+ {% endif %}
260
262
  {% endif %}
261
- {% endif %}
262
- {% if params.description %}
263
- <p class="ons-header__description">{{ params.description }}</p>
264
- {% endif %}
265
- </div>
263
+ {% if params.description %}
264
+ <p class="ons-header__description">{{ params.description }}</p>
265
+ {% endif %}
266
+ </div>
266
267
 
267
- {% if params.button %}
268
- {% if params.variants == 'neutral' %}
269
- {% set buttonVariant = "ghost-dark" %}
270
- {% else %}
271
- {% set buttonVariant = "ghost" %}
268
+ {% if params.button %}
269
+ {% if params.variants == 'neutral' %}
270
+ {% set buttonVariant = "ghost-dark" %}
271
+ {% else %}
272
+ {% set buttonVariant = "ghost" %}
273
+ {% endif %}
274
+ <div class="ons-grid__col ons-col-auto ons-u-flex-no-shrink">
275
+ {{
276
+ onsButton({
277
+ "text": params.button.text,
278
+ "classes": "ons-u-d-no@2xs@l" if params.navigation else "ons-u-d-no@2xs@m",
279
+ "variants": buttonVariant,
280
+ "name": params.button.name,
281
+ "attributes": params.button.attributes,
282
+ "url": params.button.url,
283
+ "iconType": "exit",
284
+ "iconPosition": "after"
285
+ })
286
+ }}
287
+ </div>
272
288
  {% endif %}
273
- <div class="ons-grid__col ons-col-auto ons-u-flex-no-shrink">
274
- {{
275
- onsButton({
276
- "text": params.button.text,
277
- "classes": "ons-u-d-no@2xs@l" if params.navigation else "ons-u-d-no@2xs@m",
278
- "variants": buttonVariant,
279
- "name": params.button.name,
280
- "attributes": params.button.attributes,
281
- "url": params.button.url,
282
- "iconType": "exit",
283
- "iconPosition": "after"
284
- })
285
- }}
286
- </div>
287
- {% endif %}
288
- {% if params.navigation or params.siteSearchAutosuggest %}
289
- <div class="ons-grid__col ons-col-auto ons-u-flex-no-shrink">
290
- {% if params.siteSearchAutosuggest %}
291
- {% if params.variants == 'neutral' %}
292
- {% set buttonVariant = ["small", "ghost-dark"] %}
293
- {% else %}
294
- {% set buttonVariant = ["small", "ghost"] %}
289
+ {% if params.navigation or params.siteSearchAutosuggest %}
290
+ <div class="ons-grid__col ons-col-auto ons-u-flex-no-shrink">
291
+ {% if params.siteSearchAutosuggest %}
292
+ {% if params.variants == 'neutral' %}
293
+ {% set buttonVariant = ["small", "ghost-dark"] %}
294
+ {% else %}
295
+ {% set buttonVariant = ["small", "ghost"] %}
296
+ {% endif %}
297
+ <span class="ons-grid ons-u-d-no@2xs@xs ons-u-ml-no ons-u-d-no@l">
298
+ {{
299
+ onsButton({
300
+ "text": "Search",
301
+ "classes": "ons-btn--search ons-u-ml-2xs ons-u-d-no ons-js-toggle-search",
302
+ "variants": buttonVariant,
303
+ "iconType": "search",
304
+ "iconPosition": "only",
305
+ "attributes": {
306
+ "aria-label": "Toggle search" ,
307
+ "aria-controls": "ons-site-search",
308
+ "aria-expanded": "false"
309
+ }
310
+ })
311
+ }}
312
+ </span>
295
313
  {% endif %}
296
- <span class="ons-grid ons-u-d-no@2xs@xs ons-u-ml-no ons-u-d-no@l">
314
+ {% if params.navigation.toggleNavigationButton %}
315
+ {% set buttonVariant = ["mobile", "ghost"] %}
297
316
  {{
298
317
  onsButton({
299
- "text": "Search",
300
- "classes": "ons-btn--search ons-u-ml-2xs ons-u-d-no ons-js-toggle-search",
318
+ "text": params.navigation.toggleNavigationButton.text,
319
+ "classes": "ons-u-ml-2xs ons-u-d-no ons-js-navigation-button ons-u-d-no@l",
301
320
  "variants": buttonVariant,
302
- "iconType": "search",
303
- "iconPosition": "only",
304
321
  "attributes": {
305
- "aria-label": "Toggle search" ,
306
- "aria-controls": "ons-site-search",
322
+ "aria-label": params.navigation.toggleNavigationButton.ariaLabel | default("Toggle main menu") ,
323
+ "aria-controls": params.navigation.id,
307
324
  "aria-expanded": "false"
308
325
  }
309
326
  })
310
327
  }}
311
- </span>
312
- {% endif %}
313
- {% if params.navigation.toggleNavigationButton %}
314
- {% set buttonVariant = ["mobile", "ghost"] %}
315
- {{
316
- onsButton({
317
- "text": params.navigation.toggleNavigationButton.text,
318
- "classes": "ons-u-ml-2xs ons-u-d-no ons-js-navigation-button ons-u-d-no@l",
319
- "variants": buttonVariant,
320
- "attributes": {
321
- "aria-label": params.navigation.toggleNavigationButton.ariaLabel | default("Toggle main menu") ,
322
- "aria-controls": params.navigation.id,
323
- "aria-expanded": "false"
324
- }
325
- })
326
- }}
327
- {% endif %}
328
- </div>
329
- {% endif %}
328
+ {% endif %}
329
+ </div>
330
+ {% endif %}
331
+ </div>
330
332
  </div>
331
333
  </div>
332
- </div>
334
+ {% endif %}
333
335
  {% if params.navigation %}
334
336
  {{ onsNavigation(params) }}
335
337
  {% endif %}
@@ -43,6 +43,16 @@ describe('FOR: Macro: Header', () => {
43
43
  expect($('.ons-header--variant-b').length).toBe(1);
44
44
  });
45
45
  });
46
+ describe('WHEN: variants is set to basic', () => {
47
+ test('THEN: does not render the main part of the header', () => {
48
+ const $ = cheerio.load(
49
+ renderComponent('header', {
50
+ variants: 'basic',
51
+ }),
52
+ );
53
+ expect($('.ons-header > .ons-header__main').length).toBe(0);
54
+ });
55
+ });
46
56
  });
47
57
  describe('GIVEN: Params: classes', () => {
48
58
  describe('WHEN: classes are provided', () => {
@@ -0,0 +1,11 @@
1
+ ---
2
+ 'fullWidth': true
3
+ ---
4
+
5
+ {% from "components/header/_macro.njk" import onsHeader %}
6
+
7
+ {{
8
+ onsHeader({
9
+ "variants": 'basic'
10
+ })
11
+ }}