@ons/design-system 72.9.2 → 72.10.1

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 (48) hide show
  1. package/components/char-check-limit/_macro.njk +2 -2
  2. package/components/char-check-limit/character-check.js +30 -9
  3. package/components/char-check-limit/character-check.spec.js +1 -1
  4. package/components/chart/_chart.scss +73 -1
  5. package/components/chart/_macro.njk +90 -20
  6. package/components/chart/_macro.spec.js +424 -0
  7. package/components/chart/bar-chart.js +46 -20
  8. package/components/chart/boxplot.js +37 -0
  9. package/components/chart/chart-constants.js +14 -0
  10. package/components/chart/chart.js +102 -46
  11. package/components/chart/columnrange-chart.js +94 -0
  12. package/components/chart/common-chart-options.js +65 -23
  13. package/components/chart/example-bar-chart-with-annotations.njk +1 -1
  14. package/components/chart/example-bar-chart-with-point-range-and-reference-line-annotations.njk +95 -0
  15. package/components/chart/example-bar-with-confidence-levels.njk +71 -0
  16. package/components/chart/example-clustered-column-chart.njk +1 -3
  17. package/components/chart/example-column-chart-with-annotations.njk +1 -1
  18. package/components/chart/example-column-chart-with-custom-reference-line-value.njk +56 -0
  19. package/components/chart/example-column-chart-with-range-annotations.njk +64 -0
  20. package/components/chart/example-column-chart-with-reference-line-annotations.njk +64 -0
  21. package/components/chart/example-column-with-confidence-levels.njk +61 -0
  22. package/components/chart/example-line-chart-with-annotations.njk +3 -3
  23. package/components/chart/example-line-chart-with-custom-reference-line-value.njk +224 -0
  24. package/components/chart/example-line-chart-with-markers.njk +21 -21
  25. package/components/chart/example-line-chart-with-range-annotations-inside.njk +238 -0
  26. package/components/chart/example-line-chart-with-range-annotations-outside-left-right.njk +240 -0
  27. package/components/chart/example-line-chart-with-range-annotations-outside-top-bottom.njk +239 -0
  28. package/components/chart/example-line-chart-with-reference-line-annotations.njk +236 -0
  29. package/components/chart/example-scatter-chart.njk +5 -5
  30. package/components/chart/line-chart.js +29 -11
  31. package/components/chart/range-annotations-options.js +221 -0
  32. package/components/chart/reference-line-annotations-options.js +93 -0
  33. package/components/chart/scatter-chart.js +15 -6
  34. package/components/chart/specific-chart-options.js +22 -1
  35. package/components/chart/utilities.js +97 -0
  36. package/components/checkboxes/_macro.spec.js +1 -1
  37. package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +1 -1
  38. package/components/textarea/_macro.njk +8 -6
  39. package/components/textarea/_macro.spec.js +12 -8
  40. package/components/textarea/{example-textarea-with-character-limit.njk → example-textarea-with-character-check.njk} +3 -1
  41. package/css/main.css +1 -1
  42. package/js/main.js +0 -1
  43. package/package.json +14 -14
  44. package/scripts/main.es5.js +1 -1
  45. package/scripts/main.js +1 -1
  46. package/components/char-check-limit/character-limit.js +0 -55
  47. package/components/textarea/textarea.dom.js +0 -12
  48. package/components/textarea/textarea.spec.js +0 -98
