@kth/style 0.8.2 → 0.9.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/dist/cjs/components/MenuPanel.d.ts +2 -1
- package/dist/cjs/index.js +22 -1
- package/dist/esm/components/MenuPanel.d.ts +2 -1
- package/dist/esm/index.js +22 -1
- package/package.json +1 -1
- package/scss/components/menu-panel.scss +0 -17
- package/scss/components/mobile-menu.scss +94 -0
- package/scss/tokens/icons.scss +4 -0
|
@@ -6,8 +6,9 @@ export declare function closeAllDialogs(): void;
|
|
|
6
6
|
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
7
7
|
* @param dialog A <dialog> element
|
|
8
8
|
*/
|
|
9
|
-
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement, previousDialog?: HTMLDialogElement | null): void;
|
|
10
10
|
export declare class MenuPanel {
|
|
11
11
|
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
12
12
|
static initModal(button: Element | null, modal: Element | null): void;
|
|
13
|
+
static initModals(items: NodeListOf<Element>, previousModal?: Element | null): void;
|
|
13
14
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,7 +10,7 @@ function closeAllDialogs() {
|
|
|
10
10
|
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
11
11
|
* @param dialog A <dialog> element
|
|
12
12
|
*/
|
|
13
|
-
function addEventListeners(dialog) {
|
|
13
|
+
function addEventListeners(dialog, previousDialog) {
|
|
14
14
|
const closeButton = dialog.querySelector(".kth-icon-button.close");
|
|
15
15
|
const backButton = dialog.querySelector(".kth-button.back");
|
|
16
16
|
dialog.addEventListener("keydown", (e) => {
|
|
@@ -26,6 +26,9 @@ function addEventListeners(dialog) {
|
|
|
26
26
|
if (backButton instanceof HTMLButtonElement) {
|
|
27
27
|
backButton.addEventListener("click", () => {
|
|
28
28
|
dialog.close();
|
|
29
|
+
if (previousDialog) {
|
|
30
|
+
previousDialog.showModal();
|
|
31
|
+
}
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -69,6 +72,24 @@ class MenuPanel {
|
|
|
69
72
|
modal.showModal();
|
|
70
73
|
});
|
|
71
74
|
}
|
|
75
|
+
static initModals(items, previousModal) {
|
|
76
|
+
if (previousModal && !(previousModal instanceof HTMLDialogElement))
|
|
77
|
+
return;
|
|
78
|
+
for (const item of items) {
|
|
79
|
+
if (!(item instanceof HTMLElement))
|
|
80
|
+
continue;
|
|
81
|
+
const dataId = item.getAttribute("data-id");
|
|
82
|
+
const modal = document.querySelector(`.kth-mobile-menu[data-id='${dataId}']`);
|
|
83
|
+
if (!(modal instanceof HTMLDialogElement))
|
|
84
|
+
return;
|
|
85
|
+
addEventListeners(modal, previousModal);
|
|
86
|
+
item.addEventListener("click", (e) => {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
closeAllDialogs();
|
|
89
|
+
modal.showModal();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
72
93
|
}
|
|
73
94
|
|
|
74
95
|
exports.MenuPanel = MenuPanel;
|
|
@@ -6,8 +6,9 @@ export declare function closeAllDialogs(): void;
|
|
|
6
6
|
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
7
7
|
* @param dialog A <dialog> element
|
|
8
8
|
*/
|
|
9
|
-
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement, previousDialog?: HTMLDialogElement | null): void;
|
|
10
10
|
export declare class MenuPanel {
|
|
11
11
|
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
12
12
|
static initModal(button: Element | null, modal: Element | null): void;
|
|
13
|
+
static initModals(items: NodeListOf<Element>, previousModal?: Element | null): void;
|
|
13
14
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -8,7 +8,7 @@ function closeAllDialogs() {
|
|
|
8
8
|
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
9
9
|
* @param dialog A <dialog> element
|
|
10
10
|
*/
|
|
11
|
-
function addEventListeners(dialog) {
|
|
11
|
+
function addEventListeners(dialog, previousDialog) {
|
|
12
12
|
const closeButton = dialog.querySelector(".kth-icon-button.close");
|
|
13
13
|
const backButton = dialog.querySelector(".kth-button.back");
|
|
14
14
|
dialog.addEventListener("keydown", (e) => {
|
|
@@ -24,6 +24,9 @@ function addEventListeners(dialog) {
|
|
|
24
24
|
if (backButton instanceof HTMLButtonElement) {
|
|
25
25
|
backButton.addEventListener("click", () => {
|
|
26
26
|
dialog.close();
|
|
27
|
+
if (previousDialog) {
|
|
28
|
+
previousDialog.showModal();
|
|
29
|
+
}
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
32
|
}
|
|
@@ -67,6 +70,24 @@ class MenuPanel {
|
|
|
67
70
|
modal.showModal();
|
|
68
71
|
});
|
|
69
72
|
}
|
|
73
|
+
static initModals(items, previousModal) {
|
|
74
|
+
if (previousModal && !(previousModal instanceof HTMLDialogElement))
|
|
75
|
+
return;
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
if (!(item instanceof HTMLElement))
|
|
78
|
+
continue;
|
|
79
|
+
const dataId = item.getAttribute("data-id");
|
|
80
|
+
const modal = document.querySelector(`.kth-mobile-menu[data-id='${dataId}']`);
|
|
81
|
+
if (!(modal instanceof HTMLDialogElement))
|
|
82
|
+
return;
|
|
83
|
+
addEventListeners(modal, previousModal);
|
|
84
|
+
item.addEventListener("click", (e) => {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
closeAllDialogs();
|
|
87
|
+
modal.showModal();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
70
91
|
}
|
|
71
92
|
|
|
72
93
|
export { MenuPanel };
|
package/package.json
CHANGED
|
@@ -55,21 +55,4 @@
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
.kth-menu-panel--modal {
|
|
60
|
-
background-color: var(--color-background);
|
|
61
|
-
position: fixed;
|
|
62
|
-
right: 0;
|
|
63
|
-
left: auto;
|
|
64
|
-
top: 0;
|
|
65
|
-
max-width: 32rem;
|
|
66
|
-
max-height: 100dvh;
|
|
67
|
-
width: 100dvw;
|
|
68
|
-
height: 100dvh;
|
|
69
|
-
border: 0;
|
|
70
|
-
|
|
71
|
-
.kth-button.close {
|
|
72
|
-
margin-inline-start: auto;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
58
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
@use "../tokens/spacing";
|
|
2
|
+
@use "../tokens/typography";
|
|
3
|
+
@use "../tokens/icons";
|
|
4
|
+
@use "../utils/mixins";
|
|
5
|
+
|
|
6
|
+
@layer kth-style {
|
|
7
|
+
.kth-mobile-menu {
|
|
8
|
+
background-color: var(--color-background);
|
|
9
|
+
position: fixed;
|
|
10
|
+
right: 0;
|
|
11
|
+
left: auto;
|
|
12
|
+
top: 0;
|
|
13
|
+
max-width: 32rem;
|
|
14
|
+
max-height: 100dvh;
|
|
15
|
+
width: 100dvw;
|
|
16
|
+
height: 100dvh;
|
|
17
|
+
padding: 2rem;
|
|
18
|
+
border: 0;
|
|
19
|
+
overflow-y: auto;
|
|
20
|
+
|
|
21
|
+
&__navigation {
|
|
22
|
+
height: 60px;
|
|
23
|
+
|
|
24
|
+
.kth-icon-button.close {
|
|
25
|
+
float: right;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&__header {
|
|
30
|
+
padding: 0 0 spacing.$space-32;
|
|
31
|
+
|
|
32
|
+
h2 {
|
|
33
|
+
@include typography.font-heading-m;
|
|
34
|
+
color: var(--color-primary);
|
|
35
|
+
margin-bottom: spacing.$space-4;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&__content {
|
|
40
|
+
color: var(--color-primary);
|
|
41
|
+
|
|
42
|
+
ul {
|
|
43
|
+
padding: 0;
|
|
44
|
+
list-style-type: none;
|
|
45
|
+
margin: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.kth-mobile-menu__item {
|
|
49
|
+
@include typography.font-heading-m;
|
|
50
|
+
text-decoration: none;
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
background: none;
|
|
54
|
+
border: none;
|
|
55
|
+
padding: 0;
|
|
56
|
+
color: var(--color-primary);
|
|
57
|
+
|
|
58
|
+
&::after {
|
|
59
|
+
@include icons.icon-caret-right-big;
|
|
60
|
+
background-color: var(--color-primary);
|
|
61
|
+
margin-left: 0.75rem;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&:hover {
|
|
65
|
+
text-decoration: underline;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// To avoid it affecting the cortina content
|
|
71
|
+
.kth-mobile-menu__items {
|
|
72
|
+
li:not(:last-child) {
|
|
73
|
+
margin-bottom: spacing.$space-24;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&__cortina-content {
|
|
79
|
+
li:not(:last-child) {
|
|
80
|
+
margin-bottom: spacing.$space-16;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
h3 {
|
|
84
|
+
@include typography.font-heading-s;
|
|
85
|
+
margin-bottom: spacing.$space-4;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.block:not(:first-child),
|
|
89
|
+
.col:not(:first-child) {
|
|
90
|
+
margin-top: spacing.$space-32;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|