@ons/design-system 53.0.4 → 54.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 (42) hide show
  1. package/components/accordion/_macro.njk +2 -3
  2. package/components/accordion/_macro.spec.js +3 -40
  3. package/components/accordion/accordion.dom.js +19 -0
  4. package/components/{collapsible/collapsible.group.js → accordion/accordion.js} +12 -5
  5. package/components/accordion/accordion.spec.js +56 -51
  6. package/components/autosuggest/_autosuggest.scss +1 -1
  7. package/components/browser-banner/_browser-banner.scss +39 -0
  8. package/components/browser-banner/_macro.njk +17 -0
  9. package/components/browser-banner/_macro.spec.js +83 -0
  10. package/components/checkboxes/_macro.njk +1 -1
  11. package/components/collapsible/_collapsible.scss +58 -85
  12. package/components/collapsible/_macro.njk +6 -39
  13. package/components/collapsible/_macro.spec.js +0 -53
  14. package/components/collapsible/collapsible.dom.js +3 -12
  15. package/components/collapsible/collapsible.js +3 -45
  16. package/components/collapsible/collapsible.spec.js +6 -139
  17. package/components/cookies-banner/_cookies-banner.scss +15 -7
  18. package/components/cookies-banner/_macro.njk +66 -22
  19. package/components/cookies-banner/_macro.spec.js +172 -114
  20. package/components/cookies-banner/cookies-banner.js +35 -13
  21. package/components/cookies-banner/cookies-banner.spec.js +58 -54
  22. package/components/duration/_macro.njk +1 -1
  23. package/components/duration/_macro.spec.js +1 -1
  24. package/components/fieldset/_fieldset.scss +3 -6
  25. package/components/header/_macro.njk +7 -0
  26. package/components/input/_macro.njk +20 -15
  27. package/components/input/_macro.spec.js +56 -0
  28. package/components/label/_label.scss +1 -1
  29. package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +2 -0
  30. package/components/mutually-exclusive/mutually-exclusive.number.spec.js +1 -0
  31. package/css/census.css +1 -1
  32. package/css/error.css +1 -1
  33. package/css/ids.css +1 -1
  34. package/css/main.css +1 -1
  35. package/js/main.js +1 -0
  36. package/layout/_template.njk +1 -0
  37. package/package.json +1 -1
  38. package/scripts/main.es5.js +1 -1
  39. package/scripts/main.js +2 -2
  40. package/scss/main.scss +1 -0
  41. package/scss/objects/_page.scss +1 -1
  42. package/scss/vars/_colors.scss +1 -0
@@ -1,10 +1,6 @@
1
1
  import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
2
 
3
- const EXAMPLE_COOKIES_BANNER_PAGE = renderComponent('cookies-banner', {
4
- statementTitle: 'Tell us whether you accept cookies',
5
- statementText: 'We use <a href="#0">cookies to collect information</a> about how you use census.gov.uk.',
6
- confirmationText: 'You’ve accepted all cookies. You can <a href="#0">change your cookie preferences</a> at any time.',
7
- });
3
+ const EXAMPLE_COOKIES_BANNER_PAGE = renderComponent('cookies-banner', {});
8
4
 
