@ons/design-system 72.10.6 → 72.10.8

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 (38) hide show
  1. package/components/char-check-limit/_macro.njk +5 -4
  2. package/components/char-check-limit/_macro.spec.js +167 -7
  3. package/components/char-check-limit/character-check.js +23 -17
  4. package/components/char-check-limit/character-check.spec.js +106 -1
  5. package/components/chart/_chart.scss +39 -5
  6. package/components/chart/_macro.njk +190 -152
  7. package/components/chart/_macro.spec.js +274 -21
  8. package/components/chart/annotations-options.js +1 -1
  9. package/components/chart/bar-chart.js +2 -0
  10. package/components/chart/chart-iframe-resize.dom.js +8 -0
  11. package/components/chart/chart-iframe-resize.js +16 -0
  12. package/components/chart/chart.dom.js +5 -3
  13. package/components/chart/chart.js +13 -2
  14. package/components/chart/example-area-chart.njk +2 -1
  15. package/components/chart/example-bar-chart.njk +4 -0
  16. package/components/chart/example-iframe-chart.njk +33 -0
  17. package/components/chart/example-line-chart-with-annotations.njk +3 -1
  18. package/components/chart/example-line-chart.njk +6 -1
  19. package/components/chart/example-scatter-chart.njk +4 -0
  20. package/components/chart/range-annotations-options.js +1 -1
  21. package/components/chart/reference-line-annotations-options.js +1 -1
  22. package/components/checkboxes/_macro.spec.js +3 -3
  23. package/components/input/_macro.njk +1 -2
  24. package/components/input/_macro.spec.js +2 -22
  25. package/components/input/example-input-search-with-character-check.njk +0 -1
  26. package/components/tabs/tabs.js +2 -2
  27. package/components/textarea/_macro.njk +19 -3
  28. package/components/textarea/_macro.spec.js +76 -3
  29. package/components/textarea/example-textarea-with-word-limit.njk +20 -0
  30. package/css/main.css +1 -1
  31. package/img/small/area-chart-screenshot.png +0 -0
  32. package/img/small/line-chart-screenshot.png +0 -0
  33. package/js/main.js +2 -0
  34. package/layout/_template.njk +4 -1
  35. package/package.json +6 -3
  36. package/scripts/main.es5.js +3 -1
  37. package/scripts/main.js +3 -1
  38. package/scss/objects/_page.scss +1 -1
@@ -11,7 +11,6 @@
11
11
  },
12
12
  "width": "10",
13
13
  "charCheckLimit": {
14
- "charcheckCountdown": true,
15
14
  "limit": 10,
16
15
  "charCountSingular": "{x} more character needed",
17
16
  "charCountPlural": "{x} more characters needed",
@@ -134,7 +134,7 @@ export default class Tabs {
134
134
  window.removeEventListener('hashchange', this.component.boundOnHashChange, true);
135
135
  }
136
136
 
137
- // Handle haschange so that the browser can cycle through the tab history
137
+ // Handle hashchange so that the browser can cycle through the tab history
138
138
  onHashChange() {
139
139
  const hash = window.location.hash;
140
140
  const tabWithHash = this.getTab(hash);
@@ -259,7 +259,7 @@ export default class Tabs {
259
259
  }
260
260
 
261
261
  getPanel(tab) {
262
- const panelSelector = this.getHref(tab).replace(/\./g, '\\.');
262
+ const panelSelector = this.getHref(tab).replace(/([ .:[\]{}()<>?+*~=|^$!\\])/g, '\\$1');
263
263
  const panel = this.component.querySelector(panelSelector);
264
264
  return panel;
265
265
  }
@@ -19,14 +19,17 @@
19
19
 
20
20
  <textarea
21
21
  id="{{ params.id }}"
22
- class="ons-input ons-input--textarea{{ ' ons-input--error' if params.error }}{{ ' ons-js-char-check-input' if params.charCheckLimit and params.charCheckLimit.limit }}{{ textareaExclusiveClass }}{{ ' ' + params.classes if params.classes else '' }}{% if params.width %}{{ ' ' }}ons-input--w-{{ params.width }}{% endif %}"
22
+ class="ons-input ons-input--textarea{{ ' ons-input--error' if params.error }}{{ ' ons-js-char-check-input' if (params.charCheckLimit and params.charCheckLimit.limit) or (params.wordCheckLimit and params.wordCheckLimit.limit) }}{{ textareaExclusiveClass }}{{ ' ' + params.classes if params.classes else '' }}{% if params.width %}{{ ' ' }}ons-input--w-{{ params.width }}{% endif %}"
23
23
  {% if params.name %}
24
24
  name="{{ params.name }}"
25
25
  {% endif %}
26
26
  rows="{{ params.rows | default(8) }}"
27
27
  {% if params.charCheckLimit %}
28
- data-char-check-ref="{{ params.id }}-check" data-char-check-num="{{ params.charCheckLimit.limit }}"
29
- aria-describedby="{{ params.id }}-check" data-char-check-countdown=true
28
+ data-message-check-ref="{{ params.id }}-check" data-message-check-num="{{ params.charCheckLimit.limit }}"
29
+ aria-describedby="{{ params.id }}-check"
30
+ {% elif params.wordCheckLimit %}
31
+ data-message-check-ref="{{ params.id }}-check" data-message-check-num="{{ params.wordCheckLimit.limit }}"
32
+ aria-describedby="{{ params.id }}-check"
30
33
  {% endif %}
31
34
  {% 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 %}
32
35
  >
@@ -45,6 +48,19 @@
45
48
  })