@@ -1,55 +0,0 @@
1
- import { trackEvent } from '../../js/analytics';
2
-
3
- const inputClassLimitReached = 'ons-input--limit-reached';
4
- const remainingClassLimitReached = 'ons-input__limit--reached';
5
- const attrCharLimitRef = 'data-char-limit-ref';
6
-
7
- export default class CharLimit {
8
- constructor(input) {
9
- this.input = input;
10
- this.maxLength = input.maxLength;
11
- this.limitElement = document.getElementById(input.getAttribute(attrCharLimitRef));
12
- this.singularMessage = this.limitElement.getAttribute('data-charcount-singular');
13
- this.pluralMessage = this.limitElement.getAttribute('data-charcount-plural');
14
-
15
- this.updateLimitReadout(null, true);
16
- this.limitElement.classList.remove('ons-u-d-no');
17
-
18
- input.addEventListener('input', this.updateLimitReadout.bind(this));
19
- }
20
-
21
- updateLimitReadout(event, firstRun) {
22
- const value = this.input.value;
23
- const remaining = this.maxLength - value.length;
24
- const message = remaining === 1 ? this.singularMessage : this.pluralMessage;
25
- // Prevent aria live announcement when component initialises
26
- if (!firstRun && event.inputType) {
27
- this.limitElement.setAttribute('aria-live', 'polite');
28
- this.limitElement.setAttribute('aria-live', [remaining > 0 ? 'polite' : 'assertive']);
29
- } else {
30
- this.limitElement.removeAttribute('aria-live');
31
- }
32
-
33
- this.limitElement.innerText = message.replace('{x}', remaining);
34
-
35
- this.setLimitClass(remaining, this.input, inputClassLimitReached);
36
- this.setLimitClass(remaining, this.limitElement, remainingClassLimitReached);
37
-
38
- this.track(remaining);
39
- }
40
-
41
- setLimitClass(remaining, element, limitClass) {
42
- element.classList[remaining > 0 ? 'remove' : 'add'](limitClass);
43
- }
44
-
45
- track(remaining) {
46
- if (remaining < 1) {
47
- trackEvent({
48
- event_type: 'event',
49
- event_category: 'Error',
50
- event_action: 'Textarea limit reached',
51
- event_label: `Limit of ${this.maxLength} reached/exceeded`,
52
- });
53
- }
54
- }
55
- }
@@ -1,12 +0,0 @@
1
- import domready from '../../js/domready';
2
-
3
- async function initialise() {
4
- const limitedInputs = [...document.querySelectorAll('.ons-js-char-limit-input')];
5
- if (limitedInputs.length) {
6
- const CharLimit = (await import('../char-check-limit/character-limit')).default;
7
-
8
- limitedInputs.forEach((input) => new CharLimit(input));
9
- }
10
- }
11
-
12
- domready(initialise);
@@ -1,98 +0,0 @@
1
- import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
-
3
- describe('script: textarea', () => {
4
- describe('character limit', () => {
5
- beforeEach(async () => {
6
- await setTestPage(
7
- '/test',
8
- renderComponent('textarea', {
9
- id: 'example-textarea',
10
- name: 'feedback-limited',
11
- width: '30',
12
- label: {
13
- text: 'Please provide some feedback',
14
- description: 'For example describe any difficulties you experienced in the use of this service',
15
- },
16
- charCheckLimit: {
17
- limit: 50,
18
- charCountSingular: 'You have {x} character remaining',
19
- charCountPlural: 'You have {x} characters remaining',
20
- },
21
- }),
22
- );
23
- });
24
-
25
- describe('Given that the char limit helper has initialised correctly', () => {
26
- it('the char limit readout should be visible', async () => {
27
- const hasClass = await page.$eval('#example-textarea-lim', (node) => node.classList.contains('ons-u-d-no'));
28
- expect(hasClass).toBe(false);
29
- });
30
- });
31
-
32
- describe('Given that the user has not typed into the textarea', () => {
33
- describe('when the user types into the textarea', () => {
34
- beforeEach(async () => {
35
- await page.type('#example-textarea', 'Lorem ipsum dolor.\nMorbi rhoncus amet.');
36
- });
37
-
38
- it('then the characters remaining readout reflect the number of characters remaining', async () => {
39
- const readout = await page.$eval('#example-textarea-lim', (node) => node.textContent);
40
- expect(readout).toBe('You have 12 characters remaining');
41
- });
42
- });
43
-
44
- describe('when the user reaches/exceeds the maxlength of the textarea', () => {
45
- beforeEach(async () => {
46
- await page.type('#example-textarea', 'Lorem ipsum dolor sit amet, consectetur porttitor.');
47
- });
48
-
49
- it('then the characters remaining readout reflect the number of characters remaining', async () => {
50
- const readout = await page.$eval('#example-textarea-lim', (node) => node.textContent);
51
- expect(readout).toBe('You have 0 characters remaining');
52
- });
53
-
54
- it('then the textarea should be given limit reached classes', async () => {
55
- const hasClass = await page.$eval('#example-textarea', (node) => node.classList.contains('ons-input--limit-reached'));
56
- expect(hasClass).toBe(true);
57
- });
58
-
59
- it('then the readout should be given limit reached classes', async () => {
60
- const hasClass = await page.$eval('#example-textarea-lim', (node) =>
61
- node.classList.contains('ons-input__limit--reached'),
62
- );
63
- expect(hasClass).toBe(true);
64
- });
65
- });
66
- });
67
-
68
- describe('Given that the user has reached/exceeded the maxlength of the textarea', () => {
69
- beforeEach(async () => {
70
- await page.type('#example-textarea', 'Lorem ipsum dolor sit amet, consectetur porttitor.');
71
- });
72
-
73
- describe('when the user removes a character', () => {
74
- beforeEach(async () => {
75
- await page.focus('#example-textarea');
76
- await page.keyboard.press('Backspace');
77
- });
78
-
79
- it('then the characters remaining readout reflect the number of characters remaining', async () => {
80
- const readout = await page.$eval('#example-textarea-lim', (node) => node.textContent);
81
- expect(readout).toBe('You have 1 character remaining');
82
- });
83
-
84
- it('then the textarea should not be given limit reached classes', async () => {
85
- const hasClass = await page.$eval('#example-textarea', (node) => node.classList.contains('ons-input--limit-reached'));
86
- expect(hasClass).toBe(false);
87
- });
88
-
89
- it('then the readout should not be given limit reached classes', async () => {
90
- const hasClass = await page.$eval('#example-textarea-lim', (node) =>
91
- node.classList.contains('ons-input__limit--reached'),
92
- );
93
- expect(hasClass).toBe(false);
94
- });
95
- });
96
- });
97
- });
98
- });