turbo_modal 0.2.2 → 0.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.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/app/assets/stylesheets/turbo_modal/_modal.scss +44 -16
- data/app/helpers/modal_helper.rb +20 -19
- data/app/javascript/turbo_modal/index.js +13 -1
- data/app/javascript/turbo_modal/modal_controller.js +1 -6
- data/app/javascript/turbo_modal/modal_link_controller.js +12 -0
- data/app/javascript/turbo_modal/scrim_controller.js +18 -0
- data/lib/install/turbo_modal.rb +2 -3
- data/lib/turbo_modal/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44e01e6f2393f5d94f8bd717862f49e73e049f550a9916e58ede3b561e5f3f54
|
4
|
+
data.tar.gz: 3abc1568da233389ace10ce3ca9c7b092f07833f9b46e45f588de7b4734a850a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dde473c24794b73d4991021b5a943619ed21c8ee3a5bdc01f61fe06e3fead2ac5de88c33eb509a3fe505f8aed5bbc1c951938eaa514461f6365f5cb4bc6ddacf
|
7
|
+
data.tar.gz: 131c41b10b3eecc05f7a4854d2c478b58d8405f4709d21fd584e9854cf76da690076a5e0ece96ba82466bef2f61bf373f2e0072d5b842ba0615b71c03758cfc4
|
data/README.md
CHANGED
@@ -18,6 +18,15 @@ Turbo modal provides helpers to add a basic scrim and modal target frame. These
|
|
18
18
|
@import "~@katalyst-interactive/turbo-modal";
|
19
19
|
```
|
20
20
|
|
21
|
+
### Import turbo_modal stimulus controllers
|
22
|
+
```js
|
23
|
+
/* application.js */
|
24
|
+
import TurboModal from "@katalyst-interactive/turbo-modal"
|
25
|
+
application.load(TurboModal)
|
26
|
+
```
|
27
|
+
|
28
|
+
### Show a modal
|
29
|
+
|
21
30
|
To get a modal displaying you will need 2 things:
|
22
31
|
1. A `modal_link` (or programmatic trigger)
|
23
32
|
2. Some `modal_content`
|
@@ -1,30 +1,59 @@
|
|
1
|
-
.modal {
|
1
|
+
.modal-wrapper {
|
2
2
|
position: fixed;
|
3
|
-
top:
|
4
|
-
|
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 & {
|
14
|
+
align-items: flex-end;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
.modal {
|
19
|
+
min-width: 40rem;
|
20
|
+
max-height: 100%;
|
21
|
+
display: flex;
|
22
|
+
position: relative;
|
23
|
+
top: unset;
|
24
|
+
left: unset;
|
6
25
|
background: white;
|
7
26
|
border-radius: 4px;
|
8
|
-
padding:
|
27
|
+
padding: 0;
|
9
28
|
--animation-in : slide-in;
|
10
29
|
--animation-out : slide-out;
|
30
|
+
pointer-events: auto;
|
31
|
+
margin: 2rem;
|
32
|
+
|
33
|
+
@media screen and(max-width: 45rem) {
|
34
|
+
min-width: 100%;
|
35
|
+
}
|
36
|
+
|
37
|
+
.modal-content {
|
38
|
+
overflow-y: scroll;
|
39
|
+
padding: 2rem;
|
40
|
+
}
|
11
41
|
|
12
42
|
.fullscreen & {
|
13
43
|
@media screen and(max-width: 45rem) {
|
14
|
-
|
15
|
-
left: 0;
|
16
|
-
right: 0;
|
17
|
-
bottom: 0;
|
44
|
+
margin: 0;
|
18
45
|
border-radius: 0;
|
46
|
+
height: 100%;
|
47
|
+
flex-grow: 1;
|
19
48
|
}
|
20
49
|
}
|
21
50
|
|
22
51
|
.bottom-sheet & {
|
23
52
|
top: unset;
|
24
|
-
|
25
|
-
|
26
|
-
right: 0;
|
53
|
+
width: 100%;
|
54
|
+
margin: 0;
|
27
55
|
min-height: 40vh;
|
56
|
+
transform: unset;
|
28
57
|
--animation-in : slide-up;
|
29
58
|
--animation-out : slide-down;
|
30
59
|
|
@@ -37,7 +66,6 @@
|
|
37
66
|
.animate-in {
|
38
67
|
animation: var(--animation-in);
|
39
68
|
animation-duration: 0.25s;
|
40
|
-
animation-fill-mode: forwards;
|
41
69
|
|
42
70
|
.fullscreen & {
|
43
71
|
@media screen and(max-width: 45rem) {
|
@@ -62,24 +90,24 @@
|
|
62
90
|
@keyframes slide-in {
|
63
91
|
from {
|
64
92
|
opacity: 0;
|
65
|
-
transform:
|
93
|
+
transform: translateY(35%);
|
66
94
|
}
|
67
95
|
|
68
96
|
to {
|
69
97
|
opacity: 1;
|
70
|
-
transform:
|
98
|
+
transform: translateY(0%);
|
71
99
|
}
|
72
100
|
}
|
73
101
|
|
74
102
|
@keyframes slide-out {
|
75
103
|
from {
|
76
104
|
opacity: 1;
|
77
|
-
transform:
|
105
|
+
transform: translateY(0%);
|
78
106
|
}
|
79
107
|
|
80
108
|
to {
|
81
109
|
opacity: 0;
|
82
|
-
transform:
|
110
|
+
transform: translateY(35%);
|
83
111
|
}
|
84
112
|
}
|
85
113
|
|
data/app/helpers/modal_helper.rb
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
module ModalHelper
|
4
4
|
MODAL_ID = "modal"
|
5
|
-
LINK_OPTIONS = { data: {
|
5
|
+
LINK_OPTIONS = { data: {
|
6
|
+
turbo_frame: MODAL_ID,
|
7
|
+
controller: "modal-link",
|
8
|
+
action: "modal-link#onClick",
|
9
|
+
modal_type: "",
|
10
|
+
} }.freeze
|
6
11
|
|
7
12
|
def modal_tag(modal_id = MODAL_ID)
|
8
13
|
turbo_frame_tag modal_id, data: { controller: "modal", modal_target: "turboFrame", action: <<~ACTIONS }
|
@@ -11,34 +16,30 @@ module ModalHelper
|
|
11
16
|
ACTIONS
|
12
17
|
end
|
13
18
|
|
19
|
+
# @see ActionView::Helpers::UrlHelper#link_to for argument details
|
14
20
|
def modal_link_to(name = nil, options = nil, html_options = nil, &block)
|
15
21
|
if block
|
16
|
-
link_to name, LINK_OPTIONS.deep_merge(options || {}),
|
22
|
+
link_to name, LINK_OPTIONS.deep_merge(options || {}), &block
|
17
23
|
else
|
18
|
-
link_to name, options, LINK_OPTIONS.deep_merge(html_options || {})
|
24
|
+
link_to name, options, LINK_OPTIONS.deep_merge(html_options || {})
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
22
|
-
|
23
|
-
options = LINK_OPTIONS.deep_merge(options)
|
24
|
-
if block
|
25
|
-
link_to text || path, options, &block
|
26
|
-
else
|
27
|
-
link_to text, path, options
|
28
|
-
end
|
29
|
-
end
|
28
|
+
alias modal_link modal_link_to
|
30
29
|
|
31
30
|
def modal_content(options = {}, &block)
|
32
31
|
modal_id = options.fetch(:modal_id, MODAL_ID)
|
33
32
|
turbo_frame_tag modal_id, data: { hidden: "" } do
|
34
|
-
tag.div(class: "modal
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
tag.div(class: "modal-wrapper") do
|
34
|
+
tag.div(class: "modal animate-in #{options.delete(:modal_classes)}",
|
35
|
+
data: {
|
36
|
+
action: <<~ACTIONS
|
37
|
+
keyup@window->modal#keyup
|
38
|
+
scrim:hide@window->modal#close
|
39
|
+
ACTIONS
|
40
|
+
}) do
|
41
|
+
yield if block
|
42
|
+
end
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -1,4 +1,16 @@
|
|
1
1
|
import ModalController, { openModal, closeModal } from "./modal_controller";
|
2
|
+
import ModalLinkController from "./modal_link_controller";
|
2
3
|
import ScrimController, { showScrim, hideScrim } from "./scrim_controller";
|
3
4
|
|
4
|
-
|
5
|
+
const Definitions = [
|
6
|
+
{ identifier: "modal", controllerConstructor: ModalController },
|
7
|
+
{ identifier: "modal-link", controllerConstructor: ModalLinkController },
|
8
|
+
{ identifier: "scrim", controllerConstructor: ScrimController }
|
9
|
+
];
|
10
|
+
|
11
|
+
export {
|
12
|
+
Definitions as default,
|
13
|
+
ModalController, openModal, closeModal,
|
14
|
+
ScrimController, showScrim, hideScrim,
|
15
|
+
ModalLinkController
|
16
|
+
};
|
@@ -2,7 +2,7 @@ import { Controller } from "stimulus";
|
|
2
2
|
import { hideScrim, showScrim } from "./scrim_controller";
|
3
3
|
|
4
4
|
/**
|
5
|
-
* Shows a Turbo modal when triggered by a `
|
5
|
+
* Shows a Turbo modal when triggered by a `modal:open` event (e.g. `openModal`).
|
6
6
|
*/
|
7
7
|
class ModalController extends Controller {
|
8
8
|
static targets = ["turboFrame"];
|
@@ -45,11 +45,6 @@ class ModalController extends Controller {
|
|
45
45
|
closeModal();
|
46
46
|
}
|
47
47
|
}
|
48
|
-
|
49
|
-
onLinkClick(e) {
|
50
|
-
const modal_link = e.target.closest("a[data-modal-type]")
|
51
|
-
openModal(modal_link.href, modal_link.dataset.modalType);
|
52
|
-
}
|
53
48
|
}
|
54
49
|
|
55
50
|
/**
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Controller } from "stimulus";
|
2
|
+
import { openModal } from "./modal_controller";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Shows a Turbo modal when clicked.
|
6
|
+
*/
|
7
|
+
export default class ModalLinkController extends Controller {
|
8
|
+
onClick(e) {
|
9
|
+
e.preventDefault();
|
10
|
+
openModal(this.element.href, this.element.dataset.modalType);
|
11
|
+
}
|
12
|
+
}
|
@@ -15,15 +15,25 @@ class ScrimController extends Controller {
|
|
15
15
|
|
16
16
|
show(event) {
|
17
17
|
delete this.scrimTarget.dataset.hidden;
|
18
|
+
document.body.style.height = "100vh";
|
19
|
+
document.body.style.overflow = "hidden";
|
18
20
|
}
|
19
21
|
|
20
22
|
hide(event) {
|
21
23
|
this.scrimTarget.dataset.hidden = "";
|
24
|
+
unclipScreen();
|
22
25
|
}
|
23
26
|
|
24
27
|
onClick(event) {
|
25
28
|
window.dispatchEvent(new Event("scrim:hide"));
|
26
29
|
}
|
30
|
+
|
31
|
+
disconnect() {
|
32
|
+
this.scrimTarget.dataset.hidden = "";
|
33
|
+
unclipScreen();
|
34
|
+
super.disconnect();
|
35
|
+
}
|
36
|
+
|
27
37
|
}
|
28
38
|
|
29
39
|
/**
|
@@ -40,4 +50,12 @@ function hideScrim() {
|
|
40
50
|
window.dispatchEvent(new Event("scrim:hide"));
|
41
51
|
}
|
42
52
|
|
53
|
+
/**
|
54
|
+
* Unclips body to viewport size
|
55
|
+
*/
|
56
|
+
function unclipScreen() {
|
57
|
+
document.body.style.height = "unset";
|
58
|
+
document.body.style.overflow = "unset";
|
59
|
+
}
|
60
|
+
|
43
61
|
export { ScrimController as default, showScrim, hideScrim }
|
data/lib/install/turbo_modal.rb
CHANGED
@@ -20,6 +20,5 @@ say "Install Turbo Modal"
|
|
20
20
|
say "Turbo Modal #{TurboModal::VERSION} requires Stimulus@2.0.0", :yellow
|
21
21
|
run "yarn add @katalyst-interactive/turbo-modal"
|
22
22
|
|
23
|
-
append_to_file "app/javascript/controllers/index.js", %(\nimport
|
24
|
-
append_to_file "app/javascript/controllers/index.js", %(application.
|
25
|
-
append_to_file "app/javascript/controllers/index.js", %(application.register("modal", ModalController)\n)
|
23
|
+
append_to_file "app/javascript/controllers/index.js", %(\nimport TurboModal from "@katalyst-interactive/turbo-modal"\n)
|
24
|
+
append_to_file "app/javascript/controllers/index.js", %(application.load(TurboModal)\n)
|
data/lib/turbo_modal/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.1
|
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-
|
12
|
+
date: 2022-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- app/helpers/scrim_helper.rb
|
61
61
|
- app/javascript/turbo_modal/index.js
|
62
62
|
- app/javascript/turbo_modal/modal_controller.js
|
63
|
+
- app/javascript/turbo_modal/modal_link_controller.js
|
63
64
|
- app/javascript/turbo_modal/scrim_controller.js
|
64
65
|
- config/routes.rb
|
65
66
|
- lib/install/turbo_modal.rb
|