turbo_modal 0.3.2 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0078dc10ef887436764ed4b1dd676e73ada176603190f8d8eb8eb02bd19837c5'
4
- data.tar.gz: 777a55c156dd52f49b66b8eec882a7d093dbd5e3b7f9884bf4999eacbdb00d38
3
+ metadata.gz: 1784474a3a799b2c623b1705a5cf0df011bd809287a81342ceb605fc29930ef3
4
+ data.tar.gz: 733288280786b1cd6c8463db2351101fbfe7e668f05ac4e0f6367a4309c8b438
5
5
  SHA512:
6
- metadata.gz: 3f19861545c075e19cad1f516c05e022ee7fed7b64825e922b4c62fbc4f8a65ef59525db850fe6488cc26a89da3555c39493abc4fee8f78871025a0b503c7a2c
7
- data.tar.gz: dd29b5c61a67d68721cc57a4806b0f62cf15c421444598981074d258767a727840774769e0d920655cccd40a4af2d6a474f42f82ebf88b1114aef9b4b15d0a7d
6
+ metadata.gz: 28206680aa24756513e5e593cc601cb55b56642b56d67ff826ffff8e55dd7dcaa23904e36aa7c74c1b40a22b2451bbf2edcfb4118766b9a2dab97d37549cbb46
7
+ data.tar.gz: fddf55d488c5a7f3b1e9953550c9b054cf47e42c0895ea342a2f9d6ffd6cef947a2037532d45d941012e7d689030ddb6a2288ef9e58a292b1196c41c1b4b38ba
@@ -1,29 +1,57 @@
1
- .modal {
1
+ .modal-wrapper {
2
2
  position: fixed;
3
- top: 50%;
4
- left: 50%;
3
+ top: 0;
4
+ bottom: 0;
5
+ left: 0;
6
+ right: 0;
5
7
  z-index: 11;
8
+ display: flex;
9
+ justify-content: center;
10
+ align-items: center;
11
+ pointer-events: none;
12
+ }
13
+ .bottom-sheet .modal-wrapper {
14
+ align-items: flex-end;
15
+ }
16
+
17
+ .modal {
18
+ min-width: 40rem;
19
+ max-height: 100%;
20
+ display: flex;
21
+ position: relative;
22
+ top: unset;
23
+ left: unset;
6
24
  background: white;
7
25
  border-radius: 4px;
8
- padding: 2rem;
26
+ padding: 0;
9
27
  --animation-in: slide-in;
10
28
  --animation-out: slide-out;
29
+ pointer-events: auto;
30
+ margin: 2rem;
31
+ }
32
+ @media screen and (max-width: 45rem) {
33
+ .modal {
34
+ min-width: 100%;
35
+ }
36
+ }
37
+ .modal .modal-content {
38
+ overflow-y: scroll;
39
+ padding: 2rem;
11
40
  }
12
41
  @media screen and (max-width: 45rem) {
13
42
  .fullscreen .modal {
14
- top: 0;
15
- left: 0;
16
- right: 0;
17
- bottom: 0;
43
+ margin: 0;
18
44
  border-radius: 0;
45
+ height: 100%;
46
+ flex-grow: 1;
19
47
  }
20
48
  }
21
49
  .bottom-sheet .modal {
22
50
  top: unset;
23
- bottom: 0;
24
- left: 0;
25
- right: 0;
51
+ width: 100%;
52
+ margin: 0;
26
53
  min-height: 40vh;
54
+ transform: unset;
27
55
  --animation-in: slide-up;
28
56
  --animation-out: slide-down;
29
57
  }
@@ -36,7 +64,6 @@
36
64
  .animate-in {
37
65
  animation: var(--animation-in);
38
66
  animation-duration: 0.25s;
39
- animation-fill-mode: forwards;
40
67
  }
41
68
  @media screen and (max-width: 45rem) {
42
69
  .fullscreen .animate-in {
@@ -58,21 +85,21 @@
58
85
  @keyframes slide-in {
59
86
  from {
60
87
  opacity: 0;
61
- transform: translate(-50%, -35%);
88
+ transform: translateY(35%);
62
89
  }
63
90
  to {
64
91
  opacity: 1;
65
- transform: translate(-50%, -50%);
92
+ transform: translateY(0%);
66
93
  }
67
94
  }
68
95
  @keyframes slide-out {
69
96
  from {
70
97
  opacity: 1;
71
- transform: translate(-50%, -50%);
98
+ transform: translateY(0%);
72
99
  }
73
100
  to {
74
101
  opacity: 0;
75
- transform: translate(-50%, -35%);
102
+ transform: translateY(35%);
76
103
  }
77
104
  }
78
105
  @keyframes slide-in-left {
@@ -19,6 +19,9 @@ class ModalController extends Controller {
19
19
  open(e) {
20
20
  this.turboFrameTarget.src = e.detail.url;
21
21
  this.typeValue = e.detail.type;
22
+ if (event.detail.dismissable) {
23
+ this.turboFrameTarget.dataset.dismissable = "";
24
+ }
22
25
  showScrim(e.detail.dismiss);
23
26
  }
24
27
 
@@ -31,6 +34,7 @@ class ModalController extends Controller {
31
34
  setTimeout(() => {
32
35
  modal_element.remove();
33
36
  this.turboFrameTarget.src = null;
37
+ delete this.turboFrameTarget.dataset.dismissable;
34
38
 
35
39
  if (this.typeValue !== "") {
36
40
  this.turboFrameTarget.classList.remove(this.typeValue);
@@ -41,7 +45,7 @@ class ModalController extends Controller {
41
45
  }
42
46
 
43
47
  keyup(event) {
44
- if (event.key === "Escape") {
48
+ if (event.key === "Escape" && this.turboFrameTarget.dataset.dismissable === "") {
45
49
  closeModal();
46
50
  }
47
51
  }
@@ -14,37 +14,36 @@ class ScrimController extends Controller {
14
14
  static targets = ["scrim"];
15
15
 
16
16
  show(event) {
17
+ clipScreen(this);
17
18
  delete this.scrimTarget.dataset.hidden;
18
- document.body.style.height = "100vh";
19
- document.body.style.overflow = "hidden";
20
-
21
- if (!event.detail.dismiss) {
22
- this.scrimTarget.style.pointerEvents = "none";
19
+ if (event.detail.dismissable) {
20
+ this.scrimTarget.dataset.dismissable = "";
23
21
  }
24
22
  }
25
23
 
26
- hide(event) {
24
+ hide(event = null) {
25
+ delete this.scrimTarget.dataset.dismissable;
27
26
  this.scrimTarget.dataset.hidden = "";
28
- unclipScreen();
27
+ unclipScreen(this);
29
28
  }
30
29
 
31
30
  onClick(event) {
32
- window.dispatchEvent(new Event("scrim:hide"));
31
+ if (this.scrimTarget.dataset.dismissable === "") {
32
+ window.dispatchEvent(new Event("scrim:hide"));
33
+ }
33
34
  }
34
35
 
35
36
  disconnect() {
36
- this.scrimTarget.dataset.hidden = "";
37
- unclipScreen();
37
+ this.hide();
38
38
  super.disconnect();
39
39
  }
40
-
41
40
  }
42
41
 
43
42
  /**
44
43
  * Show the scrim element
45
44
  */
46
45
  function showScrim(dismiss = true) {
47
- window.dispatchEvent(new CustomEvent("scrim:show", { detail: { dismiss: dismiss }}));
46
+ window.dispatchEvent(new CustomEvent("scrim:show", { detail: { dismissable: dismiss } }));
48
47
  }
49
48
 
50
49
  /**
@@ -54,12 +53,22 @@ function hideScrim() {
54
53
  window.dispatchEvent(new Event("scrim:hide"));
55
54
  }
56
55
 
56
+ /**
57
+ * Clips body to viewport size
58
+ */
59
+ function clipScreen(controller) {
60
+ controller.previousHeight = document.body.style.height || "unset";
61
+ controller.previousOverflow = document.body.style.overflow || "unset";
62
+ document.body.style.height = "100vh";
63
+ document.body.style.overflow = "hidden";
64
+ }
65
+
57
66
  /**
58
67
  * Unclips body to viewport size
59
68
  */
60
- function unclipScreen() {
61
- document.body.style.height = "unset";
62
- document.body.style.overflow = "unset";
69
+ function unclipScreen(controller) {
70
+ document.body.style.height = controller.previousHeight;
71
+ document.body.style.overflow = controller.previousOverflow;
63
72
  }
64
73
 
65
74
  export { ScrimController as default, showScrim, hideScrim }
@@ -1,3 +1,3 @@
1
1
  module TurboModal
2
- VERSION = "0.3.2".freeze
2
+ VERSION = "0.3.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_modal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Cornthwaite
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-10 00:00:00.000000000 Z
12
+ date: 2022-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails