ultimate_turbo_modal 1.4.1 → 1.6.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: 979f1d2dadd3743aee45d26edc2057af3f859c26d58117726c1c1b1919f07fda
4
- data.tar.gz: 24160dc417e83b5ad8ee7bf055a71ef4e62f4ce18882c14b8e114cb6f1e292f9
3
+ metadata.gz: 19886fb7dd818b59f8aad64fa2c917783e690d63797761b63dd2ef4422ef119a
4
+ data.tar.gz: a1c5449b028638a5b7d39b2ea7707accf037d402fc1361ffc8d075b28181bde4
5
5
  SHA512:
6
- metadata.gz: e27b7b9068f0c1c514746344aa68be336c799f7e1deea6d2d82ad124a0b6818b7fdded1e1a0070d628f936e28d764e10669d5b50d24b4297b9e11d4f3d0daa15
7
- data.tar.gz: ebec1a181719537ab872b45d60896f18b7b586d12466cbae8dec1c04fa3f6a481351fdc563ba91051f41068e21bad65b8bc962758475423dd183946a7112cba4
6
+ metadata.gz: 8395f4d9a00f83fffcdb0293a967867b52a00e74ad3716bab49b5923f8c541e9a953246f3196abc434ddccc0daa3c8868caf78c6d915154b978ead3900628bc2
7
+ data.tar.gz: 17f6c1e20e67e8447fc41f3cbe708d4a2899acf9fcdfbd8ea753960c8daeb2789c572acbc9ee107b6524472ac2e78c1cb77d4b3b18cafa7911028c9336b801e4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.6.0] - 2023-12-25
2
+
3
+ - Support for Ruby 3.3
4
+
5
+ ## [1.5.0] - 2023-11-28
6
+
7
+ - Allow whitelisting out-of-modal CSS selectors to not dismiss modal when clicked
8
+
1
9
  ## [1.4.1] - 2023-11-26
2
10
 
3
11
  - Make Tailwind transition smoother on pages with multiple z-index
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ultimate_turbo_modal (1.4.1)
4
+ ultimate_turbo_modal (1.6.0)
5
5
  phlex-rails (>= 1.0, < 2.0)
6
6
  rails (>= 7)
7
7
  stimulus-rails
data/README.md CHANGED
@@ -26,6 +26,7 @@ It currently ships in a two flavors: Tailwind CSS, and regular, vanilla CSS. It
26
26
  - Support for long, scrollable modals
27
27
  - Properly locks the background page when scrolling a long modal
28
28
  - Click outside the modal to dismiss
29
+ - Option to whitelist CSS selectors that won't dismiss the modal when clicked outside the modal (ie: datepicker)
29
30
  - Keyboard control; ESC to dismiss
30
31
  - Automatic (or not) close button
31
32
 
@@ -70,6 +71,7 @@ UltimateTurboModal.configure do |config|
70
71
  config.header = true
71
72
  config.header_divider = true
72
73
  config.footer_divider = true
74
+ config.allowed_click_outside_selector = nil
73
75
  end
74
76
  ```
75
77
 
@@ -173,6 +175,11 @@ Whether to display a divider below the header.
173
175
 
174
176
  Whether to display a divider above the footer. The divider will not appear if no footer was specified.
175
177
 
178
+ ### `allowed_click_outside_selector`, default: `nil`
179
+
180
+ A string of CSS selectors that can be clicked outside of the modal without dismissing the modal. Useful for elements
181
+ such as datepickers.
182
+
176
183
  ### Example usage with options
177
184
 
178
185
  ```erb
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Phlex
4
4
  module DeferredRenderWithMainContent
5
- def template(&)
6
- output = capture(&)
5
+ def template(&block)
6
+ output = capture(&block)
7
7
  super { unsafe_raw(output) }
8
8
  end
9
9
  end
@@ -2,37 +2,40 @@
2
2
 
3
3
  class UltimateTurboModal::Base < Phlex::HTML
4
4
  prepend Phlex::DeferredRenderWithMainContent
5
- # @param padding [Boolean] Whether to add padding around the modal content
5
+ # @param advance [Boolean] Whether to update the browser history when opening and closing the modal
6
+ # @param allowed_click_outside_selector [String] CSS selectors for elements that are allowed to be clicked outside of the modal without dismissing the modal
6
7
  # @param close_button [Boolean] Whether to show a close button
