ultimate_turbo_modal 1.2.0 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a456aa7e0fdb49a0b9ae53817f965df422145433f6d981811cbb0172126422dd
4
- data.tar.gz: 4fdb91772d698e7d1987024acb165f1ef8380446d600c5146b834025cb84c497
3
+ metadata.gz: b09b8cb53143af89cae066415021da467520342232aa61eec3c53b93fbc57b0d
4
+ data.tar.gz: b8c033322d1af2cf0117e7bbadf914668bdd8c7eb540487eadaccd31722a3473
5
5
  SHA512:
6
- metadata.gz: 63ae9236655b7d2d300507413808a5771ca205dc12d08eecc48a3f256ddf24525f8b2b401a432a4df035d6fbd929c738e0a74c5bd1036a1f16b62b786ce756bb
7
- data.tar.gz: d5fc098465cdba81f1981e49cce9721e049db78d02a448e734ea60f0c41b6119311a15e1ac922c7d0667d274431cb86bacaf9d3310c2ee51979f695cee3135ac
6
+ metadata.gz: fbe3f49e69952e28b6fcd3b26d7423700d10f5703a6802acb5be6a9dbdf7cff0003e01a44c4afdae255fd314f78e9c008f1d40f95f78254d6d8c6600762b398d
7
+ data.tar.gz: 66a67b13c8dfc6e8b1b0b36a091d1595034cce465196aa73c03f8fedcf09db4f1e733b8c13041f8e923fd6ab52697adb54b0e33e8308a3092365af062b9fd6b5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.3.0] - 2023-11-14
2
+
3
+ - Added ability to pass in a `title` block.
4
+
5
+ ## [1.2.1] - 2023-11-11
6
+
7
+ - Fix footer divider not showing
8
+
1
9
  ## [1.2.0] - 2023-11-05
2
10
 
3
11
  - Dark mode support
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ultimate_turbo_modal (1.2.0)
4
+ ultimate_turbo_modal (1.3.0)
5
5
  phlex-rails (>= 1.0, < 2.0)
6
6
  rails (>= 7)
7
7
  stimulus-rails
data/README.md CHANGED
@@ -75,14 +75,14 @@ end
75
75
 
76
76
  5. Register the Stimulus controller in `app/javascript/controllers/index.js` adding the following lines at the end.
77
77
 
78
- ```js
78
+ ```javascript
79
79
  import setupUltimateTurboModal from "ultimate_turbo_modal";
80
80
  setupUltimateTurboModal(application);
