@ons/design-system 62.1.0 → 62.2.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
@@ -81,6 +81,16 @@ To run all axe tests:
81
81
  yarn test --testNamePattern="axe"
82
82
  ```
83
83
 
84
+ ### Snapshot test for base page template
85
+
86
+ There is a snapshot test of the base page template that runs alongside the component tests. The snapshot will need to be updated if the base page template is changed.
87
+
88
+ To update the snapshot:
89
+
90
+ ```bash
91
+ yarn test --testNamePattern="base page template" -u
92
+ ```
93
+
84
94
  ### Run tests locally in watch mode
85
95
 
86
96
  This will watch for changed files based on git uncommitted files.
@@ -22,7 +22,9 @@
22
22
  {% call onsDetails({
23
23
  "id": params.definition.id,
24
24
  "classes": 'ons-u-mb-m',
25
- "title": params.definition.title
25
+ "title": params.definition.title,
26
+ "headingAttributes": params.definition.headingAttributes,
27
+ "contentAttributes": params.definition.contentAttributes
26
28
  }) %}
27
29
  {% if params.definition.content %}
28
30
  {{ params.definition.content | safe }}
@@ -35,7 +37,9 @@
35
37
  {% set questionGuidance %}
36
38
  {% from "components/panel/_macro.njk" import onsPanel %}
37
39
  {% call onsPanel({
38
- "classes": "ons-question-guidance ons-u-mb-m"
40
+ "id": params.guidance.id,
41
+ "classes": "ons-question-guidance ons-u-mb-m",
42
+ "attributes": params.guidance.attributes
39
43
  }) %}
40
44
  {% if params.guidance.content %}
41
45
  {{ params.guidance.content | safe }}
@@ -65,6 +69,30 @@
65
69
  class="ons-question ons-u-mb-l{% if params.classes %} {{ params.classes }}{% endif %}"
66
70
  {% if params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
67
71
  >
72
+ {% set additionalContent %}
73
+ {% if params.warning %}
74
+ {% from "components/panel/_macro.njk" import onsPanel %}
75
+ {% call onsPanel({
76
+ "id": params.warning.id,
77
+ "type": "warn"
78
+ }) %}
79
+ <p>{{ params.warning.body }}</p>
80
+ {% endcall %}
81
+ {% endif %}
82
+
83
+ {% if params.instruction %}
84
+ {{- instHtml | safe -}}
85
+ {% endif %}
86
+
87
+ {% if params.definition %}
88
+ {{- questionDefinition | safe -}}
89
+ {% endif %}
90
+
91
+ {% if params.guidance %}
92
+ {{- questionGuidance | safe -}}
93
+ {% endif %}
94
+ {% endset %}
95
+
68
96
  {% if params.legendIsQuestionTitle %}
69
97
  {% from "components/fieldset/_macro.njk" import onsFieldset %}
70
98
 
@@ -78,6 +106,7 @@
78
106
  "legendClasses": params.legendClasses,
79
107
  "legendTitleClasses": params.legendTitleClasses
80
108
  }) %}
109
+ {{- additionalContent | safe -}}
81
110
  {{ content }}
82
111
  {% endcall %}
83
112
  </div>
@@ -91,17 +120,7 @@
91
120
  {{- descHtml | safe -}}
92
121
  {% endif %}
93
122
 
94
- {% if params.instruction %}
95
- {{- instHtml | safe -}}
96
- {% endif %}
97
-
98
- {% if params.definition %}
99
- {{- questionDefinition | safe -}}
100
- {% endif %}
101
-
102
- {% if params.guidance %}
103
- {{- questionGuidance | safe -}}
104
- {% endif %}
123
+ {{- additionalContent | safe -}}
105
124
 
106
125
  <div class="ons-question__answer ons-u-mb-m">
107
126
  {{ caller() if caller }}
@@ -113,7 +132,9 @@
113
132
  {% call onsDetails({
114
133
  "id": params.justification.id,
115
134
  "classes": 'ons-u-mb-m',
116
- "title": params.justification.title | default('Why we ask this question')
135
+ "title": params.justification.title | default('Why we ask this question'),
136
+ "headingAttributes": params.justification.headingAttributes,
137
+ "contentAttributes": params.justification.contentAttributes
117
138
  }) %}
118
139
  {{ params.justification.content | safe }}
119
140
  {% endcall %}
@@ -11,6 +11,14 @@ const EXAMPLE_QUESTION_BASIC = {
11
11
  description: 'Question description',
12
12
  };
13
13
 
14
+ const EXAMPLE_QUESTION_WARNING = {
15
+ ...EXAMPLE_QUESTION_BASIC,
16
+ warning: {
17
+ id: 'warning-id',
18
+ body: 'Warning content',
19
+ },
20
+ };
21
+
14
22
  const EXAMPLE_QUESTION_DEFINITION = {
15
23
  ...EXAMPLE_QUESTION_BASIC,
16
24
  definition: {
@@ -70,6 +78,7 @@ const EXAMPLE_QUESTION_DESCRIPTION_FIRST = {
70
78
  describe('macro: question', () => {
71
79
  describe.each([
72
80
  ['with basic parameters', EXAMPLE_QUESTION_BASIC],
81
+ ['with warning', EXAMPLE_QUESTION_WARNING],
73
82
  ['with definition', EXAMPLE_QUESTION_DEFINITION],
74
83
  ['with guidance', EXAMPLE_QUESTION_GUIDANCE],
75
84
  ['with justification', EXAMPLE_QUESTION_JUSTIFICATION],
@@ -80,6 +89,7 @@ describe('macro: question', () => {
80
89
  [
81
90
  'with all options combined',
82
91
  {
92
+ ...EXAMPLE_QUESTION_WARNING,
83
93
  ...EXAMPLE_QUESTION_DEFINITION,
84
94
  ...EXAMPLE_QUESTION_GUIDANCE,
85
95
  ...EXAMPLE_QUESTION_JUSTIFICATION,
@@ -162,6 +172,24 @@ describe('macro: question', () => {
162
172
  });
163
173
  });
164
174
 
175
+ describe('mode: with warning', () => {
176
+ it('outputs the expected panel', () => {
177
+ const faker = templateFaker();
178
+ const panelSpy = faker.spy('panel');
179
+
180
+ faker.renderComponent('question', EXAMPLE_QUESTION_WARNING);
181
+
182
+ expect(panelSpy.occurrences[0]).toHaveProperty('id', 'warning-id');
183
+ expect(panelSpy.occurrences[0]).toHaveProperty('type', 'warn');
184
+ });
185
+
186
+ it('outputs the expected panel content', () => {
187
+ const $ = cheerio.load(renderComponent('question', EXAMPLE_QUESTION_WARNING));
188
+
189
+ expect($('.ons-panel__body > p').text()).toBe('Warning content');
190
+ });
191
+ });
192
+
165
193
  describe('mode: with definition', () => {
166
194
  it('outputs the expected details', () => {
167
195
  const faker = templateFaker();
@@ -4,9 +4,7 @@ layout: ~
4
4
  ---
5
5
  {% extends "layout/_template.njk" %}
6
6
  {% from "components/question/_macro.njk" import onsQuestion %}
7
- {% from "components/details/_macro.njk" import onsDetails %}
8
7
  {% from "components/input/_macro.njk" import onsInput %}
9
- {% from "components/button/_macro.njk" import onsButton %}
10
8
 
11
9
  {% set pageConfig = {
12
10
  "header": {
@@ -4,10 +4,7 @@ layout: ~
4
4
  ---
5
5
  {% extends "layout/_template.njk" %}
6
6
  {% from "components/question/_macro.njk" import onsQuestion %}
7
- {% from "components/details/_macro.njk" import onsDetails %}
8
- {% from "components/panel/_macro.njk" import onsPanel %}
9
7
  {% from "components/radios/_macro.njk" import onsRadios %}
10
- {% from "components/button/_macro.njk" import onsButton %}
11
8
 
12
9
  {% set pageConfig = {
13
10
  "header": {
@@ -65,34 +62,34 @@ layout: ~
65
62
  }) %}
66
63
 
67
64
  {{ onsRadios({
68
- "id": "number-of-employees",
69
- "name": "number-of-employees",
70
- "legend": questionTitle,
71
- "legendClasses": "ons-u-vh",
72
- "radios": [
73
- {
74
- "id": "number-of-employees-1-9",
75
- "label": {
76
- "text": "1 – 9 employees"
77
- },
78
- "value": "1-9"
79
- },
80
- {
81
- "id": "number-of-employees-10-49",
82
- "label": {
83
- "text": "10 – 49 employees"
65
+ "id": "number-of-employees",
66
+ "name": "number-of-employees",
67
+ "legend": questionTitle,
68
+ "legendClasses": "ons-u-vh",
69
+ "radios": [
70
+ {
71
+ "id": "number-of-employees-1-9",
72
+ "label": {
73
+ "text": "1 – 9 employees"
74
+ },
75
+ "value": "1-9"
84
76
  },
85
- "value": "10-49"
86
- },
87
- {
88
- "id": "number-of-employees-50-100",
89
- "label": {
90
- "text": "50 – 100+ employees",
91
- "description": "Include multi-corporations"
77
+ {
78
+ "id": "number-of-employees-10-49",
79
+ "label": {
80
+ "text": "10 – 49 employees"
81
+ },
82
+ "value": "10-49"
92
83
  },
93
- "value": "50-100"
94
- }
95
- ]
84
+ {
85
+ "id": "number-of-employees-50-100",
86
+ "label": {
87
+ "text": "50 – 100+ employees",
88
+ "description": "Include multi-corporations"
89
+ },
90
+ "value": "50-100"
91
+ }
92
+ ]
96
93
  }) }}
97
94
 
98
95
  {% endcall %}
@@ -6,9 +6,6 @@ layout: ~
6
6
 
7
7
  {% extends "layout/_template.njk" %}
8
8
  {% from "components/question/_macro.njk" import onsQuestion %}
9
- {% from "components/details/_macro.njk" import onsDetails %}
10
- {% from "components/input/_macro.njk" import onsInput %}
11
- {% from "components/button/_macro.njk" import onsButton %}
12
9
 
13
10
  {% set pageConfig = {
14
11
  "header": {
@@ -4,9 +4,7 @@ layout: ~
4
4
  ---
5
5
  {% extends "layout/_template.njk" %}
6
6
  {% from "components/question/_macro.njk" import onsQuestion %}
7
- {% from "components/details/_macro.njk" import onsDetails %}
8
7
  {% from "components/input/_macro.njk" import onsInput %}
9
- {% from "components/button/_macro.njk" import onsButton %}
10
8
 
11
9
  {% set pageConfig = {
12
10
  "header": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ons/design-system",
3
3
  "description": "ONS Design System built CSS, JS, and Nunjucks templates",
4
- "version": "62.1.0",
4
+ "version": "62.2.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {