@t007/dialog 0.0.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.
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ (() => {
3
+ // ../utils/dist/index.js
4
+ function isSameURL(src1, src2) {
5
+ if (typeof src1 !== "string" || typeof src2 !== "string" || !src1 || !src2) return false;
6
+ try {
7
+ const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
8
+ return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
9
+ } catch {
10
+ return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
11
+ }
12
+ }
13
+ function createEl(tag, props = {}, dataset = {}, styles = {}) {
14
+ return assignEl(tag ? document?.createElement(tag) : void 0, props, dataset, styles) ?? null;
15
+ }
16
+ function assignEl(el, props = {}, dataset = {}, styles = {}) {
17
+ if (!el) return;
18
+ for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
19
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
20
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
21
+ }
22
+ function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
23
+ w.t007 ??= {}, w.t007._resourceCache ??= {};
24
+ if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
25
+ const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
26
+ if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
27
+ w.t007._resourceCache[src] = new Promise((resolve, reject) => {
28
+ (function tryLoad(remaining, el) {
29
+ const onerror = () => {
30
+ el?.remove?.();
31
+ if (remaining > 1) {
32
+ setTimeout(tryLoad, 1e3, remaining - 1);
33
+ console.warn(`Retrying ${type} load (${attempts - remaining + 1}): ${src}...`);
34
+ } else {
35
+ delete w.t007._resourceCache[src];
36
+ reject(new Error(`${type} load failed after ${attempts} attempts: ${src}`));
37
+ }
38
+ };
39
+ const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
40
+ if (type === "script") w.document.body.append(el = createEl("script", { src: url, type: module ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
41
+ else if (type === "style") w.document.head.append(el = createEl("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
42
+ else reject(new Error(`Unsupported resource type: ${type}`));
43
+ })(attempts);
44
+ });
45
+ return w.t007._resourceCache[src];
46
+ }
47
+ function onAllMethods(owner, callback) {
48
+ let proto = owner;
49
+ while (proto && proto !== Object.prototype) {
50
+ for (const method of Object.getOwnPropertyNames(proto)) {
51
+ if (method === "constructor") continue;
52
+ if ("function" !== typeof Object.getOwnPropertyDescriptor(proto, method)?.value) continue;
53
+ callback(method, owner);
54
+ }
55
+ proto = Object.getPrototypeOf(proto);
56
+ }
57
+ }
58
+ function bindAllMethods(owner) {
59
+ onAllMethods(owner, (method, owner2) => {
60
+ owner2[method] = owner2[method].bind(owner2);
61
+ });
62
+ }
63
+ var _SCROLLERS = /* @__PURE__ */ new WeakMap();
64
+ var _SCROLLER_R_OBSERVER = typeof window !== "undefined" ? new ResizeObserver((entries) => entries.forEach(({ target }) => _SCROLLERS.get(target)?.update())) : null;
65
+ var _SCROLLER_M_OBSERVER = typeof window !== "undefined" ? new MutationObserver((entries) => {
66
+ const els = /* @__PURE__ */ new Set();
67
+ for (const entry of entries) {
68
+ let node = entry.target instanceof Element ? entry.target : null;
69
+ while (node && !_SCROLLERS.has(node)) node = node.parentElement;
70
+ if (node) els.add(node);
71
+ }
72
+ for (const el of els) _SCROLLERS.get(el)?.update();
73
+ }) : null;
74
+
75
+ // src/index.js
76
+ var T007_Dialog = class {
77
+ dialog;
78
+ confirmBtn;
79
+ cancelBtn;
80
+ constructor(resolve) {
81
+ bindAllMethods(this);
82
+ this.resolve = resolve;
83
+ document.body.append(
84
+ this.dialog = createEl("dialog", {
85
+ className: "t007-dialog",
86
+ closedBy: "any"
87
+ })
88
+ );
89
+ this.dialog.addEventListener("cancel", this.cancel);
90
+ }
91
+ show() {
92
+ this.dialog.showModal();
93
+ this.confirmBtn.focus();
94
+ }
95
+ remove() {
96
+ this.dialog.close();
97
+ this.dialog.remove();
98
+ }
99
+ confirm() {
100
+ this.remove();
101
+ this.resolve(true);
102
+ }
103
+ cancel() {
104
+ this.remove();
105
+ this.resolve(false);
106
+ }
107
+ };
108
+ var T007_Alert_Dialog = class extends T007_Dialog {
109
+ constructor({ message, resolve, options }) {
110
+ super(resolve);
111
+ this.render(message, options);
112
+ }
113
+ render(message, options = {}) {
114
+ this.dialog.innerHTML = `
115
+ <div class="t007-dialog-top-section">
116
+ <p class="t007-dialog-question">${message}</p>
117
+ </div>
118
+ <div class="t007-dialog-bottom-section">
119
+ <button class="t007-dialog-confirm-button" type="button">${options.confirmText || "OK"}</button>
120
+ </div>
121
+ `;
122
+ this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
123
+ this.confirmBtn.addEventListener("click", this.confirm);
124
+ this.show();
125
+ }
126
+ };
127
+ var T007_Confirm_Dialog = class extends T007_Dialog {
128
+ constructor({ question, resolve, options }) {
129
+ super(resolve);
130
+ this.render(question, options);
131
+ }
132
+ render(question, options = {}) {
133
+ this.dialog.innerHTML = `
134
+ <div class="t007-dialog-top-section">
135
+ <p class="t007-dialog-question">${question}</p>
136
+ </div>
137
+ <div class="t007-dialog-bottom-section">
138
+ <button class="t007-dialog-confirm-button" type="button">${options.confirmText || "OK"}</button>
139
+ <button class="t007-dialog-cancel-button" type="button">${options.cancelText || "Cancel"}</button>
140
+ </div>
141
+ `;
142
+ this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
143
+ this.cancelBtn = this.dialog.querySelector(".t007-dialog-cancel-button");
144
+ this.confirmBtn.addEventListener("click", this.confirm);
145
+ this.cancelBtn.addEventListener("click", this.cancel);
146
+ this.show();
147
+ }
148
+ };
149
+ var T007_Prompt_Dialog = class extends T007_Dialog {
150
+ constructor({ question, defaultValue, resolve, options }) {
151
+ super(resolve);
152
+ this.render(question, defaultValue, options);
153
+ }
154
+ async render(question, defaultValue, options = {}) {
155
+ await loadResource(window.T007_INPUT_JS_SRC, "script");
156
+ options.value = defaultValue;
157
+ this.dialog.innerHTML = `
158
+ <form class="t007-input-form" novalidate>
159
+ <div class="t007-dialog-top-section">
160
+ <p class="t007-dialog-question">${question}</p>
161
+ </div>
162
+ <div class="t007-dialog-bottom-section">
163
+ <button class="t007-dialog-confirm-button" type="submit">${options.confirmText || "OK"}</button>
164
+ <button class="t007-dialog-cancel-button" type="button">${options.cancelText || "Cancel"}</button>
165
+ </div>
166
+ </form>
167
+ `;
168
+ (this.form = this.dialog.querySelector("form")).lastElementChild.insertAdjacentElement("beforebegin", t007.FM?.field(options) || createEl("input", options));
169
+ this.form.onSubmit = this.confirm;
170
+ this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
171
+ this.cancelBtn = this.dialog.querySelector(".t007-dialog-cancel-button");
172
+ this.cancelBtn.addEventListener("click", this.cancel);
173
+ t007.FM?.handleFormValidation?.(this.form);
174
+ this.show();
175
+ }
176
+ show() {
177
+ this.dialog.showModal();
178
+ this.form.elements[0]?.focus();
179
+ this.form.elements[0]?.select?.();
180
+ }
181
+ confirm() {
182
+ this.remove();
183
+ this.resolve(this.form.elements[0]?.value);
184
+ }
185
+ cancel() {
186
+ this.remove();
187
+ this.resolve(null);
188
+ }
189
+ };
190
+ function alert(message, options) {
191
+ return new Promise((resolve) => new T007_Alert_Dialog({ message, resolve, options }));
192
+ }
193
+ function confirm(question, options) {
194
+ return new Promise((resolve) => new T007_Confirm_Dialog({ question, resolve, options }));
195
+ }
196
+ function prompt(question, defaultValue, options) {
197
+ return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
198
+ }
199
+ if (typeof window !== "undefined") {
200
+ window.t007 ??= {};
201
+ window.T007_DIALOG_CSS_SRC ??= `https://unpkg.com/@t007/dialog@latest/style.css`;
202
+ window.T007_INPUT_JS_SRC ??= `https://unpkg.com/@t007/input@latest`;
203
+ t007.alert = alert;
204
+ t007.confirm = confirm;
205
+ t007.prompt = prompt;
206
+ loadResource(T007_DIALOG_CSS_SRC), loadResource(window.T007_INPUT_JS_SRC, "script");
207
+ window.Alert ??= t007.alert;
208
+ window.Confirm ??= t007.confirm;
209
+ window.Prompt ??= t007.prompt;
210
+ console.log("%cT007 Dialogs attached to window!", "color: darkturquoise");
211
+ }
212
+ })();
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ // src/index.js
2
+ import { bindAllMethods, createEl, loadResource } from "@t007/utils";
3
+ var T007_Dialog = class {
4
+ dialog;
5
+ confirmBtn;
6
+ cancelBtn;
7
+ constructor(resolve) {
8
+ bindAllMethods(this);
9
+ this.resolve = resolve;
10
+ document.body.append(
11
+ this.dialog = createEl("dialog", {
12
+ className: "t007-dialog",
13
+ closedBy: "any"
14
+ })
15
+ );
16
+ this.dialog.addEventListener("cancel", this.cancel);
17
+ }
18
+ show() {
19
+ this.dialog.showModal();
20
+ this.confirmBtn.focus();
21
+ }
22
+ remove() {
23
+ this.dialog.close();
24
+ this.dialog.remove();
25
+ }
26
+ confirm() {
27
+ this.remove();
28
+ this.resolve(true);
29
+ }
30
+ cancel() {
31
+ this.remove();
32
+ this.resolve(false);
33
+ }
34
+ };
35
+ var T007_Alert_Dialog = class extends T007_Dialog {
36
+ constructor({ message, resolve, options }) {
37
+ super(resolve);
38
+ this.render(message, options);
39
+ }
40
+ render(message, options = {}) {
41
+ this.dialog.innerHTML = `
42
+ <div class="t007-dialog-top-section">
43
+ <p class="t007-dialog-question">${message}</p>
44
+ </div>
45
+ <div class="t007-dialog-bottom-section">
46
+ <button class="t007-dialog-confirm-button" type="button">${options.confirmText || "OK"}</button>
47
+ </div>
48
+ `;
49
+ this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
50
+ this.confirmBtn.addEventListener("click", this.confirm);
51
+ this.show();
52
+ }
53
+ };
54
+ var T007_Confirm_Dialog = class extends T007_Dialog {
55
+ constructor({ question, resolve, options }) {
56
+ super(resolve);
57
+ this.render(question, options);
58
+ }
59
+ render(question, options = {}) {
60
+ this.dialog.innerHTML = `
61
+ <div class="t007-dialog-top-section">
62
+ <p class="t007-dialog-question">${question}</p>
63
+ </div>
64
+ <div class="t007-dialog-bottom-section">
65
+ <button class="t007-dialog-confirm-button" type="button">${options.confirmText || "OK"}</button>
66
+ <button class="t007-dialog-cancel-button" type="button">${options.cancelText || "Cancel"}</button>
67
+ </div>
68
+ `;
69
+ this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
70
+ this.cancelBtn = this.dialog.querySelector(".t007-dialog-cancel-button");
71
+ this.confirmBtn.addEventListener("click", this.confirm);
72
+ this.cancelBtn.addEventListener("click", this.cancel);
73
+ this.show();
74
+ }
75
+ };
76
+ var T007_Prompt_Dialog = class extends T007_Dialog {
77
+ constructor({ question, defaultValue, resolve, options }) {
78
+ super(resolve);
79
+ this.render(question, defaultValue, options);
80
+ }
81
+ async render(question, defaultValue, options = {}) {
82
+ await loadResource(window.T007_INPUT_JS_SRC, "script");
83
+ options.value = defaultValue;
84
+ this.dialog.innerHTML = `
85
+ <form class="t007-input-form" novalidate>
86
+ <div class="t007-dialog-top-section">
87
+ <p class="t007-dialog-question">${question}</p>
88
+ </div>
89
+ <div class="t007-dialog-bottom-section">
90
+ <button class="t007-dialog-confirm-button" type="submit">${options.confirmText || "OK"}</button>
91
+ <button class="t007-dialog-cancel-button" type="button">${options.cancelText || "Cancel"}</button>
92
+ </div>
93
+ </form>
94
+ `;
95
+ (this.form = this.dialog.querySelector("form")).lastElementChild.insertAdjacentElement("beforebegin", t007.FM?.field(options) || createEl("input", options));
96
+ this.form.onSubmit = this.confirm;
97
+ this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
98
+ this.cancelBtn = this.dialog.querySelector(".t007-dialog-cancel-button");
99
+ this.cancelBtn.addEventListener("click", this.cancel);
100
+ t007.FM?.handleFormValidation?.(this.form);
101
+ this.show();
102
+ }
103
+ show() {
104
+ this.dialog.showModal();
105
+ this.form.elements[0]?.focus();
106
+ this.form.elements[0]?.select?.();
107
+ }
108
+ confirm() {
109
+ this.remove();
110
+ this.resolve(this.form.elements[0]?.value);
111
+ }
112
+ cancel() {
113
+ this.remove();
114
+ this.resolve(null);
115
+ }
116
+ };
117
+ function alert(message, options) {
118
+ return new Promise((resolve) => new T007_Alert_Dialog({ message, resolve, options }));
119
+ }
120
+ function confirm(question, options) {
121
+ return new Promise((resolve) => new T007_Confirm_Dialog({ question, resolve, options }));
122
+ }
123
+ function prompt(question, defaultValue, options) {
124
+ return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
125
+ }
126
+ if (typeof window !== "undefined") {
127
+ window.t007 ??= {};
128
+ window.T007_DIALOG_CSS_SRC ??= `https://unpkg.com/@t007/dialog@latest/style.css`;
129
+ window.T007_INPUT_JS_SRC ??= `https://unpkg.com/@t007/input@latest`;
130
+ t007.alert = alert;
131
+ t007.confirm = confirm;
132
+ t007.prompt = prompt;
133
+ loadResource(T007_DIALOG_CSS_SRC), loadResource(window.T007_INPUT_JS_SRC, "script");
134
+ window.Alert ??= t007.alert;
135
+ window.Confirm ??= t007.confirm;
136
+ window.Prompt ??= t007.prompt;
137
+ console.log("%cT007 Dialogs attached to window!", "color: darkturquoise");
138
+ }
139
+ export {
140
+ alert,
141
+ confirm,
142
+ prompt
143
+ };
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@t007/dialog",
3
+ "version": "0.0.1",
4
+ "description": "A lightweight, pure JS dialog system.",
5
+ "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/tobi007-del/t007-tools.git",
10
+ "directory": "packages/dialog"
11
+ },
12
+ "homepage": "https://github.com/tobi007-del/t007-tools/tree/main/packages/dialog#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/tobi007-del/t007-tools/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "browser": "./dist/index.global.js",
20
+ "unpkg": "./dist/index.global.js",
21
+ "types": "./src/ts/types/index.d.ts",
22
+ "style": "./src/css/index.css",
23
+ "sideEffects": [
24
+ "*.css"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "types": "./src/ts/types/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.global.js"
31
+ },
32
+ "./style.css": "./src/css/index.css"
33
+ },
34
+ "scripts": {
35
+ "build": "tsup src/index.js --format esm,iife --clean"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "./src/ts/types/index.d.ts",
40
+ "./src/css/index.css"
41
+ ],
42
+ "keywords": [
43
+ "t007",
44
+ "dialog",
45
+ "modal",
46
+ "popup",
47
+ "alert",
48
+ "confirm",
49
+ "prompt",
50
+ "ui",
51
+ "vanilla-js",
52
+ "accessible"
53
+ ],
54
+ "dependencies": {
55
+ "@t007/utils": "*"
56
+ }
57
+ }
@@ -0,0 +1,251 @@
1
+ :where(:root) {
2
+ --t007-dialog-font-family: inherit;
3
+ --t007-dialog-unit: 1rem;
4
+ --t007-dialog-background: rgb(20, 20, 20);
5
+ --t007-dialog-gap: 0.8rem;
6
+ --t007-dialog-width: 26.5rem;
7
+ --t007-dialog-height: fit-content;
8
+ --t007-dialog-max-width: 90%;
9
+ --t007-dialog-max-height: 30rem;
10
+ --t007-dialog-max-content-height: 12rem;
11
+ --t007-dialog-padding: 1rem;
12
+ --t007-dialog-content-padding-block: 1.5rem;
13
+ --t007-dialog-border-radius: 1rem;
14
+ --t007-dialog-border: 0.05rem solid rgba(255, 255, 255, 0.25);
15
+ --t007-dialog-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.5), -2px -2px 6px rgba(0, 0, 0, 0.5);
16
+ --t007-dialog-backdrop-background: rgba(0, 0, 0, 0.2);
17
+ --t007-dialog-backdrop-blur: blur(6px);
18
+ --t007-dialog-message-color: whitesmoke;
19
+ --t007-dialog-message-font-size: 0.9rem;
20
+ --t007-dialog-button-font-size: 0.8rem;
21
+ --t007-dialog-button-text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
22
+ --t007-dialog-button-min-width: 4.7rem;
23
+ --t007-dialog-button-width: unset;
24
+ --t007-dialog-button-max-width: unset;
25
+ --t007-dialog-button-min-height: 2.3rem;
26
+ --t007-dialog-button-height: unset;
27
+ --t007-dialog-button-max-height: unset;
28
+ --t007-dialog-button-padding-inline: 1rem;
29
+ --t007-dialog-button-padding-block: 0.5rem;
30
+ --t007-dialog-button-border-radius: 1.25rem;
31
+ --t007-dialog-button-gap: 0.65rem;
32
+ --t007-button-outline-width: 0.15rem;
33
+ --t007-button-outline-style: solid;
34
+ /* animation styles */
35
+ --t007-dialog-start-duration: 150ms;
36
+ --t007-dialog-start-transform: translateY(-100%);
37
+ --t007-dialog-start-opacity: 0;
38
+ }
39
+
40
+ :where(:root, .t007-dialog) {
41
+ --t007-confirm-button-color: grey;
42
+ --t007-confirm-button-background: var(--t007-cancel-button-color);
43
+ --t007-cancel-button-color: greenyellow;
44
+ --t007-cancel-button-background: var(--t007-confirm-button-color);
45
+ --t007-confirm-button-outline-color: var(--t007-confirm-button-color);
46
+ --t007-cancel-button-outline-color: var(--t007-cancel-button-color);
47
+ }
48
+
49
+ :where(.t007-dialog) .t007-input-field {
50
+ --t007-input-color: var(--t007-dialog-message-color);
51
+ }
52
+
53
+ .t007-dialog,
54
+ .t007-dialog *,
55
+ .t007-dialog *::after,
56
+ .t007-dialog *::before {
57
+ box-sizing: border-box;
58
+ font-family: var(--t007-dialog-font-family);
59
+ -webkit-tap-highlight-color: transparent;
60
+ margin: 0;
61
+ padding: 0;
62
+ }
63
+
64
+ .t007-dialog *:disabled {
65
+ filter: grayscale(100%);
66
+ cursor: not-allowed;
67
+ }
68
+
69
+ .t007-dialog *:focus {
70
+ outline-style: dashed;
71
+ outline-offset: 0.1rem;
72
+ outline-width: 0;
73
+ }
74
+
75
+ .t007-dialog *:focus-visible {
76
+ outline-width: 0.15rem;
77
+ transition: none !important;
78
+ }
79
+
80
+ .t007-dialog :where(button) {
81
+ background: none;
82
+ border: none;
83
+ color: inherit;
84
+ display: flex;
85
+ align-items: center;
86
+ justify-content: center;
87
+ transition: filter 200ms ease;
88
+ }
89
+
90
+ :where(button):hover {
91
+ cursor: pointer;
92
+ filter: brightness(1.15);
93
+ }
94
+
95
+ :is(html, body):has(.t007-dialog[open]) {
96
+ overflow: hidden;
97
+ }
98
+ body:has(.t007-dialog[open]) {
99
+ overflow-y: visible; /* incase anyone has sticky content */
100
+ }
101
+
102
+ .t007-dialog,
103
+ .t007-dialog::backdrop {
104
+ position: fixed;
105
+ inset: 0;
106
+ margin: auto;
107
+ display: none;
108
+ transition-property: display, transform, opacity, backdrop-filter;
109
+ transition-duration: var(--t007-dialog-start-duration);
110
+ transition-behavior: allow-discrete;
111
+ }
112
+
113
+ .t007-dialog {
114
+ padding: 0;
115
+ margin: auto;
116
+ background: var(--t007-dialog-background);
117
+ width: var(--t007-dialog-width);
118
+ height: var(--t007-dialog-height);
119
+ max-width: var(--t007-dialog-max-width);
120
+ max-height: var(--t007-dialog-max-height);
121
+ border: var(--t007-dialog-border);
122
+ border-radius: var(--t007-dialog-border-radius);
123
+ box-shadow: var(--t007-dialog-box-shadow);
124
+ opacity: var(--t007-dialog-start-opacity);
125
+ transform: var(--t007-dialog-start-transform);
126
+ }
127
+
128
+ .t007-dialog[open] {
129
+ opacity: 1;
130
+ transform: none;
131
+ }
132
+ @starting-style {
133
+ .t007-dialog[open] {
134
+ opacity: var(--t007-dialog-start-opacity);
135
+ transform: var(--t007-dialog-start-transform);
136
+ }
137
+ }
138
+
139
+ .t007-dialog,
140
+ .t007-dialog form {
141
+ flex-direction: column;
142
+ gap: var(--t007-dialog-gap);
143
+ }
144
+ .t007-dialog[open],
145
+ .t007-dialog form {
146
+ display: flex;
147
+ }
148
+
149
+ .t007-dialog::backdrop {
150
+ background-color: transparent;
151
+ }
152
+
153
+ .t007-dialog[open]::backdrop {
154
+ display: block;
155
+ background-color: var(--t007-dialog-backdrop-background);
156
+ -webkit-backdrop-filter: var(--t007-dialog-backdrop-blur);
157
+ backdrop-filter: var(--t007-dialog-backdrop-blur);
158
+ }
159
+ @starting-style {
160
+ .t007-dialog[open]::backdrop {
161
+ background-color: transparent;
162
+ }
163
+ }
164
+
165
+ .t007-dialog > * {
166
+ padding-inline: var(--t007-dialog-padding);
167
+ }
168
+
169
+ .t007-dialog-top-section {
170
+ margin-top: var(--t007-dialog-padding);
171
+ }
172
+
173
+ .t007-dialog-bottom-section {
174
+ margin-bottom: var(--t007-dialog-padding);
175
+ }
176
+
177
+ .t007-dialog-top-section {
178
+ padding-block: var(--t007-dialog-content-padding-block);
179
+ max-height: var(--t007-dialog-max-content-height);
180
+ overflow-x: hidden;
181
+ overflow-y: auto;
182
+ }
183
+
184
+ .t007-dialog:has(.field) .t007-dialog-top-section {
185
+ padding-block-end: 0;
186
+ }
187
+
188
+ .t007-dialog-question {
189
+ color: var(--t007-dialog-message-color);
190
+ font-size: var(--t007-dialog-message-font-size);
191
+ }
192
+
193
+ .t007-dialog-bottom-section {
194
+ align-self: flex-end;
195
+ display: flex;
196
+ flex-wrap: wrap;
197
+ justify-content: flex-end;
198
+ gap: var(--t007-dialog-button-gap);
199
+ }
200
+
201
+ .t007-dialog button {
202
+ font-size: var(--t007-dialog-button-font-size);
203
+ min-width: var(--t007-dialog-button-min-width);
204
+ width: var(--t007-dialog-button-width);
205
+ max-width: var(--t007-dialog-button-max-width);
206
+ min-height: var(--t007-dialog-button-min-height);
207
+ height: var(--t007-dialog-button-height);
208
+ max-height: var(--t007-dialog-button-max-height);
209
+ padding-inline: var(--t007-dialog-button-padding-inline);
210
+ padding-block: var(--t007-dialog-button-padding-block);
211
+ border-radius: var(--t007-dialog-button-border-radius);
212
+ text-shadow: var(--t007-dialog-button-text-shadow);
213
+ transition: 100ms ease;
214
+ }
215
+
216
+ .t007-dialog-confirm-button {
217
+ color: var(--t007-confirm-button-color);
218
+ background: var(--t007-confirm-button-background);
219
+ opacity: 1;
220
+ }
221
+
222
+ .t007-dialog-cancel-button {
223
+ color: var(--t007-cancel-button-color);
224
+ background: var(--t007-cancel-button-background);
225
+ opacity: 0.9;
226
+ }
227
+
228
+ .t007-dialog button:hover {
229
+ cursor: pointer;
230
+ }
231
+
232
+ .t007-dialog-confirm-button:hover {
233
+ opacity: 0.9;
234
+ }
235
+
236
+ .t007-dialog-cancel-button:hover {
237
+ opacity: 1;
238
+ }
239
+
240
+ .t007-dialog button:focus {
241
+ outline-style: var(--t007-button-outline-style);
242
+ outline-width: var(--t007-button-outline-width);
243
+ }
244
+
245
+ .t007-dialog-confirm-button:focus {
246
+ outline-color: var(--t007-confirm-button-outline-color);
247
+ }
248
+
249
+ .t007-dialog-cancel-button:focus {
250
+ outline-color: var(--t007-cancel-button-outline-color);
251
+ }
@@ -0,0 +1,36 @@
1
+ import "@t007/utils";
2
+ import type { FieldOptions } from "@t007/input";
3
+
4
+ export interface DialogOptions extends FieldOptions {
5
+ confirmText?: string;
6
+ cancelText?: string;
7
+ value?: string;
8
+ }
9
+
10
+ // BUNDLE EXPORTS & GLOBAL DECLARATIONS
11
+ export function Alert(message: string, options?: DialogOptions): Promise<boolean>;
12
+ export function Confirm(question: string, options?: DialogOptions): Promise<boolean>;
13
+ export function Prompt(
14
+ question: string,
15
+ defaultValue?: string,
16
+ options?: DialogOptions,
17
+ ): Promise<string | null>;
18
+
19
+ declare global {
20
+ interface T007Namespace {
21
+ alert: typeof Alert;
22
+ confirm: typeof Confirm;
23
+ prompt: typeof Prompt;
24
+ }
25
+
26
+ interface Window {
27
+ t007: T007Namespace;
28
+
29
+ T007_DIALOG_CSS_SRC?: string;
30
+ T007_INPUT_JS_SRC?: string;
31
+
32
+ Alert?: T007Namespace["alert"];
33
+ Confirm?: T007Namespace["confirm"];
34
+ Prompt?: T007Namespace["prompt"];
35
+ }
36
+ }