@kth/style 1.14.1 → 1.14.2
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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
+
*/
|
|
4
|
+
export declare function closeAllDialogs(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Add basic mouse and keyboard event listeners to a dialog (<dialog>)
|
|
7
|
+
* @param dialog A <dialog> element
|
|
8
|
+
*/
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
10
|
+
/**
|
|
11
|
+
* Add mouse and keyboard event listeners to a dialog (<dialog>) that is not a modal
|
|
12
|
+
* @param dialog A <dialog> element
|
|
13
|
+
* @param button Button or clickable element used to open the dialog
|
|
14
|
+
*/
|
|
15
|
+
export declare function addNonModalEventListeners(dialog: HTMLDialogElement, button: HTMLElement): void;
|
|
16
|
+
/**
|
|
17
|
+
* Add mouse and keyboard event listeners to a modal (<dialog>)
|
|
18
|
+
* @param modal A <dialog> element
|
|
19
|
+
* @param previousModal A <dialog> element that was clicked to open the current modal
|
|
20
|
+
*/
|
|
21
|
+
export declare function addModalEventListeners(modal: HTMLDialogElement, button: HTMLElement, previousModal?: HTMLDialogElement | null): void;
|
|
22
|
+
export declare class MenuPanel {
|
|
23
|
+
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
24
|
+
static initModal(button: Element | null, modal: Element | null): void;
|
|
25
|
+
static initModals(items: NodeListOf<Element>, previousModal?: Element | null): void;
|
|
26
|
+
static initTranslationModal(button: Element | null, modal: Element | null): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MenuPanel } from "./components/MenuPanel";
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kth/style",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.2",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "./dist/cjs/types/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"import": "./dist/esm/index.js",
|
|
@@ -29,19 +30,19 @@
|
|
|
29
30
|
"assets"
|
|
30
31
|
],
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
33
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
33
34
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
34
35
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
36
|
-
"@typescript-eslint/parser": "^5.
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
37
38
|
"@typescript-eslint/utils": "^5.62.0",
|
|
38
|
-
"eslint": "^8.
|
|
39
|
+
"eslint": "^8.57.1",
|
|
39
40
|
"prop-types": "^15.8.1",
|
|
40
|
-
"rollup": "^4.
|
|
41
|
-
"sass": "^1.
|
|
41
|
+
"rollup": "^4.62.4",
|
|
42
|
+
"sass": "^1.102.0",
|
|
42
43
|
"stylelint": "^16.26.1",
|
|
43
44
|
"stylelint-config-standard-scss": "^16.0.0",
|
|
44
|
-
"svgo": "^4.0.
|
|
45
|
-
"typescript": "^5.
|
|
45
|
+
"svgo": "^4.0.2",
|
|
46
|
+
"typescript": "^5.9.3"
|
|
46
47
|
}
|
|
47
48
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
-
*/
|
|
4
|
-
function closeAllDialogs() {
|
|
5
|
-
document.querySelectorAll("dialog").forEach((dialog) => dialog.close());
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Add basic mouse and keyboard event listeners to a dialog (<dialog>)
|
|
9
|
-
* @param dialog A <dialog> element
|
|
10
|
-
*/
|
|
11
|
-
function addEventListeners(dialog) {
|
|
12
|
-
const closeButton = dialog.querySelector(".kth-icon-button.close");
|
|
13
|
-
dialog.addEventListener("keydown", (e) => {
|
|
14
|
-
if (e.key === "Escape") {
|
|
15
|
-
dialog.close();
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
if (closeButton instanceof HTMLButtonElement) {
|
|
19
|
-
closeButton.addEventListener("click", () => {
|
|
20
|
-
closeAllDialogs();
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Add mouse and keyboard event listeners to a dialog (<dialog>) that is not a modal
|
|
26
|
-
* @param dialog A <dialog> element
|
|
27
|
-
* @param button Button or clickable element used to open the dialog
|
|
28
|
-
*/
|
|
29
|
-
function addNonModalEventListeners(dialog, button) {
|
|
30
|
-
addEventListeners(dialog);
|
|
31
|
-
button.addEventListener("click", (e) => {
|
|
32
|
-
e.preventDefault();
|
|
33
|
-
if (!dialog.open) {
|
|
34
|
-
closeAllDialogs();
|
|
35
|
-
dialog.show();
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
closeAllDialogs();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
// Close the dialog if clicking outside the modal
|
|
42
|
-
document.addEventListener("click", (e) => {
|
|
43
|
-
if (dialog.open &&
|
|
44
|
-
!e.composedPath().includes(button) &&
|
|
45
|
-
!e.composedPath().includes(dialog)) {
|
|
46
|
-
e.preventDefault();
|
|
47
|
-
closeAllDialogs();
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Add mouse and keyboard event listeners to a modal (<dialog>)
|
|
53
|
-
* @param modal A <dialog> element
|
|
54
|
-
* @param previousModal A <dialog> element that was clicked to open the current modal
|
|
55
|
-
*/
|
|
56
|
-
function addModalEventListeners(modal, button, previousModal) {
|
|
57
|
-
const backButton = modal.querySelector(".kth-button.back");
|
|
58
|
-
addEventListeners(modal);
|
|
59
|
-
button.addEventListener("click", (e) => {
|
|
60
|
-
e.preventDefault();
|
|
61
|
-
closeAllDialogs();
|
|
62
|
-
modal.showModal();
|
|
63
|
-
});
|
|
64
|
-
// Close the current modal and open the previous modal with a back button
|
|
65
|
-
if (backButton instanceof HTMLButtonElement) {
|
|
66
|
-
backButton.addEventListener("click", () => {
|
|
67
|
-
modal.close();
|
|
68
|
-
if (previousModal) {
|
|
69
|
-
previousModal.showModal();
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
class MenuPanel {
|
|
75
|
-
static init(container, items) {
|
|
76
|
-
if (!container)
|
|
77
|
-
return;
|
|
78
|
-
for (const item of items) {
|
|
79
|
-
if (!(item instanceof HTMLElement))
|
|
80
|
-
continue;
|
|
81
|
-
const dialog = item.nextElementSibling;
|
|
82
|
-
if (!(dialog instanceof HTMLDialogElement))
|
|
83
|
-
continue;
|
|
84
|
-
addNonModalEventListeners(dialog, item);
|
|
85
|
-
}
|
|
86
|
-
container.addEventListener("focusout", function (e) {
|
|
87
|
-
const target = e.relatedTarget;
|
|
88
|
-
if (target && target instanceof Node && !container.contains(target)) {
|
|
89
|
-
closeAllDialogs();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
static initModal(button, modal) {
|
|
94
|
-
if (!(button instanceof HTMLElement))
|
|
95
|
-
return;
|
|
96
|
-
if (!(modal instanceof HTMLDialogElement))
|
|
97
|
-
return;
|
|
98
|
-
addModalEventListeners(modal, button);
|
|
99
|
-
}
|
|
100
|
-
static initModals(items, previousModal) {
|
|
101
|
-
if (previousModal && !(previousModal instanceof HTMLDialogElement))
|
|
102
|
-
return;
|
|
103
|
-
for (const item of items) {
|
|
104
|
-
if (!(item instanceof HTMLElement))
|
|
105
|
-
continue;
|
|
106
|
-
const dataId = item.getAttribute("data-id");
|
|
107
|
-
const modal = document.querySelector(`.kth-mobile-menu[data-id='${dataId}']`);
|
|
108
|
-
if (!(modal instanceof HTMLDialogElement))
|
|
109
|
-
return;
|
|
110
|
-
addModalEventListeners(modal, item, previousModal);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
static initTranslationModal(button, modal) {
|
|
114
|
-
if (!(button instanceof HTMLElement))
|
|
115
|
-
return;
|
|
116
|
-
if (!(modal instanceof HTMLDialogElement))
|
|
117
|
-
return;
|
|
118
|
-
// Only open the modal if there is no href
|
|
119
|
-
if (!button.getAttribute("href")) {
|
|
120
|
-
addNonModalEventListeners(modal, button);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export { MenuPanel };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint no-var: off */
|
|
2
|
-
// JavaScript that originally was placed in kth-style
|
|
3
|
-
// It copies the content of the main menu and places it in the left mobile
|
|
4
|
-
window.addEventListener("load", () => {
|
|
5
|
-
// If no mobile menu container is present, skip everything
|
|
6
|
-
if (!document.getElementById("mobileMenuList")) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
var mainMenu = document.getElementById("mainMenu"); // Get main menu
|
|
10
|
-
if (mainMenu) {
|
|
11
|
-
// For main menu items, copy a link if it exists, otherwise copy the link content
|
|
12
|
-
createMobileMenuItems(mainMenu.querySelectorAll("li"));
|
|
13
|
-
}
|
|
14
|
-
function createMobileMenuItems(menuItems, includeInline) {
|
|
15
|
-
for (var i = 0; i < menuItems.length; i++) {
|
|
16
|
-
var linkToCopy = menuItems[i].querySelector("a");
|
|
17
|
-
{
|
|
18
|
-
var listItem = document.createElement("li");
|
|
19
|
-
listItem.className =
|
|
20
|
-
menuItems[i].className !== "" ? menuItems[i].className : "nav-item";
|
|
21
|
-
if (linkToCopy) {
|
|
22
|
-
var link = document.createElement("a");
|
|
23
|
-
link.href = linkToCopy.href;
|
|
24
|
-
link.text = linkToCopy.text;
|
|
25
|
-
link.className = linkToCopy.className;
|
|
26
|
-
listItem.appendChild(link);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
listItem.innerHTML = menuItems[i].innerHTML;
|
|
30
|
-
}
|
|
31
|
-
document.getElementById("mobileMenuList")?.appendChild(listItem);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|