@madgex/design-system 14.3.1 → 14.4.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/dist/assets/icons-inline.svg +1 -1
- package/dist/assets/icons.json +1 -1
- package/dist/assets/icons.svg +1 -1
- package/dist/js/index.js +1 -1
- package/package.json +4 -4
- package/src/components/accordion/_template.njk +35 -33
- package/src/components/accordion/accordion.config.js +0 -81
- package/src/components/accordion/accordion.js +54 -43
- package/src/components/accordion/accordion.njk +1 -24
- package/src/components/accordion/accordion.spec.js +170 -0
- package/src/components/button/button.config.js +1 -42
- package/src/components/button/button.njk +1 -14
- package/src/components/card/card.config.js +0 -93
- package/src/components/card/card.njk +1 -22
- package/src/components/icons/icons.njk +1 -161
- package/src/components/inputs/combobox/README.md +22 -1
- package/src/components/inputs/combobox/combobox.njk +26 -2
- package/src/js/index.js +5 -2
- package/src/layout/containers/index.njk +1 -0
- package/src/typography/index.njk +1 -0
- package/tasks/svgsprite.js +62 -49
- package/src/components/accordion/README.md +0 -46
- package/src/components/button/README.md +0 -27
- package/src/components/card/README.md +0 -114
- package/src/components/icons/README.md +0 -62
- package/src/layout/containers/01-base-containers.njk +0 -30
- package/src/layout/containers/02-branded-containers.njk +0 -13
- package/src/layout/containers/03-ad-containers.njk +0 -6
- package/src/layout/containers/04-highlighted-containers.njk +0 -3
- package/src/layout/containers/README.md +0 -30
- package/src/layout/containers/ad-containers.config.json +0 -3
- package/src/layout/containers/base-containers.config.json +0 -3
- package/src/layout/containers/branded-containers.config.json +0 -3
- package/src/layout/containers/highlighted-containers.config.json +0 -3
- package/src/typography/font-types.config.json +0 -3
- package/src/typography/font-types.njk +0 -43
- package/src/typography/headings.njk +0 -9
- package/src/typography/lists.njk +0 -111
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
{%- from "../icons/_macro.njk" import MdsIcon -%}
|
|
2
2
|
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
<mds-accordion>
|
|
4
|
+
<details
|
|
5
|
+
class="mds-accordion
|
|
6
|
+
{%- if params.nonClosing %} mds-accordion--non-closing{% endif -%}
|
|
7
|
+
{%- if params.leftAligned %} mds-accordion--left-aligned{% endif -%}
|
|
8
|
+
{%- if params.breakpoint %} mds-accordion--breakpoint{% endif -%}
|
|
9
|
+
{%- if params.contentFirst %} mds-accordion--content-first{% endif -%}"
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
>
|
|
13
|
-
|
|
14
|
-
{%- if not params.noIcon -%}
|
|
15
|
-
{{- MdsIcon({ iconName: params.icon | default('triangle-right'), classes: "mds-accordion__icon" }) -}}
|
|
16
|
-
{{- MdsIcon({ iconName: params.iconOpen | default('triangle-down'), classes: "mds-accordion__icon--open" }) -}}
|
|
17
|
-
{%- endif -%}
|
|
18
|
-
<span class="mds-accordion__label">{{ params.label | safe }}</span>{#
|
|
19
|
-
#}<span class="mds-accordion__label--open">{{ params.labelOpen | default(params.label) | safe }}</span>
|
|
20
|
-
</summary>
|
|
21
|
-
|
|
22
|
-
<div data-test="accordion-content">
|
|
23
|
-
{{- caller() -}}
|
|
24
|
-
</div>
|
|
25
|
-
|
|
26
|
-
{%- if params.contentFirst -%}
|
|
27
|
-
<button
|
|
28
|
-
type="button"
|
|
29
|
-
class="mds-accordion__label mds-button mds-button--plain mds-padding-x-b0 {{ params.labelClasses }}"
|
|
30
|
-
aria-expanded="true"
|
|
31
|
-
>
|
|
11
|
+
{%- if params.breakpoint %} data-bp="{{ params.breakpoint }}"{% endif -%}
|
|
12
|
+
{%- if params.startsOpen %} open{% endif -%}
|
|
13
|
+
>
|
|
14
|
+
<summary class="mds-button mds-button--plain mds-padding-x-b0 {{ params.labelClasses }}">
|
|
32
15
|
{%- if not params.noIcon -%}
|
|
33
|
-
{{- MdsIcon({ iconName: params.
|
|
16
|
+
{{- MdsIcon({ iconName: params.icon | default('triangle-right'), classes: "mds-accordion__icon" }) -}}
|
|
17
|
+
{{- MdsIcon({ iconName: params.iconOpen | default('triangle-down'), classes: "mds-accordion__icon--open" }) -}}
|
|
34
18
|
{%- endif -%}
|
|
35
|
-
{{
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
<span class="mds-accordion__label">{{ params.label | safe }}</span>{#
|
|
20
|
+
#}<span class="mds-accordion__label--open">{{ params.labelOpen | default(params.label) | safe }}</span>
|
|
21
|
+
</summary>
|
|
22
|
+
|
|
23
|
+
<div data-test="accordion-content">
|
|
24
|
+
{{- caller() -}}
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
{%- if params.contentFirst -%}
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
class="mds-accordion__label mds-accordion__close-button mds-button mds-button--plain mds-padding-x-b0 {{ params.labelClasses }}"
|
|
31
|
+
aria-expanded="true"
|
|
32
|
+
>
|
|
33
|
+
{%- if not params.noIcon -%}
|
|
34
|
+
{{- MdsIcon({ iconName: params.iconOpen | default('triangle-up'), classes: "mds-accordion__icon--open" }) -}}
|
|
35
|
+
{%- endif -%}
|
|
36
|
+
{{- params.labelOpen | default(params.label) -}}
|
|
37
|
+
</button>
|
|
38
|
+
{%- endif -%}
|
|
38
39
|
|
|
39
|
-
</details>
|
|
40
|
+
</details>
|
|
41
|
+
</mds-accordion>
|
|
@@ -2,85 +2,4 @@ module.exports = {
|
|
|
2
2
|
title: 'Accordion',
|
|
3
3
|
label: 'Accordion',
|
|
4
4
|
status: 'ready',
|
|
5
|
-
context: {
|
|
6
|
-
name: 'Default',
|
|
7
|
-
label: 'View more categories',
|
|
8
|
-
labelOpen: 'View less categories',
|
|
9
|
-
content:
|
|
10
|
-
'<dl class="mds-list mds-list--definition mds-list--border"><dt class="mds-list__key">Hours</dt><dd class="mds-list__value">Full time</dd><dt class="mds-list__key">Contract</dt><dd class="mds-list__value">Permanent</dd><dt class="mds-list__key">Industry</dt><dd class="mds-list__value">Accountant, Manager</dd></dl>',
|
|
11
|
-
},
|
|
12
|
-
variants: [
|
|
13
|
-
{
|
|
14
|
-
name: 'Alternative icons',
|
|
15
|
-
context: {
|
|
16
|
-
name: 'Alt Icons',
|
|
17
|
-
label: 'View more options',
|
|
18
|
-
labelOpen: 'View less options',
|
|
19
|
-
icon: 'plus-small',
|
|
20
|
-
iconOpen: 'minus',
|
|
21
|
-
leftAligned: true,
|
|
22
|
-
content:
|
|
23
|
-
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ligula erat, dignissim non sollicitudin ut, sagittis a sapien. Quisque eget arcu sed nulla tincidunt eleifend. Maecenas sit amet velit elit. Maecenas elementum venenatis sapien sit amet elementum. Pellentesque id mauris quis tortor suscipit posuere. Donec eu consectetur tortor. Mauris id scelerisque quam. Sed scelerisque ut est quis sollicitudin. Etiam semper tempor erat, sed rhoncus ex malesuada non. Donec eu pellentesque odio. Vestibulum et suscipit risus, luctus semper nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam eu est ac libero blandit egestas ac id tellus. Suspendisse pulvinar viverra ex, a varius ligula commodo at. Vivamus dignissim neque vitae est ultrices lobortis. Cras vel pulvinar erat.</p>',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'Trigger html tag',
|
|
28
|
-
context: {
|
|
29
|
-
name: 'Trigger html tag',
|
|
30
|
-
label: 'Lorem ipsum',
|
|
31
|
-
labelClasses: 'mds-font-s2',
|
|
32
|
-
content:
|
|
33
|
-
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ligula erat, dignissim non sollicitudin ut, sagittis a sapien. Quisque eget arcu sed nulla tincidunt eleifend. Maecenas sit amet velit elit. Maecenas elementum venenatis sapien sit amet elementum. Pellentesque id mauris quis tortor suscipit posuere. Donec eu consectetur tortor. Mauris id scelerisque quam. Sed scelerisque ut est quis sollicitudin. Etiam semper tempor erat, sed rhoncus ex malesuada non. Donec eu pellentesque odio. Vestibulum et suscipit risus, luctus semper nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam eu est ac libero blandit egestas ac id tellus. Suspendisse pulvinar viverra ex, a varius ligula commodo at. Vivamus dignissim neque vitae est ultrices lobortis. Cras vel pulvinar erat.</p>',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'Content above closing label',
|
|
38
|
-
context: {
|
|
39
|
-
name: 'Content above closing label',
|
|
40
|
-
label: 'Read more...',
|
|
41
|
-
labelOpen: 'Read less',
|
|
42
|
-
noIcon: true,
|
|
43
|
-
contentFirst: true,
|
|
44
|
-
content: `<ul>
|
|
45
|
-
<li><a href="https://www.example.com">Link 1</a></li>
|
|
46
|
-
<li><a href="https://www.example.com">Link 2</a></li>
|
|
47
|
-
<li><a href="https://www.example.com">Link 3</a></li>
|
|
48
|
-
<li><a href="https://www.example.com">Link 4</a></li>
|
|
49
|
-
</ul>
|
|
50
|
-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ligula erat, dignissim non sollicitudin ut, sagittis a sapien. Quisque eget arcu sed nulla tincidunt eleifend. Maecenas sit amet velit elit. Maecenas elementum venenatis sapien sit amet elementum. Pellentesque id mauris quis tortor suscipit posuere. Donec eu consectetur tortor. Mauris id scelerisque quam. Sed scelerisque ut est quis sollicitudin. Etiam semper tempor erat, sed rhoncus ex malesuada non. Donec eu pellentesque odio. Vestibulum et suscipit risus, luctus semper nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam eu est ac libero blandit egestas ac id tellus. Suspendisse pulvinar viverra ex, a varius ligula commodo at. Vivamus dignissim neque vitae est ultrices lobortis. Cras vel pulvinar erat.</p>`,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'Non Closing',
|
|
55
|
-
context: {
|
|
56
|
-
name: 'Non Closing',
|
|
57
|
-
label: 'View more options',
|
|
58
|
-
nonClosing: true,
|
|
59
|
-
content:
|
|
60
|
-
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ligula erat, dignissim non sollicitudin ut, sagittis a sapien. Quisque eget arcu sed nulla tincidunt eleifend. Maecenas sit amet velit elit. Maecenas elementum venenatis sapien sit amet elementum. Pellentesque id mauris quis tortor suscipit posuere. Donec eu consectetur tortor. Mauris id scelerisque quam. Sed scelerisque ut est quis sollicitudin. <a href="#">Etiam semper tempor erat</a>, sed rhoncus ex malesuada non. Donec eu pellentesque odio. Vestibulum et suscipit risus, luctus semper nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam eu est ac libero blandit egestas ac id tellus. Suspendisse pulvinar viverra ex, a varius ligula commodo at. Vivamus dignissim neque vitae est ultrices lobortis. Cras vel pulvinar erat.</p>',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: 'Mobile Only',
|
|
65
|
-
context: {
|
|
66
|
-
name: 'Mobile Only',
|
|
67
|
-
label: 'View more categories',
|
|
68
|
-
labelOpen: 'View less categories',
|
|
69
|
-
breakpoint: '600px',
|
|
70
|
-
content:
|
|
71
|
-
'<dl class="mds-list mds-list--definition mds-list--border"><dt class="mds-list__key">Hours</dt><dd class="mds-list__value">Full time</dd><dt class="mds-list__key">Contract</dt><dd class="mds-list__value">Permanent</dd><dt class="mds-list__key">Industry</dt><dd class="mds-list__value">Accountant, Manager</dd></dl>',
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: 'Starts expanded',
|
|
76
|
-
context: {
|
|
77
|
-
name: 'Starts expanded',
|
|
78
|
-
label: 'View more categories',
|
|
79
|
-
labelOpen: 'View less categories',
|
|
80
|
-
startsOpen: true,
|
|
81
|
-
content:
|
|
82
|
-
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ligula erat, dignissim non sollicitudin ut, sagittis a sapien. Quisque eget arcu sed nulla tincidunt eleifend. Maecenas sit amet velit elit. Maecenas elementum venenatis sapien sit amet elementum. Pellentesque id mauris quis tortor suscipit posuere. Donec eu consectetur tortor. Mauris id scelerisque quam. Sed scelerisque ut est quis sollicitudin. <a href="#">Etiam semper tempor erat</a>, sed rhoncus ex malesuada non. Donec eu pellentesque odio. Vestibulum et suscipit risus, luctus semper nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam eu est ac libero blandit egestas ac id tellus. Suspendisse pulvinar viverra ex, a varius ligula commodo at. Vivamus dignissim neque vitae est ultrices lobortis. Cras vel pulvinar erat.</p>',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
5
|
};
|
|
@@ -1,41 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
export class MdsAccordion extends HTMLElement {
|
|
2
|
+
static accordionBreakpointClass = 'mds-accordion--breakpoint';
|
|
3
|
+
static accordionCloseButtonClass = 'mds-accordion__close-button';
|
|
4
|
+
#controller;
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
this.#controller = new AbortController();
|
|
12
|
+
// TODO: use an Observer or Listener to track window breakpoint? Or a CSS test of some kind?
|
|
13
|
+
const isBreakpointAccordion = this.#details.classList.contains(MdsAccordion.accordionBreakpointClass);
|
|
14
|
+
if (isBreakpointAccordion && !this.#useAsAccordionBasedOnBreakpoint()) {
|
|
15
|
+
this.#details.open = true;
|
|
16
|
+
this.#summary.style.display = 'none';
|
|
17
|
+
} else {
|
|
18
|
+
this.#summary.style.display = '';
|
|
19
|
+
}
|
|
20
|
+
if (this.#closeButton) {
|
|
21
|
+
this.#closeButton.addEventListener('click', this.#onClickCloseButton, { signal: this.#controller.signal });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
disconnectedCallback() {
|
|
25
|
+
this.#controller?.abort();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get #details() {
|
|
29
|
+
return this.querySelector('details');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get #summary() {
|
|
33
|
+
return this.querySelector('summary');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get #closeButton() {
|
|
37
|
+
return this.querySelector(`.${MdsAccordion.accordionCloseButtonClass}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#onClickCloseButton = () => {
|
|
41
|
+
this.#details.open = false;
|
|
42
|
+
this.#summary.focus();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** */
|
|
46
|
+
#useAsAccordionBasedOnBreakpoint() {
|
|
47
|
+
let breakpoint;
|
|
48
|
+
|
|
49
|
+
if (this.#details.dataset.bp) {
|
|
50
|
+
const breakpointValue = this.#details.dataset.bp.replace(/\D/g, '');
|
|
51
|
+
const breakpointUnit = this.#details.dataset.bp.replace(/[0-9]/g, '');
|
|
39
52
|
let fontSize;
|
|
40
53
|
let conversionValue;
|
|
41
54
|
|
|
@@ -60,7 +73,7 @@ const accordion = {
|
|
|
60
73
|
return true;
|
|
61
74
|
}
|
|
62
75
|
|
|
63
|
-
if (
|
|
76
|
+
if (window.innerWidth > breakpoint) {
|
|
64
77
|
return false;
|
|
65
78
|
}
|
|
66
79
|
|
|
@@ -68,7 +81,5 @@ const accordion = {
|
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
return true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export default accordion;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<h3>{{ name }}</h3>
|
|
4
|
-
<div>
|
|
5
|
-
{% call MdsAccordion({
|
|
6
|
-
label: label,
|
|
7
|
-
labelOpen: labelOpen,
|
|
8
|
-
labelClasses: labelClasses,
|
|
9
|
-
icon: icon,
|
|
10
|
-
iconOpen: iconOpen,
|
|
11
|
-
noIcon: noIcon,
|
|
12
|
-
startsOpen: startsOpen,
|
|
13
|
-
nonClosing: nonClosing,
|
|
14
|
-
breakpoint: breakpoint,
|
|
15
|
-
leftAligned: leftAligned,
|
|
16
|
-
contentFirst: contentFirst
|
|
17
|
-
}) -%}
|
|
18
|
-
{#
|
|
19
|
-
<!-- example - in normal use `safe` is discouraged as it is dangerous, and not needed -->
|
|
20
|
-
<div> My Accordion Content </div>
|
|
21
|
-
#}
|
|
22
|
-
{{ content | safe }}
|
|
23
|
-
{%- endcall %}
|
|
24
|
-
</div>
|
|
1
|
+
<a href="/storybook/" target="_top">Moved to Storybook</a>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, vi } from 'vitest';
|
|
2
|
+
import { MdsAccordion } from './accordion.js';
|
|
3
|
+
|
|
4
|
+
if (!customElements.get('mds-accordion')) {
|
|
5
|
+
customElements.define('mds-accordion', MdsAccordion);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function mountAccordion({ open = false, breakpoint = false, bpValue, hasCloseButton = false } = {}) {
|
|
9
|
+
const container = document.createElement('div');
|
|
10
|
+
const bpClass = breakpoint ? ` ${MdsAccordion.accordionBreakpointClass}` : '';
|
|
11
|
+
const bpAttr = bpValue ? ` data-bp="${bpValue}"` : '';
|
|
12
|
+
const closeButtonHtml = hasCloseButton
|
|
13
|
+
? `<button class="${MdsAccordion.accordionCloseButtonClass}">Close</button>`
|
|
14
|
+
: '';
|
|
15
|
+
|
|
16
|
+
container.innerHTML = `
|
|
17
|
+
<mds-accordion>
|
|
18
|
+
<details class="mds-accordion${bpClass}"${bpAttr}${open ? ' open' : ''}>
|
|
19
|
+
<summary>Accordion title</summary>
|
|
20
|
+
<div class="mds-accordion__content">
|
|
21
|
+
<p>Content</p>
|
|
22
|
+
${closeButtonHtml}
|
|
23
|
+
</div>
|
|
24
|
+
</details>
|
|
25
|
+
</mds-accordion>
|
|
26
|
+
`;
|
|
27
|
+
document.body.appendChild(container);
|
|
28
|
+
|
|
29
|
+
const accordion = container.querySelector('mds-accordion');
|
|
30
|
+
const details = container.querySelector('details');
|
|
31
|
+
const summary = container.querySelector('summary');
|
|
32
|
+
const closeButton = container.querySelector(`.${MdsAccordion.accordionCloseButtonClass}`);
|
|
33
|
+
|
|
34
|
+
return { container, accordion, details, summary, closeButton };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('MdsAccordion', () => {
|
|
38
|
+
let container;
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
container?.remove();
|
|
42
|
+
vi.restoreAllMocks();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('connectedCallback', () => {
|
|
46
|
+
it('sets summary display to empty string for a standard accordion', () => {
|
|
47
|
+
({ container } = mountAccordion());
|
|
48
|
+
const summary = container.querySelector('summary');
|
|
49
|
+
expect(summary.style.display).toBe('');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('opens details and hides summary when breakpoint accordion is above breakpoint', () => {
|
|
53
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(1200);
|
|
54
|
+
({ container } = mountAccordion({ breakpoint: true, bpValue: '768px' }));
|
|
55
|
+
const details = container.querySelector('details');
|
|
56
|
+
const summary = container.querySelector('summary');
|
|
57
|
+
|
|
58
|
+
expect(details.open).toBe(true);
|
|
59
|
+
expect(summary.style.display).toBe('none');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('keeps accordion collapsed when breakpoint accordion is below breakpoint', () => {
|
|
63
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(500);
|
|
64
|
+
({ container } = mountAccordion({ breakpoint: true, bpValue: '768px' }));
|
|
65
|
+
const details = container.querySelector('details');
|
|
66
|
+
const summary = container.querySelector('summary');
|
|
67
|
+
|
|
68
|
+
expect(details.open).toBe(false);
|
|
69
|
+
expect(summary.style.display).toBe('');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('close button', () => {
|
|
74
|
+
it('closes the details and focuses summary when close button is clicked', () => {
|
|
75
|
+
({ container } = mountAccordion({ open: true, hasCloseButton: true }));
|
|
76
|
+
const details = container.querySelector('details');
|
|
77
|
+
const summary = container.querySelector('summary');
|
|
78
|
+
const closeButton = container.querySelector(`.${MdsAccordion.accordionCloseButtonClass}`);
|
|
79
|
+
|
|
80
|
+
vi.spyOn(summary, 'focus');
|
|
81
|
+
closeButton.click();
|
|
82
|
+
|
|
83
|
+
expect(details.open).toBe(false);
|
|
84
|
+
expect(summary.focus).toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('disconnectedCallback', () => {
|
|
89
|
+
it('removes event listeners when disconnected', () => {
|
|
90
|
+
({ container } = mountAccordion({ open: true, hasCloseButton: true }));
|
|
91
|
+
const accordion = container.querySelector('mds-accordion');
|
|
92
|
+
const details = container.querySelector('details');
|
|
93
|
+
const closeButton = container.querySelector(`.${MdsAccordion.accordionCloseButtonClass}`);
|
|
94
|
+
|
|
95
|
+
// Disconnect the element
|
|
96
|
+
accordion.remove();
|
|
97
|
+
|
|
98
|
+
// Re-append the inner DOM to test that the listener was removed
|
|
99
|
+
document.body.appendChild(container);
|
|
100
|
+
details.open = true;
|
|
101
|
+
closeButton.click();
|
|
102
|
+
|
|
103
|
+
// details should still be open because the listener was aborted
|
|
104
|
+
expect(details.open).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('creates a fresh AbortController on reconnect', () => {
|
|
108
|
+
({ container } = mountAccordion({ open: true, hasCloseButton: true }));
|
|
109
|
+
const accordion = container.querySelector('mds-accordion');
|
|
110
|
+
const details = container.querySelector('details');
|
|
111
|
+
const closeButton = container.querySelector(`.${MdsAccordion.accordionCloseButtonClass}`);
|
|
112
|
+
|
|
113
|
+
// Disconnect then reconnect
|
|
114
|
+
accordion.remove();
|
|
115
|
+
container.appendChild(accordion);
|
|
116
|
+
|
|
117
|
+
// The close button listener should work again
|
|
118
|
+
details.open = true;
|
|
119
|
+
closeButton.click();
|
|
120
|
+
expect(details.open).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('breakpoint handling', () => {
|
|
125
|
+
afterEach(() => {
|
|
126
|
+
vi.restoreAllMocks();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('handles em breakpoint units', () => {
|
|
130
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(1200);
|
|
131
|
+
vi.spyOn(window, 'getComputedStyle').mockReturnValue({ 'font-size': '16px' });
|
|
132
|
+
|
|
133
|
+
({ container } = mountAccordion({ breakpoint: true, bpValue: '48em' }));
|
|
134
|
+
const details = container.querySelector('details');
|
|
135
|
+
|
|
136
|
+
// 48 * 16 = 768, window is 1200 > 768 so should open
|
|
137
|
+
expect(details.open).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('handles rem breakpoint units', () => {
|
|
141
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(1200);
|
|
142
|
+
vi.spyOn(window, 'getComputedStyle').mockReturnValue({ 'font-size': '16px' });
|
|
143
|
+
|
|
144
|
+
({ container } = mountAccordion({ breakpoint: true, bpValue: '48rem' }));
|
|
145
|
+
const details = container.querySelector('details');
|
|
146
|
+
|
|
147
|
+
// 48 * 16 = 768, window is 1200 > 768 so should open
|
|
148
|
+
expect(details.open).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('uses accordion behaviour for unknown units', () => {
|
|
152
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(1200);
|
|
153
|
+
({ container } = mountAccordion({ breakpoint: true, bpValue: '768vw' }));
|
|
154
|
+
const details = container.querySelector('details');
|
|
155
|
+
|
|
156
|
+
// Unknown unit defaults to treating as accordion
|
|
157
|
+
expect(details.open).toBe(false);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('uses accordion behaviour when no data-bp attribute is present on breakpoint accordion', () => {
|
|
161
|
+
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(1200);
|
|
162
|
+
({ container } = mountAccordion({ breakpoint: true }));
|
|
163
|
+
const details = container.querySelector('details');
|
|
164
|
+
const summary = container.querySelector('summary');
|
|
165
|
+
|
|
166
|
+
expect(details.open).toBe(false);
|
|
167
|
+
expect(summary.style.display).toBe('');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -1,45 +1,4 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
title: 'Buttons',
|
|
3
|
-
status: '
|
|
4
|
-
context: {
|
|
5
|
-
items: [
|
|
6
|
-
{
|
|
7
|
-
href: 'http://madgex.com',
|
|
8
|
-
text: 'Link button 1',
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
href: 'http://madgex.com',
|
|
12
|
-
text: 'Link Plain button 2',
|
|
13
|
-
classes: 'mds-button--plain',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
text: 'Plain button',
|
|
17
|
-
classes: 'mds-button--plain',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
text: 'Small button',
|
|
21
|
-
classes: 'mds-button--small',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
text: 'Large button',
|
|
25
|
-
classes: 'mds-button--large',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
text: 'Full width example',
|
|
29
|
-
classes: 'mds-width-full mds-width-md-auto',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
text: 'Neutral',
|
|
33
|
-
classes: 'mds-button--neutral',
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
text: 'Prevent double submit',
|
|
37
|
-
classes: 'js-mds-button-double-submit',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
text: 'With attributes',
|
|
41
|
-
attributes: { attributed: 'yes', 'other-thing': 'also' },
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
},
|
|
3
|
+
status: 'ready',
|
|
45
4
|
};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
{% from "./button/_macro.njk" import MdsButton %}
|
|
3
|
-
|
|
4
|
-
{% for item in items %}
|
|
5
|
-
{% call MdsButton({
|
|
6
|
-
href: item.href,
|
|
7
|
-
classes: item.classes,
|
|
8
|
-
attributes: item.attributes
|
|
9
|
-
}) -%}
|
|
10
|
-
{{ item.text }}
|
|
11
|
-
{%- endcall %}
|
|
12
|
-
{% endfor %}
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
<a href="/storybook/" target="_top">Moved to Storybook</a>
|
|
@@ -2,97 +2,4 @@ module.exports = {
|
|
|
2
2
|
title: 'Card',
|
|
3
3
|
label: 'Card',
|
|
4
4
|
status: 'ready',
|
|
5
|
-
context: {
|
|
6
|
-
fractalLabel: 'Card',
|
|
7
|
-
inList: false,
|
|
8
|
-
classes: '',
|
|
9
|
-
content: '<h4>Card Title</h4><p>paragraph</p>',
|
|
10
|
-
id: 'default',
|
|
11
|
-
},
|
|
12
|
-
variants: [
|
|
13
|
-
{
|
|
14
|
-
name: 'card-in-list',
|
|
15
|
-
context: {
|
|
16
|
-
fractalLabel: 'Card used in a list',
|
|
17
|
-
inList: true,
|
|
18
|
-
classes: '',
|
|
19
|
-
content: '<h4>Card used in list (li instead of div)</h4><p>paragraph</p>',
|
|
20
|
-
id: 'in-list',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'card-with-highlight',
|
|
25
|
-
context: {
|
|
26
|
-
fractalLabel: 'Card with background',
|
|
27
|
-
inList: false,
|
|
28
|
-
classes: 'mds-card--highlighted',
|
|
29
|
-
content: '<h4>Card Title</h4><p>paragraph</p>',
|
|
30
|
-
id: 'with-background',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'card-with-custom-styling',
|
|
35
|
-
context: {
|
|
36
|
-
fractalLabel: 'Card with custom styling',
|
|
37
|
-
inList: false,
|
|
38
|
-
classes: 'mds-card--1',
|
|
39
|
-
content: '<h4>Card Title</h4><p>paragraph</p>',
|
|
40
|
-
id: 'with-custom-styling',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'card-with-badges',
|
|
45
|
-
context: {
|
|
46
|
-
fractalLabel: 'Card with badges',
|
|
47
|
-
inList: false,
|
|
48
|
-
content: '<h4>Card Title</h4><p>paragraph</p>',
|
|
49
|
-
id: 'with-badge',
|
|
50
|
-
badges: {
|
|
51
|
-
left: [
|
|
52
|
-
{
|
|
53
|
-
label: 'Top Job',
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
right: [
|
|
57
|
-
{
|
|
58
|
-
label: 'Approved Employer',
|
|
59
|
-
styleId: '1',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
label: 'New',
|
|
63
|
-
styleId: 'new',
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: 'link-card',
|
|
71
|
-
context: {
|
|
72
|
-
fractalLabel: 'Card with a link',
|
|
73
|
-
link: {
|
|
74
|
-
href: 'https://www.google.com',
|
|
75
|
-
title: 'Card with link',
|
|
76
|
-
containerElement: 'h3',
|
|
77
|
-
},
|
|
78
|
-
classes: '',
|
|
79
|
-
content: '<p>content</p><p>content</p><p>content</p><p>content</p>',
|
|
80
|
-
id: 'with link',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: 'list-link-card',
|
|
85
|
-
context: {
|
|
86
|
-
fractalLabel: 'Card with link used in a list',
|
|
87
|
-
inList: true,
|
|
88
|
-
link: {
|
|
89
|
-
href: 'https://www.google.com',
|
|
90
|
-
title: 'Card with link',
|
|
91
|
-
},
|
|
92
|
-
classes: '',
|
|
93
|
-
content: '<p>content</p><p>content</p><p>content</p><p>content</p>',
|
|
94
|
-
id: 'in-list',
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
5
|
};
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<div class="mds-margin-bottom-b5">
|
|
4
|
-
<h2>{{ fractalLabel }}</h2>
|
|
5
|
-
{%- if inList -%}
|
|
6
|
-
<ul>
|
|
7
|
-
{%- endif -%}
|
|
8
|
-
|
|
9
|
-
{% call MdsCard({
|
|
10
|
-
inList: inList,
|
|
11
|
-
classes: classes,
|
|
12
|
-
id: id,
|
|
13
|
-
badges: badges,
|
|
14
|
-
link: link
|
|
15
|
-
}) -%}
|
|
16
|
-
<!-- example - in normal use `safe` is discouraged as it is dangerous, and not needed -->
|
|
17
|
-
{{ content | safe }}
|
|
18
|
-
{%- endcall %}
|
|
19
|
-
{%- if inList -%}
|
|
20
|
-
</ul>
|
|
21
|
-
{%- endif -%}
|
|
22
|
-
</div>
|
|
1
|
+
<a href="/storybook/" target="_top">Moved to Storybook</a>
|