7
- # @param close_button_sr_label [String] Close button label for screen readers
8
8
  # @param close_button_data_action [String] `data-action` attribute for the close button
9
- # @param advance [Boolean] Whether to update the browser history when opening and closing the modal
10
- # @param header_divider [Boolean] Whether to show a divider between the header and the main content
9
+ # @param close_button_sr_label [String] Close button label for screen readers
11
10
  # @param footer_divider [Boolean] Whether to show a divider between the main content and the footer
12
- # @param title [String] The title of the modal
11
+ # @param header_divider [Boolean] Whether to show a divider between the header and the main content
12
+ # @param padding [Boolean] Whether to add padding around the modal content
13
13
  # @param request [ActionDispatch::Request] The current Rails request object
14
+ # @param title [String] The title of the modal
14
15
  def initialize(
15
- padding: UltimateTurboModal.configuration.padding,
16
+ advance: UltimateTurboModal.configuration.advance,
17
+ allowed_click_outside_selector: UltimateTurboModal.configuration.allowed_click_outside_selector,
16
18
  close_button: UltimateTurboModal.configuration.close_button,
17
- close_button_sr_label: "Close modal",
18
19
  close_button_data_action: "modal#hideModal",
19
- advance: UltimateTurboModal.configuration.advance,
20
+ close_button_sr_label: "Close modal",
21
+ footer_divider: UltimateTurboModal.configuration.footer_divider,
20
22
  header: UltimateTurboModal.configuration.header,
21
23
  header_divider: UltimateTurboModal.configuration.header_divider,
22
- footer_divider: UltimateTurboModal.configuration.footer_divider,
23
- title: nil, request: nil
24
+ padding: UltimateTurboModal.configuration.padding,
25
+ request: nil, title: nil
24
26
  )
25
- @padding = padding
26
- @close_button = close_button
27
- @close_button_sr_label = close_button_sr_label
28
- @close_button_data_action = close_button_data_action
29
27
  @advance = !!advance
30
28
  @advance_url = advance if advance.present? && advance.is_a?(String)
31
- @title = title
29
+ @allowed_click_outside_selector = allowed_click_outside_selector
30
+ @close_button = close_button
31
+ @close_button_data_action = close_button_data_action
32
+ @close_button_sr_label = close_button_sr_label
33
+ @footer_divider = footer_divider
32
34
  @header = header
33
35
  @header_divider = header_divider
34
- @footer_divider = footer_divider
36
+ @padding = padding
35
37
  @request = request
38
+ @title = title
36
39
 
37
40
  unless self.class.include?(Turbo::FramesHelper)
38
41
  self.class.include Turbo::FramesHelper
@@ -67,7 +70,7 @@ class UltimateTurboModal::Base < Phlex::HTML
67
70
 
68
71
  private
69
72
 
70
- attr_accessor :request
73
+ attr_accessor :request, :allowed_click_outside_selector
71
74
 
72
75
  def padding? = !!@padding
73
76
 
@@ -81,7 +84,7 @@ class UltimateTurboModal::Base < Phlex::HTML
81
84
 
82
85
  def footer? = @footer.present?
83
86
 
84
- def header_divider? = !!@header_divider && (@title_block || title?)
87
+ def header_divider? = !!@header_divider && (@title_block.present? || title?)
85
88
 
86
89
  def footer_divider? = !!@footer_divider && footer?
87
90
 
@@ -104,26 +107,26 @@ class UltimateTurboModal::Base < Phlex::HTML
104
107
 
105
108
  ## HTML components
106
109
 
107
- def modal(&)
110
+ def modal(&block)
108
111
  outer_divs do
109
112
  div_content do
110
113
  div_header
111
- div_main(&)
114
+ div_main(&block)
112
115
  div_footer if footer?
113
116
  end
114
117
  end
115
118
  end
116
119
 
117
- def outer_divs(&)
120
+ def outer_divs(&block)
118
121
  div_dialog do
119
122
  div_overlay
120
123
  div_outer do
121
- div_inner(&)
124
+ div_inner(&block)
122
125
  end
123
126
  end
124
127
  end
125
128
 
