@lemonadejs/modal 2.2.0 → 2.3.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/README.md +18 -16
- package/dist/index.d.ts +21 -0
- package/dist/index.js +98 -1
- package/dist/style.css +14 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,21 +83,23 @@ You can configure things such as position, size, and functionalities.
|
|
|
83
83
|
|
|
84
84
|
#### Modal Properties
|
|
85
85
|
|
|
86
|
-
| Property
|
|
87
|
-
|
|
88
|
-
| title?
|
|
89
|
-
| height?
|
|
90
|
-
| width?
|
|
91
|
-
| top?
|
|
92
|
-
| left?
|
|
93
|
-
| draggable?
|
|
94
|
-
| resizable?
|
|
95
|
-
| closed?
|
|
96
|
-
| closable?
|
|
97
|
-
| minimized?
|
|
98
|
-
| minimizable? | boolean | Enables the minimize button
|
|
99
|
-
| center?
|
|
100
|
-
| url?
|
|
86
|
+
| Property | Type | Description |
|
|
87
|
+
|--------------|---------|--------------------------------------------------------------------|
|
|
88
|
+
| title? | string | The header title of the modal |
|
|
89
|
+
| height? | number | The height of the modal in pixels |
|
|
90
|
+
| width? | number | The width of the modal in pixels |
|
|
91
|
+
| top? | number | The vertical position of the modal within its container in pixels |
|
|
92
|
+
| left? | number | The horizontal position of the modal within its container in pixels |
|
|
93
|
+
| draggable? | boolean | Determines if the modal can be dragged |
|
|
94
|
+
| resizable? | boolean | Determines if the modal can be resized |
|
|
95
|
+
| closed? | boolean | Controls the open and close state of the modal |
|
|
96
|
+
| closable? | boolean | Enables the close button |
|
|
97
|
+
| minimized? | boolean | Controls the minimized state of the modal |
|
|
98
|
+
| minimizable? | boolean | Enables the minimize button |
|
|
99
|
+
| center? | boolean | Enables rendering the modal in the center of its parent container |
|
|
100
|
+
| url? | string | The URL from which to fetch and render content |
|
|
101
|
+
| autoadjust? | boolean | Adjust the position when the modal is outside the viewport |
|
|
102
|
+
| autoclose? | boolean | Close when the modal loses focus |
|
|
101
103
|
|
|
102
104
|
#### Modal Events
|
|
103
105
|
|
|
@@ -113,4 +115,4 @@ The LemonadeJS Modal is released under the MIT.
|
|
|
113
115
|
## Other Tools
|
|
114
116
|
|
|
115
117
|
- [jSuites](https://jsuites.net/v4/)
|
|
116
|
-
- [Jspreadsheet](https://jspreadsheet.com)
|
|
118
|
+
- [Jspreadsheet Data Grid](https://jspreadsheet.com)
|
package/dist/index.d.ts
CHANGED
|
@@ -10,21 +10,42 @@ interface Modal {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface options {
|
|
13
|
+
/** Close the modal when it loses the focus */
|
|
14
|
+
autoclose?: boolean;
|
|
15
|
+
/** Modal is closed */
|
|
13
16
|
closed?: boolean;
|
|
17
|
+
/** Modal can be closed */
|
|
14
18
|
closable?: boolean;
|
|
19
|
+
/** Modal is minimized */
|
|
15
20
|
minimized?: boolean;
|
|
21
|
+
/** Modal can be minimized */
|
|
16
22
|
minimizable?: boolean;
|
|
23
|
+
/** Modal can be resized */
|
|
17
24
|
resizable?: boolean;
|
|
25
|
+
/** Modal can be moved from its original position */
|
|
18
26
|
draggable?: boolean;
|
|
27
|
+
/** Modal is automatic align center */
|
|
19
28
|
center?: boolean;
|
|
29
|
+
/** Title of the modal */
|
|
20
30
|
title?: string;
|
|
31
|
+
/** Width of the modal */
|
|
21
32
|
width?: number;
|
|
33
|
+
/** Height of the modal */
|
|
22
34
|
height?: number;
|
|
35
|
+
/** Position top */
|
|
23
36
|
top?: number;
|
|
37
|
+
/** Position Left */
|
|
24
38
|
left?: number;
|
|
39
|
+
/** Load the content from a remote URL */
|
|
40
|
+
url?: string;
|
|
41
|
+
/** Ensures modal will be visible on screen */
|
|
42
|
+
autoadjust?: boolean;
|
|
43
|
+
/** Responsive mode. Default is true */
|
|
44
|
+
responsive?: boolean;
|
|
25
45
|
}
|
|
26
46
|
|
|
27
47
|
interface instance {
|
|
48
|
+
autoclose: boolean;
|
|
28
49
|
closed: boolean;
|
|
29
50
|
closable: boolean;
|
|
30
51
|
minimized: boolean;
|
package/dist/index.js
CHANGED
|
@@ -131,6 +131,28 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
const adjustTop = function() {
|
|
135
|
+
let self = this;
|
|
136
|
+
let rect = self.el.getBoundingClientRect();
|
|
137
|
+
self.el.style.marginTop = '';
|
|
138
|
+
let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
|
|
139
|
+
if (limit < 0) {
|
|
140
|
+
self.el.style.marginTop = limit - 10 + 'px';
|
|
141
|
+
}
|
|
142
|
+
console.log(limit)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const adjustLeft = function() {
|
|
146
|
+
let self = this;
|
|
147
|
+
self.el.style.marginLeft = '';
|
|
148
|
+
let rect = self.el.getBoundingClientRect();
|
|
149
|
+
// Make sure component will be visible on page
|
|
150
|
+
let limit = document.documentElement.clientWidth - (rect.left + rect.width);
|
|
151
|
+
if (limit < 0) {
|
|
152
|
+
self.el.style.marginLeft = limit - 10 + 'px';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
134
156
|
const Modal = function (template) {
|
|
135
157
|
let self = this;
|
|
136
158
|
|
|
@@ -156,11 +178,39 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
156
178
|
self.left = (window.innerWidth - self.width) / 2;
|
|
157
179
|
}
|
|
158
180
|
|
|
181
|
+
// Dimensions
|
|
182
|
+
if (self.width) {
|
|
183
|
+
self.el.style.width = self.width + 'px';
|
|
184
|
+
}
|
|
185
|
+
if (self.height) {
|
|
186
|
+
self.el.style.height = self.height + 'px';
|
|
187
|
+
}
|
|
188
|
+
if (self.top) {
|
|
189
|
+
self.el.style.top = self.top + 'px';
|
|
190
|
+
}
|
|
191
|
+
if (self.left) {
|
|
192
|
+
self.el.style.left = self.left + 'px';
|
|
193
|
+
}
|
|
194
|
+
|
|
159
195
|
// Full screen
|
|
160
196
|
if (self.height > 260) {
|
|
161
197
|
self.el.classList.add('fullscreen');
|
|
162
198
|
}
|
|
163
199
|
|
|
200
|
+
// Responsive
|
|
201
|
+
if (document.documentElement.clientWidth < 800 && self.responsive !== false) {
|
|
202
|
+
self.el.setAttribute('data-responsive', true);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Focus out of the component
|
|
206
|
+
self.el.addEventListener('focusout', function(e) {
|
|
207
|
+
if (self.autoclose === true) {
|
|
208
|
+
if (!self.el.contains(e.relatedTarget)) {
|
|
209
|
+
self.closed = true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
164
214
|
// Close and stop propagation
|
|
165
215
|
document.addEventListener('keydown', (e) => {
|
|
166
216
|
if (e.key === 'Escape' && self.closed === false) {
|
|
@@ -176,6 +226,15 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
176
226
|
self.closed ? Dispatch.call(self,'onclose') : Dispatch.call(self,'onopen');
|
|
177
227
|
} else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
|
|
178
228
|
self.el.style[property] = self[property] + 'px';
|
|
229
|
+
|
|
230
|
+
// Adjust position
|
|
231
|
+
if (self.autoadjust) {
|
|
232
|
+
if (property === 'top') {
|
|
233
|
+
adjustTop.call(self);
|
|
234
|
+
} else if (property === 'left') {
|
|
235
|
+
adjustLeft.call(self);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
179
238
|
}
|
|
180
239
|
}
|
|
181
240
|
|
|
@@ -236,7 +295,45 @@ if (! lemonade && typeof(require) === 'function') {
|
|
|
236
295
|
let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
|
|
237
296
|
|
|
238
297
|
if (self.minimizable === true && corner === true) {
|
|
239
|
-
self.minimized = ! self.minimized;
|
|
298
|
+
self.minimized = ! self.minimized;
|
|
299
|
+
|
|
300
|
+
// Handles minimized modal positioning
|
|
301
|
+
if (self.minimized) {
|
|
302
|
+
if (!lemonade.minimizedModals) {
|
|
303
|
+
lemonade.minimizedModals = []
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
lemonade.minimizedModals.push(self)
|
|
307
|
+
|
|
308
|
+
let rowIndex = Math.floor((lemonade.minimizedModals.length - 1) / 5)
|
|
309
|
+
let row = lemonade.minimizedModals.filter((_, i) => rowIndex === Math.floor((i) / 5))
|
|
310
|
+
|
|
311
|
+
self.left = self.el.offsetLeft
|
|
312
|
+
self.el.style.left = 10 + ((row.length - 1) * (self.width || 310))
|
|
313
|
+
self.el.style.marginBottom = rowIndex * 50
|
|
314
|
+
} else {
|
|
315
|
+
let index = lemonade.minimizedModals.indexOf(self)
|
|
316
|
+
let right = lemonade.minimizedModals.slice(index + 1)
|
|
317
|
+
|
|
318
|
+
lemonade.minimizedModals.splice(index, 1)
|
|
319
|
+
|
|
320
|
+
for (let i = 0; i < right.length; i++) {
|
|
321
|
+
let rowIndex = Math.floor((index + i + 1) / 5)
|
|
322
|
+
let column = ((i + index + 1) % 5)
|
|
323
|
+
|
|
324
|
+
if (rowIndex !== 0 && column === 0) {
|
|
325
|
+
right[i].el.style.left = 10 + ((5 - 1) * (self.width || 310))
|
|
326
|
+
right[i].el.style.marginBottom = 10 + ((rowIndex - 1) * 50)
|
|
327
|
+
} else if (rowIndex !== 0) {
|
|
328
|
+
right[i].el.style.left = right[i].el.offsetLeft - (self.width || 310)
|
|
329
|
+
} else {
|
|
330
|
+
right[i].el.style.left = right[i].el.offsetLeft - (self.width || 310)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
self.el.style.left = 'initial'
|
|
335
|
+
self.el.style.marginBottom = 0
|
|
336
|
+
}
|
|
240
337
|
} else if (self.closable === true && corner === true) {
|
|
241
338
|
self.closed = true;
|
|
242
339
|
} else if (! self.minimized) {
|
package/dist/style.css
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
position: absolute;
|
|
3
3
|
min-width: 150px;
|
|
4
4
|
min-height: 120px;
|
|
5
|
-
width: 300px;
|
|
6
|
-
height: 260px;
|
|
7
5
|
border-radius: 4px;
|
|
8
6
|
z-index: 9;
|
|
9
7
|
background-color: #fff;
|
|
@@ -15,25 +13,23 @@
|
|
|
15
13
|
will-change: transform;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
.lm-modal
|
|
19
|
-
|
|
16
|
+
.lm-modal[data-responsive] {
|
|
17
|
+
width: 100% !important;
|
|
18
|
+
bottom: 0;
|
|
19
|
+
left: 0;
|
|
20
|
+
border: 0;
|
|
21
|
+
border-radius: 0;
|
|
22
|
+
transform: none;
|
|
23
|
+
animation: slide-bottom-in 0.4s forwards;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
left: 0;
|
|
27
|
-
border: 0;
|
|
28
|
-
border-radius: 0;
|
|
29
|
-
transform: none;
|
|
30
|
-
animation: slide-bottom-in 0.4s forwards;
|
|
31
|
-
}
|
|
26
|
+
.lm-modal[data-responsive].fullscreen {
|
|
27
|
+
top: 0;
|
|
28
|
+
height: 100% !important;
|
|
29
|
+
}
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
height: 100% !important;
|
|
36
|
-
}
|
|
31
|
+
.lm-modal.moving {
|
|
32
|
+
cursor: move !important;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
.lm-modal-picker {
|
|
@@ -100,7 +96,6 @@
|
|
|
100
96
|
min-height: 0;
|
|
101
97
|
height: 45px !important;
|
|
102
98
|
top: initial !important;
|
|
103
|
-
left: initial !important;
|
|
104
99
|
overflow: hidden;
|
|
105
100
|
}
|
|
106
101
|
|
package/package.json
CHANGED