@nuralyui/modal 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.
- package/demo/modal-demo.d.ts +20 -0
- package/demo/modal-demo.d.ts.map +1 -0
- package/demo/modal-demo.js +104 -0
- package/demo/modal-demo.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/modal.component.d.ts +24 -0
- package/modal.component.d.ts.map +1 -0
- package/modal.component.js +202 -0
- package/modal.component.js.map +1 -0
- package/package.json +15 -0
- package/react.d.ts +3 -0
- package/react.d.ts.map +1 -0
- package/react.js +12 -0
- package/react.js.map +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Google Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { LitElement } from 'lit';
|
|
7
|
+
import '../modal.component';
|
|
8
|
+
export declare class ElMeenuElement extends LitElement {
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
modal1: boolean;
|
|
11
|
+
modal2: boolean;
|
|
12
|
+
modal1_1: boolean;
|
|
13
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'hy-modals-demo': ElMeenuElement;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=modal-demo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-demo.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/demo/modal-demo.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,OAAO,EAAC,UAAU,EAAO,MAAM,KAAK,CAAC;AAGrC,OAAO,oBAAoB,CAAC;AAE5B,qBACa,cAAe,SAAQ,UAAU;IAE5C,MAAM,UAAQ;IAEd,MAAM,UAAS;IAEf,MAAM,UAAS;IAGf,QAAQ,UAAS;cAEE,MAAM;CA8D1B;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,cAAc,CAAC;KAClC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2023 Google Laabidi Aymen
|
|
6
|
+
* SPDX-License-Identifier: MIT
|
|
7
|
+
*/
|
|
8
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
};
|
|
14
|
+
import { LitElement, html } from 'lit';
|
|
15
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
16
|
+
import '../modal.component';
|
|
17
|
+
let ElMeenuElement = class ElMeenuElement extends LitElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.isOpen = true;
|
|
21
|
+
this.modal1 = false;
|
|
22
|
+
this.modal2 = false;
|
|
23
|
+
this.modal1_1 = false;
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
return html `
|
|
27
|
+
<div id="overlay-container"></div>
|
|
28
|
+
<button
|
|
29
|
+
@click=${() => {
|
|
30
|
+
this.modal1 = !this.modal1;
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
Toggle Modale</button
|
|
34
|
+
>qsd
|
|
35
|
+
<modal-component label="Modal Title" ?isOpen=${this.modal1}>
|
|
36
|
+
<p>This is the content of the modal.</p>
|
|
37
|
+
<div slot="footer">
|
|
38
|
+
<button
|
|
39
|
+
@click=${() => {
|
|
40
|
+
this.modal2 = !this.modal2;
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
Custom Action
|
|
44
|
+
</button>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<modal-component ?isOpen=${this.modal2} label="Modal Title 2">
|
|
48
|
+
<div slot="footer">
|
|
49
|
+
<h2>Modal Title</h2>
|
|
50
|
+
<p>This is the content of the modal.</p>
|
|
51
|
+
<button
|
|
52
|
+
@click=${() => {
|
|
53
|
+
this.modal2 = !this.modal2;
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
Close this modal
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
</modal-component>
|
|
60
|
+
</modal-component>
|
|
61
|
+
|
|
62
|
+
<button
|
|
63
|
+
@click=${() => {
|
|
64
|
+
this.modal1_1 = !this.modal1_1;
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
Toggle Modale</button
|
|
68
|
+
>qsd
|
|
69
|
+
<modal-component ?isOpen=${this.modal1_1}>
|
|
70
|
+
<h2>Modal Title</h2>
|
|
71
|
+
<p>This is the content of the modal.lmjqsdmlqjsdlmjqsdmljqsdlmqjsdqs</p>
|
|
72
|
+
<button
|
|
73
|
+
@click=${() => {
|
|
74
|
+
this.modal2 = !this.modal2;
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
Custom Action
|
|
78
|
+
</button>
|
|
79
|
+
<modal-component ?isOpen=${this.modal2}>
|
|
80
|
+
<h2>Modal Title</h2>
|
|
81
|
+
<p>This is the content of the modal.</p>
|
|
82
|
+
<button>Custom Action</button>
|
|
83
|
+
</modal-component>
|
|
84
|
+
</modal-component>
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__decorate([
|
|
89
|
+
state()
|
|
90
|
+
], ElMeenuElement.prototype, "isOpen", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
state()
|
|
93
|
+
], ElMeenuElement.prototype, "modal1", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
state()
|
|
96
|
+
], ElMeenuElement.prototype, "modal2", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
state()
|
|
99
|
+
], ElMeenuElement.prototype, "modal1_1", void 0);
|
|
100
|
+
ElMeenuElement = __decorate([
|
|
101
|
+
customElement('hy-modals-demo')
|
|
102
|
+
], ElMeenuElement);
|
|
103
|
+
export { ElMeenuElement };
|
|
104
|
+
//# sourceMappingURL=modal-demo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-demo.js","sourceRoot":"","sources":["../../../../src/components/modal/demo/modal-demo.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,uDAAuD;AACvD;;;;GAIG;;;;;;;AAEH,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,KAAK,CAAC;AACrC,OAAO,EAAC,aAAa,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAEvD,OAAO,oBAAoB,CAAC;AAG5B,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,UAAU;IAA9C;;QAEE,WAAM,GAAG,IAAI,CAAC;QAEd,WAAM,GAAG,KAAK,CAAC;QAEf,WAAM,GAAG,KAAK,CAAC;QAGf,aAAQ,GAAG,KAAK,CAAC;IAgEnB,CAAC;IA9DoB,MAAM;QACvB,OAAO,IAAI,CAAA;;;iBAGE,GAAG,EAAE;YACZ,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QAC7B,CAAC;;;;qDAI4C,IAAI,CAAC,MAAM;;;;qBAI3C,GAAG,EAAE;YACZ,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QAC7B,CAAC;;;;;;mCAMsB,IAAI,CAAC,MAAM;;;;;uBAKvB,GAAG,EAAE;YACZ,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QAC7B,CAAC;;;;;;;;;iBASE,GAAG,EAAE;YACZ,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;QACjC,CAAC;;;;iCAIwB,IAAI,CAAC,QAAQ;;;;mBAI3B,GAAG,EAAE;YACZ,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QAC7B,CAAC;;;;mCAIwB,IAAI,CAAC,MAAM;;;;;;KAMzC,CAAC;IACJ,CAAC;CACF,CAAA;AAvEC;IADC,KAAK,EAAE;8CACM;AAEd;IADC,KAAK,EAAE;8CACO;AAEf;IADC,KAAK,EAAE;8CACO;AAGf;IADC,KAAK,EAAE;gDACS;AATN,cAAc;IAD1B,aAAa,CAAC,gBAAgB,CAAC;GACnB,cAAc,CAyE1B;SAzEY,cAAc","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * @license\n * Copyright 2023 Google Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport {LitElement, html} from 'lit';\nimport {customElement, state} from 'lit/decorators.js';\n\nimport '../modal.component';\n\n@customElement('hy-modals-demo')\nexport class ElMeenuElement extends LitElement {\n @state()\n isOpen = true;\n @state()\n modal1 = false;\n @state()\n modal2 = false;\n\n @state()\n modal1_1 = false;\n\n protected override render() {\n return html`\n <div id=\"overlay-container\"></div>\n <button\n @click=${() => {\n this.modal1 = !this.modal1;\n }}\n >\n Toggle Modale</button\n >qsd\n <modal-component label=\"Modal Title\" ?isOpen=${this.modal1}>\n <p>This is the content of the modal.</p>\n <div slot=\"footer\">\n <button\n @click=${() => {\n this.modal2 = !this.modal2;\n }}\n >\n Custom Action\n </button>\n </div>\n\n <modal-component ?isOpen=${this.modal2} label=\"Modal Title 2\">\n <div slot=\"footer\">\n <h2>Modal Title</h2>\n <p>This is the content of the modal.</p>\n <button\n @click=${() => {\n this.modal2 = !this.modal2;\n }}\n >\n Close this modal\n </button>\n </div>\n </modal-component>\n </modal-component>\n\n <button\n @click=${() => {\n this.modal1_1 = !this.modal1_1;\n }}\n >\n Toggle Modale</button\n >qsd\n <modal-component ?isOpen=${this.modal1_1}>\n <h2>Modal Title</h2>\n <p>This is the content of the modal.lmjqsdmlqjsdlmjqsdmljqsdlmqjsdqs</p>\n <button\n @click=${() => {\n this.modal2 = !this.modal2;\n }}\n >\n Custom Action\n </button>\n <modal-component ?isOpen=${this.modal2}>\n <h2>Modal Title</h2>\n <p>This is the content of the modal.</p>\n <button>Custom Action</button>\n </modal-component>\n </modal-component>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'hy-modals-demo': ElMeenuElement;\n }\n}\n"]}
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/modal/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/modal/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './modal.component.js';\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export declare class ModalComponent extends LitElement {
|
|
3
|
+
static styles: import("lit").CSSResult;
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
label: string;
|
|
6
|
+
private offsetX;
|
|
7
|
+
private offsetY;
|
|
8
|
+
private isDragging;
|
|
9
|
+
private initialX;
|
|
10
|
+
private initialY;
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
disconnectedCallback(): void;
|
|
13
|
+
private startDrag;
|
|
14
|
+
private drag;
|
|
15
|
+
private handleKeyDown;
|
|
16
|
+
private handleOutsideClick;
|
|
17
|
+
private isChildDialog;
|
|
18
|
+
closeModal(): void;
|
|
19
|
+
private adjustDialogPosition;
|
|
20
|
+
updated(changedProperties: Map<string | number | symbol, unknown>): void;
|
|
21
|
+
private stopDrag;
|
|
22
|
+
render(): import("lit").TemplateResult<1>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=modal.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.component.d.ts","sourceRoot":"","sources":["../../../src/components/modal/modal.component.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,UAAU,EAAC,MAAM,KAAK,CAAC;AAI1C,qBAAa,cAAe,SAAQ,UAAU;IAC5C,OAAgB,MAAM,0BA0DpB;IAGF,MAAM,EAAG,OAAO,CAAC;IAGjB,KAAK,SAAM;IAGX,OAAO,CAAC,OAAO,CAAK;IAGpB,OAAO,CAAC,OAAO,CAAK;IAEpB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,QAAQ,CAAK;IAEZ,iBAAiB;IASjB,oBAAoB;IAS7B,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,aAAa;IAWrB,UAAU;IASV,OAAO,CAAC,oBAAoB;IAcnB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC;IAY1E,OAAO,CAAC,QAAQ;IAIP,MAAM;CAwBhB"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
import { css, html, LitElement } from 'lit';
|
|
9
|
+
import { property, state } from 'lit/decorators.js';
|
|
10
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
11
|
+
export class ModalComponent extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.label = '';
|
|
15
|
+
this.offsetX = 0;
|
|
16
|
+
this.offsetY = 0;
|
|
17
|
+
this.isDragging = false;
|
|
18
|
+
this.initialX = 0;
|
|
19
|
+
this.initialY = 0;
|
|
20
|
+
}
|
|
21
|
+
connectedCallback() {
|
|
22
|
+
super.connectedCallback();
|
|
23
|
+
// this.addEventListener('mousedown', this.startDrag);
|
|
24
|
+
document.addEventListener('mousemove', this.drag.bind(this));
|
|
25
|
+
// this.addEventListener('mouseup', this.stopDrag);
|
|
26
|
+
document.addEventListener('keydown', this.handleKeyDown.bind(this));
|
|
27
|
+
// document.addEventListener('click', this.handleOutsideClick.bind(this));
|
|
28
|
+
}
|
|
29
|
+
disconnectedCallback() {
|
|
30
|
+
super.disconnectedCallback();
|
|
31
|
+
// this.removeEventListener('mousedown', this.startDrag);
|
|
32
|
+
document.removeEventListener('mousemove', this.drag);
|
|
33
|
+
// this.removeEventListener('mouseup', this.stopDrag);
|
|
34
|
+
document.removeEventListener('keydown', this.handleKeyDown.bind(this));
|
|
35
|
+
document.removeEventListener('click', this.handleOutsideClick.bind(this));
|
|
36
|
+
}
|
|
37
|
+
startDrag(event) {
|
|
38
|
+
if (event.target instanceof HTMLElement) {
|
|
39
|
+
this.isDragging = true;
|
|
40
|
+
this.initialX = event.clientX - this.offsetX;
|
|
41
|
+
this.initialY = event.clientY - this.offsetY;
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
drag(event) {
|
|
46
|
+
if (this.isDragging) {
|
|
47
|
+
this.offsetX = event.clientX - this.initialX;
|
|
48
|
+
this.offsetY = event.clientY - this.initialY;
|
|
49
|
+
this.style.transform = `translate(${this.offsetX}px, ${this.offsetY}px)`;
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
handleKeyDown(event) {
|
|
54
|
+
if (event.key === 'Escape') {
|
|
55
|
+
this.closeModal();
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
handleOutsideClick(event) {
|
|
60
|
+
if (this.isOpen && !this.isChildDialog(event.target)) {
|
|
61
|
+
this.closeModal();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
isChildDialog(target) {
|
|
65
|
+
let element = target.parentElement;
|
|
66
|
+
while (element !== null) {
|
|
67
|
+
if (element.tagName === 'DIALOG') {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
element = element.parentElement;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
closeModal() {
|
|
75
|
+
this.isOpen = false;
|
|
76
|
+
this.offsetX = 0;
|
|
77
|
+
this.offsetY = 0;
|
|
78
|
+
this.style.transform = 'none';
|
|
79
|
+
this.dispatchEvent(new CustomEvent('close'));
|
|
80
|
+
}
|
|
81
|
+
adjustDialogPosition() {
|
|
82
|
+
var _a;
|
|
83
|
+
if (this.isOpen) {
|
|
84
|
+
const dialog = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.modal');
|
|
85
|
+
if (dialog) {
|
|
86
|
+
const contentHeight = dialog.clientHeight;
|
|
87
|
+
const windowHeight = window.innerHeight;
|
|
88
|
+
const dialogHeight = Math.min(contentHeight + 40, windowHeight - 40);
|
|
89
|
+
const topPosition = Math.max((windowHeight - dialogHeight) / 2, 0);
|
|
90
|
+
dialog.style.top = `${topPosition}px`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
updated(changedProperties) {
|
|
95
|
+
super.updated(changedProperties);
|
|
96
|
+
if (changedProperties.has('isOpen')) {
|
|
97
|
+
if (this.isOpen) {
|
|
98
|
+
// The dialog has been opened
|
|
99
|
+
this.adjustDialogPosition();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
stopDrag() {
|
|
104
|
+
this.isDragging = false;
|
|
105
|
+
}
|
|
106
|
+
render() {
|
|
107
|
+
const backdropStyles = {
|
|
108
|
+
display: this.isOpen ? 'block' : 'none',
|
|
109
|
+
};
|
|
110
|
+
const modalStyles = {
|
|
111
|
+
transform: `translate(${this.offsetX}px, ${this.offsetY}px)`,
|
|
112
|
+
};
|
|
113
|
+
return html `
|
|
114
|
+
<div class="backdrop" style=${styleMap(backdropStyles)}></div>
|
|
115
|
+
|
|
116
|
+
<dialog class="modal" ?open="${this.isOpen}" style=${styleMap(modalStyles)}>
|
|
117
|
+
<hy-icon
|
|
118
|
+
class="close-icon"
|
|
119
|
+
name="window-close"
|
|
120
|
+
style="float: right;"
|
|
121
|
+
@click=${() => (this.closeModal())}
|
|
122
|
+
></hy-icon>
|
|
123
|
+
<h2 class="dialog-label" @mousedown=${this.startDrag} @mouseup=${this.stopDrag}>${this.label}</h2>
|
|
124
|
+
<slot></slot>
|
|
125
|
+
<slot name="footer"></slot>
|
|
126
|
+
</dialog>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
ModalComponent.styles = css `
|
|
131
|
+
:host {
|
|
132
|
+
font-size: 16px;
|
|
133
|
+
}
|
|
134
|
+
.modal {
|
|
135
|
+
position: fixed;
|
|
136
|
+
z-index: 9999;
|
|
137
|
+
background-color: #ffffff;
|
|
138
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
dialog {
|
|
142
|
+
border: 0;
|
|
143
|
+
box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12),
|
|
144
|
+
0 9px 28px 8px rgba(0, 0, 0, 0.05);
|
|
145
|
+
min-width: 400px;
|
|
146
|
+
min-height: 200px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.dialog-label {
|
|
150
|
+
cursor: move;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.backdrop {
|
|
154
|
+
position: fixed;
|
|
155
|
+
top: 0;
|
|
156
|
+
left: 0;
|
|
157
|
+
width: 100%;
|
|
158
|
+
height: 100%;
|
|
159
|
+
background-color: rgba(0, 0, 0, 0.3);
|
|
160
|
+
z-index: 9998;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.close-icon {
|
|
164
|
+
cursor: pointer;
|
|
165
|
+
}
|
|
166
|
+
::slotted([slot='footer']) {
|
|
167
|
+
/* Styles applied specifically to slotted elements with slot="custom-slot" */
|
|
168
|
+
bottom: 0;
|
|
169
|
+
position: absolute;
|
|
170
|
+
text-align: end;
|
|
171
|
+
margin-bottom: 10px;
|
|
172
|
+
width : 93%;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
::slotted([slot='content']) {
|
|
176
|
+
padding: 0px 24px 20px 24px;
|
|
177
|
+
}
|
|
178
|
+
@media (prefers-color-scheme: dark) {
|
|
179
|
+
.modal {
|
|
180
|
+
background-color: rgb(74, 74, 74);
|
|
181
|
+
color: #ffffff;
|
|
182
|
+
}
|
|
183
|
+
.backdrop {
|
|
184
|
+
background-color: rgba(0, 0, 0, 0.3);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
`;
|
|
189
|
+
__decorate([
|
|
190
|
+
property({ type: Boolean })
|
|
191
|
+
], ModalComponent.prototype, "isOpen", void 0);
|
|
192
|
+
__decorate([
|
|
193
|
+
property({ type: String })
|
|
194
|
+
], ModalComponent.prototype, "label", void 0);
|
|
195
|
+
__decorate([
|
|
196
|
+
state()
|
|
197
|
+
], ModalComponent.prototype, "offsetX", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
state()
|
|
200
|
+
], ModalComponent.prototype, "offsetY", void 0);
|
|
201
|
+
customElements.define('modal-component', ModalComponent);
|
|
202
|
+
//# sourceMappingURL=modal.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.component.js","sourceRoot":"","sources":["../../../src/components/modal/modal.component.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,OAAO,EAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAC,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAC,MAAM,6BAA6B,CAAC;AAErD,MAAM,OAAO,cAAe,SAAQ,UAAU;IAA9C;;QAiEE,UAAK,GAAG,EAAE,CAAC;QAGH,YAAO,GAAG,CAAC,CAAC;QAGZ,YAAO,GAAG,CAAC,CAAC;QAEZ,eAAU,GAAG,KAAK,CAAC;QACnB,aAAQ,GAAG,CAAC,CAAC;QACb,aAAQ,GAAG,CAAC,CAAC;IA8HvB,CAAC;IA5HU,iBAAiB;QACxB,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,sDAAsD;QACtD,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,mDAAmD;QACnD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC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K,EAAE;+CACY;AAGpB;IADC,KAAK,EAAE;+CACY;AAoItB,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {css, html, LitElement} from 'lit';\nimport {property, state} from 'lit/decorators.js';\nimport {styleMap} from 'lit/directives/style-map.js';\n\nexport class ModalComponent extends LitElement {\n static override styles = css`\n :host {\n font-size: 16px;\n }\n .modal {\n position: fixed;\n z-index: 9999;\n background-color: #ffffff;\n box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);\n }\n\n dialog {\n border: 0;\n box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12),\n 0 9px 28px 8px rgba(0, 0, 0, 0.05);\n min-width: 400px;\n min-height: 200px;\n }\n\n .dialog-label {\n cursor: move;\n }\n\n .backdrop {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.3);\n z-index: 9998;\n }\n\n .close-icon {\n cursor: pointer;\n }\n ::slotted([slot='footer']) {\n /* Styles applied specifically to slotted elements with slot=\"custom-slot\" */\n bottom: 0;\n position: absolute;\n text-align: end;\n margin-bottom: 10px;\n width : 93%;\n }\n\n ::slotted([slot='content']) {\n padding: 0px 24px 20px 24px;\n }\n @media (prefers-color-scheme: dark) {\n .modal {\n background-color: rgb(74, 74, 74);\n color: #ffffff;\n } \n .backdrop {\n background-color: rgba(0, 0, 0, 0.3);\n }\n }\n\n `;\n\n @property({type: Boolean})\n isOpen!: boolean;\n\n @property({type: String})\n label = '';\n\n @state()\n private offsetX = 0;\n\n @state()\n private offsetY = 0;\n\n private isDragging = false;\n private initialX = 0;\n private initialY = 0;\n\n override connectedCallback() {\n super.connectedCallback();\n // this.addEventListener('mousedown', this.startDrag);\n document.addEventListener('mousemove', this.drag.bind(this));\n // this.addEventListener('mouseup', this.stopDrag);\n document.addEventListener('keydown', this.handleKeyDown.bind(this));\n // document.addEventListener('click', this.handleOutsideClick.bind(this));\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n // this.removeEventListener('mousedown', this.startDrag);\n document.removeEventListener('mousemove', this.drag);\n // this.removeEventListener('mouseup', this.stopDrag);\n document.removeEventListener('keydown', this.handleKeyDown.bind(this));\n document.removeEventListener('click', this.handleOutsideClick.bind(this));\n }\n\n private startDrag(event: MouseEvent) {\n if (event.target instanceof HTMLElement) {\n this.isDragging = true;\n this.initialX = event.clientX - this.offsetX;\n this.initialY = event.clientY - this.offsetY;\n event.preventDefault();\n }\n }\n\n private drag(event: MouseEvent) {\n if (this.isDragging) {\n this.offsetX = event.clientX - this.initialX;\n this.offsetY = event.clientY - this.initialY;\n this.style.transform = `translate(${this.offsetX}px, ${this.offsetY}px)`;\n event.preventDefault();\n }\n }\n\n private handleKeyDown(event: KeyboardEvent) {\n if (event.key === 'Escape') {\n this.closeModal();\n event.preventDefault();\n }\n }\n\n private handleOutsideClick(event: MouseEvent) {\n if (this.isOpen && !this.isChildDialog(event.target as HTMLElement)) {\n this.closeModal();\n\n }\n }\n\n private isChildDialog(target: HTMLElement): boolean {\n let element = target.parentElement;\n while (element !== null) {\n if (element.tagName === 'DIALOG') {\n return true;\n }\n element = element.parentElement;\n }\n return false;\n }\n\n closeModal() {\n this.isOpen = false;\n this.offsetX = 0;\n this.offsetY = 0;\n this.style.transform = 'none';\n this.dispatchEvent(new CustomEvent('close'));\n\n }\n\n private adjustDialogPosition() {\n if (this.isOpen) {\n const dialog = this.shadowRoot?.querySelector('.modal') as HTMLElement;\n if (dialog) {\n\n const contentHeight = dialog.clientHeight;\n const windowHeight = window.innerHeight;\n const dialogHeight = Math.min(contentHeight + 40, windowHeight - 40);\n\n const topPosition = Math.max((windowHeight - dialogHeight) / 2, 0);\n dialog.style.top = `${topPosition}px`;\n }\n }\n }\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated(changedProperties);\n\n if (changedProperties.has('isOpen')) {\n if (this.isOpen) {\n // The dialog has been opened\n this.adjustDialogPosition();\n }\n\n }\n }\n\n private stopDrag() {\n this.isDragging = false;\n }\n\n override render() {\n const backdropStyles = {\n display: this.isOpen ? 'block' : 'none',\n };\n const modalStyles = {\n transform: `translate(${this.offsetX}px, ${this.offsetY}px)`,\n };\n\n return html`\n <div class=\"backdrop\" style=${styleMap(backdropStyles)}></div>\n\n <dialog class=\"modal\" ?open=\"${this.isOpen}\" style=${styleMap(modalStyles)}>\n <hy-icon\n class=\"close-icon\"\n name=\"window-close\"\n style=\"float: right;\"\n @click=${() => (this.closeModal())}\n ></hy-icon>\n <h2 class=\"dialog-label\" @mousedown=${this.startDrag} @mouseup=${this.stopDrag}>${this.label}</h2>\n <slot></slot>\n <slot name=\"footer\"></slot>\n </dialog>\n `;\n }\n}\n\ncustomElements.define('modal-component', ModalComponent);\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nuralyui/modal",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"dayjs": "^1.11.7"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"author": "Labidi Aymen",
|
|
14
|
+
"license": "ISC"
|
|
15
|
+
}
|
package/react.d.ts
ADDED
package/react.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/components/modal/react.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,eAAO,MAAM,OAAO,iEAOlB,CAAC"}
|
package/react.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createComponent } from '@lit-labs/react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { ModalComponent } from './modal.component.js';
|
|
4
|
+
export const HyInput = createComponent({
|
|
5
|
+
tagName: 'hy-modal',
|
|
6
|
+
elementClass: ModalComponent,
|
|
7
|
+
react: React,
|
|
8
|
+
events: {
|
|
9
|
+
//valueChange: 'valueChange',
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=react.js.map
|
package/react.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../src/components/modal/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC;IACrC,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,cAAc;IAC5B,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;IACN,6BAA6B;KAC9B;CACF,CAAC,CAAC","sourcesContent":["import {createComponent} from '@lit-labs/react';\nimport * as React from 'react';\nimport {ModalComponent} from './modal.component.js';\nexport const HyInput = createComponent({\n tagName: 'hy-modal',\n elementClass: ModalComponent,\n react: React,\n events: {\n //valueChange: 'valueChange',\n },\n});\n"]}
|