moderntw_confirms 1.0.0 → 1.1.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 +4 -4
- data/CHANGELOG.md +6 -5
- data/README.md +7 -6
- data/lib/generators/moderntw_confirms/install/templates/_moderntw_confirms_modal.html.erb +12 -8
- data/lib/generators/moderntw_confirms/install/templates/moderntw_confirms.rb +5 -1
- data/lib/moderntw_confirms/version.rb +1 -1
- data/lib/moderntw_confirms.rb +4 -1
- data/vendor/assets/javascripts/moderntw_confirms.js +54 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eea06d5f7f409a050c8ab276951527339aff43908982b4877c47a71de28bfaf6
|
|
4
|
+
data.tar.gz: 588cdb9a1b4e27bc6bb192f17eda678abfc58c0a9538f25c030331682630a377
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2599ffd51032afaeea169def98bea6bb72e521433ffa4717d5ce2c8f7bdda94f13679789e47873182ae4383e351fcab5b131cb4e20545cdf6ccbc57700ab8525
|
|
7
|
+
data.tar.gz: 0ff0eb7dec6ab092c8e512420a49a9be2024e23e5577240d67c769b9bea2770238254ad7d8a3d6b9b61e9e9af2b19df1db56a756f0bde5d91a3c4a7d4e63654f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
3
|
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
4
|
|
|
8
|
-
## [
|
|
5
|
+
## [1.1.0] - 2024-05-xx
|
|
6
|
+
- Default to native confirms on mobile with optional opt-in via config[:enable_on_mobile]
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- Default to native browser confirms on mobile devices with the option to re-enable Tailwind modals via `config[:enable_on_mobile]`
|
|
9
10
|
|
|
10
11
|
## [0.1.0] - 2025-10-21
|
|
11
12
|
|
|
@@ -21,4 +22,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
21
22
|
- Optional Stimulus controller for advanced customization
|
|
22
23
|
- Configurable Tailwind classes via initializer
|
|
23
24
|
- Dynamic content support (works with AJAX/Turbo loaded content)
|
|
24
|
-
- Focus management for accessibility
|
|
25
|
+
- Focus management for accessibility
|
data/README.md
CHANGED
|
@@ -96,9 +96,14 @@ ModerntwConfirms.configure do |config|
|
|
|
96
96
|
config[:modal_class] = "rounded-3xl shadow-2xl"
|
|
97
97
|
config[:confirm_button_class] = "bg-indigo-600 hover:bg-indigo-700"
|
|
98
98
|
config[:cancel_button_class] = "bg-gray-200 hover:bg-gray-300"
|
|
99
|
+
config[:enable_on_mobile] = true # Opt into modals on phones/tablets
|
|
99
100
|
end
|
|
100
101
|
```
|
|
101
102
|
|
|
103
|
+
### Mobile Behavior
|
|
104
|
+
|
|
105
|
+
Native confirmation dialogs feel familiar on mobile, so the gem defaults to using the browser's built-in confirms for touch devices. If you prefer the Tailwind modal experience everywhere, set `config[:enable_on_mobile] = true` in your initializer.
|
|
106
|
+
|
|
102
107
|
### Animation Customization
|
|
103
108
|
|
|
104
109
|
The animations use CSS transitions and can be modified in the modal partial:
|
|
@@ -133,16 +138,12 @@ The modal includes automatic fallback to native browser confirms for older brows
|
|
|
133
138
|
|
|
134
139
|
## Development
|
|
135
140
|
|
|
136
|
-
After checking out the repo,
|
|
141
|
+
After checking out the repo, run:
|
|
137
142
|
|
|
138
143
|
```bash
|
|
139
|
-
cd test_confirms_app
|
|
140
144
|
bundle install
|
|
141
|
-
rails server
|
|
142
145
|
```
|
|
143
146
|
|
|
144
|
-
Visit http://localhost:3000 to see the examples.
|
|
145
|
-
|
|
146
147
|
### Running Tests
|
|
147
148
|
|
|
148
149
|
```bash
|
|
@@ -170,4 +171,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
170
171
|
|
|
171
172
|
## Acknowledgments
|
|
172
173
|
|
|
173
|
-
Built with Rails and Tailwind CSS. Special thanks to the Rails and Hotwire communities for their excellent frameworks.
|
|
174
|
+
Built with Rails and Tailwind CSS. Special thanks to the Rails and Hotwire communities for their excellent frameworks.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
<% config = ModerntwConfirms.config %>
|
|
2
|
+
<% enable_on_mobile = config.fetch(:enable_on_mobile, false) %>
|
|
3
|
+
|
|
1
4
|
<div id="moderntw-confirm-modal"
|
|
2
5
|
class="hidden fixed inset-0 z-[99999] overflow-y-auto"
|
|
3
6
|
aria-labelledby="moderntw-modal-title"
|
|
4
7
|
aria-modal="true"
|
|
5
8
|
role="dialog"
|
|
6
|
-
data-turbo-permanent
|
|
9
|
+
data-turbo-permanent
|
|
10
|
+
data-enable-on-mobile="<%= enable_on_mobile %>">
|
|
7
11
|
|
|
8
12
|
<div class="fixed inset-0" data-modal-backdrop>
|
|
9
13
|
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm"></div>
|
|
@@ -62,7 +66,7 @@
|
|
|
62
66
|
|
|
63
67
|
<style>
|
|
64
68
|
#moderntw-confirm-modal {
|
|
65
|
-
transition: opacity
|
|
69
|
+
transition: opacity 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
66
70
|
will-change: opacity;
|
|
67
71
|
}
|
|
68
72
|
|
|
@@ -75,7 +79,7 @@
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
#moderntw-confirm-modal [data-modal-panel] {
|
|
78
|
-
transition:
|
|
82
|
+
transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 180ms ease-out;
|
|
79
83
|
will-change: transform, opacity;
|
|
80
84
|
}
|
|
81
85
|
|
|
@@ -85,20 +89,20 @@
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
#moderntw-confirm-modal:not(.modal-showing) [data-modal-panel] {
|
|
88
|
-
transform: scale(0.
|
|
92
|
+
transform: scale(0.95) translateY(10px);
|
|
89
93
|
opacity: 0;
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
@supports (backdrop-filter: blur(0px)) or (-webkit-backdrop-filter: blur(0px)) {
|
|
93
97
|
#moderntw-confirm-modal [data-modal-backdrop] > div {
|
|
94
|
-
-webkit-backdrop-filter: blur(
|
|
95
|
-
backdrop-filter: blur(
|
|
98
|
+
-webkit-backdrop-filter: blur(10px);
|
|
99
|
+
backdrop-filter: blur(10px);
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
@supports not ((backdrop-filter: blur(0px)) or (-webkit-backdrop-filter: blur(0px))) {
|
|
100
104
|
#moderntw-confirm-modal [data-modal-backdrop] > div {
|
|
101
|
-
background-color: rgba(17, 24, 39, 0.
|
|
105
|
+
background-color: rgba(17, 24, 39, 0.72);
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
|
-
</style>
|
|
108
|
+
</style>
|
|
@@ -17,4 +17,8 @@ ModerntwConfirms.configure do |config|
|
|
|
17
17
|
# You can also add custom classes for specific use cases:
|
|
18
18
|
# For delete confirmations, you might want red buttons:
|
|
19
19
|
# config[:delete_confirm_button_class] = "bg-red-500 hover:bg-red-600 text-white font-semibold py-2 px-4 rounded"
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
# Use Tailwind modal confirms on mobile devices (defaults to native mobile confirms)
|
|
22
|
+
# Set to true if you prefer the custom modal experience on phones and tablets
|
|
23
|
+
# config[:enable_on_mobile] = true
|
|
24
|
+
end
|
data/lib/moderntw_confirms.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
|
4
|
+
|
|
3
5
|
require_relative "moderntw_confirms/version"
|
|
4
6
|
require_relative "moderntw_confirms/engine" if defined?(Rails)
|
|
5
7
|
|
|
@@ -11,7 +13,8 @@ module ModerntwConfirms
|
|
|
11
13
|
backdrop_class: "bg-black bg-opacity-50",
|
|
12
14
|
modal_class: "bg-white rounded-lg shadow-xl",
|
|
13
15
|
confirm_button_class: "bg-blue-500 hover:bg-blue-600 text-white font-semibold py-2 px-4 rounded",
|
|
14
|
-
cancel_button_class: "bg-gray-300 hover:bg-gray-400 text-gray-800 font-semibold py-2 px-4 rounded"
|
|
16
|
+
cancel_button_class: "bg-gray-300 hover:bg-gray-400 text-gray-800 font-semibold py-2 px-4 rounded",
|
|
17
|
+
enable_on_mobile: false
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
def self.configure
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
this.initialized = false;
|
|
10
10
|
this.initializationAttempts = 0;
|
|
11
11
|
this.maxInitAttempts = 3;
|
|
12
|
+
this.useModal = true;
|
|
13
|
+
this.enableOnMobile = false;
|
|
12
14
|
|
|
13
15
|
try {
|
|
14
16
|
this.init();
|
|
@@ -48,6 +50,13 @@
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
this.setupModalElements();
|
|
53
|
+
this.readConfiguration();
|
|
54
|
+
this.useModal = this.shouldUseModal();
|
|
55
|
+
|
|
56
|
+
if (!this.useModal) {
|
|
57
|
+
console.info('ModerntwConfirms: Using native browser confirms on mobile devices.');
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
this.interceptTurboConfirms();
|
|
52
61
|
this.setupModalHandlers();
|
|
53
62
|
this.initialized = true;
|
|
@@ -59,6 +68,8 @@
|
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
fallbackToNative() {
|
|
71
|
+
this.useModal = false;
|
|
72
|
+
|
|
62
73
|
if (window.Turbo && window.Turbo.config && window.Turbo.config.forms) {
|
|
63
74
|
Turbo.config.forms.confirm = (message) => {
|
|
64
75
|
return Promise.resolve(window.confirm(message));
|
|
@@ -213,7 +224,7 @@
|
|
|
213
224
|
}
|
|
214
225
|
|
|
215
226
|
showModal(message, callback) {
|
|
216
|
-
if (!this.modal || !this.initialized) {
|
|
227
|
+
if (!this.modal || !this.initialized || !this.useModal) {
|
|
217
228
|
const result = window.confirm(message);
|
|
218
229
|
if (callback) callback(result);
|
|
219
230
|
return;
|
|
@@ -373,6 +384,47 @@
|
|
|
373
384
|
this.modal.removeEventListener('keydown', this.tabHandler);
|
|
374
385
|
}
|
|
375
386
|
}
|
|
387
|
+
|
|
388
|
+
readConfiguration() {
|
|
389
|
+
try {
|
|
390
|
+
if (!this.modal || !this.modal.dataset) {
|
|
391
|
+
this.enableOnMobile = false;
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
this.enableOnMobile = this.modal.dataset.enableOnMobile === 'true';
|
|
396
|
+
} catch (error) {
|
|
397
|
+
console.error('ModerntwConfirms: Error reading configuration', error);
|
|
398
|
+
this.enableOnMobile = false;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
shouldUseModal() {
|
|
403
|
+
try {
|
|
404
|
+
if (this.enableOnMobile) {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return !this.isMobileDevice();
|
|
409
|
+
} catch (error) {
|
|
410
|
+
console.error('ModerntwConfirms: Error determining modal usage preference', error);
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
isMobileDevice() {
|
|
416
|
+
try {
|
|
417
|
+
const touchCapable = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0);
|
|
418
|
+
const narrowViewport = window.matchMedia ? window.matchMedia('(max-width: 768px)').matches : false;
|
|
419
|
+
const userAgent = navigator.userAgent || navigator.vendor || window.opera || '';
|
|
420
|
+
const mobileRegex = /Mobi|Android|iP(ad|hone|od)|Silk|Kindle|BlackBerry|IEMobile|Opera Mini/i;
|
|
421
|
+
|
|
422
|
+
return touchCapable && (narrowViewport || mobileRegex.test(userAgent));
|
|
423
|
+
} catch (error) {
|
|
424
|
+
console.error('ModerntwConfirms: Error detecting device type', error);
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
376
428
|
}
|
|
377
429
|
|
|
378
430
|
if (typeof window !== 'undefined') {
|
|
@@ -401,4 +453,4 @@
|
|
|
401
453
|
setTimeout(initializeOnce, 100);
|
|
402
454
|
}
|
|
403
455
|
}
|
|
404
|
-
})();
|
|
456
|
+
})();
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moderntw_confirms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robin Ciubotaru
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-10-
|
|
11
|
+
date: 2025-10-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|