turbo_modal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1a0c324d77710010d3d592e4c12f4978aebe32db754dcd6b9b9ca98c2de0d8d
4
+ data.tar.gz: '028ea286edf98dda94c3eab35135fb9f7a9052793cd46864f7a654f1e30934d8'
5
+ SHA512:
6
+ metadata.gz: b40bde5c79717d35e361292ec4a1bee89ccae813891656352cb47220110c1fe39e16885627821a9e56bb836343489ba4c1dd97efab71143f322761517b3b7710
7
+ data.tar.gz: 140066b0316bdd7e8ce3a69f3bc349395cae2b38e34a4dc64d500fd175147e9821fa4c5110792ca4e756d0572f7e861ad6f7548297e65364d551e12bf8e0a198
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Alan Cornthwaite
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # TurboModal
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'turbo_modal'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install turbo_modal
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
9
+
10
+ require "rake/testtask"
11
+
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = false
16
+ end
17
+
18
+ task default: :test
File without changes
@@ -0,0 +1,131 @@
1
+ .modal {
2
+ position: fixed;
3
+ top: 50%;
4
+ left: 50%;
5
+ z-index: 11;
6
+ background: white;
7
+ border-radius: 4px;
8
+ padding: 2rem;
9
+ --animation-in: slide-in;
10
+ --animation-out: slide-out;
11
+ --mobile-breakpoint: 45rem;
12
+ }
13
+ @media screen and (max-width: var(--mobile-breakpoint)) {
14
+ .fullscreen .modal {
15
+ top: 0;
16
+ left: 0;
17
+ right: 0;
18
+ bottom: 0;
19
+ border-radius: 0;
20
+ }
21
+ }
22
+ .bottom-sheet .modal {
23
+ top: unset;
24
+ bottom: 0;
25
+ left: 0;
26
+ right: 0;
27
+ min-height: 40vh;
28
+ --animation-in: slide-up;
29
+ --animation-out: slide-down;
30
+ }
31
+ @media screen and (max-width: var(--mobile-breakpoint)) {
32
+ .bottom-sheet .modal {
33
+ min-height: 65vh;
34
+ }
35
+ }
36
+
37
+ .animate-in {
38
+ animation: var(--animation-in);
39
+ animation-duration: 0.25s;
40
+ animation-fill-mode: forwards;
41
+ }
42
+ @media screen and (max-width: var(--mobile-breakpoint)) {
43
+ .fullscreen .animate-in {
44
+ --animation-in: slide-in-left;
45
+ }
46
+ }
47
+
48
+ .animate-out {
49
+ animation: var(--animation-out);
50
+ animation-duration: 0.25s;
51
+ animation-fill-mode: forwards;
52
+ }
53
+ @media screen and (max-width: var(--mobile-breakpoint)) {
54
+ .fullscreen .animate-out {
55
+ --animation-out: slide-out-right;
56
+ }
57
+ }
58
+
59
+ @keyframes slide-in {
60
+ from {
61
+ opacity: 0;
62
+ transform: translate(-50%, -35%);
63
+ }
64
+ to {
65
+ opacity: 1;
66
+ transform: translate(-50%, -50%);
67
+ }
68
+ }
69
+ @keyframes slide-out {
70
+ from {
71
+ opacity: 1;
72
+ transform: translate(-50%, -50%);
73
+ }
74
+ to {
75
+ opacity: 0;
76
+ transform: translate(-50%, -35%);
77
+ }
78
+ }
79
+ @keyframes slide-in-left {
80
+ from {
81
+ opacity: 0;
82
+ transform: translateX(100%);
83
+ }
84
+ to {
85
+ opacity: 1;
86
+ transform: translateX(0);
87
+ }
88
+ }
89
+ @keyframes slide-out-right {
90
+ from {
91
+ opacity: 1;
92
+ transform: translateX(0);
93
+ }
94
+ to {
95
+ opacity: 0;
96
+ transform: translateX(100%);
97
+ }
98
+ }
99
+ @keyframes slide-up {
100
+ from {
101
+ opacity: 0;
102
+ transform: translateY(100%);
103
+ }
104
+ to {
105
+ opacity: 1;
106
+ transform: translateY(0);
107
+ }
108
+ }
109
+ @keyframes slide-down {
110
+ from {
111
+ opacity: 1;
112
+ transform: translateY(0);
113
+ }
114
+ to {
115
+ opacity: 0;
116
+ transform: translateY(100%);
117
+ }
118
+ }
119
+ .scrim {
120
+ position: fixed;
121
+ top: 0;
122
+ bottom: 0;
123
+ left: 0;
124
+ right: 0;
125
+ background: rgba(0, 0, 0, 0.6);
126
+ z-index: 11;
127
+ }
128
+
129
+ .scrim[data-hidden] {
130
+ display: none;
131
+ }
@@ -0,0 +1,2 @@
1
+ @use "modal";
2
+ @use "scrim";
@@ -0,0 +1,133 @@
1
+ .modal {
2
+ position: fixed;
3
+ top: 50%;
4
+ left: 50%;
5
+ z-index: 11;
6
+ background: white;
7
+ border-radius: 4px;
8
+ padding: 2rem;
9
+ --animation-in : slide-in;
10
+ --animation-out : slide-out;
11
+ --mobile-breakpoint: 45rem;
12
+
13
+ .fullscreen & {
14
+ @media screen and(max-width: var(--mobile-breakpoint)) {
15
+ top: 0;
16
+ left: 0;
17
+ right: 0;
18
+ bottom: 0;
19
+ border-radius: 0;
20
+ }
21
+ }
22
+
23
+ .bottom-sheet & {
24
+ top: unset;
25
+ bottom: 0;
26
+ left: 0;
27
+ right: 0;
28
+ min-height: 40vh;
29
+ --animation-in : slide-up;
30
+ --animation-out : slide-down;
31
+
32
+ @media screen and(max-width: var(--mobile-breakpoint)) {
33
+ min-height: 65vh;
34
+ }
35
+ }
36
+ }
37
+
38
+ .animate-in {
39
+ animation: var(--animation-in);
40
+ animation-duration: 0.25s;
41
+ animation-fill-mode: forwards;
42
+
43
+ .fullscreen & {
44
+ @media screen and(max-width: var(--mobile-breakpoint)) {
45
+ --animation-in: slide-in-left;
46
+ }
47
+ }
48
+ }
49
+
50
+ .animate-out {
51
+ animation: var(--animation-out);
52
+ animation-duration: 0.25s;
53
+ animation-fill-mode: forwards;
54
+
55
+ .fullscreen & {
56
+ @media screen and(max-width: var(--mobile-breakpoint)) {
57
+ --animation-out: slide-out-right;
58
+ }
59
+ }
60
+ }
61
+
62
+
63
+ @keyframes slide-in {
64
+ from {
65
+ opacity: 0;
66
+ transform: translate(-50%, -35%);
67
+ }
68
+
69
+ to {
70
+ opacity: 1;
71
+ transform: translate(-50%, -50%);
72
+ }
73
+ }
74
+
75
+ @keyframes slide-out {
76
+ from {
77
+ opacity: 1;
78
+ transform: translate(-50%, -50%);
79
+ }
80
+
81
+ to {
82
+ opacity: 0;
83
+ transform: translate(-50%, -35%);
84
+ }
85
+ }
86
+
87
+ @keyframes slide-in-left {
88
+ from {
89
+ opacity: 0;
90
+ transform: translateX(100%);
91
+ }
92
+
93
+ to {
94
+ opacity: 1;
95
+ transform: translateX(0);
96
+ }
97
+ }
98
+
99
+ @keyframes slide-out-right {
100
+ from {
101
+ opacity: 1;
102
+ transform: translateX(0);
103
+ }
104
+
105
+ to {
106
+ opacity: 0;
107
+ transform: translateX(100%);
108
+ }
109
+ }
110
+
111
+ @keyframes slide-up {
112
+ from {
113
+ opacity: 0;
114
+ transform: translateY(100%);
115
+ }
116
+
117
+ to {
118
+ opacity: 1;
119
+ transform: translateY(0);
120
+ }
121
+ }
122
+
123
+ @keyframes slide-down {
124
+ from {
125
+ opacity: 1;
126
+ transform: translateY(0);
127
+ }
128
+
129
+ to {
130
+ opacity: 0;
131
+ transform: translateY(100%);
132
+ }
133
+ }
@@ -0,0 +1,13 @@
1
+ .scrim {
2
+ position: fixed;
3
+ top: 0;
4
+ bottom: 0;
5
+ left: 0;
6
+ right: 0;
7
+ background: rgba(0, 0, 0, 0.6);
8
+ z-index: 11;
9
+ }
10
+
11
+ .scrim[data-hidden] {
12
+ display: none;
13
+ }
@@ -0,0 +1 @@
1
+ @use "turbo_modal/index";
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ModalHelper
4
+ MODAL_ID = "modal"
5
+ DEFAULT_OPTIONS = { data: { turbo_frame: MODAL_ID, action: "modal#showModal", modal_type: "" } }.freeze
6
+
7
+ def modal_tag(modal_id = MODAL_ID)
8
+ turbo_frame_tag modal_id, data: { modal_target: "turboFrame" }
9
+ end
10
+
11
+ def modal_link_to(name = nil, options = nil, html_options = nil, &block)
12
+ if block
13
+ link_to name, DEFAULT_OPTIONS.deep_merge(options || {}), html_options, &block
14
+ else
15
+ link_to name, options, DEFAULT_OPTIONS.deep_merge(html_options || {}), &block
16
+ end
17
+ end
18
+
19
+ def modal_link(text = nil, path = nil, options = {}, &block)
20
+ options = DEFAULT_OPTIONS.deep_merge(options)
21
+ if block
22
+ link_to text || path, options, &block
23
+ else
24
+ link_to text, path, options
25
+ end
26
+ end
27
+
28
+ def modal_content(options = {}, &block)
29
+ modal_id = options.fetch(:modal_id, MODAL_ID)
30
+ turbo_frame_tag modal_id, class: "hidden" do
31
+ tag.div(class: "modal animate-in #{options.delete(:modal_classes)}",
32
+ data: {
33
+ action: "keyup@document->modal#keyup scrim-hide@window->modal#close",
34
+ }) do
35
+ yield if block
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ScrimHelper
4
+ def scrim_tag
5
+ tag.div(class: "scrim", data: { scrim_target: "scrim", action: "click->scrim#hide", hidden: true })
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ import ModalController from "./modal_controller";
2
+ import ScrimController from "./scrim_controller";
3
+
4
+ export { ModalController, ScrimController }
@@ -0,0 +1,42 @@
1
+ import { Controller } from "stimulus";
2
+
3
+ export default class ModalController extends Controller {
4
+ static targets = ["turboFrame"];
5
+
6
+ static values = {
7
+ type: String
8
+ }
9
+
10
+ typeValueChanged(value) {
11
+ if (value === "") return;
12
+ this.turboFrameTarget.classList.add(value);
13
+ }
14
+
15
+ close() {
16
+ if (this.turboFrameTarget.src === null) return;
17
+
18
+ const modal_element = this.turboFrameTarget.querySelector(".modal")
19
+ modal_element.classList.remove("animate-in");
20
+ modal_element.classList.add("animate-out");
21
+ setTimeout(() => {
22
+ modal_element.remove();
23
+ this.turboFrameTarget.src = null;
24
+
25
+ if (this.typeValue !== "") {
26
+ this.turboFrameTarget.classList.remove(this.typeValue);
27
+ this.typeValue = "";
28
+ }
29
+ window.dispatchEvent(new Event("hide-scrim", { bubbles: true }))
30
+ }, 250);
31
+ }
32
+
33
+ keyup(event) {
34
+ if (event.key === 'Escape') this.close();
35
+ }
36
+
37
+ showModal(e) {
38
+ const modal_link = e.target.closest("a[data-modal-type]")
39
+ this.typeValue = modal_link.dataset.modalType
40
+ window.dispatchEvent(new Event("show-scrim", { bubbles: true }))
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ import { Controller } from "stimulus"
2
+
3
+ class ScrimController extends Controller {
4
+ static targets = ["scrim"];
5
+
6
+ show(event) {
7
+ delete this.scrimTarget.dataset.hidden;
8
+ }
9
+
10
+ hide(event) {
11
+ this.scrimTarget.dataset.hidden = "hidden";
12
+ window.dispatchEvent(new Event("scrim-hide", { bubbles: true }))
13
+ }
14
+ }
15
+
16
+ export default ScrimController;
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../turbo_modal/version"
2
+
3
+ entry_path = case Rails.version[0].to_i
4
+ when 6
5
+ "app/javascripts/packs/application.js"
6
+ when 7
7
+ "app/javascripts/application.js"
8
+ else
9
+ exit "Turbo Modal requires rails 6 or higher"
10
+ end
11
+
12
+ if Rails.root.join(entry_path).exist?
13
+ say "Import Turbo Modal"
14
+ append_to_file entry_path, %(import "@katalyst-interactive/turbo-modal"\n)
15
+ else
16
+ say "You must import @katalyst-interactive/turbo-modal in your JavaScript entrypoint file", :red
17
+ end
18
+
19
+ say "Install Turbo Modal"
20
+ say "Turbo Modal #{TurboModal::VERSION} requires Stimulus@2.0.0", :yellow
21
+ run "yarn add @katalyst-interactive/turbo-modal"
22
+
23
+ append_to_file "app/javascript/controllers/index.js", %(\nimport { ScrimController, ModalController } from "@katalyst-interactive/turbo-modal"\n)
24
+ append_to_file "app/javascript/controllers/index.js", %(application.register("scrim", ScrimController)\n)
25
+ append_to_file "app/javascript/controllers/index.js", %(application.register("modal", ModalController)\n)
@@ -0,0 +1,35 @@
1
+ # desc "Explaining what the task does"
2
+ # task :turbo_modal do
3
+ # # Task goes here
4
+ # end
5
+
6
+ def run_template_path(path)
7
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
8
+ end
9
+
10
+ def stimulus_installed?
11
+ (Rails.root.join("app/javascript/controllers/index.js")).exist?
12
+ end
13
+
14
+ def switch_on_stimulus
15
+ system "yarn add stimulus@2.0.0"
16
+ end
17
+
18
+ def switch_on_turbo
19
+ Rake::Task["turbo:install"].invoke
20
+ end
21
+
22
+ namespace :turbo_modal do
23
+ desc "Install turbo_modal packages"
24
+ task install: %i[stimulus turbo] do
25
+ run_template_path "turbo_modal"
26
+ end
27
+
28
+ task :stimulus do
29
+ switch_on_stimulus unless stimulus_installed?
30
+ end
31
+
32
+ task :turbo do
33
+ switch_on_turbo
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ module TurboModal
2
+ class Engine < ::Rails::Engine
3
+ config.autoload_once_paths = %W(#{root}/app/helpers)
4
+
5
+ PRECOMPILE_ASSETS = %w( turbo_modal.css )
6
+
7
+ initializer "turbo_modal.assets" do
8
+ if Rails.application.config.respond_to?(:assets)
9
+ Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
10
+ end
11
+ end
12
+
13
+ initializer "turbo_modal.helpers", before: :load_config_initializers do
14
+ ActiveSupport.on_load(:action_controller_base) do
15
+ helper TurboModal::Engine.helpers
16
+ end
17
+
18
+ ActiveSupport.on_load(:action_view_base) do
19
+ helper TurboModal::Engine.helpers
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module TurboModal
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,7 @@
1
+ require "turbo-rails"
2
+ require "turbo_modal/version"
3
+ require "turbo_modal/engine"
4
+
5
+ module TurboModal
6
+ # Your code goes here...
7
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turbo_modal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alan Cornthwaite
8
+ - Matt Redmond
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-10-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 6.1.3
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 6.1.3.1
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: 6.1.3
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 6.1.3.1
34
+ - !ruby/object:Gem::Dependency
35
+ name: turbo-rails
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 7.1.1
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 7.1.1
48
+ description: ''
49
+ email:
50
+ - alan.cornthwaite@katalyst.com.au
51
+ - matt.redmond@katalyst.com.au
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - MIT-LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - app/assets/config/turbo_modal_manifest.js
60
+ - app/assets/dist/turbo_modal.css
61
+ - app/assets/stylesheets/turbo_modal.scss
62
+ - app/assets/stylesheets/turbo_modal/_index.scss
63
+ - app/assets/stylesheets/turbo_modal/_modal.scss
64
+ - app/assets/stylesheets/turbo_modal/_scrim.scss
65
+ - app/helpers/modal_helper.rb
66
+ - app/helpers/scrim_helper.rb
67
+ - app/javascript/turbo_modal/index.js
68
+ - app/javascript/turbo_modal/modal_controller.js
69
+ - app/javascript/turbo_modal/scrim_controller.js
70
+ - config/routes.rb
71
+ - lib/install/turbo_modal.rb
72
+ - lib/tasks/turbo_modal_tasks.rake
73
+ - lib/turbo_modal.rb
74
+ - lib/turbo_modal/engine.rb
75
+ - lib/turbo_modal/version.rb
76
+ homepage: https://github.com/katalyst/turbo_modal
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ homepage_uri: https://github.com/katalyst/turbo_modal
82
+ source_code_uri: https://github.com/katalyst/turbo_modal
83
+ changelog_uri: https://github.com/katalyst/turbo_modal
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.1.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Modal library that uses Turbo and Stimulus because we are in the future now.
103
+ test_files: []