@kth/style 0.6.3-alpha.0 → 0.6.4
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 +13 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +74 -0
- package/dist/cjs/react.d.ts +1 -0
- package/dist/cjs/react.js +7 -0
- package/dist/esm/components/MenuPanel.d.ts +13 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/react.d.ts +1 -0
- package/dist/esm/react.js +5 -0
- package/package.json +3 -2
- package/scss/components/button.scss +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
+
*/
|
|
4
|
+
export declare function closeAllDialogs(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
7
|
+
* @param dialog A <dialog> element
|
|
8
|
+
*/
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
10
|
+
export declare class MenuPanel {
|
|
11
|
+
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
12
|
+
static initModal(button: Element | null, modal: Element | null): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MenuPanel } from "./components/MenuPanel";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
5
|
+
*/
|
|
6
|
+
function closeAllDialogs() {
|
|
7
|
+
document.querySelectorAll("dialog").forEach((dialog) => dialog.close());
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
11
|
+
* @param dialog A <dialog> element
|
|
12
|
+
*/
|
|
13
|
+
function addEventListeners(dialog) {
|
|
14
|
+
const closeButton = dialog.querySelector(".kth-button.close");
|
|
15
|
+
const backButton = dialog.querySelector(".kth-button.back");
|
|
16
|
+
dialog.addEventListener("keydown", (e) => {
|
|
17
|
+
if (e.key === "Escape") {
|
|
18
|
+
dialog.close();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (closeButton instanceof HTMLButtonElement) {
|
|
22
|
+
closeButton.addEventListener("click", () => {
|
|
23
|
+
closeAllDialogs();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (backButton instanceof HTMLButtonElement) {
|
|
27
|
+
backButton.addEventListener("click", () => {
|
|
28
|
+
dialog.close();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class MenuPanel {
|
|
33
|
+
static init(container, items) {
|
|
34
|
+
if (!container)
|
|
35
|
+
return;
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
if (!(item instanceof HTMLElement))
|
|
38
|
+
continue;
|
|
39
|
+
const dialog = item.nextElementSibling;
|
|
40
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
41
|
+
continue;
|
|
42
|
+
addEventListeners(dialog);
|
|
43
|
+
item.addEventListener("click", (e) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
if (!dialog.open) {
|
|
46
|
+
closeAllDialogs();
|
|
47
|
+
dialog.show();
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
closeAllDialogs();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
container.addEventListener("focusout", function (e) {
|
|
55
|
+
const target = e.relatedTarget;
|
|
56
|
+
if (target && target instanceof Node && !container.contains(target)) {
|
|
57
|
+
closeAllDialogs();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
static initModal(button, modal) {
|
|
62
|
+
if (!(button instanceof HTMLElement))
|
|
63
|
+
return;
|
|
64
|
+
if (!(modal instanceof HTMLDialogElement))
|
|
65
|
+
return;
|
|
66
|
+
addEventListeners(modal);
|
|
67
|
+
button.addEventListener("click", (e) => {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
modal.showModal();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.MenuPanel = MenuPanel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hello(): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Close all <dialog>s (modal and non-modal) in a document
|
|
3
|
+
*/
|
|
4
|
+
export declare function closeAllDialogs(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Add mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
7
|
+
* @param dialog A <dialog> element
|
|
8
|
+
*/
|
|
9
|
+
export declare function addEventListeners(dialog: HTMLDialogElement): void;
|
|
10
|
+
export declare class MenuPanel {
|
|
11
|
+
static init(container: HTMLElement | null, items: NodeListOf<Element>): void;
|
|
12
|
+
static initModal(button: Element | null, modal: Element | null): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MenuPanel } from "./components/MenuPanel";
|
|
@@ -0,0 +1,72 @@
|
|
|
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 mouse and keyboard event listeners to a menu panel (<dialog>)
|
|
9
|
+
* @param dialog A <dialog> element
|
|
10
|
+
*/
|
|
11
|
+
function addEventListeners(dialog) {
|
|
12
|
+
const closeButton = dialog.querySelector(".kth-button.close");
|
|
13
|
+
const backButton = dialog.querySelector(".kth-button.back");
|
|
14
|
+
dialog.addEventListener("keydown", (e) => {
|
|
15
|
+
if (e.key === "Escape") {
|
|
16
|
+
dialog.close();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (closeButton instanceof HTMLButtonElement) {
|
|
20
|
+
closeButton.addEventListener("click", () => {
|
|
21
|
+
closeAllDialogs();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (backButton instanceof HTMLButtonElement) {
|
|
25
|
+
backButton.addEventListener("click", () => {
|
|
26
|
+
dialog.close();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class MenuPanel {
|
|
31
|
+
static init(container, items) {
|
|
32
|
+
if (!container)
|
|
33
|
+
return;
|
|
34
|
+
for (const item of items) {
|
|
35
|
+
if (!(item instanceof HTMLElement))
|
|
36
|
+
continue;
|
|
37
|
+
const dialog = item.nextElementSibling;
|
|
38
|
+
if (!(dialog instanceof HTMLDialogElement))
|
|
39
|
+
continue;
|
|
40
|
+
addEventListeners(dialog);
|
|
41
|
+
item.addEventListener("click", (e) => {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (!dialog.open) {
|
|
44
|
+
closeAllDialogs();
|
|
45
|
+
dialog.show();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
closeAllDialogs();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
container.addEventListener("focusout", function (e) {
|
|
53
|
+
const target = e.relatedTarget;
|
|
54
|
+
if (target && target instanceof Node && !container.contains(target)) {
|
|
55
|
+
closeAllDialogs();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
static initModal(button, modal) {
|
|
60
|
+
if (!(button instanceof HTMLElement))
|
|
61
|
+
return;
|
|
62
|
+
if (!(modal instanceof HTMLDialogElement))
|
|
63
|
+
return;
|
|
64
|
+
addEventListeners(modal);
|
|
65
|
+
button.addEventListener("click", (e) => {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
modal.showModal();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { MenuPanel };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hello(): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kth/style",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"import": "./dist/esm/react.js",
|
|
13
13
|
"require": "./dist/cjs/react.js"
|
|
14
14
|
},
|
|
15
|
-
"./scss/*": "./scss/*"
|
|
15
|
+
"./scss/*": "./scss/*",
|
|
16
|
+
"./assets/*": "./assets/*"
|
|
16
17
|
},
|
|
17
18
|
"scripts": {
|
|
18
19
|
"clean": "rm -rf dist",
|