@andreyshpigunov/x 0.4.4 → 0.5.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.
@@ -28,241 +28,245 @@ All right reserved.
28
28
  --modal-overlay-background-color: #00000066;
29
29
  }
30
30
 
31
- html.modal--active body {
32
- overflow: hidden;
33
- }
34
-
35
- /* !- Modal window content */
36
- [x-modal] {
37
- display: none;
38
- }
39
-
40
- /* !- Modal wrapper */
41
- .modal {
42
- position: fixed;
43
- z-index: -10000;
44
- top: 0;
45
- bottom: 0;
46
- left: 0;
47
- right: 0;
48
- padding: 0;
49
- pointer-events: none;
50
- display: none;
51
- }
52
- .modal--ready {
53
- z-index: 10000;
54
- pointer-events: all;
55
- display: block;
56
- }
57
- .modal--z1 { z-index: 10001 }
58
- .modal--z2 { z-index: 10002 }
59
- .modal--z3 { z-index: 10003 }
60
- .modal--z4 { z-index: 10004 }
61
- .modal--z5 { z-index: 10005 }
62
- .modal--z6 { z-index: 10006 }
63
- .modal--z7 { z-index: 10007 }
64
- .modal--z8 { z-index: 10008 }
65
- .modal--z9 { z-index: 10009 }
66
- .modal--z10 { z-index: 10010 }
67
-
68
- /* !- Overlay */
69
- .modal-overlay {
70
- position: absolute;
71
- z-index: 10010;
72
- top: 0;
73
- bottom: 0;
74
- left: 0;
75
- right: 0;
76
- background-color: var(--modal-overlay-background-color);
77
- }
78
-
79
- /* ! -Main structure */
80
- .modal-outer {
81
- position: relative;
82
- z-index: 10020;
83
- width: 100%;
84
- height: 100%;
85
- padding-top: var(--modal-margin-top);
86
- padding-bottom: var(--modal-margin-bottom);
87
- padding-left: var(--modal-margin-left);
88
- padding-right: var(--modal-margin-right);
89
- overflow: auto;
90
- overscroll-behavior: contain;
91
- -webkit-overflow-scrolling: touch;
92
- }
93
- .modal-inner {
94
- display: flex;
95
- flex-direction: column;
96
- min-height: 100%;
97
- }
31
+ @layer modal {
98
32
 
99
- /* !- Modal window */
100
- .modal-window {
101
- position: relative;
102
- z-index: 10030;
103
- width: 100%;
104
- max-width: 80rem;
105
- margin: auto;
106
- padding-top: var(--modal-padding-top);
107
- padding-bottom: var(--modal-padding-bottom);
108
- padding-left: var(--modal-padding-left);
109
- padding-right: var(--modal-padding-right);
110
- text-align: left;
111
- background: var(--modal-background);
112
- box-shadow: var(--modal-box-shadow);
113
- border-radius: var(--modal-border-radius);
114
- }
115
-
116
- /* !- Close cross */
117
- .modal-rail {
118
- position: absolute;
119
- top: var(--modal-closer-margin);
120
- bottom: var(--modal-closer-margin);
121
- right: var(--modal-closer-margin);
122
- width: 0;
33
+ html.modal_active body {
34
+ overflow: hidden;
35
+ }
36
+
37
+ /* !- Modal window content */
38
+ [x-modal] {
39
+ display: none;
40
+ }
123
41
 
124
- .modal-close {
42
+ /* !- Modal wrapper */
43
+ .modal {
44
+ position: fixed;
45
+ z-index: -10000;
46
+ top: 0;
47
+ bottom: 0;
48
+ left: 0;
49
+ right: 0;
50
+ padding: 0;
51
+ pointer-events: none;
52
+ display: none;
53
+ }
54
+ .modal_ready {
55
+ z-index: 10000;
56
+ pointer-events: all;
125
57
  display: block;
126
- position: sticky;
127
- z-index: 10040;
128
- top: calc(var(--modal-closer-margin) - var(--modal-margin-top));
58
+ }
59
+ .modal_z1 { z-index: 10001 }
60
+ .modal_z2 { z-index: 10002 }
61
+ .modal_z3 { z-index: 10003 }
62
+ .modal_z4 { z-index: 10004 }
63
+ .modal_z5 { z-index: 10005 }
64
+ .modal_z6 { z-index: 10006 }
65
+ .modal_z7 { z-index: 10007 }
66
+ .modal_z8 { z-index: 10008 }
67
+ .modal_z9 { z-index: 10009 }
68
+ .modal_z10 { z-index: 10010 }
69
+
70
+ /* !- Overlay */
71
+ .modal-overlay {
72
+ position: absolute;
73
+ z-index: 10010;
74
+ top: 0;
75
+ bottom: 0;
76
+ left: 0;
77
+ right: 0;
78
+ background-color: var(--modal-overlay-background-color);
79
+ }
80
+
81
+ /* ! -Main structure */
82
+ .modal-outer {
83
+ position: relative;
84
+ z-index: 10020;
85
+ width: 100%;
86
+ height: 100%;
87
+ padding-top: var(--modal-margin-top);
88
+ padding-bottom: var(--modal-margin-bottom);
89
+ padding-left: var(--modal-margin-left);
90
+ padding-right: var(--modal-margin-right);
91
+ overflow: auto;
92
+ overscroll-behavior: contain;
93
+ -webkit-overflow-scrolling: touch;
94
+ }
95
+ .modal-inner {
96
+ display: flex;
97
+ flex-direction: column;
98
+ min-height: 100%;
99
+ }
100
+
101
+ /* !- Modal window */
102
+ .modal-window {
103
+ position: relative;
104
+ z-index: 10030;
105
+ width: 100%;
106
+ max-width: 80rem;
107
+ margin: auto;
108
+ padding-top: var(--modal-padding-top);
109
+ padding-bottom: var(--modal-padding-bottom);
110
+ padding-left: var(--modal-padding-left);
111
+ padding-right: var(--modal-padding-right);
112
+ text-align: left;
129
113
  background: var(--modal-background);
130
- width: var(--modal-closer-area);
131
- height: var(--modal-closer-area);
132
- margin-left: calc(-1 * var(--modal-closer-area));
133
- font-weight: 200;
134
- border: none;
114
+ box-shadow: var(--modal-box-shadow);
135
115
  border-radius: var(--modal-border-radius);
116
+ }
117
+
118
+ /* !- Close cross */
119
+ .modal-rail {
120
+ position: absolute;
121
+ top: var(--modal-closer-margin);
122
+ bottom: var(--modal-closer-margin);
123
+ right: var(--modal-closer-margin);
124
+ width: 0;
136
125
 
137
- will-change: opacity;
138
- opacity: 0;
139
- transition: opacity .15s ease-out;
140
-
141
- &:before,
142
- &:after {
143
- content: "";
126
+ .modal-close {
144
127
  display: block;
145
- position: absolute;
146
- top: calc(var(--modal-closer-area) / 2 - var(--modal-closer-width) / 2);
147
- left: calc((var(--modal-closer-area) - var(--modal-closer-size)) / 2);
148
- width: var(--modal-closer-size);
149
- height: var(--modal-closer-width);
128
+ position: sticky;
129
+ z-index: 10040;
130
+ top: calc(var(--modal-closer-margin) - var(--modal-margin-top));
131
+ background: var(--modal-background);
132
+ width: var(--modal-closer-area);
133
+ height: var(--modal-closer-area);
134
+ margin-left: calc(-1 * var(--modal-closer-area));
135
+ font-weight: 200;
136
+ border: none;
137
+ border-radius: var(--modal-border-radius);
150
138
 
151
- will-change: color;
152
- background: var(--modal-closer-color);
153
- transition: background .15s ease-out;
154
- transform-origin: center;
155
- }
156
- &:before {
157
- transform: rotate(-45deg);
158
- }
159
- &:after {
160
- transform: rotate(45deg);
139
+ will-change: opacity;
140
+ opacity: 0;
141
+ transition: opacity .15s ease-out;
142
+
143
+ &:before,
144
+ &:after {
145
+ content: "";
146
+ display: block;
147
+ position: absolute;
148
+ top: calc(var(--modal-closer-area) / 2 - var(--modal-closer-width) / 2);
149
+ left: calc((var(--modal-closer-area) - var(--modal-closer-size)) / 2);
150
+ width: var(--modal-closer-size);
151
+ height: var(--modal-closer-width);
152
+
153
+ will-change: color;
154
+ background: var(--modal-closer-color);
155
+ transition: background .15s ease-out;
156
+ transform-origin: center;
157
+ }
158
+ &:before {
159
+ transform: rotate(-45deg);
160
+ }
161
+ &:after {
162
+ transform: rotate(45deg);
163
+ }
161
164
  }
162
165
  }
163
- }
164
- .modal--active .modal-rail {
165
-
166
- .modal-close {
167
- opacity: 1;
166
+ .modal_active .modal-rail {
168
167
 
169
- @media (any-hover: hover) {
170
- &:hover:before,
171
- &:hover:after,
172
- &:active:before,
173
- &:active:after {
174
- background: var(--modal-closer-color-hover);
168
+ .modal-close {
169
+ opacity: 1;
170
+
171
+ @media (any-hover: hover) {
172
+ &:hover:before,
173
+ &:hover:after,
174
+ &:active:before,
175
+ &:active:after {
176
+ background: var(--modal-closer-color-hover);
177
+ }
175
178
  }
176
179
  }
177
180
  }
178
- }
179
-
180
- /*
181
- !- Effects
182
- https://github.com/codrops/ModalWindowEffects
183
- */
184
- .modal {
185
- & .modal-overlay {
186
- will-change: opacity;
187
- opacity: 0;
188
- transition: opacity .2s ease-out;
189
- }
190
- &.modal--active .modal-overlay {
191
- opacity: 1;
192
- }
193
- }
194
-
195
- /* !- Default */
196
- .modal {
197
- & .modal-window {
198
- will-change: visibility, opacity, transform;
199
- opacity: 0;
200
- transform: scale(.97);
201
- transform-origin: center top;
202
- transition: all .2s ease-out;
203
- }
204
- &.modal--active .modal-window {
205
- transform: scale(1);
206
- opacity: 1;
207
- }
208
- }
209
-
210
- /* !- Zoom in */
211
- .modal--effect-in {
212
- & .modal-window {
213
- transform: scale(.9);
214
- }
215
- &.modal--active .modal-window {
216
- transform: scale(1);
217
- }
218
- }
219
-
220
- /* !- Zoom out */
221
- .modal--effect-out {
222
- & .modal-window {
223
- transform: scale(1.1);
181
+
182
+ /*
183
+ !- Effects
184
+ https://github.com/codrops/ModalWindowEffects
185
+ */
186
+ .modal {
187
+ & .modal-overlay {
188
+ will-change: opacity;
189
+ opacity: 0;
190
+ transition: opacity .2s ease-out;
191
+ }
192
+ &.modal_active .modal-overlay {
193
+ opacity: 1;
194
+ }
224
195
  }
225
- &.modal--active .modal-window {
226
- transform: scale(1);
196
+
197
+ /* !- Default */
198
+ .modal {
199
+ & .modal-window {
200
+ will-change: visibility, opacity, transform;
201
+ opacity: 0;
202
+ transform: scale(.97);
203
+ transform-origin: center top;
204
+ transition: all .2s ease-out;
205
+ }
206
+ &.modal_active .modal-window {
207
+ transform: scale(1);
208
+ opacity: 1;
209
+ }
227
210
  }
228
- }
229
-
230
- /* !- Slide up */
231
- .modal--effect-up {
232
- & .modal-window {
233
- transform: translateY(30px);
211
+
212
+ /* !- Zoom in */
213
+ .modal_effect-in {
214
+ & .modal-window {
215
+ transform: scale(.9);
216
+ }
217
+ &.modal_active .modal-window {
218
+ transform: scale(1);
219
+ }
234
220
  }
235
- &.modal--active .modal-window {
236
- transform: translateY(0);
221
+
222
+ /* !- Zoom out */
223
+ .modal_effect-out {
224
+ & .modal-window {
225
+ transform: scale(1.1);
226
+ }
227
+ &.modal_active .modal-window {
228
+ transform: scale(1);
229
+ }
237
230
  }
238
- }
239
-
240
- /* !- Slide down */
241
- .modal--effect-down {
242
- & .modal-window {
243
- transform: translateY(-30px);
231
+
232
+ /* !- Slide up */
233
+ .modal_effect-up {
234
+ & .modal-window {
235
+ transform: translateY(30px);
236
+ }
237
+ &.modal_active .modal-window {
238
+ transform: translateY(0);
239
+ }
244
240
  }
245
- &.modal--active .modal-window {
246
- transform: translateY(0);
241
+
242
+ /* !- Slide down */
243
+ .modal_effect-down {
244
+ & .modal-window {
245
+ transform: translateY(-30px);
246
+ }
247
+ &.modal_active .modal-window {
248
+ transform: translateY(0);
249
+ }
247
250
  }
248
- }
249
-
250
- /* !- Slide from left */
251
- .modal--effect-left {
252
- & .modal-window {
253
- transform: translateX(-30px);
251
+
252
+ /* !- Slide from left */
253
+ .modal_effect-left {
254
+ & .modal-window {
255
+ transform: translateX(-30px);
256
+ }
257
+ &.modal_active .modal-window {
258
+ transform: translateX(0);
259
+ }
254
260
  }
255
- &.modal--active .modal-window {
256
- transform: translateX(0);
261
+
262
+ /* !- Slide from right */
263
+ .modal_effect-right {
264
+ & .modal-window {
265
+ transform: translateX(30px);
266
+ }
267
+ &.modal_active .modal-window {
268
+ transform: translateX(0);
269
+ }
257
270
  }
258
- }
259
271
 
260
- /* !- Slide from right */
261
- .modal--effect-right {
262
- & .modal-window {
263
- transform: translateX(30px);
264
- }
265
- &.modal--active .modal-window {
266
- transform: translateX(0);
267
- }
268
272
  }
@@ -13,7 +13,7 @@
13
13
  * modal.init();
14
14
  *
15
15
  * HTML structure:
16
- * <div x-modal="myModal" class="modal--hash" data-window-class="max800">
16
+ * <div x-modal="myModal" class="modal_hash" data-window-class="max800">
17
17
  * <h2>Modal Title</h2>
18
18
  * <p>Modal content goes here</p>
19
19
  * <button class="modal-close">Close</button>
@@ -92,8 +92,8 @@
92
92
  *
93
93
  * - `x-modal="id"` - Required attribute to define modal
94
94
  * - `x-modal-open="id"` - Attribute for links/buttons that open modal
95
- * - `modal--hash` - Class to enable URL hash integration (#id)
96
- * - `modal--uniq` - Class to close other modals when this one opens
95
+ * - `modal_hash` - Class to enable URL hash integration (#id)
96
+ * - `modal_uniq` - Class to close other modals when this one opens
97
97
  * - `data-window-class` - Attribute to add classes to modal window
98
98
  *
99
99
  * Features:
@@ -102,8 +102,8 @@
102
102
  * - ESC key to close topmost modal
103
103
  * - Click overlay to close
104
104
  * - Click .modal-close button to close
105
- * - URL hash integration (modal--hash class)
106
- * - Unique modal mode (modal--uniq class)
105
+ * - URL hash integration (modal_hash class)
106
+ * - Unique modal mode (modal_uniq class)
107
107
  * - Lock mechanism to prevent overlapping animations
108
108
  * - Global classes on <html> element
109
109
  *
@@ -136,7 +136,7 @@
136
136
  * @example
137
137
  * // Vanilla JS — plain HTML
138
138
  * // index.html:
139
- * // <div x-modal="myModal" class="modal--hash" data-window-class="max800">
139
+ * // <div x-modal="myModal" class="modal_hash" data-window-class="max800">
140
140
  * // <h2>Title</h2>
141
141
  * // <p>Content</p>
142
142
  * // <button type="button" class="modal-close">Close</button>
@@ -291,7 +291,7 @@ class Modal {
291
291
 
292
292
  if (window.location.hash === '#' + id) {
293
293
  const el = lib.qs('#' + id);
294
- if (el && el.classList.contains('modal--hash')) this.show(id);
294
+ if (el && el.classList.contains('modal_hash')) this.show(id);
295
295
  }
296
296
  }
297
297
  }
@@ -304,7 +304,7 @@ class Modal {
304
304
  */
305
305
  _setupGlobalListeners() {
306
306
  this._clickHandler = e => {
307
- if (!lib.qs('.modal--active')) return;
307
+ if (!lib.qs('.modal_active')) return;
308
308
  const target = e.target;
309
309
  const isClose = target.classList && target.classList.contains('modal-close');
310
310
  const isOverlay = !target.closest || !target.closest('.modal-window');
@@ -317,7 +317,7 @@ class Modal {
317
317
 
318
318
  this._keydownHandler = e => {
319
319
  if (e.key !== 'Escape') return;
320
- const modals = lib.qsa('.modal--active');
320
+ const modals = lib.qsa('.modal_active');
321
321
  const len = modals.length;
322
322
  if (!len) return;
323
323
  const id = modals[len - 1].getAttribute('id');
@@ -351,24 +351,24 @@ class Modal {
351
351
  const modal = lib.qs('#' + id);
352
352
  if (!modal) return;
353
353
 
354
- if (modal.classList.contains('modal--uniq')) await this.hideAll();
354
+ if (modal.classList.contains('modal_uniq')) await this.hideAll();
355
355
 
356
356
  this.lockCount++;
357
357
  try {
358
- await lib.addClass(modal, 'modal--ready');
358
+ await lib.addClass(modal, 'modal_ready');
359
359
  await lib.sleep(10);
360
360
  modal.dispatchEvent(new CustomEvent('modal:ready'));
361
361
 
362
- if (modal.classList.contains('modal--hash')) history.replaceState(null, '', '#' + id);
362
+ if (modal.classList.contains('modal_hash')) history.replaceState(null, '', '#' + id);
363
363
 
364
364
  if (this.html) {
365
- lib.addClass(this.html, 'modal--active');
366
- lib.addClass(this.html, id + '--active');
365
+ lib.addClass(this.html, 'modal_active');
366
+ lib.addClass(this.html, id + '_active');
367
367
  }
368
368
  lib.addClass('[x-modal-open=' + id + ']', 'active');
369
369
  this.modalLevel++;
370
- lib.addClass(modal, 'modal--z' + this.modalLevel);
371
- await lib.addClass(modal, 'modal--active');
370
+ lib.addClass(modal, 'modal_z' + this.modalLevel);
371
+ await lib.addClass(modal, 'modal_active');
372
372
 
373
373
  const modalOuter = lib.qs('.modal-outer', modal);
374
374
  if (modalOuter) modalOuter.scrollTo(0, 1);
@@ -398,16 +398,16 @@ class Modal {
398
398
 
399
399
  this.lockCount++;
400
400
  try {
401
- if (modal.classList.contains('modal--hash') && window.location.hash === '#' + id) {
401
+ if (modal.classList.contains('modal_hash') && window.location.hash === '#' + id) {
402
402
  history.replaceState(null, document.title, window.location.pathname + window.location.search);
403
403
  }
404
404
  lib.removeClass('[x-modal-open=' + id + ']', 'active');
405
- await lib.removeClass(modal, 'modal--active', 200);
406
- lib.removeClass(modal, 'modal--z' + this.modalLevel);
405
+ await lib.removeClass(modal, 'modal_active', 200);
406
+ lib.removeClass(modal, 'modal_z' + this.modalLevel);
407
407
  modal.dispatchEvent(new CustomEvent('modal:close'));
408
- if (this.html) lib.removeClass(this.html, id + '--active');
408
+ if (this.html) lib.removeClass(this.html, id + '_active');
409
409
  this.modalLevel--;
410
- if (this.modalLevel === 0 && this.html) lib.removeClass(this.html, 'modal--active');
410
+ if (this.modalLevel === 0 && this.html) lib.removeClass(this.html, 'modal_active');
411
411
  } catch (_) {
412
412
  } finally {
413
413
  this.lockCount--;
@@ -422,7 +422,7 @@ class Modal {
422
422
  */
423
423
  async hideAll() {
424
424
  if (typeof document === 'undefined') return;
425
- const modals = lib.qsa('.modal--active');
425
+ const modals = lib.qsa('.modal_active');
426
426
  for (let i = 0; i < modals.length; i++) {
427
427
  const id = modals[i].getAttribute('id');
428
428
  if (id) await this.hide(id);
@@ -437,7 +437,7 @@ class Modal {
437
437
  isActive(id) {
438
438
  if (typeof document === 'undefined' || !id || typeof id !== 'string' || !this._isValidId(id)) return false;
439
439
  const modal = lib.qs('#' + id);
440
- return modal ? modal.classList.contains('modal--active') : false;
440
+ return modal ? modal.classList.contains('modal_active') : false;
441
441
  }
442
442
  }
443
443