9
5
  describe('script: cookies-banner', () => {
10
6
  beforeEach(async () => {
@@ -18,73 +14,81 @@ describe('script: cookies-banner', () => {
18
14
  const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
19
15
  expect(displayStyle).toBe('block');
20
16
  });
17
+ describe.each([
18
+ ['accepting cookies', 'accept', true],
19
+ ['rejecting cookies', 'reject', false],
20
+ ])('action: %s', (_, action, value) => {
21
+ it(`sets all cookies to ${value} when ${_}`, async () => {
22
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
23
+
24
+ await page.click(`.ons-js-${action}-cookies`);
25
+
26
+ const cookies = await page.cookies();
27
+ const ons_cookie_policy = cookies.find(cookie => cookie.name === 'ons_cookie_policy');
28
+ const policy = JSON.parse(ons_cookie_policy.value.replace(/'/g, '"'));
29
+
30
+ expect(policy).toEqual({
31
+ essential: true,
32
+ settings: value,
33
+ usage: value,
34
+ campaigns: value,
35
+ });
36
+ });
21
37
 
22
- it('sets all cookies to true when accepting cookies', async () => {
23
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
38
+ it(`sets seen cookie message when ${_}`, async () => {
39
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
24
40
 
25
- await page.click('.ons-js-accept-cookies');
41
+ await page.click(`.ons-js-${action}-cookies`);
26
42
 
27
- const cookies = await page.cookies();
28
- const ons_cookie_policy = cookies.find(cookie => cookie.name === 'ons_cookie_policy');
29
- const policy = JSON.parse(ons_cookie_policy.value.replace(/'/g, '"'));
43
+ const cookies = await page.cookies();
44
+ const ons_cookie_message_displayed = cookies.find(cookie => cookie.name === 'ons_cookie_message_displayed');
30
45
 
31
- expect(policy).toEqual({
32
- essential: true,
33
- settings: true,
34
- usage: true,
35
- campaigns: true,
46
+ expect(ons_cookie_message_displayed.value).toBe('true');
36
47
  });
37
- });
38
-
39
- it('sets seen cookie message when accepting cookies', async () => {
40
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
41
48
 
42
- await page.click('.ons-js-accept-cookies');
49
+ it(`should hide the primary message when pressing the ${action} button`, async () => {
50
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
43
51
 
44
- const cookies = await page.cookies();
45
- const ons_cookie_message_displayed = cookies.find(cookie => cookie.name === 'ons_cookie_message_displayed');
52
+ await page.click(`.ons-js-${action}-cookies`);
46
53
 
47
- expect(ons_cookie_message_displayed.value).toBe('true');
48
- });
54
+ const displayStyle = await page.$eval('.ons-cookies-banner__primary', node =>
55
+ window.getComputedStyle(node).getPropertyValue('display'),
56
+ );
57
+ expect(displayStyle).toBe('none');
58
+ });
49
59
 
50
- it('should hide the primary message when pressing the accept button', async () => {
51
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
60
+ it(`should show the secondary message when pressing the ${action} button`, async () => {
61
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
52
62
 
53
- await page.click('.ons-js-accept-cookies');
63
+ await page.click(`.ons-js-${action}-cookies`);
54
64
 
55
- const displayStyle = await page.$eval('.ons-cookies-banner__primary', node =>
56
- window.getComputedStyle(node).getPropertyValue('display'),
57
- );
58
- expect(displayStyle).toBe('none');
65
+ const displayStyle = await page.$eval('.ons-cookies-banner__confirmation', node =>
66
+ window.getComputedStyle(node).getPropertyValue('display'),
67
+ );
68
+ expect(displayStyle).not.toBe('none');
69
+ });
59
70
  });
60
71
 
61
- it('should show the secondary message when pressing the accept button', async () => {
62
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
63
-
64
- await page.click('.ons-js-accept-cookies');
65
-
66
- const displayStyle = await page.$eval('.ons-cookies-banner__confirmation', node =>
67
- window.getComputedStyle(node).getPropertyValue('display'),
68
- );
69
- expect(displayStyle).not.toBe('none');
70
- });
71
- //...
72
- it('should hide the secondary message when pressing the hide button', async () => {
73
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
72
+ describe('confirmation banner', () => {
73
+ it('should hide the confirmation message when pressing the hide button', async () => {
74
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
74
75
 
75
- await page.click('.ons-js-accept-cookies');
76
- await page.click('.ons-js-hide-button');
76
+ await page.click('.ons-js-accept-cookies');
77
+ await page.click('.ons-js-hide-button');
77
78
 
78
- const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
79
- expect(displayStyle).toBe('none');
79
+ const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
80
+ expect(displayStyle).toBe('none');
81
+ });
80
82
  });
81
83
 
82
- it('does not show the banner if user has acknowledged the banner previously and consent cookie is present', async () => {
83
- await page.setCookie({ name: 'ons_cookie_message_displayed', value: 'true' });
84
+ describe('cookie preferences confirmed', () => {
85
+ it('does not show the banner if user has acknowledged the banner previously and consent cookie is present', async () => {
86
+ await page.setCookie({ name: 'ons_cookie_message_displayed', value: 'true' });
84
87
 
85
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
88
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
86
89
 
87
- const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
88
- expect(displayStyle).toBe('none');
90
+ const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
91
+ expect(displayStyle).toBe('none');
92
+ });
89
93
  });
90
94
  });
@@ -84,7 +84,7 @@
84
84
  "id": params.id,
85
85
  "legend": params.legendOrLabel,
86
86
  "description": params.description,
87
- "legendClasses": 'ons-u-mb-xs ' + (params.legendClasses if params.legendClasses else ''),
87
+ "legendClasses": params.legendClasses,
88
88
  "error": params.error,
89
89
  "legendIsQuestionTitle": params.legendIsQuestionTitle,
90
90
  "dontWrap": params.dontWrap
@@ -127,7 +127,7 @@ describe('macro: duration', () => {
127
127
  id: 'duration',
128
128
  legend: 'How long have you lived at this address?',
129
129
  description: 'Enter “0” into the years field if you have lived at this address for less than a year',
130
- legendClasses: 'ons-u-mb-xs custom-legend-class',
130
+ legendClasses: 'custom-legend-class',
131
131
  dontWrap: true,
132
132
  legendIsQuestionTitle: true,
133
133
  error: false,
@@ -1,6 +1,7 @@
1
1
  .ons-fieldset {
2
2
  &__legend {
3
- @extend .ons-label;
3
+ font-weight: $font-weight-bold;
4
+ margin: 0 0 0.6rem;
4
5
  }
5
6
 
6
7
  &__description:not(&__description--title) {
@@ -11,14 +12,10 @@
11
12
  font-weight: normal;
12
13
  }
13
14
 
14
- .ons-fieldset {
15
- &__legend {
16
- margin: 0 0 0.6rem;
17
- }
15
+ > * .ons-fieldset {
18
16
  .ons-fieldset {
19
17
  &__legend {
20
18
  font-weight: normal;
21
- margin: 0;
22
19
  }
23
20
  }
24
21
  }
@@ -2,6 +2,7 @@
2
2
  {% from "components/button/_macro.njk" import onsButton %}
3
3
  {% from "components/icons/_macro.njk" import onsIcon %}
4
4
  {% from "components/navigation/_macro.njk" import onsNavigation %}
5
+ {% from "components/browser-banner/_macro.njk" import onsBrowserBanner %}
5
6
 
6
7
  {% set title_tag = "h1" if params.titleAsH1 else "div" %}
7
8
  {% set currentLanguageISOCode = "en" %}
@@ -12,6 +13,12 @@
12
13
  {% endif %}
13
14
 
14
15
  <header class="ons-header {% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}{% if params.variants is not string %}{% for variant in params.variants %} ons-header--{{ variant }}{% endfor %}{% else %} ons-header--{{ params.variants }}{% endif %}" role="banner">
16
+ {{
17
+ onsBrowserBanner({
18
+ "lang": currentLanguageISOCode,
19
+ "wide": params.wide
20
+ })
21
+ }}
15
22
  {% if params.phase is defined and params.phase %}
16
23
  {% from "components/phase-banner/_macro.njk" import onsPhaseBanner %}
17
24
  {{ onsPhaseBanner(params.phase) }}
@@ -27,7 +27,7 @@
27
27
  type="{{ type }}"
28
28
  id="{{ params.id }}"
29
29
  class="ons-input ons-input--text ons-input-type__input{% if params.error is defined and params.error %} ons-input--error{% endif %}{% if params.searchButton is defined and params.searchButton %} ons-search__input{% endif %}{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}{% if params.width is defined and params.width %} ons-input{% if params.type is defined and (params.type == 'number' or params.type == 'tel') %}-number{% endif %}--w-{{ params.width }}{% endif %}{{ exclusiveClass }}{{ inputPlaceholder }}"
30
- {% if params.prefix is defined and params.prefix or params.suffix is defined and params.suffix %}aria-labelledby="{{ params.prefix.id if params.prefix }}{{ params.suffix.id if params.suffix }}"{% endif %}
30
+ {% if ((params.prefix is defined and params.prefix) and (params.prefix.id is defined and params.prefix.id)) or ((params.suffix is defined and params.suffix) and (params.suffix.id is defined and params.suffix.id)) %}aria-labelledby="{{ params.prefix.id if params.prefix.id }}{{ params.suffix.id if params.suffix.id }}"{% endif %}
31
31
  {% if params.name is defined and params.name %}name="{{ params.name }}"{% endif %}
32
32
  {% if params.value is defined and params.value %}value="{{ params.value }}"{% endif %}
33
33
  {% if params.accept is defined and params.accept %}accept="{{ params.accept }}"{% endif %}
@@ -71,21 +71,26 @@
71
71
  {% endif %}
72
72
 
73
73
  {% if params.prefix is defined and params.prefix or params.suffix is defined and params.suffix %}
74
- {% if params.prefix is defined and params.prefix %}
75
- {% set prefixClass = " ons-input-type--prefix" %}
76
- {% endif %}
74
+ {% if (params.prefix is defined and params.prefix and params.prefix.id is defined and params.prefix.id) or (params.suffix is defined and params.suffix and params.suffix.id is defined and params.suffix.id) %}
75
+ {% if (params.prefix.title is defined and params.prefix.title) or (params.suffix.title is defined and params.suffix.title) %}
76
+ {% if params.prefix is defined and params.prefix %}
77
+ {% set prefixClass = " ons-input-type--prefix" %}
78
+ {% endif %}
77
79
 
78
- <span class="ons-input-type{{ prefixClass }}">
79
- <span class="ons-input-type__inner">
80
- {{ input | safe }}
81
- {% set abbr = params.prefix or params.suffix %}
82
- <abbr
83
- {% if abbr.id is defined and abbr.id %}id="{{ abbr.id }}" {% endif %}
84
- class="ons-input-type__type ons-js-input-abbr"
85
- title="{{ abbr.title }}"
86
- >{{ abbr.text or abbr.title }}</abbr>
87
- </span>
88
- </span>
80
+ <span class="ons-input-type{{ prefixClass }}">
81
+ <span class="ons-input-type__inner">
82
+ {{ input | safe }}
83
+
84
+ {% set abbr = params.prefix or params.suffix %}
85
+ <abbr
86
+ id="{{ abbr.id }}"
87
+ class="ons-input-type__type ons-js-input-abbr"
88
+ title="{{ abbr.title }}"
89
+ >{{ abbr.text or abbr.title }}</abbr>
90
+ </span>
91
+ </span>
92
+ {% endif %}
93
+ {% endif %}
89
94
  {% elif params.searchButton is defined and params.searchButton %}
90
95
  <span class="ons-grid--flex ons-search">
91
96
  {% call onsSearch({
@@ -429,6 +429,34 @@ describe('macro: input', () => {
429
429
  ).toBe('Example prefix text');
430
430
  });
431
431
 
432
+ it('does not render prefix element when `prefix.id` not set', () => {
433
+ const $ = cheerio.load(
434
+ renderComponent('input', {
435
+ ...EXAMPLE_INPUT_MINIMAL,
436
+ prefix: {
437
+ title: 'Example prefix title',
438
+ text: 'Example prefix text',
439
+ },
440
+ }),
441
+ );
442
+
443
+ expect($('.ons-input-type--prefix').length).toBe(0);
444
+ });
445
+
446
+ it('does not render prefix element when `prefix.title` not set', () => {
447
+ const $ = cheerio.load(
448
+ renderComponent('input', {
449
+ ...EXAMPLE_INPUT_MINIMAL,
450
+ prefix: {
451
+ text: 'Example prefix text',
452
+ id: 'example-prefix-id',
453
+ },
454
+ }),
455
+ );
456
+
457
+ expect($('.ons-input-type--prefix').length).toBe(0);
458
+ });
459
+
432
460
  it('adds `aria-labelledby` attribute when `suffix` is provided', () => {
433
461
  const $ = cheerio.load(
434
462
  renderComponent('input', {
@@ -485,6 +513,34 @@ describe('macro: input', () => {
485
513
  });
486
514
  });
487
515
 
516
+ it('does not render suffix element when `suffix.id` not set', () => {
517
+ const $ = cheerio.load(
518
+ renderComponent('input', {
519
+ ...EXAMPLE_INPUT_MINIMAL,
520
+ suffix: {
521
+ title: 'Example suffix title',
522
+ text: 'Example suffix text',
523
+ },
524
+ }),
525
+ );
526
+
527
+ expect($('.ons-input').length).toBe(0);
528
+ });
529
+
530
+ it('does not render suffix element when `suffix.title` not set', () => {
531
+ const $ = cheerio.load(
532
+ renderComponent('input', {
533
+ ...EXAMPLE_INPUT_MINIMAL,
534
+ suffix: {
535
+ text: 'Example suffix text',
536
+ id: 'example-suffix-id',
537
+ },
538
+ }),
539
+ );
540
+
541
+ expect($('.ons-input').length).toBe(0);
542
+ });
543
+
488
544
  describe('search', () => {
489
545
  it('renders `search` component', () => {
490
546
  const faker = templateFaker();
@@ -2,7 +2,7 @@
2
2
  color: inherit;
3
3
  display: block;
4
4
  font-weight: $font-weight-bold;
5
- margin-bottom: 0.4rem;
5
+ margin: 0 0 0.6rem;
6
6
 
7
7
  &__description {
8
8
  @extend .ons-u-fs-s;
@@ -11,6 +11,7 @@ const EXAMPLE_MUTUALLY_EXCLUSIVE_DURATION_PARAMS = {
11
11
  name: 'address-duration-years',
12
12
  suffix: {
13
13
  text: 'Years',
14
+ id: 'address-duration-years-suffix',
14
15
  },
15
16
  attributes: {
16
17
  min: 0,
@@ -22,6 +23,7 @@ const EXAMPLE_MUTUALLY_EXCLUSIVE_DURATION_PARAMS = {
22
23
  name: 'address-duration-months',
23
24
  suffix: {
24
25
  text: 'Months',
26
+ id: 'address-duration-months-suffix',
25
27
  },
26
28
  attributes: {
27
29
  min: 0,
@@ -16,6 +16,7 @@ const EXAMPLE_MUTUALLY_EXCLUSIVE_NUMBER_INPUT_PARAMS = {
16
16
  prefix: {
17
17
  title: 'Pounds',
18
18
  text: '£',
19
+ id: 'currency-prefix',
19
20
  },
20
21
  mutuallyExclusive: {
21
22
  or: 'Or',