126
- def div_dialog(&)
129
+ def div_dialog(&block)
127
130
  div(id: "modal-container",
128
131
  class: self.class::DIV_DIALOG_CLASSES,
129
132
  role: "dialog",
@@ -135,6 +138,7 @@ class UltimateTurboModal::Base < Phlex::HTML
135
138
  controller: "modal",
136
139
  modal_target: "container",
137
140
  modal_advance_url_value: advance_url,
141
+ modal_allowed_click_outside_selector_value: allowed_click_outside_selector,
138
142
  action: "turbo:submit-end->modal#submitEnd keyup@window->modal#closeWithKeyboard click@window->modal#outsideModalClicked click->modal#outsideModalClicked",
139
143
  transition_enter: "ease-out duration-100",
140
144
  transition_enter_start: "opacity-0",
@@ -148,30 +152,30 @@ class UltimateTurboModal::Base < Phlex::HTML
148
152
  close_button: close_button?.to_s,
149
153
  header_divider: header_divider?.to_s,
150
154
  footer_divider: footer_divider?.to_s
151
- }, &)
155
+ }, &block)
152
156
  end
153
157
 
154
158
  def div_overlay
155
159
  div(id: "modal-overlay", class: self.class::DIV_OVERLAY_CLASSES)
156
160
  end
157
161
 
158
- def div_outer(&)
159
- div(id: "modal-outer", class: self.class::DIV_OUTER_CLASSES, &)
162
+ def div_outer(&block)
163
+ div(id: "modal-outer", class: self.class::DIV_OUTER_CLASSES, &block)
160
164
  end
161
165
 
162
- def div_inner(&)
163
- div(id: "modal-inner", class: self.class::DIV_INNER_CLASSES, &)
166
+ def div_inner(&block)
167
+ div(id: "modal-inner", class: self.class::DIV_INNER_CLASSES, &block)
164
168
  end
165
169
 
166
- def div_content(&)
167
- div(id: "modal-content", class: self.class::DIV_CONTENT_CLASSES, data: {modal_target: "content"}, &)
170
+ def div_content(&block)
171
+ div(id: "modal-content", class: self.class::DIV_CONTENT_CLASSES, data: {modal_target: "content"}, &block)
168
172
  end
169
173
 
170
- def div_main(&)
171
- div(id: "modal-main", class: self.class::DIV_MAIN_CLASSES, &)
174
+ def div_main(&block)
175
+ div(id: "modal-main", class: self.class::DIV_MAIN_CLASSES, &block)
172
176
  end
173
177
 
174
- def div_header(&)
178
+ def div_header(&block)
175
179
  div(id: "modal-header", class: self.class::DIV_HEADER_CLASSES) do
176
180
  div_title
177
181
  button_close
@@ -203,13 +207,13 @@ class UltimateTurboModal::Base < Phlex::HTML
203
207
  end
204
208
  end
205
209
 
206
- def close_button_tag(&)
210
+ def close_button_tag(&block)
207
211
  button(type: "button",
208
212
  aria: {label: "close"},
209
213
  class: self.class::CLOSE_BUTTON_TAG_CLASSES,
210
214
  data: {
211
215
  action: @close_button_data_action
212
- }, &)
216
+ }, &block)
213
217
  end
214
218
 
215
219
  def icon_close
@@ -11,10 +11,12 @@ module UltimateTurboModal
11
11
  end
12
12
 
13
13
  delegate :flavor, :flavor=, :close_button, :close_button=,
14
- :advance, :advance=, :padding, :padding=, to: :configuration
14
+ :advance, :advance=, :padding, :padding=,
15
+ :allowed_click_outside_selector, :allowed_click_outside_selector=, to: :configuration
15
16
 
16
17
  class Configuration
17
18
  attr_reader :flavor, :close_button, :advance, :padding, :header, :header_divider, :footer_divider
19
+ attr_accessor :allowed_click_outside_selector
18
20
 
19
21
  def initialize
20
22
  @flavor = :tailwind
@@ -24,6 +26,7 @@ module UltimateTurboModal
24
26
  @header = true
25
27
  @header_divider = true
26
28
  @footer_divider = true
29
+ @allowed_click_outside_selector = []
27
30
  end
28
31
 
29
32
  def flavor=(flavor)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UltimateTurboModal
4
- VERSION = "1.4.1"
4
+ VERSION = "1.6.0"
5
5
  end
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.4.1
4
+ version: 1.6.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-26 00:00:00.000000000 Z
11
+ date: 2023-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex-rails