@ons/design-system 60.0.3 → 61.0.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.
- package/components/access-code/_macro.njk +6 -8
- package/components/accordion/_macro.njk +2 -3
- package/components/accordion/_macro.spec.js +9 -9
- package/components/accordion/accordion.dom.js +4 -4
- package/components/accordion/accordion.js +14 -14
- package/components/accordion/accordion.spec.js +6 -6
- package/components/collapsible/_macro.njk +20 -28
- package/components/collapsible/_macro.spec.js +15 -15
- package/components/{collapsible/_collapsible.scss → details/_details.scss} +14 -14
- package/components/details/_macro.njk +30 -0
- package/components/details/_macro.spec.js +151 -0
- package/components/details/details.dom.js +13 -0
- package/components/details/details.js +66 -0
- package/components/details/details.spec.js +103 -0
- package/components/hero/_hero.scss +2 -2
- package/components/modal/modal.js +12 -6
- package/components/modal/modal.spec.js +0 -11
- package/components/question/_macro.njk +4 -4
- package/components/question/_macro.spec.js +14 -14
- package/components/summary/_macro.njk +1 -1
- package/components/summary/_macro.spec.js +148 -1
- package/components/summary/_summary.scss +6 -2
- package/components/table/_macro.spec.js +10 -8
- package/components/timeout-modal/_macro.njk +19 -20
- package/components/timeout-modal/timeout-modal.spec.js +17 -13
- package/components/video/_macro.njk +18 -4
- package/components/video/_macro.spec.js +46 -33
- package/components/video/_video.scss +4 -0
- package/components/video/video.dom.js +13 -0
- package/components/video/video.js +30 -0
- package/components/video/video.spec.js +72 -0
- package/css/main.css +3 -3
- package/css/print.css +1 -1
- package/js/analytics.js +1 -5
- package/js/main.js +2 -1
- package/js/timeout.js +7 -0
- package/package.json +2 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -1
- package/scss/objects/_page.scss +1 -1
- package/scss/objects/_spacing.scss +1 -1
- package/scss/overrides/hcm.scss +1 -1
- package/scss/print.scss +1 -1
- package/components/collapsible/collapsible.dom.js +0 -13
- package/components/collapsible/collapsible.js +0 -66
- package/components/collapsible/collapsible.spec.js +0 -103
package/scss/main.scss
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
@import '../components/card/card';
|
|
14
14
|
@import '../components/checkboxes/checkbox';
|
|
15
15
|
@import '../components/checkboxes/checkboxes';
|
|
16
|
-
@import '../components/
|
|
16
|
+
@import '../components/details/details';
|
|
17
17
|
@import '../components/content-pagination/content-pagination';
|
|
18
18
|
@import '../components/cookies-banner/cookies-banner';
|
|
19
19
|
@import '../components/document-list/document-list';
|
package/scss/objects/_page.scss
CHANGED
package/scss/overrides/hcm.scss
CHANGED
package/scss/print.scss
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import domready from '../../js/domready';
|
|
2
|
-
|
|
3
|
-
async function initialiseCollapsibles() {
|
|
4
|
-
const collapsibleComponents = [...document.querySelectorAll('.ons-js-collapsible')];
|
|
5
|
-
const accordionComponents = [...document.querySelectorAll('.ons-js-accordion')];
|
|
6
|
-
|
|
7
|
-
if (collapsibleComponents.length && !accordionComponents.length) {
|
|
8
|
-
const Collapsible = (await import('./collapsible')).default;
|
|
9
|
-
collapsibleComponents.map(element => new Collapsible(element));
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
domready(initialiseCollapsibles);
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export default class Collapsible {
|
|
2
|
-
constructor(collapsibleElement) {
|
|
3
|
-
this.saveState = collapsibleElement.getAttribute('data-save-state') === 'true';
|
|
4
|
-
this.open = collapsibleElement.getAttribute('data-open') === 'true';
|
|
5
|
-
this.group = collapsibleElement.getAttribute('data-group');
|
|
6
|
-
|
|
7
|
-
// Elements
|
|
8
|
-
this.collapsible = collapsibleElement;
|
|
9
|
-
this.collapsibleHeader = this.collapsible.querySelector('.ons-js-collapsible-heading');
|
|
10
|
-
|
|
11
|
-
// Initialise
|
|
12
|
-
const collapsibleId = collapsibleElement.getAttribute('id');
|
|
13
|
-
|
|
14
|
-
if (localStorage.getItem(collapsibleId) || this.open) {
|
|
15
|
-
this.setOpen(true);
|
|
16
|
-
this.collapsible['setAttribute']('open', '');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
this.collapsibleHeader.addEventListener('click', this.toggle.bind(this));
|
|
20
|
-
this.collapsibleHeader.addEventListener('keydown', this.keyboardInteraction.bind(this));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
toggle(event) {
|
|
24
|
-
event.preventDefault();
|
|
25
|
-
this.setOpen(!this.isOpen);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
setOpen(open) {
|
|
29
|
-
if (open !== this.isOpen) {
|
|
30
|
-
const action = open ? 'Open' : 'Close';
|
|
31
|
-
const openAttribute = open ? 'set' : 'remove';
|
|
32
|
-
|
|
33
|
-
this.isOpen = open;
|
|
34
|
-
this.collapsible[`${openAttribute}Attribute`]('open', '');
|
|
35
|
-
this.collapsibleHeader.setAttribute('data-ga-action', `${action} panel`);
|
|
36
|
-
|
|
37
|
-
if (this.onOpen && this.onClose) {
|
|
38
|
-
if (open) {
|
|
39
|
-
this.onOpen();
|
|
40
|
-
} else {
|
|
41
|
-
this.onClose();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (this.saveState === true && open === true) {
|
|
47
|
-
localStorage.setItem(this.collapsible.getAttribute('id'), true);
|
|
48
|
-
} else {
|
|
49
|
-
localStorage.removeItem(this.collapsible.getAttribute('id'));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
keyboardInteraction(event) {
|
|
54
|
-
const keyCode = event.which;
|
|
55
|
-
switch (keyCode) {
|
|
56
|
-
// Enter/Space
|
|
57
|
-
case 13:
|
|
58
|
-
case 32:
|
|
59
|
-
event.preventDefault();
|
|
60
|
-
event.stopPropagation();
|
|
61
|
-
|
|
62
|
-
this.toggle(event);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
|
|
2
|
-
|
|
3
|
-
const EXAMPLE_COLLAPSIBLE_BASIC = {
|
|
4
|
-
id: 'collapsible-id',
|
|
5
|
-
title: 'Title for collapsible',
|
|
6
|
-
content: 'Content for collapsible',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('script: collapsible', () => {
|
|
10
|
-
it('begins open when specified', async () => {
|
|
11
|
-
await setTestPage(
|
|
12
|
-
'/test',
|
|
13
|
-
renderComponent('collapsible', {
|
|
14
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
15
|
-
open: true,
|
|
16
|
-
}),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
20
|
-
expect(openAttribute).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('when the collapsible heading is clicked to open the collapsible', () => {
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
26
|
-
await page.click('.ons-js-collapsible-heading');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('sets the `open` attribute', async () => {
|
|
30
|
-
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
31
|
-
expect(openAttribute).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('sets the `ga` attributes', async () => {
|
|
35
|
-
const gaHeadingAttribute = await page.$eval('.ons-js-collapsible-heading', element => element.getAttribute('data-ga-action'));
|
|
36
|
-
|
|
37
|
-
expect(gaHeadingAttribute).toBe('Open panel');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('when the collapsible heading is focused', () => {
|
|
42
|
-
beforeEach(async () => {
|
|
43
|
-
await setTestPage('/test', renderComponent('collapsible', EXAMPLE_COLLAPSIBLE_BASIC));
|
|
44
|
-
await page.focus('.ons-js-collapsible-heading');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('when the space bar is pressed', () => {
|
|
48
|
-
beforeEach(async () => {
|
|
49
|
-
await page.keyboard.press('Space');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('opens the collapsible content', async () => {
|
|
53
|
-
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
54
|
-
expect(openAttribute).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('when the Enter key is pressed', () => {
|
|
59
|
-
beforeEach(async () => {
|
|
60
|
-
await page.keyboard.press('Enter');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('opens the collapsible content', async () => {
|
|
64
|
-
const openAttribute = await page.$eval('.ons-js-collapsible', node => node.open !== null);
|
|
65
|
-
expect(openAttribute).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('when the state is set to save', () => {
|
|
71
|
-
beforeEach(async () => {
|
|
72
|
-
await setTestPage(
|
|
73
|
-
'/test',
|
|
74
|
-
renderComponent('collapsible', {
|
|
75
|
-
...EXAMPLE_COLLAPSIBLE_BASIC,
|
|
76
|
-
saveState: true,
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('when the collapsible is opened', () => {
|
|
82
|
-
beforeEach(async () => {
|
|
83
|
-
await page.click('.ons-js-collapsible-heading');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('sets state in localStorage', async () => {
|
|
87
|
-
const localStorage = await page.evaluate(() => localStorage.getItem('collapsible-id'));
|
|
88
|
-
expect(localStorage).toBe('true');
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('when the collapsible is closed', () => {
|
|
93
|
-
beforeEach(async () => {
|
|
94
|
-
await page.click('.ons-js-collapsible-heading');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('removes state in localStorage', async () => {
|
|
98
|
-
const localStorage = await page.evaluate(() => localStorage.getItem('collapsible-id'));
|
|
99
|
-
expect(localStorage).toBe(null);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|