@lemonadejs/modal 2.7.1 → 2.8.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 +60 -1
- package/dist/index.js +75 -51
- package/dist/style.css +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -62,6 +62,65 @@ export default function App() {
|
|
|
62
62
|
}
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
Quick example with React
|
|
66
|
+
|
|
67
|
+
```jsx
|
|
68
|
+
import React, { useRef } from 'react';
|
|
69
|
+
import Modal from '@lemonadejs/modal/dist/react';
|
|
70
|
+
import '@lemonadejs/modal/dist/style.css';
|
|
71
|
+
|
|
72
|
+
export default function App() {
|
|
73
|
+
const modal = useRef();
|
|
74
|
+
|
|
75
|
+
const toggle = () => {
|
|
76
|
+
modal.current.closed = !modal.current.closed;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div>
|
|
81
|
+
<Modal center={true} width={400} height={200} title="My window modal" ref={modal}>
|
|
82
|
+
<div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', padding: '10px' }}>
|
|
83
|
+
<p>Quick example!</p>
|
|
84
|
+
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
|
|
85
|
+
</div>
|
|
86
|
+
</Modal>
|
|
87
|
+
<input type="button" value="Toggle Modal" id="button" onClick={toggle} />
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Quick example with Vue
|
|
94
|
+
|
|
95
|
+
```vue
|
|
96
|
+
<template>
|
|
97
|
+
<Modal ref='modal' :center="true" :width="400" :height="200" title="My window modal" >
|
|
98
|
+
<div style="display: flex; flex-direction: column; justify-content: center; padding: 10px;">
|
|
99
|
+
<p>Quick example!</p>
|
|
100
|
+
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
|
|
101
|
+
</div>
|
|
102
|
+
</Modal>
|
|
103
|
+
<input type="button" value="Toggle Modal" id="button" @click="toggleModal" />
|
|
104
|
+
</template>
|
|
105
|
+
<script>
|
|
106
|
+
import Modal from '@lemonadejs/modal/dist/vue';
|
|
107
|
+
import '@lemonadejs/modal/dist/style.css'
|
|
108
|
+
|
|
109
|
+
export default {
|
|
110
|
+
name: 'App',
|
|
111
|
+
components: {
|
|
112
|
+
Modal,
|
|
113
|
+
},
|
|
114
|
+
methods: {
|
|
115
|
+
toggleModal() {
|
|
116
|
+
console.log(this.$refs.modal);
|
|
117
|
+
this.$refs.modal.current.closed = !this.$refs.modal.current.closed;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
</script>
|
|
122
|
+
```
|
|
123
|
+
|
|
65
124
|
Programmatical - Quick example with Javascript
|
|
66
125
|
|
|
67
126
|
```html
|
|
@@ -139,5 +198,5 @@ The LemonadeJS Modal is released under the MIT.
|
|
|
139
198
|
|
|
140
199
|
## Other Tools
|
|
141
200
|
|
|
142
|
-
- [jSuites](https://jsuites.net/
|
|
201
|
+
- [jSuites](https://jsuites.net/docs)
|
|
143
202
|
- [Jspreadsheet Data Grid](https://jspreadsheet.com)
|
package/dist/index.js
CHANGED
|
@@ -280,7 +280,10 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
280
280
|
|
|
281
281
|
if (self.position) {
|
|
282
282
|
if (self.position === 'absolute') {
|
|
283
|
-
|
|
283
|
+
let w = document.documentElement.offsetWidth;
|
|
284
|
+
if (w > viewportWidth) {
|
|
285
|
+
viewportWidth = w;
|
|
286
|
+
}
|
|
284
287
|
} else if (self.position !== 'center') {
|
|
285
288
|
margin = 0;
|
|
286
289
|
}
|
|
@@ -288,9 +291,17 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
288
291
|
|
|
289
292
|
let rightEdgeDistance = viewportWidth - (self.el.offsetLeft + self.el.offsetWidth);
|
|
290
293
|
let transformX = 0;
|
|
291
|
-
|
|
292
|
-
|
|
294
|
+
|
|
295
|
+
if (self.position === 'absolute') {
|
|
296
|
+
if (rightEdgeDistance < 5) {
|
|
297
|
+
transformX = (-1 * self.el.offsetWidth) - margin;
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
if (rightEdgeDistance < 0) {
|
|
301
|
+
transformX = rightEdgeDistance - margin;
|
|
302
|
+
}
|
|
293
303
|
}
|
|
304
|
+
|
|
294
305
|
if (self.el.offsetLeft < 0) {
|
|
295
306
|
transformX = margin - self.el.offsetLeft;
|
|
296
307
|
}
|
|
@@ -310,7 +321,10 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
310
321
|
|
|
311
322
|
if (self.position) {
|
|
312
323
|
if (self.position === 'absolute') {
|
|
313
|
-
|
|
324
|
+
let h = document.documentElement.offsetHeight;
|
|
325
|
+
if (h > viewportHeight) {
|
|
326
|
+
viewportHeight = h;
|
|
327
|
+
}
|
|
314
328
|
} else if (self.position !== 'center') {
|
|
315
329
|
margin = 0;
|
|
316
330
|
}
|
|
@@ -318,8 +332,15 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
318
332
|
|
|
319
333
|
let bottomEdgeDistance = viewportHeight - (self.el.offsetTop + self.el.offsetHeight);
|
|
320
334
|
let transformY = 0;
|
|
321
|
-
|
|
322
|
-
|
|
335
|
+
|
|
336
|
+
if (self.position === 'absolute') {
|
|
337
|
+
if (bottomEdgeDistance < 5) {
|
|
338
|
+
transformY = (-1 * self.el.offsetHeight) - margin;
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
if (bottomEdgeDistance < 0) {
|
|
342
|
+
transformY = bottomEdgeDistance - margin;
|
|
343
|
+
}
|
|
323
344
|
}
|
|
324
345
|
|
|
325
346
|
if (self.el.offsetTop < 0) {
|
|
@@ -413,7 +434,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
413
434
|
if (self.backdrop === true) {
|
|
414
435
|
backdrop = document.createElement('div');
|
|
415
436
|
backdrop.classList.add('lm-modal-backdrop');
|
|
416
|
-
backdrop.addEventListener('
|
|
437
|
+
backdrop.addEventListener('click', function() {
|
|
417
438
|
self.closed = true;
|
|
418
439
|
})
|
|
419
440
|
}
|
|
@@ -550,50 +571,18 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
550
571
|
}
|
|
551
572
|
|
|
552
573
|
self.mousedown = function(e) {
|
|
553
|
-
// Get mouse coordinates
|
|
554
|
-
let [x,y] = getCoords(e);
|
|
555
|
-
controls.x = x;
|
|
556
|
-
controls.y = y;
|
|
557
|
-
// Root element of the component
|
|
558
|
-
let item = self.el;
|
|
559
|
-
// Get the position and dimensions
|
|
560
|
-
let rect = item.getBoundingClientRect();
|
|
561
|
-
|
|
562
|
-
controls.e = item;
|
|
563
|
-
controls.w = rect.width;
|
|
564
|
-
controls.h = rect.height;
|
|
565
|
-
|
|
566
|
-
let corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 34;
|
|
567
|
-
|
|
568
|
-
// Check if the click in on close
|
|
569
|
-
if (isTrue(self.closable)) {
|
|
570
|
-
if (corner) {
|
|
571
|
-
self.closed = true;
|
|
572
|
-
|
|
573
|
-
if (isTrue(self.minimizable)) {
|
|
574
|
-
removeMini(self);
|
|
575
|
-
}
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 65;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// Check if the click in on minimize
|
|
583
|
-
if (isTrue(self.minimizable)) {
|
|
584
|
-
if (corner) {
|
|
585
|
-
// Handles minimized modal positioning
|
|
586
|
-
if (self.minimized === true) {
|
|
587
|
-
removeMini(self);
|
|
588
|
-
} else {
|
|
589
|
-
setMini(self);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
574
|
if (! self.minimized) {
|
|
575
|
+
// Get mouse coordinates
|
|
576
|
+
let [x,y] = getCoords(e);
|
|
577
|
+
controls.x = x;
|
|
578
|
+
controls.y = y;
|
|
579
|
+
// Root element of the component
|
|
580
|
+
let item = self.el;
|
|
581
|
+
// Get the position and dimensions
|
|
582
|
+
let rect = item.getBoundingClientRect();
|
|
583
|
+
controls.e = item;
|
|
584
|
+
controls.w = rect.width;
|
|
585
|
+
controls.h = rect.height;
|
|
597
586
|
// If is not minimized
|
|
598
587
|
if (controls.type === 'resize') {
|
|
599
588
|
// Make sure the width and height is defined for the modal
|
|
@@ -627,6 +616,41 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
627
616
|
}
|
|
628
617
|
}
|
|
629
618
|
|
|
619
|
+
self.click = function(e) {
|
|
620
|
+
// Get mouse coordinates
|
|
621
|
+
let [x,y] = getCoords(e);
|
|
622
|
+
// Get the position and dimensions
|
|
623
|
+
let rect = self.el.getBoundingClientRect();
|
|
624
|
+
// Right
|
|
625
|
+
let right = rect.width - (x - rect.left);
|
|
626
|
+
// Corner
|
|
627
|
+
let corner = (y - rect.top) < 40 && right > 10 && right < 34;
|
|
628
|
+
// Check if the click in on close
|
|
629
|
+
if (isTrue(self.closable)) {
|
|
630
|
+
if (corner) {
|
|
631
|
+
self.closed = true;
|
|
632
|
+
|
|
633
|
+
if (isTrue(self.minimizable)) {
|
|
634
|
+
removeMini(self);
|
|
635
|
+
}
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
corner = (y - rect.top) < 40 && right > 10 && right < 65;
|
|
640
|
+
}
|
|
641
|
+
// Check if the click in on minimize
|
|
642
|
+
if (isTrue(self.minimizable)) {
|
|
643
|
+
if (corner) {
|
|
644
|
+
// Handles minimized modal positioning
|
|
645
|
+
if (self.minimized === true) {
|
|
646
|
+
removeMini(self);
|
|
647
|
+
} else {
|
|
648
|
+
setMini(self);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
630
654
|
self.open = function() {
|
|
631
655
|
if (self.closed === true) {
|
|
632
656
|
self.closed = false;
|
|
@@ -639,7 +663,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
639
663
|
}
|
|
640
664
|
}
|
|
641
665
|
|
|
642
|
-
return `<div class="lm-modal" animation="{{self.animation}}" position="{{self.position}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" overflow="{{self.overflow}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown
|
|
666
|
+
return `<div class="lm-modal" animation="{{self.animation}}" position="{{self.position}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" overflow="{{self.overflow}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown" onmousemove="self.mousemove" onclick="self.click" tabindex="-1">
|
|
643
667
|
<div class="lm-modal-title" data-icon="{{self.icon}}">{{self.title}}</div>
|
|
644
668
|
<div>${template}</div>
|
|
645
669
|
</div>`
|
package/dist/style.css
CHANGED
|
@@ -4,27 +4,27 @@
|
|
|
4
4
|
min-height: 240px;
|
|
5
5
|
border-radius: 5px;
|
|
6
6
|
z-index: 15;
|
|
7
|
-
background-color: #fff;
|
|
7
|
+
background-color: var(--lm-background-color, #fff);
|
|
8
8
|
box-sizing: border-box;
|
|
9
9
|
box-shadow: 0 0 12px rgb(0 0 0 / 22%);
|
|
10
10
|
opacity: 1;
|
|
11
11
|
will-change: transform;
|
|
12
|
-
border: 1px solid #
|
|
12
|
+
border: 1px solid var(--lm-border-color, #ccc);
|
|
13
13
|
outline: none;
|
|
14
14
|
margin: 0;
|
|
15
15
|
display: flex;
|
|
16
16
|
flex-direction: column;
|
|
17
17
|
transition: opacity 0.4s ease, top 0.4s ease, left 0.4s ease, width 0.4s ease, height 0.4s ease;
|
|
18
|
+
color: var(--lm-font-color, #000);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
.lm-modal-title {
|
|
21
22
|
width: 100%;
|
|
22
|
-
border-bottom: 1px solid #
|
|
23
|
+
border-bottom: 1px solid var(--lm-border-color, #ccc);
|
|
23
24
|
padding: 10px;
|
|
24
25
|
box-sizing: border-box;
|
|
25
26
|
font-size: 1.2em;
|
|
26
27
|
line-height: 24px;
|
|
27
|
-
background: #fff;
|
|
28
28
|
user-select: none;
|
|
29
29
|
display: flex;
|
|
30
30
|
border-radius: 5px;
|
|
@@ -170,4 +170,4 @@
|
|
|
170
170
|
min-width: initial;
|
|
171
171
|
min-height: initial;
|
|
172
172
|
overflow: hidden;
|
|
173
|
-
}
|
|
173
|
+
}
|