phlexy_ui 0.1.8 → 0.1.9
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/lib/phlexy_ui/button.rb +38 -45
- data/lib/phlexy_ui/version.rb +1 -1
- 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: 2442fc77587b1b97a19ebcbd234473202f73dae6f7acfc3feedb570e57525944
|
4
|
+
data.tar.gz: b77cf08ad3f977de8fcd04f1ccb5f090a638beb36353c6b1ef2a7ac2f55c1831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 525b56ee4587186d2cbfdd8a5180b2975f7bd76954e852f039745ee029d8f62eec5a88688bc14e2c1f8d5b8d63dad7208477e8bee2c71c15f430d2dad8270aea
|
7
|
+
data.tar.gz: e856be656fec15626d2982824587f03b6fd61d3b13f22707b28153a6267fbfc7f59ee1fa85c5854c9679aac651d8b54398212395f110d925379f96dca1d9bda9
|
data/lib/phlexy_ui/button.rb
CHANGED
@@ -16,52 +16,10 @@ module PhlexyUI
|
|
16
16
|
options:
|
17
17
|
).then do |classes|
|
18
18
|
if modal
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
# onclick: "#{modal}.showModal()"
|
24
|
-
#
|
25
|
-
# However, currently, Phlex does not allow you to use the "onclick"
|
26
|
-
# attribute.
|
27
|
-
#
|
28
|
-
# Once Phlex 2.0 is released, it will add a #safe method
|
29
|
-
# that will allow us to replace this with a single line:
|
30
|
-
#
|
31
|
-
# onclick: safe("#{modal}.showModal()")
|
32
|
-
#
|
33
|
-
# For now, at least this only runs once and uses event delegation
|
34
|
-
# so that it only adds a single event listener to the document.body.
|
35
|
-
#
|
36
|
-
# The downside is a bigger HTML payload.
|
37
|
-
options[:data] ||= {}
|
38
|
-
options[:data][:modal] = modal
|
39
|
-
script do
|
40
|
-
unsafe_raw <<~JS
|
41
|
-
// Will be replaced with a single line on the <button> once Phlex 2.0 is released.
|
42
|
-
(() => {
|
43
|
-
if (window.PhlexyUI && window.PhlexyUI.modalInitialized) {
|
44
|
-
return;
|
45
|
-
}
|
46
|
-
|
47
|
-
document.body.addEventListener("click", (event) => {
|
48
|
-
if (event.target.tagName === 'BUTTON' &&
|
49
|
-
event.target.dataset.modal) {
|
50
|
-
const modal = document.getElementById(event.target.dataset.modal);
|
51
|
-
if (modal) {
|
52
|
-
modal.showModal();
|
53
|
-
}
|
54
|
-
}
|
55
|
-
});
|
56
|
-
|
57
|
-
if (!window.PhlexyUI) window.PhlexyUI = {};
|
58
|
-
window.PhlexyUI.modalInitialized = true;
|
59
|
-
})();
|
60
|
-
JS
|
61
|
-
end
|
19
|
+
build_button_via_unsafe_raw(classes, &)
|
20
|
+
else
|
21
|
+
public_send(as, class: classes, **options, &)
|
62
22
|
end
|
63
|
-
|
64
|
-
public_send(as, class: classes, **options, &)
|
65
23
|
end
|
66
24
|
end
|
67
25
|
|
@@ -69,6 +27,41 @@ module PhlexyUI
|
|
69
27
|
|
70
28
|
attr_reader :modal
|
71
29
|
|
30
|
+
# TODO: Remove this once Phlex 2.0 is released.
|
31
|
+
#
|
32
|
+
# The cleanest way to do this is with a single:
|
33
|
+
#
|
34
|
+
# onclick: "#{Phlex::Escape.html_escape(modal)}.showModal()"
|
35
|
+
#
|
36
|
+
# However, currently, Phlex does not allow you to use the "onclick"
|
37
|
+
# attribute.
|
38
|
+
#
|
39
|
+
# Once Phlex 2.0 is released, it will add a #safe method
|
40
|
+
# that will allow us to replace this with a single line:
|
41
|
+
#
|
42
|
+
# onclick: safe("#{Phlex::Escape.html_escape(modal)}.showModal()")
|
43
|
+
def build_button_via_unsafe_raw(classes, &)
|
44
|
+
classes = Phlex::Escape.html_escape(classes.join(" "))
|
45
|
+
@options = options
|
46
|
+
.merge(onclick: "#{modal}.showModal()")
|
47
|
+
.reduce("") do |acc, (k, v)|
|
48
|
+
if k == :data
|
49
|
+
v.each do |k, v|
|
50
|
+
k = Phlex::Escape.html_escape(k)
|
51
|
+
v = Phlex::Escape.html_escape(v)
|
52
|
+
acc += " data-#{k}=\"#{v}\""
|
53
|
+
end
|
54
|
+
acc
|
55
|
+
else
|
56
|
+
k = Phlex::Escape.html_escape(k)
|
57
|
+
v = Phlex::Escape.html_escape(v)
|
58
|
+
"#{acc} #{k}=\"#{v}\""
|
59
|
+
end
|
60
|
+
end.strip
|
61
|
+
|
62
|
+
unsafe_raw %(<button class="#{classes}" #{options}>#{capture(&)}</button>)
|
63
|
+
end
|
64
|
+
|
72
65
|
register_modifiers(
|
73
66
|
# "sm:no-animation"
|
74
67
|
# "md:no-animation"
|
data/lib/phlexy_ui/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlexy_ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Alejandro Aguilar Ramos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|