phlexy_ui 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9af209a8c35542f7bce170fc57d12aad6094383f5b2d02e99356e65a2303094
4
- data.tar.gz: 66de1dc598260d76985c4167f4b6be257079b58412c0c292f0297cf9f7e6220f
3
+ metadata.gz: 2442fc77587b1b97a19ebcbd234473202f73dae6f7acfc3feedb570e57525944
4
+ data.tar.gz: b77cf08ad3f977de8fcd04f1ccb5f090a638beb36353c6b1ef2a7ac2f55c1831
5
5
  SHA512:
6
- metadata.gz: 43b1563b99263306f57a817a06717351eb50531a5bda3de368021937ad2f80afa0d7393b26639ad5f9c64e84b642404341ac4f89de502c333ad23a12cb450715
7
- data.tar.gz: 87cc196de8b27500fd6b087a0a8b75bfc7b0f27b5f9dc7a4041a817c2db0aff23abd2df33f1d231fc09cb8af226b5df87d6a5a055d2ad8fb1a2653d8ca656e1d
6
+ metadata.gz: 525b56ee4587186d2cbfdd8a5180b2975f7bd76954e852f039745ee029d8f62eec5a88688bc14e2c1f8d5b8d63dad7208477e8bee2c71c15f430d2dad8270aea
7
+ data.tar.gz: e856be656fec15626d2982824587f03b6fd61d3b13f22707b28153a6267fbfc7f59ee1fa85c5854c9679aac651d8b54398212395f110d925379f96dca1d9bda9
@@ -2,9 +2,10 @@
2
2
 
3
3
  module PhlexyUI
4
4
  class Button < Base
5
- def initialize(*, as: :button, **)
5
+ def initialize(*, as: :button, modal: nil, **)
6
6
  super(*, **)
7
7
  @as = as
8
+ @modal = modal
8
9
  end
9
10
 
10
11
  def view_template(&)
@@ -14,14 +15,54 @@ module PhlexyUI
14
15
  base_modifiers:,
15
16
  options:
16
17
  ).then do |classes|
17
- public_send(as, class: classes, **options, &)
18
+ if modal
19
+ build_button_via_unsafe_raw(classes, &)
20
+ else
21
+ public_send(as, class: classes, **options, &)
22
+ end
18
23
  end
19
24
  end
20
25
 
21
26
  private
22
27
 
28
+ attr_reader :modal
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
+
23
65
  register_modifiers(
24
- # Modifiers
25
66
  # "sm:no-animation"
26
67
  # "md:no-animation"
27
68
  # "lg:no-animation"
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhlexyUI
4
+ class Modal < Base
5
+ def initialize(*, id:, **)
6
+ super(*, **)
7
+ @id = id
8
+ end
9
+
10
+ def view_template(&)
11
+ generate_classes!(
12
+ component_html_class: :modal,
13
+ modifiers_map: modifiers,
14
+ base_modifiers:,
15
+ options:
16
+ ).then do |classes|
17
+ dialog(id:, class: classes, **options, &)
18
+ end
19
+ end
20
+
21
+ def body(*, as: :div, **options, &)
22
+ generate_classes!(
23
+ component_html_class: :"modal-box",
24
+ options:
25
+ ).then do |classes|
26
+ if base_modifiers.include?(:tap_outside_to_close)
27
+ public_send(as, class: classes, **options, &)
28
+ backdrop
29
+ else
30
+ public_send(as, class: classes, **options, &)
31
+ end
32
+ end
33
+ end
34
+
35
+ def action(*, as: :div, **options, &)
36
+ generate_classes!(
37
+ component_html_class: :"modal-action",
38
+ options:
39
+ ).then do |classes|
40
+ public_send(as, class: classes, **options, &)
41
+ end
42
+ end
43
+
44
+ def backdrop(*, **options, &)
45
+ generate_classes!(
46
+ component_html_class: :"modal-backdrop",
47
+ options:
48
+ ).then do |classes|
49
+ form method: :dialog, class: classes, **options do
50
+ button
51
+ end
52
+ end
53
+ end
54
+
55
+ def close_button(*, **, &)
56
+ form method: :dialog do
57
+ render PhlexyUI::Button.new(*, **, &)
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ register_modifiers(
64
+ # "sm:modal-open"
65
+ # "md:modal-open"
66
+ # "lg:modal-open"
67
+ open: "modal-open",
68
+ # "sm:modal-top"
69
+ # "md:modal-top"
70
+ # "lg:modal-top"
71
+ top: "modal-top",
72
+ # "sm:modal-bottom"
73
+ # "md:modal-bottom"
74
+ # "lg:modal-bottom"
75
+ bottom: "modal-bottom",
76
+ # "sm:modal-middle"
77
+ # "md:modal-middle"
78
+ # "lg:modal-middle"
79
+ middle: "modal-middle"
80
+ )
81
+ end
82
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexyUI
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  end
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.7
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-26 00:00:00.000000000 Z
11
+ date: 2024-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -113,6 +113,7 @@ files:
113
113
  - lib/phlexy_ui/mask.rb
114
114
  - lib/phlexy_ui/menu.rb
115
115
  - lib/phlexy_ui/menu_item.rb
116
+ - lib/phlexy_ui/modal.rb
116
117
  - lib/phlexy_ui/navbar.rb
117
118
  - lib/phlexy_ui/sub_menu.rb
118
119
  - lib/phlexy_ui/tab.rb