@ons/design-system 69.0.0 → 70.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.
package/README.md CHANGED
@@ -158,3 +158,4 @@ yarn build
158
158
 
159
159
  - "render whitespace" set to "all"
160
160
  - "insert spaces when pressing tab" checked
161
+ - "trim trailing whitespace" checked
@@ -45,7 +45,7 @@
45
45
  cursor: pointer;
46
46
  margin: 0;
47
47
  outline: none;
48
- padding: $input-padding-horizontal;
48
+ padding: $input-padding-vertical $input-padding-horizontal;
49
49
 
50
50
  &:not(:last-child) {
51
51
  border-bottom: 1px solid var(--ons-color-input-border);
@@ -1,6 +1,6 @@
1
1
  {%- macro onsCard(params) -%}
2
2
 
3
- {% set titleSize = params.titleSize | default('2') %}
3
+ {% set headingLevel = params.headingLevel | default(2) %}
4
4
 
5
5
  <div class="ons-card">
6
6
  <a href="{{ params.url }}" class="ons-card__link">
@@ -11,9 +11,9 @@
11
11
  <img class="ons-card__image ons-u-mb-s " height="100" width="303" srcset="{{ params.image.placeholderURL if params.image.placeholderURL }}/img/small/placeholder-card.png 1x, {{ params.image.placeholderURL if params.image.placeholderURL }}/img/large/placeholder-card.png 2x" src="{{ params.image.placeholderURL if params.image.placeholderURL }}/img/small/placeholder-card.png" alt="" loading="lazy">
12
12
  {% endif %}
13
13
  {%- endif -%}
14
- <h{{ titleSize }} class="ons-card__title {{ params.titleClasses | default('ons-u-fs-m')}}" id="{{ params.id }}">
14
+ <h{{ headingLevel }} class="ons-card__title {{ params.titleClasses | default('ons-u-fs-m')}}" id="{{ params.id }}">
15
15
  {{ params.title }}
16
- </h{{ titleSize }}>
16
+ </h{{ headingLevel }}>
17
17
  </a>
18
18
 
19
19
  <p id="{{ params.textId }}">{{ params.text }}</p>
@@ -56,11 +56,11 @@ describe('macro: card', () => {
56
56
  it.each([
57
57
  [1, 'h1'],
58
58
  [4, 'h4'],
59
- ])('has the correct element type for the provided `titleSize` (%i -> %s)', (titleSize, expectedTitleTag) => {
59
+ ])('has the correct element type for the provided `headingLevel` (%i -> %s)', (headingLevel, expectedTitleTag) => {
60
60
  const $ = cheerio.load(
61
61
  renderComponent('card', {
62
62
  ...EXAMPLE_CARD_WITHOUT_IMAGE,
63
- titleSize,
63
+ headingLevel,
64
64
  }),
65
65
  );
66
66
 
@@ -117,11 +117,11 @@ describe('macro: card', () => {
117
117
  it.each([
118
118
  [1, 'h1'],
119
119
  [4, 'h4'],
120
- ])('has the correct element type for the provided `titleSize` (%i -> %s)', (titleSize, expectedTitleTag) => {
120
+ ])('has the correct element type for the provided `headingLevel` (%i -> %s)', (headingLevel, expectedTitleTag) => {
121
121
  const $ = cheerio.load(
122
122
  renderComponent('card', {
123
123
  ...EXAMPLE_CARD_WITH_IMAGE,
124
- titleSize,
124
+ headingLevel,
125
125
  }),
126
126
  );
127
127
 
@@ -1,8 +1,9 @@
1
- {% from "components/date-field-input/_macro.njk" import onsDateFieldInput %}
1
+ {% from "components/multiple-input-fields/_macro.njk" import onsMultipleInputFields %}
2
+ {% from "components/input/_macro.njk" import onsInput %}
2
3
 
3
4
  {% macro onsDateInput(params) %}
4
5
  {% set exclusiveClass = " ons-js-exclusive-group-item" if params.mutuallyExclusive else "" %}
5
- {%- set numberOfFields = 0 -%}
6
+ {%- set numberOfFields = 0 -%}
6
7
 
7
8
  {%- if params.day -%}
8
9
  {%- set numberOfFields = numberOfFields + 1 -%}
@@ -16,82 +17,83 @@
16
17
  {%- set numberOfFields = numberOfFields + 1 -%}
17
18
  {%- endif -%}
18
19
 
19
- {% set fields = [] %}
20
- {% if params.day %}
21
- {% set dayField = {
22
- "id": params.id + "-day",
23
- "label": {
24
- "text": params.day.label.text if numberOfFields > 1 else params.legendOrLabel,
25
- "description": params.day.label.description if numberOfFields > 1 else params.description,
26
- "id": params.id + "-day-label"
27
- },
28
- "name": params.day.name,
29
- "width": "2",
30
- "min": 1,
31
- "max": 31,
32
- "maxLength": 2,
33
- "attributes": params.day.attributes,
34
- "value": params.day.value,
35
- "classes": (" ons-input--error" if (params.error and params.day.error) or (params.error and not params.day.error and not params.month.error and not params.year.error) else "") + exclusiveClass | default("")
36
- } %}
37
- {% set fields = (fields.push(dayField), fields) %}
38
- {% endif %}
39
- {% if params.month %}
40
- {% set monthField = {
41
- "id": params.id + "-month",
42
- "label": {
43
- "text": params.month.label.text if numberOfFields > 1 else params.legendOrLabel,
44
- "description": params.month.label.description if numberOfFields > 1 else params.description,
45
- "id": params.id + "-month-label"
46
- },
47
- "name": params.month.name,
48
- "width": "2",
49
- "min": 1,
50
- "max": 12,
51
- "maxLength": 2,
52
- "attributes": params.month.attributes,
53
- "value": params.month.value,
54
- "classes": (" ons-input--error" if (params.error and params.month.error) or (params.error and not params.day.error and not params.month.error and not params.year.error) else "") + exclusiveClass | default("")
55
- } %}
56
- {% set fields = (fields.push(monthField), fields) %}
57
- {% endif %}
58
- {% if params.year %}
59
- {% set yearField = {
60
- "id": params.id + "-year",
61
- "label": {
62
- "text": params.year.label.text if numberOfFields > 1 else params.legendOrLabel,
63
- "description": params.year.label.description if numberOfFields > 1 else params.description,
64
- "id": params.id + "-year-label"
65
- },
66
- "name": params.year.name,
67
- "width": "4",
68
- "min": 1000,
69
- "max": 3000,
70
- "maxLength": 4,
71
- "attributes": params.year.attributes,
72
- "value": params.year.value,
73
- "classes": (" ons-input--error" if (params.error and params.year.error) or (params.error and not params.day.error and not params.month.error and not params.year.error) else "") + exclusiveClass | default("")
74
- } %}
75
- {% set fields = (fields.push(yearField), fields) %}
76
- {% endif %}
20
+ {% set fields %}
21
+ {% if params.day %}
22
+ {{ onsInput({
23
+ "id": params.id + "-day",
24
+ "type": "number",
25
+ "name": params.day.name,
26
+ "classes": (" ons-input--error" if (params.error and params.day.error) or (params.error and not params.day.error and not params.month.error and not params.year.error) else "") + exclusiveClass | default(""),
27
+ "width": "2",
28
+ "min": 1,
29
+ "max": 31,
30
+ "maxLength": 2,
31
+ "attributes": params.day.attributes,
32
+ "label": {
33
+ "text": params.day.label.text if numberOfFields > 1 else params.legendOrLabel,
34
+ "description": params.day.label.description if numberOfFields > 1 else params.description,
35
+ "id": params.id + "-day-label"
36
+ },
37
+ "value": params.day.value,
38
+ "error": params.error if numberOfFields < 2
39
+ }) }}
40
+ {% endif %}
77
41
 
78
- {{ onsDateFieldInput({
42
+ {% if params.month %}
43
+ {{ onsInput({
44
+ "id": params.id + "-month",
45
+ "type": "number",
46
+ "name": params.month.name,
47
+ "classes": (" ons-input--error" if (params.error and params.month.error) or (params.error and not params.day.error and not params.month.error and not params.year.error) else "") + exclusiveClass | default(""),
48
+ "width": "2",
49
+ "min": 1,
50
+ "max": 12,
51
+ "maxLength": 2,
52
+ "attributes": params.month.attributes,
53
+ "label": {
54
+ "text": params.month.label.text if numberOfFields > 1 else params.legendOrLabel,
55
+ "description": params.month.label.description if numberOfFields > 1 else params.description,
56
+ "id": params.id + "-month-label"
57
+ },
58
+ "value": params.month.value,
59
+ "error": params.error if numberOfFields < 2
60
+ }) }}
61
+ {% endif %}
62
+
63
+ {% if params.year %}
64
+ {{ onsInput({
65
+ "id": params.id + "-year",
66
+ "type": "number",
67
+ "name": params.year.name,
68
+ "classes": (" ons-input--error" if (params.error and params.year.error) or (params.error and not params.day.error and not params.month.error and not params.year.error) else "") + exclusiveClass | default(""),
69
+ "width": "4",
70
+ "min": 1000,
71
+ "max": 3000,
72
+ "maxLength": 4,
73
+ "attributes": params.year.attributes,
74
+ "label": {
75
+ "text": params.year.label.text if numberOfFields > 1 else params.legendOrLabel,
76
+ "description": params.year.label.description if numberOfFields > 1 else params.description,
77
+ "id": params.id + "-year-label"
78
+ },
79
+ "value": params.year.value,
80
+ "error": params.error if numberOfFields < 2
81
+ }) }}
82
+ {% endif %}
83
+ {% endset %}
84
+
85
+ {{ onsMultipleInputFields({
79
86
  "id": params.id,
80
87
  "legendOrLabel": params.legendOrLabel,
81
88
  "description": params.description,
82
89
  "mutuallyExclusive": params.mutuallyExclusive,
83
- "fields": fields,
84
90
  "numberOfFields": numberOfFields,
91
+ "fields": fields,
85
92
  "error": params.error,
86
93
  "legend": params.legendOrLabel,
87
94
  "dontWrap": params.dontWrap,
88
- "legendClasses": params.legendClasses,
89
- "legendIsQuestionTitle": params.legendIsQuestionTitle,
90
95
  "classes": params.classes,
91
- "exclusiveOptions": params.mutuallyExclusive.exclusiveOptions,
92
- "or": params.mutuallyExclusive.or,
93
- "deselectMessage": params.mutuallyExclusive.deselectMessage,
94
- "deselectGroupAdjective": params.mutuallyExclusive.deselectGroupAdjective,
95
- "deselectExclusiveOptionAdjective": params.mutuallyExclusive.deselectExclusiveOptionAdjective
96
+ "legendClasses": params.legendClasses,
97
+ "legendIsQuestionTitle": params.legendIsQuestionTitle
96
98
  }) }}
97
99
  {% endmacro %}
@@ -107,7 +107,7 @@ const EXAMPLE_YEAR_FIELD_WITH_ERROR = {
107
107
  },
108
108
  };
109
109
 
110
- const EXAMPLE_YEAR_FIELD_WITH_NO_ERROR = {
110
+ const EXAMPLE_YEAR_FIELD_WITH_ERROR_FALSE = {
111
111
  year: {
112
112
  label: {
113
113
  text: 'Year',
@@ -148,9 +148,9 @@ const EXAMPLE_DATE_MULTIPLE_FIELDS_WITH_ERROR = {
148
148
  ...EXAMPLE_YEAR_FIELD_WITH_ERROR,
149
149
  };
150
150
 
151
- const EXAMPLE_DATE_MULTIPLE_FIELDS_WITH_NO_ERROR = {
151
+ const EXAMPLE_DATE_SINGLE_FIELD_WITH_ERROR_FALSE = {
152
152
  ...EXAMPLE_DATE_INPUT_BASE,
153
- ...EXAMPLE_YEAR_FIELD_WITH_NO_ERROR,
153
+ ...EXAMPLE_YEAR_FIELD_WITH_ERROR_FALSE,
154
154
  };
155
155
 
156
156
  describe('macro: date input', () => {
@@ -177,6 +177,7 @@ describe('macro: date input', () => {
177
177
  max: 31,
178
178
  maxLength: 2,
179
179
  classes: '',
180
+ error: '',
180
181
  label: {
181
182
  text: 'Day',
182
183
  description: 'The day',
@@ -204,6 +205,7 @@ describe('macro: date input', () => {
204
205
  max: 12,
205
206
  maxLength: 2,
206
207
  classes: '',
208
+ error: '',
207
209
  label: {
208
210
  text: 'Month',
209
211
  description: 'The month',
@@ -231,6 +233,7 @@ describe('macro: date input', () => {
231
233
  max: 3000,
232
234
  maxLength: 4,
233
235
  classes: '',
236
+ error: '',
234
237
  label: {
235
238
  text: 'Year',
236
239
  description: 'The year',
@@ -249,6 +252,12 @@ describe('macro: date input', () => {
249
252
  expect($(div).hasClass('ons-field-group')).toBe(true);
250
253
  });
251
254
 
255
+ it('has the correct number of inputs', () => {
256
+ const $ = cheerio.load(renderComponent('date-input', EXAMPLE_DATE_MULTIPLE_FIELDS));
257
+ const $inputs = $('.ons-input');
258
+ expect($inputs.length).toBe(3);
259
+ });
260
+
252
261
  it('has the expected `fieldset` output', () => {
253
262
  const faker = templateFaker();
254
263
  const fieldsetSpy = faker.spy('fieldset');
@@ -356,6 +365,12 @@ describe('macro: date input', () => {
356
365
  });
357
366
  });
358
367
 
368
+ it('has the correct number of inputs', () => {
369
+ const $ = cheerio.load(renderComponent('date-input', EXAMPLE_DATE_SINGLE_FIELD));
370
+ const $inputs = $('.ons-input');
371
+ expect($inputs.length).toBe(1);
372
+ });
373
+
359
374
  it('has the expected `error` output', () => {
360
375
  const faker = templateFaker();
361
376
  const errorSpy = faker.spy('error');
@@ -371,7 +386,7 @@ describe('macro: date input', () => {
371
386
  });
372
387
  });
373
388
 
374
- describe('mode: multiple fields with single field error', () => {
389
+ describe('mode: multiple fields with errors', () => {
375
390
  it('passes jest-axe checks', async () => {
376
391
  const $ = cheerio.load(renderComponent('date-input', EXAMPLE_DATE_MULTIPLE_FIELDS_WITH_SINGLE_ERROR));
377
392
 
@@ -394,7 +409,7 @@ describe('macro: date input', () => {
394
409
  });
395
410
 
396
411
  it('does not provide error class when error parameter set to false', async () => {
397
- const $ = cheerio.load(renderComponent('date-input', EXAMPLE_DATE_MULTIPLE_FIELDS_WITH_NO_ERROR));
412
+ const $ = cheerio.load(renderComponent('date-input', EXAMPLE_DATE_SINGLE_FIELD_WITH_ERROR_FALSE));
398
413
  const $errorContent = $('.ons-input--error');
399
414
 
400
415
  expect($errorContent.length).toBe(0);
@@ -0,0 +1,27 @@
1
+ {% from "components/date-input/_macro.njk" import onsDateInput %}
2
+
3
+ {{
4
+ onsDateInput({
5
+ "id": "date-input-example-double",
6
+ "legendOrLabel": "Month and year of last MOT",
7
+ "description": "For example, 3 2023",
8
+ "month": {
9
+ "label": {
10
+ "text": "Month"
11
+ },
12
+ "name": "month",
13
+ "attributes": {
14
+ "autocomplete": "mot-month"
15
+ }
16
+ },
17
+ "year": {
18
+ "label": {
19
+ "text": "Year"
20
+ },
21
+ "name": "year",
22
+ "attributes": {
23
+ "autocomplete": "mot-year"
24
+ }
25
+ }
26
+ })
27
+ }}
@@ -0,0 +1,18 @@
1
+ {% from "components/date-input/_macro.njk" import onsDateInput %}
2
+
3
+ {{
4
+ onsDateInput({
5
+ "id": "date-input-example-single",
6
+ "legendOrLabel": "Year of birth",
7
+ "description": "For example, 1980",
8
+ "year": {
9
+ "label": {
10
+ "text": "Year"
11
+ },
12
+ "name": "year",
13
+ "attributes": {
14
+ "autocomplete": "bday-year"
15
+ }
16
+ }
17
+ })
18
+ }}
@@ -1,7 +1,10 @@
1
- {% from "components/date-field-input/_macro.njk" import onsDateFieldInput %}
1
+ {% from "components/multiple-input-fields/_macro.njk" import onsMultipleInputFields %}
2
+ {% from "components/input/_macro.njk" import onsInput %}
2
3
 
3
4
  {% macro onsDuration(params) %}
5
+ {% set exclusiveClass = " ons-js-exclusive-group-item" if params.mutuallyExclusive else "" %}
4
6
  {% set numberOfFields = 0 %}
7
+
5
8
  {% if params.field1 %}
6
9
  {% set numberOfFields = numberOfFields + 1 %}
7
10
  {% endif %}
@@ -10,54 +13,55 @@
10
13
  {% set numberOfFields = numberOfFields + 1 %}
11
14
  {% endif %}
12
15
 
13
- {% set fields = [] %}
14
- {% if params.field1 %}
15
- {% set field1 = {
16
- "id": params.field1.id,
17
- "name": params.field1.name,
18
- "attributes": params.field1.attributes,
19
- "label": {
20
- "text": params.legendOrLabel if numberOfFields < 2,
21
- "description": params.description if numberOfFields < 2
22
- },
23
- "suffix": {
24
- "text": params.field1.suffix.text,
25
- "title": params.field1.suffix.title,
26
- "id": params.field1.suffix.id
27
- },
28
- "width": "2",
29
- "fieldId": params.id if numberOfFields < 2,
30
- "value": params.field1.value,
31
- "error": params.error if numberOfFields < 2,
32
- "classes": (" ons-input--error" if (params.error and params.field1.error) or (params.error and not params.field1.error and not params.field2.error) else "") + (" ons-js-exclusive-group-item" if params.mutuallyExclusive else "")
33
- } %}
34
- {% set fields = (fields.push(field1), fields) %}
35
- {% endif %}
16
+ {% set fields %}
17
+ {% if params.field1 %}
18
+ {{ onsInput({
19
+ "id": params.field1.id,
20
+ "type": "number",
21
+ "name": params.field1.name,
22
+ "classes": (" ons-input--error" if (params.error and params.field1.error) or (numberOfFields > 1 and params.error and not params.field1.error and not params.field2.error) else "") + exclusiveClass | default(""),
23
+ "width": "2",
24
+ "attributes": params.field1.attributes,
25
+ "value": params.field1.value,
26
+ "suffix": {
27
+ "text": params.field1.suffix.text,
28
+ "title": params.field1.suffix.title,
29
+ "id": params.field1.suffix.id
30
+ },
31
+ "label": {
32
+ "text": params.legendOrLabel if numberOfFields < 2,
33
+ "description": params.description if numberOfFields < 2
34
+ },
35
+ "fieldId": params.id if numberOfFields < 2,
36
+ "error": params.error if numberOfFields < 2
37
+ }) }}
38
+ {% endif %}
36
39
 
37
- {% if params.field2 %}
38
- {% set field2 = {
39
- "id": params.field2.id,
40
- "name": params.field2.name,
41
- "attributes": params.field2.attributes,
42
- "width": "2",
43
- "label": {
44
- "text": params.legendOrLabel if numberOfFields < 2,
45
- "description": params.description if numberOfFields < 2
46
- },
47
- "suffix": {
48
- "text": params.field2.suffix.text,
49
- "title": params.field2.suffix.title,
50
- "id": params.field2.suffix.id
51
- },
52
- "value": params.field2.value,
53
- "error": params.error if numberOfFields < 2,
54
- "fieldId": params.id if numberOfFields < 2,
55
- "classes": (" ons-input--error" if (params.error and params.field2.error) or (params.error and not params.field1.error and not params.field2.error) else "") + (" ons-js-exclusive-group-item" if params.mutuallyExclusive else "")
56
- } %}
57
- {% set fields = (fields.push(field2), fields) %}
58
- {% endif %}
59
-
60
- {{ onsDateFieldInput({
40
+ {% if params.field2 %}
41
+ {{ onsInput({
42
+ "id": params.field2.id,
43
+ "type": "number",
44
+ "name": params.field2.name,
45
+ "classes": (" ons-input--error" if (params.error and params.field2.error) or (numberOfFields > 1 and params.error and not params.field1.error and not params.field2.error) else "") + exclusiveClass | default(""),
46
+ "width": "2",
47
+ "attributes": params.field2.attributes,
48
+ "value": params.field2.value,
49
+ "suffix": {
50
+ "text": params.field2.suffix.text,
51
+ "title": params.field2.suffix.title,
52
+ "id": params.field2.suffix.id
53
+ },
54
+ "label": {
55
+ "text": params.legendOrLabel if numberOfFields < 2,
56
+ "description": params.description if numberOfFields < 2
57
+ },
58
+ "fieldId": params.id if numberOfFields < 2,
59
+ "error": params.error if numberOfFields < 2
60
+ }) }}
61
+ {% endif %}
62
+ {% endset %}
63
+
64
+ {{ onsMultipleInputFields({
61
65
  "id": params.id,
62
66
  "legendOrLabel": params.legendOrLabel,
63
67
  "description": params.description,