@paroicms/tiny-modal 0.1.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/tiny-modal.css +40 -0
- package/dist/tiny-modal.css.map +1 -0
- package/dist/tiny-modal.d.ts +14 -0
- package/dist/tiny-modal.js +50 -0
- package/package.json +35 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
2
|
+
.TinyModal {
|
|
3
|
+
background: transparent;
|
|
4
|
+
border: none;
|
|
5
|
+
margin: 0;
|
|
6
|
+
max-width: none;
|
|
7
|
+
padding: 0;
|
|
8
|
+
}
|
|
9
|
+
.TinyModal::backdrop {
|
|
10
|
+
background-color: transparent;
|
|
11
|
+
}
|
|
12
|
+
.TinyModal-closeBtn {
|
|
13
|
+
align-items: center;
|
|
14
|
+
background-color: #bbb;
|
|
15
|
+
border-radius: 50%;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
display: flex;
|
|
18
|
+
font-size: 30px;
|
|
19
|
+
font-weight: bold;
|
|
20
|
+
height: 40px;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
line-height: 1;
|
|
23
|
+
position: absolute;
|
|
24
|
+
right: 50px;
|
|
25
|
+
top: 10px;
|
|
26
|
+
width: 40px;
|
|
27
|
+
z-index: 2;
|
|
28
|
+
}
|
|
29
|
+
.TinyModal-closeBtn::before {
|
|
30
|
+
content: "×";
|
|
31
|
+
}
|
|
32
|
+
.TinyModal-closeBtn:hover, .TinyModal-closeBtn:focus {
|
|
33
|
+
background-color: #888;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.HiddenForTinyModal {
|
|
37
|
+
display: none !important;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*# sourceMappingURL=tiny-modal.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../src/tiny-modal.scss"],"names":[],"mappings":";AAAA;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAGF;EAEE;;;AAKN;EACE","file":"tiny-modal.css"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface TinyModal {
|
|
2
|
+
open: () => void;
|
|
3
|
+
close: () => void;
|
|
4
|
+
on: (event: "open" | "close", listener: TinyModalEventListener) => void;
|
|
5
|
+
}
|
|
6
|
+
export type TinyModalEventListener = () => void;
|
|
7
|
+
export default function initializeTinyModal(options: {
|
|
8
|
+
openButton?: string | HTMLElement;
|
|
9
|
+
dialogContent: HTMLElement;
|
|
10
|
+
}): TinyModal;
|
|
11
|
+
export default function initializeTinyModal(options: {
|
|
12
|
+
openButton?: string | HTMLElement;
|
|
13
|
+
dialogContent: string;
|
|
14
|
+
}): TinyModal | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export default function initializeTinyModal({ openButton, dialogContent, }) {
|
|
2
|
+
const openBtnEl = openButton
|
|
3
|
+
? typeof openButton === "string"
|
|
4
|
+
? document.querySelector(openButton)
|
|
5
|
+
: openButton
|
|
6
|
+
: undefined;
|
|
7
|
+
const contentEl = typeof dialogContent === "string" ? document.querySelector(dialogContent) : dialogContent;
|
|
8
|
+
if (!contentEl)
|
|
9
|
+
return;
|
|
10
|
+
if (!(contentEl instanceof HTMLTemplateElement)) {
|
|
11
|
+
contentEl.classList.remove("HiddenForTinyModal");
|
|
12
|
+
}
|
|
13
|
+
const dialogEl = document.createElement("dialog");
|
|
14
|
+
dialogEl.classList.add("TinyModal");
|
|
15
|
+
const closeBtnEl = document.createElement("button");
|
|
16
|
+
closeBtnEl.classList.add("TinyModal-closeBtn");
|
|
17
|
+
dialogEl.appendChild(closeBtnEl);
|
|
18
|
+
const wrapperEl = document.createElement("div");
|
|
19
|
+
wrapperEl.classList.add("TinyModal-wrapper");
|
|
20
|
+
wrapperEl.appendChild(contentEl instanceof HTMLTemplateElement ? contentEl.content.cloneNode(true) : contentEl);
|
|
21
|
+
dialogEl.appendChild(wrapperEl);
|
|
22
|
+
document.body.appendChild(dialogEl);
|
|
23
|
+
const eventListeners = new Map();
|
|
24
|
+
function on(event, listener) {
|
|
25
|
+
if (!eventListeners.has(event)) {
|
|
26
|
+
eventListeners.set(event, []);
|
|
27
|
+
}
|
|
28
|
+
eventListeners.get(event)?.push(listener);
|
|
29
|
+
}
|
|
30
|
+
function trigger(eventName) {
|
|
31
|
+
if (eventListeners.has(eventName)) {
|
|
32
|
+
eventListeners.get(eventName)?.forEach((listener) => listener());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function open() {
|
|
36
|
+
dialogEl.showModal();
|
|
37
|
+
document.body.style.overflow = "hidden";
|
|
38
|
+
trigger("open");
|
|
39
|
+
}
|
|
40
|
+
function close() {
|
|
41
|
+
dialogEl.close();
|
|
42
|
+
}
|
|
43
|
+
openBtnEl?.addEventListener("click", open);
|
|
44
|
+
closeBtnEl.addEventListener("click", close);
|
|
45
|
+
dialogEl.addEventListener("close", () => {
|
|
46
|
+
document.body.style.overflow = "";
|
|
47
|
+
trigger("close");
|
|
48
|
+
});
|
|
49
|
+
return { open, close, on };
|
|
50
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paroicms/tiny-modal",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tiny modal library for creating modal dialogs",
|
|
5
|
+
"author": "Paroi Team",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://gitlab.com/paroi/opensource/paroicms.git",
|
|
9
|
+
"directory": "packages/tiny-modal"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc && npm run scss",
|
|
13
|
+
"clear": "rimraf dist/*",
|
|
14
|
+
"dev": "tsc --watch --preserveWatchOutput",
|
|
15
|
+
"scss": "sass src/tiny-modal.scss dist/tiny-modal.css",
|
|
16
|
+
"scss:watch": "sass --watch src/tiny-modal.scss dist/tiny-modal.css"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"paroicms",
|
|
20
|
+
"modal"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"module": "dist/tiny-modal.js",
|
|
25
|
+
"typings": "dist/tiny-modal.d.ts",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"sass": "~1.83.4",
|
|
28
|
+
"rimraf": "~6.0.1",
|
|
29
|
+
"typescript": "~5.7.3",
|
|
30
|
+
"@paroicms/public-anywhere-lib": "0.14.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
]
|
|
35
|
+
}
|