@lemonadejs/modal 2.7.2 → 2.8.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/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/v4/)
201
+ - [jSuites](https://jsuites.net/docs)
143
202
  - [Jspreadsheet Data Grid](https://jspreadsheet.com)
package/dist/index.js CHANGED
@@ -280,18 +280,23 @@ if (!lemonade && typeof (require) === 'function') {
280
280
 
281
281
  if (self.position) {
282
282
  if (self.position === 'absolute') {
283
- viewportWidth = document.documentElement.offsetWidth;
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
  }
287
290
  }
288
291
 
289
- let rightEdgeDistance = viewportWidth - (self.el.offsetLeft + self.el.offsetWidth);
292
+ let el = self.el.getBoundingClientRect();
293
+
294
+ let rightEdgeDistance = viewportWidth - (el.left + el.width);
290
295
  let transformX = 0;
291
296
 
292
297
  if (self.position === 'absolute') {
293
- if (rightEdgeDistance < 5) {
294
- transformX = (-1 * self.el.offsetWidth) - margin;
298
+ if (rightEdgeDistance < 0) {
299
+ transformX = rightEdgeDistance - margin - 10; // 10 is the scroll width
295
300
  }
296
301
  } else {
297
302
  if (rightEdgeDistance < 0) {
@@ -299,8 +304,8 @@ if (!lemonade && typeof (require) === 'function') {
299
304
  }
300
305
  }
301
306
 
302
- if (self.el.offsetLeft < 0) {
303
- transformX = margin - self.el.offsetLeft;
307
+ if (el.left < 0) {
308
+ transformX = margin - el.left;
304
309
  }
305
310
  if (transformX !== 0) {
306
311
  self.el.style.marginLeft = transformX + 'px';
@@ -318,18 +323,23 @@ if (!lemonade && typeof (require) === 'function') {
318
323
 
319
324
  if (self.position) {
320
325
  if (self.position === 'absolute') {
321
- viewportHeight = document.documentElement.offsetHeight;
326
+ let h = document.documentElement.offsetHeight;
327
+ if (h > viewportHeight) {
328
+ //viewportHeight = h;
329
+ }
322
330
  } else if (self.position !== 'center') {
323
331
  margin = 0;
324
332
  }
325
333
  }
326
334
 
327
- let bottomEdgeDistance = viewportHeight - (self.el.offsetTop + self.el.offsetHeight);
335
+ let el = self.el.getBoundingClientRect();
336
+
337
+ let bottomEdgeDistance = viewportHeight - (el.top + el.height);
328
338
  let transformY = 0;
329
339
 
330
340
  if (self.position === 'absolute') {
331
341
  if (bottomEdgeDistance < 5) {
332
- transformY = (-1 * self.el.offsetHeight) - margin;
342
+ transformY = (-1 * el.height) - margin - 20;
333
343
  }
334
344
  } else {
335
345
  if (bottomEdgeDistance < 0) {
@@ -337,8 +347,8 @@ if (!lemonade && typeof (require) === 'function') {
337
347
  }
338
348
  }
339
349
 
340
- if (self.el.offsetTop < 0) {
341
- transformY = margin - self.el.offsetTop;
350
+ if (el.top < 0) {
351
+ transformY = margin - el.top;
342
352
  }
343
353
  if (transformY !== 0) {
344
354
  self.el.style.marginTop = transformY + 'px';
@@ -428,7 +438,7 @@ if (!lemonade && typeof (require) === 'function') {
428
438
  if (self.backdrop === true) {
429
439
  backdrop = document.createElement('div');
430
440
  backdrop.classList.add('lm-modal-backdrop');
431
- backdrop.addEventListener('mousedown', function() {
441
+ backdrop.addEventListener('click', function() {
432
442
  self.closed = true;
433
443
  })
434
444
  }
@@ -565,50 +575,18 @@ if (!lemonade && typeof (require) === 'function') {
565
575
  }
566
576
 
567
577
  self.mousedown = function(e) {
568
- // Get mouse coordinates
569
- let [x,y] = getCoords(e);
570
- controls.x = x;
571
- controls.y = y;
572
- // Root element of the component
573
- let item = self.el;
574
- // Get the position and dimensions
575
- let rect = item.getBoundingClientRect();
576
-
577
- controls.e = item;
578
- controls.w = rect.width;
579
- controls.h = rect.height;
580
-
581
- let corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 34;
582
-
583
- // Check if the click in on close
584
- if (isTrue(self.closable)) {
585
- if (corner) {
586
- self.closed = true;
587
-
588
- if (isTrue(self.minimizable)) {
589
- removeMini(self);
590
- }
591
- return;
592
- }
593
-
594
- corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 65;
595
- }
596
-
597
- // Check if the click in on minimize
598
- if (isTrue(self.minimizable)) {
599
- if (corner) {
600
- // Handles minimized modal positioning
601
- if (self.minimized === true) {
602
- removeMini(self);
603
- } else {
604
- setMini(self);
605
- }
606
-
607
- return;
608
- }
609
- }
610
-
611
578
  if (! self.minimized) {
579
+ // Get mouse coordinates
580
+ let [x,y] = getCoords(e);
581
+ controls.x = x;
582
+ controls.y = y;
583
+ // Root element of the component
584
+ let item = self.el;
585
+ // Get the position and dimensions
586
+ let rect = item.getBoundingClientRect();
587
+ controls.e = item;
588
+ controls.w = rect.width;
589
+ controls.h = rect.height;
612
590
  // If is not minimized
613
591
  if (controls.type === 'resize') {
614
592
  // Make sure the width and height is defined for the modal
@@ -642,6 +620,41 @@ if (!lemonade && typeof (require) === 'function') {
642
620
  }
643
621
  }
644
622
 
623
+ self.click = function(e) {
624
+ // Get mouse coordinates
625
+ let [x,y] = getCoords(e);
626
+ // Get the position and dimensions
627
+ let rect = self.el.getBoundingClientRect();
628
+ // Right
629
+ let right = rect.width - (x - rect.left);
630
+ // Corner
631
+ let corner = (y - rect.top) < 40 && right > 10 && right < 34;
632
+ // Check if the click in on close
633
+ if (isTrue(self.closable)) {
634
+ if (corner) {
635
+ self.closed = true;
636
+
637
+ if (isTrue(self.minimizable)) {
638
+ removeMini(self);
639
+ }
640
+ return;
641
+ }
642
+
643
+ corner = (y - rect.top) < 40 && right > 10 && right < 65;
644
+ }
645
+ // Check if the click in on minimize
646
+ if (isTrue(self.minimizable)) {
647
+ if (corner) {
648
+ // Handles minimized modal positioning
649
+ if (self.minimized === true) {
650
+ removeMini(self);
651
+ } else {
652
+ setMini(self);
653
+ }
654
+ }
655
+ }
656
+ }
657
+
645
658
  self.open = function() {
646
659
  if (self.closed === true) {
647
660
  self.closed = false;
@@ -654,7 +667,7 @@ if (!lemonade && typeof (require) === 'function') {
654
667
  }
655
668
  }
656
669
 
657
- 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(e)" onmousemove="self.mousemove(e)" tabindex="-1">
670
+ 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">
658
671
  <div class="lm-modal-title" data-icon="{{self.icon}}">{{self.title}}</div>
659
672
  <div>${template}</div>
660
673
  </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 #bbb;
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 #e9e9e9;
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
+ }
package/package.json CHANGED
@@ -13,9 +13,9 @@
13
13
  "modal js"
14
14
  ],
15
15
  "dependencies": {
16
- "lemonadejs": "^4.1.1"
16
+ "lemonadejs": "^4.2.2"
17
17
  },
18
18
  "main": "dist/index.js",
19
19
  "types": "dist/index.d.ts",
20
- "version": "2.7.2"
20
+ "version": "2.8.1"
21
21
  }