@lemonadejs/modal 2.2.1 → 2.3.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
@@ -83,21 +83,23 @@ You can configure things such as position, size, and functionalities.
83
83
 
84
84
  #### Modal Properties
85
85
 
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 |
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
@@ -36,6 +36,12 @@ interface options {
36
36
  top?: number;
37
37
  /** Position Left */
38
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;
39
45
  }
40
46
 
41
47
  interface instance {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- if (! lemonade && typeof(require) === 'function') {
1
+ if (!lemonade && typeof (require) === 'function') {
2
2
  var lemonade = require('lemonadejs');
3
3
  }
4
4
 
@@ -14,6 +14,8 @@ if (! lemonade && typeof(require) === 'function') {
14
14
  let controls = {};
15
15
  // Width of the border
16
16
  let cornerSize = 10;
17
+ // Container with minimized modals
18
+ const minimizedModals = [];
17
19
 
18
20
  // Get the coordinates of the action
19
21
  const getCoords = function(e) {
@@ -131,6 +133,31 @@ if (! lemonade && typeof(require) === 'function') {
131
133
  }
132
134
  }
133
135
 
136
+ const adjustTop = function() {
137
+ let self = this;
138
+ let rect = self.el.getBoundingClientRect();
139
+ self.el.style.marginTop = '';
140
+ let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
141
+ if (limit < 0) {
142
+ self.el.style.marginTop = limit - 10 + 'px';
143
+ }
144
+ }
145
+
146
+ const adjustLeft = function() {
147
+ let self = this;
148
+ let rect = self.el.getBoundingClientRect();
149
+ self.el.style.marginLeft = '';
150
+ // Make sure component will be visible on page
151
+ let limit = document.documentElement.clientWidth - (rect.left + rect.width);
152
+ if (limit < 0) {
153
+ self.el.style.marginLeft = limit - 10 + 'px';
154
+ }
155
+ }
156
+
157
+ const isTrue = function(e) {
158
+ return e === true || e === 1 || e === 'true';
159
+ }
160
+
134
161
  const Modal = function (template) {
135
162
  let self = this;
136
163
 
@@ -156,11 +183,34 @@ if (! lemonade && typeof(require) === 'function') {
156
183
  self.left = (window.innerWidth - self.width) / 2;
157
184
  }
158
185
 
186
+ // Dimensions
187
+ if (self.width) {
188
+ self.el.style.width = self.width + 'px';
189
+ } else if (self.el.offsetWidth) {
190
+ self.width = self.el.offsetWidth;
191
+ }
192
+ if (self.height) {
193
+ self.el.style.height = self.height + 'px';
194
+ } else if (self.el.offsetHeight) {
195
+ self.height = self.el.offsetHeight;
196
+ }
197
+ if (self.top) {
198
+ self.el.style.top = self.top + 'px';
199
+ }
200
+ if (self.left) {
201
+ self.el.style.left = self.left + 'px';
202
+ }
203
+
159
204
  // Full screen
160
205
  if (self.height > 260) {
161
206
  self.el.classList.add('fullscreen');
162
207
  }
163
208
 
209
+ // Responsive
210
+ if (document.documentElement.clientWidth < 800 && self.responsive !== false) {
211
+ self.el.setAttribute('data-responsive', true);
212
+ }
213
+
164
214
  // Focus out of the component
165
215
  self.el.addEventListener('focusout', function(e) {
166
216
  if (self.autoclose === true) {
@@ -185,6 +235,15 @@ if (! lemonade && typeof(require) === 'function') {
185
235
  self.closed ? Dispatch.call(self,'onclose') : Dispatch.call(self,'onopen');
186
236
  } else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
187
237
  self.el.style[property] = self[property] + 'px';
238
+
239
+ // Adjust position
240
+ if (self.autoadjust) {
241
+ if (property === 'top') {
242
+ adjustTop.call(self);
243
+ } else if (property === 'left') {
244
+ adjustLeft.call(self);
245
+ }
246
+ }
188
247
  }
189
248
  }
190
249
 
@@ -228,6 +287,39 @@ if (! lemonade && typeof(require) === 'function') {
228
287
  }
229
288
  }
230
289
 
290
+ const refreshMinimized = function() {
291
+ let items = minimizedModals;
292
+ let numOfItems = items.length;
293
+ let width = 0;
294
+ let height = 5;
295
+ for (let i = 0; i < numOfItems; i++) {
296
+ let item = items[i];
297
+ item.el.style.marginLeft = width;
298
+ item.el.style.marginBottom = height;
299
+ width += 205;
300
+
301
+ if (document.body.offsetWidth - width < 205) {
302
+ width = 0;
303
+ height += 50;
304
+ }
305
+ }
306
+ }
307
+
308
+ const setMini = function(self) {
309
+ // Minimize modals
310
+ minimizedModals.push(self);
311
+ // Refresh positions
312
+ refreshMinimized.call(self);
313
+ }
314
+
315
+ const removeMini = function(self) {
316
+ minimizedModals.splice(minimizedModals.indexOf(self), 1);
317
+ self.el.style.marginLeft = '';
318
+ self.el.style.marginBottom = '';
319
+ // Refresh positions
320
+ refreshMinimized.call(self);
321
+ }
322
+
231
323
  self.mousedown = function(e) {
232
324
  // Get mouse coordinates
233
325
  let [x,y] = getCoords(e);
@@ -244,9 +336,15 @@ if (! lemonade && typeof(require) === 'function') {
244
336
 
245
337
  let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
246
338
 
247
- if (self.minimizable === true && corner === true) {
339
+ if (isTrue(self.minimizable) && corner === true) {
248
340
  self.minimized = ! self.minimized;
249
- } else if (self.closable === true && corner === true) {
341
+ // Handles minimized modal positioning
342
+ if (self.minimized) {
343
+ setMini(self);
344
+ } else {
345
+ removeMini(self);
346
+ }
347
+ } else if (isTrue(self.closable) && corner === true) {
250
348
  self.closed = true;
251
349
  } else if (! self.minimized) {
252
350
  // If is not minimized
@@ -265,7 +363,7 @@ if (! lemonade && typeof(require) === 'function') {
265
363
  }
266
364
 
267
365
  e.preventDefault();
268
- } else if (self.draggable === true && self.title && y - rect.top < 40) {
366
+ } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
269
367
  // Action
270
368
  controls.type = 'move';
271
369
  // Callback
@@ -285,10 +383,21 @@ if (! lemonade && typeof(require) === 'function') {
285
383
 
286
384
  return function (root, options) {
287
385
  if (typeof(root) === 'object') {
288
- let template = root.innerHTML;
289
- root.innerHTML = '';
290
-
291
- lemonade.render(Modal, root, options, template)
386
+ // Keep the DOM elements
387
+ let elements = [];
388
+ while (root.firstChild) {
389
+ elements.push(root.firstChild);
390
+ root.firstChild.remove();
391
+ }
392
+ // Create the modal
393
+ let e = lemonade.render(Modal, root, options, '');
394
+ // Append any elements inside the modal
395
+ if (elements.length) {
396
+ while (elements[0]) {
397
+ e.appendChild(elements[0]);
398
+ elements.shift();
399
+ }
400
+ }
292
401
  return options;
293
402
  } else {
294
403
  return Modal.call(this, root)
package/dist/style.css CHANGED
@@ -1,39 +1,39 @@
1
1
  .lm-modal {
2
2
  position: absolute;
3
- min-width: 150px;
4
- min-height: 120px;
5
- width: 300px;
6
- height: 260px;
7
- border-radius: 4px;
3
+ min-width: 300px;
4
+ min-height: 240px;
5
+ border-radius: 5px;
8
6
  z-index: 9;
9
7
  background-color: #fff;
10
- border: 1px solid #ccc;
11
8
  box-sizing: border-box;
12
- box-shadow: 0 0 4px 3px rgba(80,80,80,.1);
9
+ box-shadow: 1px 1px 5px 1px rgba(0,0,0,.1);
13
10
  opacity: 1;
14
11
  transition: opacity 0.5s ease;
15
12
  will-change: transform;
13
+ border: 1px solid #e9e9e9;
16
14
  }
17
15
 
18
- .lm-modal.moving {
19
- cursor: move !important;
16
+ .lm-modal:focus {
17
+ z-index: 10;
18
+ }
19
+
20
+ .lm-modal[data-responsive] {
21
+ width: 100% !important;
22
+ bottom: 0;
23
+ left: 0;
24
+ border: 0;
25
+ border-radius: 0;
26
+ transform: none;
27
+ animation: slide-bottom-in 0.4s forwards;
20
28
  }
21
29
 
22
- @media only screen and (max-width : 800px) {
23
- .lm-modal {
24
- width: 100% !important;
25
- bottom: 0;
26
- left: 0;
27
- border: 0;
28
- border-radius: 0;
29
- transform: none;
30
- animation: slide-bottom-in 0.4s forwards;
31
- }
30
+ .lm-modal[data-responsive].fullscreen {
31
+ top: 0;
32
+ height: 100% !important;
33
+ }
32
34
 
33
- .lm-modal.fullscreen {
34
- top: 0;
35
- height: 100% !important;
36
- }
35
+ .lm-modal.moving {
36
+ cursor: move !important;
37
37
  }
38
38
 
39
39
  .lm-modal-picker {
@@ -57,7 +57,7 @@
57
57
  display: block;
58
58
  position: relative;
59
59
  width: 100%;
60
- border-bottom: 1px solid #ccc;
60
+ border-bottom: 1px solid #e9e9e9;
61
61
  padding: 10px;
62
62
  box-sizing: border-box;
63
63
  font-size: 1.2em;
@@ -96,12 +96,15 @@
96
96
  }
97
97
 
98
98
  .lm-modal[minimized="true"] {
99
- bottom: 10px;
100
- min-height: 0;
101
- height: 45px !important;
99
+ bottom: 0;
102
100
  top: initial !important;
103
101
  left: initial !important;
102
+ width: 200px !important;
103
+ height: 45px !important;
104
+ min-width: initial;
105
+ min-height: initial;
104
106
  overflow: hidden;
107
+ transition: margin 0.2s ease-in-out;
105
108
  }
106
109
 
107
110
  .lm-modal[minimized="true"]::after {
package/package.json CHANGED
@@ -16,5 +16,5 @@
16
16
  "lemonadejs": "^3.4.0"
17
17
  },
18
18
  "main": "dist/index.js",
19
- "version": "2.2.1"
19
+ "version": "2.3.1"
20
20
  }
package/src/index.html DELETED
@@ -1,20 +0,0 @@
1
- <script src="https://cdn.jsdelivr.net/npm/lemonadejs@3.3.1/dist/lemonade.min.js"></script>
2
-
3
- <script type="text/javascript" src="../dist/index.js"></script>
4
- <link rel="stylesheet" href="../dist/style.css" />
5
-
6
- <div id="root">
7
- <div>
8
-
9
- </div>
10
- </div>
11
-
12
- <script>
13
- const root = document.getElementById("root")
14
-
15
- Modal(root, {
16
- title: 'Nicolas Jesse',
17
- minimizable: true,
18
- height: 350,
19
- })
20
- </script>