-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodal.js
140 lines (121 loc) · 3.02 KB
/
modal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const modalTemplate = document.createElement('template');
modalTemplate.innerHTML = `
<style>
.modal {
background-color: #fefefe;
margin: 15% auto;
border: 1px solid #888;
width: 70%;
border-radius: 10px;
padding: 0;
}
.modal-header,
.modal-footer {
display: flex;
align-items: center;
height: 60px;
padding: 0 20px;
box-sizing: border-box;
}
.modal-header {
justify-content: space-between;
border-bottom: 1px solid #ddd;
}
.modal-footer {
justify-content: flex-end;
border-top: 1px solid #ddd;
}
.modal-header {
margin: 0;
font-size: 18px;
font-weight: 500;
}
.modal-body {
text-align: justify;
padding: 0 30px;
font-size: 13px;
max-height: 400px;
line-height: 1.5;
width: 100%;
box-sizing: border-box;
word-wrap: break-word;
white-space: normal;
overflow: auto;
}
::backdrop {
background-color: rgba(0, 0, 0, 0.4);
}
.close-icon {
color: #aaa;
float: right;
font-size: 20px;
font-weight: bold;
}
.close-icon:hover,
.close-icon:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
button {
background-color: #2d8fc1;
color: white;
border: none;
padding: 5px 15px;
border-radius: 20px;
cursor: pointer;
outline: none;
}
button:hover {
background-color: #2d8fc1;
transform: scale(1.05);
}
</style>
<dialog class="modal">
<div class="modal-header">
<slot name="header">
<div>Default Title</div>
</slot>
<span class="close-icon">×</span>
</div>
<div class="modal-body">
<slot name="content">
</slot>
</div>
<div class="modal-footer">
<button class="close-button">Close</button>
</div>
</dialog>
`;
class TooltipModal extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(modalTemplate.content.cloneNode(true));
this.modal = this.shadowRoot.querySelector('.modal');
this.closeIcon = this.shadowRoot.querySelector('.close-icon');
this.closeButton = this.shadowRoot.querySelector('.close-button');
this.addCloseEventListener();
}
addCloseEventListener() {
this.closeIcon.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('close'));
});
this.closeButton.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('close'));
});
this.modal.addEventListener('click', (event) => {
if (event.target === this.modal) {
this.dispatchEvent(new CustomEvent('close'));
}
});
}
showModal() {
this.modal.showModal();
}
close() {
this.modal.close();
}
}
customElements.define('iobio-modal', TooltipModal);
export {TooltipModal};