81
81
  ```
82
82
 
83
83
  6. If using the Tailwind flavor, add the following to `tailwind.config.js`:
84
84
 
85
- ```
85
+ ```javascript
86
86
  // For npm/yarn
87
87
  const { getUltimateTurboModalPath } = require('ultimate_turbo_modal/gemPath');
88
88
 
@@ -97,16 +97,17 @@ const { getUltimateTurboModalPath } = require('ultimate_turbo_modal/gemPath');
97
97
 
98
98
  and then in the `content` section, add `getUltimateTurboModalPath()` as follow:
99
99
 
100
- ```
101
- content: [
102
- './public/*.html',
103
- './app/helpers/**/*.rb',
104
- './app/javascript/**/*.js',
105
- './app/views/**/*.{erb,haml,html,slim,rb}',
106
- getUltimateTurboModalPath()
100
+ ```javascript
101
+ content: [
102
+ './public/*.html',
103
+ './app/helpers/**/*.rb',
104
+ './app/javascript/**/*.js',
105
+ './app/views/**/*.{erb,haml,html,slim,rb}',
106
+ getUltimateTurboModalPath()
107
+ ]
107
108
  ```
108
109
 
109
- 7. Optionally (but recommended), configure UTMR to use Idiomorph. See below for details.
110
+ 1. Optionally (but recommended), configure UTMR to use Idiomorph. See below for details.
110
111
 
111
112
  &nbsp;
112
113
  &nbsp;
@@ -158,7 +159,7 @@ If a URL is specified as a String, the browser history will advance, and the URL
158
159
 
159
160
  ### `title`, default: `nil`
160
161
 
161
- Title to display in the modal header.
162
+ Title to display in the modal header. Alternatively, you can set the title with a block.
162
163
 
163
164
  ### `header`, default: `true`
164
165
 
@@ -172,8 +173,6 @@ Whether to display a divider below the header.
172
173
 
173
174
  Whether to display a divider above the footer. The divider will not appear if no footer was specified.
174
175
 
175
-
176
-
177
176
  ### Example usage with options
178
177
 
179
178
  ```erb
@@ -188,6 +187,24 @@ Whether to display a divider above the footer. The divider will not appear if no
188
187
  <% end %>
189
188
  ```
190
189
 
190
+ ### Title and Footer
191
+
192
+ You can set a custom title and footer by passing a block. For example
193
+
194
+ ```erb
195
+ <%= modal do |m| %>
196
+ <% m.title do %>
197
+ <div>My Title</div>
198
+ <% end %>
199
+
200
+ Modal body
201
+
202
+ <% m.footer do %>
203
+ <input type="submit" form="myform">Submit</input>
204
+ <% end %>
205
+ <% end %>
206
+ ```
207
+
191
208
  ## Installing & Configuring Idiomorph
192
209
 
193
210
  Idiomorph can morph Turbo Frame responses to allow seemless navigation within Turbo Frames
@@ -202,7 +219,7 @@ In the meantime, add `<script src="https://unpkg.com/idiomorph"></script>` to yo
202
219
 
203
220
  And the following code to `application.js`:
204
221
 
205
- ```js
222
+ ```javascript
206
223
  addEventListener("turbo:before-frame-render", (event) => {
207
224
  event.detail.render = (currentElement, newElement) => {
208
225
  Idiomorph.morph(currentElement, newElement, {
@@ -0,0 +1,8 @@
1
+ module Phlex
2
+ module DeferredRenderWithMainContent
3
+ def template(&)
4
+ output = capture(&)
5
+ super { unsafe_raw(output) }
6
+ end
7
+ end
8
+ end
@@ -1,4 +1,5 @@
1
1
  class UltimateTurboModal::Base < Phlex::HTML
2
+ prepend Phlex::DeferredRenderWithMainContent
2
3
  # @param padding [Boolean] Whether to add padding around the modal content
3
4
  # @param close_button [Boolean] Whether to show a close button.
4
5
  # @param advance [Boolean] Whether to update the browser history when opening and closing the modal
@@ -48,25 +49,31 @@ class UltimateTurboModal::Base < Phlex::HTML
48
49
  end
49
50
  end
50
51
 
52
+ def title(&block)
53
+ @title_block = block
54
+ end
55
+
51
56
  def footer(&block)
52
57
  @footer = block
53
58
  end
54
59
 
55
60
  private
56
61
 
57
- attr_accessor :request, :title
62
+ attr_accessor :request
58
63
 
59
64
  def padding? = !!@padding
60
65
 
61
66
  def close_button? = !!@close_button
62
67
 
68
+ def title_block? = !!@title_block
69
+
63
70
  def title? = !!@title
64
71
 
65
72
  def header? = !!@header
66
73
 
67
74
  def footer? = @footer.present?
68
75
 
69
- def header_divider? = !!@header_divider && title?
76
+ def header_divider? = !!@header_divider && (@title_block || title?)
70
77
 
71
78
  def footer_divider? = !!@footer_divider && footer?
72
79
 
@@ -76,6 +76,12 @@ module UltimateTurboModal::Flavors
76
76
  div(id: "modal-main", class: "group-data-[padding=true]:p-4 group-data-[padding=true]:pt-2", &)
77
77
  end
78
78
 
79
+ def header_block
80
+ return if @header_block.blank?
81
+ render @header_block
82
+ nil
83
+ end
84
+
79
85
  def div_header(&)
80
86
  div(id: "modal-header", class: "flex justify-between items-center w-full py-4 rounded-t dark:border-gray-600 group-data-[header-divider=true]:border-b group-data-[header=false]:absolute") do
81
87
  div_title
@@ -85,7 +91,11 @@ module UltimateTurboModal::Flavors
85
91
 
86
92
  def div_title
87
93
  div(id: "modal-title", class: "pl-4") do
88
- h3(id: "modal-title-h", class: "group-data-[title=false]:hidden text-lg font-semibold text-gray-900 dark:text-white") { @title }
94
+ if @title_block.present?
95
+ render @title_block
96
+ else
97
+ h3(id: "modal-title-h", class: "group-data-[title=false]:hidden text-lg font-semibold text-gray-900 dark:text-white") { @title }
98
+ end
89
99
  end
90
100
  end
91
101
 
@@ -79,7 +79,11 @@ module UltimateTurboModal::Flavors
79
79
 
80
80
  def div_title
81
81
  div(id: "modal-title", class: "modal-title") do
82
- h3(id: "modal-title-h", class: "modal-title-h") { @title }
82
+ if @title_block.present?
83
+ render @title_block
84
+ else
85
+ h3(id: "modal-title-h", class: "modal-title-h") { @title }
86
+ end
83
87
  end
84
88
  end
85
89
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UltimateTurboModal
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "ultimate_turbo_modal/version"
4
+ require "phlex/deferred_render_with_main_content"
4
5
  require "ultimate_turbo_modal/configuration"
5
6
  require "ultimate_turbo_modal/railtie"
6
7
  require "ultimate_turbo_modal/base"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultimate_turbo_modal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Mercier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-05 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex-rails
@@ -90,6 +90,7 @@ files:
90
90
  - LICENSE.txt
91
91
  - README.md
92
92
  - Rakefile
93
+ - lib/phlex/deferred_render_with_main_content.rb
93
94
  - lib/ultimate_turbo_modal.rb
94
95
  - lib/ultimate_turbo_modal/base.rb
95
96
  - lib/ultimate_turbo_modal/configuration.rb