@lemonadejs/modal 2.3.0 → 2.3.2

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/dist/index.d.ts CHANGED
@@ -10,8 +10,6 @@ interface Modal {
10
10
  }
11
11
 
12
12
  interface options {
13
- /** Close the modal when it loses the focus */
14
- autoclose?: boolean;
15
13
  /** Modal is closed */
16
14
  closed?: boolean;
17
15
  /** Modal can be closed */
@@ -38,10 +36,14 @@ interface options {
38
36
  left?: number;
39
37
  /** Load the content from a remote URL */
40
38
  url?: string;
41
- /** Ensures modal will be visible on screen */
42
- autoadjust?: boolean;
43
39
  /** Responsive mode. Default is true */
44
40
  responsive?: boolean;
41
+ /** Bring to front on focus */
42
+ layers?: boolean;
43
+ /** Close the modal when it loses the focus */
44
+ 'auto-close'?: boolean;
45
+ /** Ensures modal will be visible on screen */
46
+ 'auto-adjust'?: boolean;
45
47
  }
46
48
 
47
49
  interface instance {
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
- if (! lemonade && typeof(require) === 'function') {
1
+ /**
2
+ * pin the modal to the left panel
3
+ */
4
+ if (!lemonade && typeof (require) === 'function') {
2
5
  var lemonade = require('lemonadejs');
3
6
  }
4
7
 
@@ -14,6 +17,8 @@ if (! lemonade && typeof(require) === 'function') {
14
17
  let controls = {};
15
18
  // Width of the border
16
19
  let cornerSize = 10;
20
+ // Container with minimized modals
21
+ const minimizedModals = [];
17
22
 
18
23
  // Get the coordinates of the action
19
24
  const getCoords = function(e) {
@@ -131,15 +136,47 @@ if (! lemonade && typeof(require) === 'function') {
131
136
  }
132
137
  }
133
138
 
139
+ const refreshMinimized = function() {
140
+ let items = minimizedModals;
141
+ let numOfItems = items.length;
142
+ let width = 0;
143
+ let height = 5;
144
+ for (let i = 0; i < numOfItems; i++) {
145
+ let item = items[i];
146
+ item.el.style.marginLeft = width;
147
+ item.el.style.marginBottom = height;
148
+ width += 205;
149
+
150
+ if (document.body.offsetWidth - width < 205) {
151
+ width = 0;
152
+ height += 50;
153
+ }
154
+ }
155
+ }
156
+
157
+ const setMini = function(self) {
158
+ // Minimize modals
159
+ minimizedModals.push(self);
160
+ // Refresh positions
161
+ refreshMinimized.call(self);
162
+ }
163
+
164
+ const removeMini = function(self) {
165
+ minimizedModals.splice(minimizedModals.indexOf(self), 1);
166
+ self.el.style.marginLeft = '';
167
+ self.el.style.marginBottom = '';
168
+ // Refresh positions
169
+ refreshMinimized.call(self);
170
+ }
171
+
134
172
  const adjustTop = function() {
135
173
  let self = this;
136
- let rect = self.el.getBoundingClientRect();
137
174
  self.el.style.marginTop = '';
175
+ let rect = self.el.getBoundingClientRect();
138
176
  let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
139
177
  if (limit < 0) {
140
178
  self.el.style.marginTop = limit - 10 + 'px';
141
179
  }
142
- console.log(limit)
143
180
  }
144
181
 
145
182
  const adjustLeft = function() {
@@ -153,6 +190,10 @@ if (! lemonade && typeof(require) === 'function') {
153
190
  }
154
191
  }
155
192
 
193
+ const isTrue = function(e) {
194
+ return e === true || e === 1 || e === 'true';
195
+ }
196
+
156
197
  const Modal = function (template) {
157
198
  let self = this;
158
199
 
@@ -181,9 +222,13 @@ if (! lemonade && typeof(require) === 'function') {
181
222
  // Dimensions
182
223
  if (self.width) {
183
224
  self.el.style.width = self.width + 'px';
225
+ } else if (self.el.offsetWidth) {
226
+ self.width = self.el.offsetWidth;
184
227
  }
185
228
  if (self.height) {
186
229
  self.el.style.height = self.height + 'px';
230
+ } else if (self.el.offsetHeight) {
231
+ self.height = self.el.offsetHeight;
187
232
  }
188
233
  if (self.top) {
189
234
  self.el.style.top = self.top + 'px';
@@ -202,9 +247,14 @@ if (! lemonade && typeof(require) === 'function') {
202
247
  self.el.setAttribute('data-responsive', true);
203
248
  }
204
249
 
250
+ // Bring to front on focus
251
+ if (self.layers !== false) {
252
+ self.el.classList.add('lm-modal-layers');
253
+ }
254
+
205
255
  // Focus out of the component
206
256
  self.el.addEventListener('focusout', function(e) {
207
- if (self.autoclose === true) {
257
+ if (isTrue(self['auto-close'])) {
208
258
  if (!self.el.contains(e.relatedTarget)) {
209
259
  self.closed = true;
210
260
  }
@@ -228,7 +278,7 @@ if (! lemonade && typeof(require) === 'function') {
228
278
  self.el.style[property] = self[property] + 'px';
229
279
 
230
280
  // Adjust position
231
- if (self.autoadjust) {
281
+ if (isTrue(self['auto-adjust'])) {
232
282
  if (property === 'top') {
233
283
  adjustTop.call(self);
234
284
  } else if (property === 'left') {
@@ -294,47 +344,15 @@ if (! lemonade && typeof(require) === 'function') {
294
344
 
295
345
  let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
296
346
 
297
- if (self.minimizable === true && corner === true) {
298
- self.minimized = ! self.minimized;
299
-
347
+ if (isTrue(self.minimizable) && corner === true) {
348
+ self.minimized = ! self.minimized;
300
349
  // Handles minimized modal positioning
301
350
  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
351
+ setMini(self);
314
352
  } 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
353
+ removeMini(self);
336
354
  }
337
- } else if (self.closable === true && corner === true) {
355
+ } else if (isTrue(self.closable) && corner === true) {
338
356
  self.closed = true;
339
357
  } else if (! self.minimized) {
340
358
  // If is not minimized
@@ -353,7 +371,7 @@ if (! lemonade && typeof(require) === 'function') {
353
371
  }
354
372
 
355
373
  e.preventDefault();
356
- } else if (self.draggable === true && self.title && y - rect.top < 40) {
374
+ } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
357
375
  // Action
358
376
  controls.type = 'move';
359
377
  // Callback
@@ -373,10 +391,21 @@ if (! lemonade && typeof(require) === 'function') {
373
391
 
374
392
  return function (root, options) {
375
393
  if (typeof(root) === 'object') {
376
- let template = root.innerHTML;
377
- root.innerHTML = '';
378
-
379
- lemonade.render(Modal, root, options, template)
394
+ // Keep the DOM elements
395
+ let elements = [];
396
+ while (root.firstChild) {
397
+ elements.push(root.firstChild);
398
+ root.firstChild.remove();
399
+ }
400
+ // Create the modal
401
+ let e = lemonade.render(Modal, root, options, '');
402
+ // Append any elements inside the modal
403
+ if (elements.length) {
404
+ while (elements[0]) {
405
+ e.appendChild(elements[0]);
406
+ elements.shift();
407
+ }
408
+ }
380
409
  return options;
381
410
  } else {
382
411
  return Modal.call(this, root)
package/dist/style.css CHANGED
@@ -1,16 +1,20 @@
1
1
  .lm-modal {
2
2
  position: absolute;
3
- min-width: 150px;
4
- min-height: 120px;
5
- border-radius: 4px;
3
+ min-width: 300px;
4
+ min-height: 240px;
5
+ border-radius: 5px;
6
6
  z-index: 9;
7
7
  background-color: #fff;
8
- border: 1px solid #ccc;
9
8
  box-sizing: border-box;
10
- box-shadow: 0 0 4px 3px rgba(80,80,80,.1);
9
+ box-shadow: 1px 1px 5px 1px rgba(0,0,0,.1);
11
10
  opacity: 1;
12
11
  transition: opacity 0.5s ease;
13
12
  will-change: transform;
13
+ border: 1px solid #e9e9e9;
14
+ }
15
+
16
+ .lm-modal-layers:focus {
17
+ z-index: 10;
14
18
  }
15
19
 
16
20
  .lm-modal[data-responsive] {
@@ -53,7 +57,7 @@
53
57
  display: block;
54
58
  position: relative;
55
59
  width: 100%;
56
- border-bottom: 1px solid #ccc;
60
+ border-bottom: 1px solid #e9e9e9;
57
61
  padding: 10px;
58
62
  box-sizing: border-box;
59
63
  font-size: 1.2em;
@@ -92,11 +96,15 @@
92
96
  }
93
97
 
94
98
  .lm-modal[minimized="true"] {
95
- bottom: 10px;
96
- min-height: 0;
97
- height: 45px !important;
99
+ bottom: 0;
98
100
  top: initial !important;
101
+ left: initial !important;
102
+ width: 200px !important;
103
+ height: 45px !important;
104
+ min-width: initial;
105
+ min-height: initial;
99
106
  overflow: hidden;
107
+ transition: margin 0.2s ease-in-out;
100
108
  }
101
109
 
102
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.3.0"
19
+ "version": "2.3.2"
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>