46
49
  %}
47
50
  {% endcall %}
51
+ {% elif params.wordCheckLimit and params.wordCheckLimit.limit %}
52
+ {%
53
+ call onsCharLimit({
54
+ "id": params.id ~ "-check",
55
+ "variant": "word",
56
+ "limit": params.wordCheckLimit.limit,
57
+ "wordCountSingular": params.wordCheckLimit.wordCountSingular,
58
+ "wordCountPlural": params.wordCheckLimit.wordCountPlural,
59
+ "wordCountOverLimitSingular": params.wordCheckLimit.wordCountOverLimitSingular,
60
+ "wordCountOverLimitPlural": params.wordCheckLimit.wordCountOverLimitPlural
61
+ })
62
+ %}
63
+ {% endcall %}
48
64
  {% endif %}
49
65
  {% endset %}
50
66
 
@@ -27,6 +27,17 @@ const EXAMPLE_TEXTAREA_WITH_CHARACTER_LIMIT = {
27
27
  },
28
28
  };
29
29
 
30
+ const EXAMPLE_TEXTAREA_WITH_WORD_LIMIT = {
31
+ ...EXAMPLE_TEXTAREA,
32
+ width: 30,
33
+ wordCheckLimit: {
34
+ limit: 5,
35
+ wordCountSingular: 'You have {x} word remaining',
36
+ wordCountPlural: 'You have {x} words remaining',
37
+ wordCountOverLimitSingular: '{x} word too many',
38
+ wordCountOverLimitPlural: '{x} words too many',
39
+ },
40
+ };
30
41
  const EXAMPLE_TEXTAREA_WITH_ERROR = {
31
42
  ...EXAMPLE_TEXTAREA,
32
43
  error: {
@@ -212,13 +223,13 @@ describe('macro: textarea', () => {
212
223
  it('has the provided maximum length', () => {
213
224
  const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_CHARACTER_LIMIT));
214
225
 
215
- expect($('.ons-input--textarea').attr('data-char-check-num')).toBe('200');
226
+ expect($('.ons-input--textarea').attr('data-message-check-num')).toBe('200');
216
227
  });
217
228
 
218
229
  it('has data attribute which references the character check component', () => {
219
230
  const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_CHARACTER_LIMIT));
220
231
 
221
- expect($('.ons-input--textarea').attr('data-char-check-ref')).toBe('example-id-check');
232
+ expect($('.ons-input--textarea').attr('data-message-check-ref')).toBe('example-id-check');
222
233
  });
223
234
 
224
235
  it('has `aria-describedby` attribute which references the character limit component', () => {
@@ -227,7 +238,7 @@ describe('macro: textarea', () => {
227
238
  expect($('.ons-input--textarea').attr('aria-describedby')).toBe('example-id-check');
228
239
  });
229
240
 
230
- it('renders character limit component', () => {
241
+ it('renders character check limit component', () => {
231
242
  const faker = templateFaker();
232
243
  const charCheckLimitSpy = faker.spy('char-check-limit');
233
244
 
@@ -244,6 +255,68 @@ describe('macro: textarea', () => {
244
255
  });
245
256
  });
246
257
 
258
+ describe('with word check', () => {
259
+ it('has the `ons-js-char-check-input` class', () => {
260
+ const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_WORD_LIMIT));
261
+
262
+ expect($('.ons-input--textarea').hasClass('ons-js-char-check-input')).toBe(true);
263
+ });
264
+
265
+ it('has the provided maximum length', () => {
266
+ const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_WORD_LIMIT));
267
+
268
+ expect($('.ons-input--textarea').attr('data-message-check-num')).toBe('5');
269
+ });
270
+
271
+ it('has data attribute which references the word check component', () => {
272
+ const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_WORD_LIMIT));
273
+
274
+ expect($('.ons-input--textarea').attr('data-message-check-ref')).toBe('example-id-check');
275
+ });
276
+
277
+ it('has `aria-describedby` attribute which references the word limit component', () => {
278
+ const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_WORD_LIMIT));
279
+
280
+ expect($('.ons-input--textarea').attr('aria-describedby')).toBe('example-id-check');
281
+ });
282
+
283
+ it('renders char check limit component which counts words instead of characters', () => {
284
+ const faker = templateFaker();
285
+ const charCheckLimitSpy = faker.spy('char-check-limit');
286
+
287
+ faker.renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_WORD_LIMIT);
288
+
289
+ expect(charCheckLimitSpy.occurrences).toContainEqual({
290
+ id: 'example-id-check',
291
+ limit: 5,
292
+ variant: 'word',
293
+ wordCountSingular: 'You have {x} word remaining',
294
+ wordCountPlural: 'You have {x} words remaining',
295
+ wordCountOverLimitSingular: '{x} word too many',
296
+ wordCountOverLimitPlural: '{x} words too many',
297
+ });
298
+ });
299
+ });
300
+
301
+ describe('with character check and word check', () => {
302
+ it('only renders char check limit component which counts characters', () => {
303
+ const faker = templateFaker();
304
+ const charCheckLimitSpy = faker.spy('char-check-limit');
305
+
306
+ faker.renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_WORD_LIMIT);
307
+
308
+ expect(charCheckLimitSpy.occurrences).toContainEqual({
309
+ id: 'example-id-check',
310
+ limit: 5,
311
+ variant: 'word',
312
+ wordCountSingular: 'You have {x} word remaining',
313
+ wordCountPlural: 'You have {x} words remaining',
314
+ wordCountOverLimitSingular: '{x} word too many',
315
+ wordCountOverLimitPlural: '{x} words too many',
316
+ });
317
+ });
318
+ });
319
+
247
320
  describe('with error', () => {
248
321
  it('has the `error` modifier class', () => {
249
322
  const $ = cheerio.load(renderComponent('textarea', EXAMPLE_TEXTAREA_WITH_ERROR));
@@ -0,0 +1,20 @@
1
+ {% from "components/textarea/_macro.njk" import onsTextarea %}
2
+
3
+ {{
4
+ onsTextarea({
5
+ "id": "textarea-word-limit",
6
+ "name": "feedback-limited",
7
+ "width": "30",
8
+ "label": {
9
+ "text": "Please provide some feedback",
10
+ "description": "For example, describe any difficulties you experienced in the use of this service"
11
+ },
12
+ "wordCheckLimit": {
13
+ "limit": 150,
14
+ "wordCountSingular": "You have {x} word remaining",
15
+ "wordCountPlural": "You have {x} words remaining",
16
+ "wordCountOverLimitSingular": "You are {x} word over the limit",
17
+ "wordCountOverLimitPlural": "You are {x} words over the limit"
18
+ }
19
+ })
20
+ }}