fluxbit_view_components 0.3.0 → 0.4.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.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/app/assets/javascripts/fluxbit_view_components/assigner_controller.js +49 -0
  4. data/app/assets/javascripts/fluxbit_view_components/auto_submit_controller.js +39 -0
  5. data/app/assets/javascripts/fluxbit_view_components/drawer_controller.js +135 -0
  6. data/app/assets/javascripts/fluxbit_view_components/index.js +56 -0
  7. data/app/assets/javascripts/fluxbit_view_components/method_link_controller.js +143 -0
  8. data/app/assets/javascripts/fluxbit_view_components/modal_controller.js +118 -0
  9. data/app/assets/javascripts/fluxbit_view_components/password_controller.js +170 -0
  10. data/app/assets/javascripts/fluxbit_view_components/progress_controller.js +374 -0
  11. data/app/assets/javascripts/fluxbit_view_components/row_click_controller.js +32 -0
  12. data/app/assets/javascripts/fluxbit_view_components/select_all_controller.js +122 -0
  13. data/app/assets/javascripts/fluxbit_view_components/spinner_percent_controller.js +174 -0
  14. data/app/assets/javascripts/fluxbit_view_components/theme_button_controller.js +90 -0
  15. data/app/assets/javascripts/fluxbit_view_components.js +1175 -0
  16. data/app/components/fluxbit/accordion_component.rb +125 -0
  17. data/app/components/fluxbit/alert_component.rb +8 -8
  18. data/app/components/fluxbit/avatar_component.rb +11 -12
  19. data/app/components/fluxbit/avatar_group_component.rb +1 -1
  20. data/app/components/fluxbit/badge_component.rb +8 -7
  21. data/app/components/fluxbit/banner_component.rb +139 -0
  22. data/app/components/fluxbit/bottom_navigation_component.rb +437 -0
  23. data/app/components/fluxbit/breadcrumb_component.rb +66 -0
  24. data/app/components/fluxbit/button_component.rb +39 -11
  25. data/app/components/fluxbit/button_group_component.rb +1 -1
  26. data/app/components/fluxbit/card_component.rb +26 -23
  27. data/app/components/fluxbit/carousel_component.rb +154 -0
  28. data/app/components/fluxbit/component.rb +24 -3
  29. data/app/components/fluxbit/drawer_component.html.erb +30 -0
  30. data/app/components/fluxbit/drawer_component.rb +125 -0
  31. data/app/components/fluxbit/dropdown_component.rb +41 -0
  32. data/app/components/fluxbit/dropdown_item_component.rb +68 -0
  33. data/app/components/fluxbit/flex_component.rb +1 -1
  34. data/app/components/fluxbit/form/component.rb +15 -8
  35. data/app/components/fluxbit/form/dropzone_component.rb +3 -3
  36. data/app/components/fluxbit/form/field_component.rb +4 -2
  37. data/app/components/fluxbit/form/help_text_component.rb +1 -1
  38. data/app/components/fluxbit/form/label_component.rb +10 -3
  39. data/app/components/fluxbit/form/password_component.rb +247 -0
  40. data/app/components/fluxbit/form/radio_group_button_component.rb +126 -0
  41. data/app/components/fluxbit/form/select_component.rb +108 -11
  42. data/app/components/fluxbit/form/text_field_component.rb +40 -23
  43. data/app/components/fluxbit/form/toggle_component.rb +2 -2
  44. data/app/components/fluxbit/form/upload_image_component.html.erb +3 -3
  45. data/app/components/fluxbit/form/upload_image_component.rb +12 -1
  46. data/app/components/fluxbit/gravatar_component.rb +7 -0
  47. data/app/components/fluxbit/icon_helpers.rb +167 -0
  48. data/app/components/fluxbit/link_component.rb +42 -0
  49. data/app/components/fluxbit/modal_component.rb +28 -31
  50. data/app/components/fluxbit/pagination_component.rb +206 -0
  51. data/app/components/fluxbit/popover_component.rb +14 -14
  52. data/app/components/fluxbit/progress_component.rb +196 -0
  53. data/app/components/fluxbit/skeleton_component.rb +237 -0
  54. data/app/components/fluxbit/speed_dial_action_component.html.erb +30 -0
  55. data/app/components/fluxbit/speed_dial_action_component.rb +59 -0
  56. data/app/components/fluxbit/speed_dial_component.html.erb +33 -0
  57. data/app/components/fluxbit/speed_dial_component.rb +73 -0
  58. data/app/components/fluxbit/spinner_component.rb +71 -0
  59. data/app/components/fluxbit/spinner_percent_component.rb +174 -0
  60. data/app/components/fluxbit/stepper_component.rb +223 -0
  61. data/app/components/fluxbit/tab_component.rb +44 -25
  62. data/app/components/fluxbit/table_component.rb +186 -0
  63. data/app/components/fluxbit/table_group_component.rb +28 -0
  64. data/app/components/fluxbit/theme_button_component.rb +64 -0
  65. data/app/components/fluxbit/timeline_component.rb +63 -0
  66. data/app/components/fluxbit/timeline_item_component.html.erb +64 -0
  67. data/app/components/fluxbit/timeline_item_component.rb +78 -0
  68. data/app/components/fluxbit/tooltip_component.rb +2 -2
  69. data/app/helpers/fluxbit/components_helper.rb +74 -4
  70. data/app/helpers/fluxbit/form_builder.rb +64 -15
  71. data/app/helpers/fluxbit/view_helper.rb +71 -0
  72. data/config/locales/en.yml +37 -4
  73. data/config/locales/pt-BR.yml +36 -0
  74. data/lib/fluxbit/config/accordion_component.rb +73 -0
  75. data/lib/fluxbit/config/avatar_component.rb +11 -11
  76. data/lib/fluxbit/config/badge_component.rb +14 -11
  77. data/lib/fluxbit/config/banner_component.rb +60 -0
  78. data/lib/fluxbit/config/bottom_navigation_component.rb +74 -0
  79. data/lib/fluxbit/config/breadcrumb_component.rb +24 -0
  80. data/lib/fluxbit/config/button_component.rb +6 -4
  81. data/lib/fluxbit/config/card_component.rb +23 -12
  82. data/lib/fluxbit/config/carousel_component.rb +33 -0
  83. data/lib/fluxbit/config/drawer_component.rb +48 -0
  84. data/lib/fluxbit/config/dropdown_component.rb +29 -0
  85. data/lib/fluxbit/config/form/check_box_component.rb +1 -1
  86. data/lib/fluxbit/config/form/dropzone_component.rb +1 -1
  87. data/lib/fluxbit/config/form/help_text_component.rb +1 -1
  88. data/lib/fluxbit/config/form/label_component.rb +3 -2
  89. data/lib/fluxbit/config/form/password_component.rb +19 -0
  90. data/lib/fluxbit/config/form/radio_group_button_component.rb +24 -0
  91. data/lib/fluxbit/config/form/text_field_component.rb +11 -11
  92. data/lib/fluxbit/config/form/toggle_component.rb +5 -5
  93. data/lib/fluxbit/config/link_component.rb +24 -0
  94. data/lib/fluxbit/config/modal_component.rb +1 -1
  95. data/lib/fluxbit/config/pagination_component.rb +31 -0
  96. data/lib/fluxbit/config/popover_component.rb +1 -1
  97. data/lib/fluxbit/config/progress_component.rb +63 -0
  98. data/lib/fluxbit/config/skeleton_component.rb +82 -0
  99. data/lib/fluxbit/config/speed_dial_component.rb +50 -0
  100. data/lib/fluxbit/config/spinner_component.rb +30 -0
  101. data/lib/fluxbit/config/spinner_percent_component.rb +61 -0
  102. data/lib/fluxbit/config/stepper_component.rb +299 -0
  103. data/lib/fluxbit/config/tab_component.rb +6 -0
  104. data/lib/fluxbit/config/table_component.rb +75 -0
  105. data/lib/fluxbit/config/theme_button_component.rb +19 -0
  106. data/lib/fluxbit/config/timeline_component.rb +77 -0
  107. data/lib/fluxbit/view_components/engine.rb +11 -3
  108. data/lib/fluxbit/view_components/version.rb +1 -1
  109. data/lib/fluxbit/view_components.rb +20 -0
  110. data/lib/generators/fluxbit/devise_views_generator.rb +116 -0
  111. data/lib/generators/fluxbit/pagy_generator.rb +39 -0
  112. data/lib/generators/fluxbit/scaffold_generator.rb +165 -0
  113. data/lib/generators/fluxbit/templates/_alert.html.erb.tt +1 -0
  114. data/lib/generators/fluxbit/templates/_flash.html.erb.tt +15 -0
  115. data/lib/generators/fluxbit/templates/_form.html.erb.tt +38 -0
  116. data/lib/generators/fluxbit/templates/_metadata.html.erb.tt +44 -0
  117. data/lib/generators/fluxbit/templates/controller.rb.tt +406 -0
  118. data/lib/generators/fluxbit/templates/create.turbo_stream.erb.tt +7 -0
  119. data/lib/generators/fluxbit/templates/destroy.turbo_stream.erb.tt +3 -0
  120. data/lib/generators/fluxbit/templates/destroy_all.turbo_stream.erb.tt +9 -0
  121. data/lib/generators/fluxbit/templates/devise_views/confirmations/new.html.erb +11 -0
  122. data/lib/generators/fluxbit/templates/devise_views/layouts/devise.html.erb +64 -0
  123. data/lib/generators/fluxbit/templates/devise_views/mailer/confirmation_instructions.html.erb +5 -0
  124. data/lib/generators/fluxbit/templates/devise_views/mailer/email_changed.html.erb +7 -0
  125. data/lib/generators/fluxbit/templates/devise_views/mailer/password_changed.html.erb +3 -0
  126. data/lib/generators/fluxbit/templates/devise_views/mailer/reset_password_instructions.html.erb +8 -0
  127. data/lib/generators/fluxbit/templates/devise_views/mailer/unlock_instructions.html.erb +7 -0
  128. data/lib/generators/fluxbit/templates/devise_views/passwords/edit.html.erb +29 -0
  129. data/lib/generators/fluxbit/templates/devise_views/passwords/new.html.erb +11 -0
  130. data/lib/generators/fluxbit/templates/devise_views/registrations/edit.html.erb +43 -0
  131. data/lib/generators/fluxbit/templates/devise_views/registrations/new.html.erb +34 -0
  132. data/lib/generators/fluxbit/templates/devise_views/sessions/new.html.erb +15 -0
  133. data/lib/generators/fluxbit/templates/devise_views/shared/_error_messages.html.erb +14 -0
  134. data/lib/generators/fluxbit/templates/devise_views/shared/_links.html.erb +25 -0
  135. data/lib/generators/fluxbit/templates/devise_views/unlocks/new.html.erb +11 -0
  136. data/lib/generators/fluxbit/templates/edit.html.erb.tt +47 -0
  137. data/lib/generators/fluxbit/templates/fluxbit_pagy.css +27 -0
  138. data/lib/generators/fluxbit/templates/i18n.en.yml.tt +121 -0
  139. data/lib/generators/fluxbit/templates/i18n.pt-BR.yml.tt +121 -0
  140. data/lib/generators/fluxbit/templates/index.html.erb.tt +254 -0
  141. data/lib/generators/fluxbit/templates/index.json.jbuilder.tt +33 -0
  142. data/lib/generators/fluxbit/templates/new.html.erb.tt +47 -0
  143. data/lib/generators/fluxbit/templates/partial.html.erb.tt +61 -0
  144. data/lib/generators/fluxbit/templates/policy.rb.tt +36 -0
  145. data/lib/generators/fluxbit/templates/send_alert_via_drawer.erb.tt +10 -0
  146. data/lib/generators/fluxbit/templates/show.html.erb.tt +44 -0
  147. data/lib/generators/fluxbit/templates/show.json.jbuilder.tt +6 -0
  148. data/lib/generators/fluxbit/templates/update.turbo_stream.erb.tt +10 -0
  149. data/lib/generators/fluxbit/templates/update_all.turbo_stream.erb.tt +20 -0
  150. data/lib/install/install.rb +58 -0
  151. metadata +107 -18
  152. data/app/helpers/fluxbit/classes_helper.rb +0 -9
@@ -0,0 +1,237 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # The `Fluxbit::SkeletonComponent` is a customizable skeleton loading component that extends `Fluxbit::Component`.
5
+ # It provides animated placeholders for content that is loading, supporting various types like text, images, cards,
6
+ # avatars, and more complex layouts.
7
+ #
8
+ # @example Basic usage
9
+ # = fx_skeleton
10
+ # = fx_skeleton(variant: :image)
11
+ # = fx_skeleton(variant: :card)
12
+ #
13
+ # @see docs/02_Components/Skeleton.md For detailed documentation.
14
+ class Fluxbit::SkeletonComponent < Fluxbit::Component
15
+ include Fluxbit::Config::SkeletonComponent
16
+
17
+ ##
18
+ # Initializes the skeleton component with the given properties.
19
+ #
20
+ # @param [Hash] **props The properties to customize the skeleton.
21
+ # @option props [Symbol] :variant (:default) The type of skeleton (:default, :text, :image, :video, :avatar, :card, :widget, :list, :testimonial, :button).
22
+ # @option props [Boolean] :animation (true) Whether to show the pulse animation.
23
+ # @option props [Integer] :rows (3) Number of text rows for default/text variants.
24
+ # @option props [Symbol] :size (:medium) Size for avatar, image, and video variants (:small, :medium, :large).
25
+ # @option props [Integer] :lines (nil) Number of lines for text-based variants.
26
+ # @option props [String] :remove_class ('') CSS classes to remove from the default class list.
27
+ # @option props [Hash] **props Remaining options declared as HTML attributes.
28
+ #
29
+ # @return [Fluxbit::SkeletonComponent]
30
+ def initialize(**props)
31
+ super
32
+ @props = props
33
+
34
+ @variant = options(@props.delete(:variant),
35
+ collection: [ :default, :text, :image, :video, :avatar, :card, :widget, :list, :testimonial, :button ],
36
+ default: @@variant)
37
+ @animation = options(@props.delete(:animation), default: @@animation)
38
+ @rows = options(@props.delete(:rows), default: @@rows).to_i
39
+ @size = options(@props.delete(:size), collection: [ :small, :medium, :large ], default: :medium)
40
+ @lines = @props.delete(:lines)&.to_i
41
+
42
+ declare_classes
43
+ @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
44
+ @props[:role] = "status"
45
+ @props["aria-label"] = "Loading"
46
+ end
47
+
48
+ def call
49
+ tag.div(**@props) do
50
+ case @variant
51
+ when :default, :text
52
+ render_text_skeleton
53
+ when :image
54
+ render_image_skeleton
55
+ when :video
56
+ render_video_skeleton
57
+ when :avatar
58
+ render_avatar_skeleton
59
+ when :card
60
+ render_card_skeleton
61
+ when :widget
62
+ render_widget_skeleton
63
+ when :list
64
+ render_list_skeleton
65
+ when :testimonial
66
+ render_testimonial_skeleton
67
+ when :button
68
+ render_button_skeleton
69
+ end
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def declare_classes
76
+ base_classes = []
77
+ base_classes << styles[:base] if @animation
78
+ base_classes << styles[:container]
79
+
80
+ add(class: base_classes.join(" "), to: @props, first_element: true)
81
+ end
82
+
83
+ def render_text_skeleton
84
+ lines_count = @lines || @rows
85
+ content = []
86
+
87
+ lines_count.times do |index|
88
+ width_class = case index
89
+ when 0 then styles[:widths][:first_line]
90
+ when lines_count - 1 then styles[:widths][:last_line]
91
+ else styles[:widths][:full]
92
+ end
93
+
94
+ content << tag.div(class: "#{styles[:text][:line]} #{width_class} #{styles[:spacing][:small]}")
95
+ end
96
+
97
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
98
+ safe_join(content)
99
+ end
100
+
101
+ def render_image_skeleton
102
+ content = []
103
+ content << tag.div(class: "#{styles[:image][:container]} #{styles[:image][@size]}") do
104
+ concat(
105
+ tag.svg(class: styles[:image][:icon],
106
+ "aria-hidden": "true",
107
+ xmlns: "http://www.w3.org/2000/svg",
108
+ fill: "currentColor",
109
+ viewBox: "0 0 20 18") do
110
+ concat(
111
+ tag.path(d: "M18 0H2a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2Zm-5.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3Zm4.376 10.481A1 1 0 0 1 16 15H4a1 1 0 0 1-.895-1.447l3.5-7A1 1 0 0 1 7.468 6a.965.965 0 0 1 .9.5l2.775 4.757 1.546-1.887a1 1 0 0 1 1.618.1l2.541 4a1 1 0 0 1 .028 1.011Z")
112
+ )
113
+ end
114
+ )
115
+ end
116
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
117
+ safe_join(content)
118
+ end
119
+
120
+ def render_video_skeleton
121
+ content = []
122
+ content << tag.div(class: "#{styles[:video][:container]} #{styles[:video][@size]}") do
123
+ concat(
124
+ tag.svg(class: styles[:video][:icon],
125
+ "aria-hidden": "true",
126
+ xmlns: "http://www.w3.org/2000/svg",
127
+ fill: "currentColor",
128
+ viewBox: "0 0 16 20") do
129
+ concat(
130
+ tag.path(d: "M5 5V.13a2.96 2.96 0 0 0-1.293.749L.879 3.707A2.98 2.98 0 0 0 .13 5H5Z")
131
+ )
132
+ concat(
133
+ tag.path(d: "M14.066 0H7v5a2 2 0 0 1-2 2H0v11a1.97 1.97 0 0 0 1.934 2h12.132A1.97 1.97 0 0 0 16 18V2a1.97 1.97 0 0 0-1.934-2ZM9 13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2Zm4 .382a1 1 0 0 1-1.447.894L10 13v-2l1.553-1.276a1 1 0 0 1 1.447.894v2.764Z")
134
+ )
135
+ end
136
+ )
137
+ end
138
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
139
+ safe_join(content)
140
+ end
141
+
142
+ def render_avatar_skeleton
143
+ content = []
144
+ content << tag.div(class: styles[:avatar][@size])
145
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
146
+ safe_join(content)
147
+ end
148
+
149
+ def render_card_skeleton
150
+ tag.div(class: styles[:card][:container]) do
151
+ content = []
152
+ content << tag.div(class: "#{styles[:card][:header]} #{styles[:spacing][:medium]} #{styles[:widths][:card_header]}")
153
+
154
+ lines_count = @lines || @rows
155
+ lines_count.times do |index|
156
+ width_class = index == lines_count - 1 ? styles[:widths][:last_line] : styles[:widths][:full]
157
+ spacing_class = index < lines_count - 1 ? styles[:spacing][:small] : ""
158
+ content << tag.div(class: "#{styles[:card][:body]} #{spacing_class} #{width_class}")
159
+ end
160
+
161
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
162
+ safe_join(content)
163
+ end
164
+ end
165
+
166
+ def render_widget_skeleton
167
+ tag.div(class: styles[:widget][:container]) do
168
+ content = []
169
+ content << tag.div(class: "#{styles[:widget][:title]} #{styles[:widths][:widget_title]}")
170
+
171
+ lines_count = @lines || @rows
172
+ lines_count.times do |index|
173
+ width_class = index == lines_count - 1 ? styles[:widths][:last_line] : styles[:widths][:full]
174
+ spacing_class = index < lines_count - 1 ? styles[:spacing][:small] : ""
175
+ content << tag.div(class: "#{styles[:widget][:content]} #{spacing_class} #{width_class}")
176
+ end
177
+
178
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
179
+ safe_join(content)
180
+ end
181
+ end
182
+
183
+ def render_list_skeleton
184
+ tag.div(class: styles[:list][:container]) do
185
+ content = []
186
+
187
+ lines_count = @lines || @rows
188
+ lines_count.times do
189
+ content << tag.div(class: styles[:list][:item]) do
190
+ concat(tag.div(class: styles[:list][:avatar]))
191
+ concat(
192
+ tag.div(class: styles[:list][:content]) do
193
+ concat(tag.div(class: "#{styles[:text][:line]} #{styles[:widths][:list_name]} #{styles[:spacing][:small]}"))
194
+ concat(tag.div(class: "#{styles[:text][:small]} #{styles[:widths][:list_content]}"))
195
+ end
196
+ )
197
+ end
198
+ end
199
+
200
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
201
+ safe_join(content)
202
+ end
203
+ end
204
+
205
+ def render_testimonial_skeleton
206
+ tag.div(class: styles[:testimonial][:container]) do
207
+ content = []
208
+
209
+ lines_count = @lines || @rows
210
+ lines_count.times do |index|
211
+ width = index == lines_count - 1 ? styles[:widths][:testimonial_last] : styles[:widths][:full]
212
+ spacing_class = index < lines_count - 1 ? styles[:spacing][:small] : ""
213
+ content << tag.div(class: "#{styles[:testimonial][:quote]} #{width} #{spacing_class}")
214
+ end
215
+
216
+ content << tag.div(class: styles[:testimonial][:author]) do
217
+ concat(tag.div(class: styles[:testimonial][:avatar]))
218
+ concat(
219
+ tag.div do
220
+ concat(tag.div(class: "#{styles[:text][:line]} #{styles[:widths][:testimonial_name]} #{styles[:spacing][:small]}"))
221
+ concat(tag.div(class: "#{styles[:text][:small]} #{styles[:widths][:testimonial_title]}"))
222
+ end
223
+ )
224
+ end
225
+
226
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
227
+ safe_join(content)
228
+ end
229
+ end
230
+
231
+ def render_button_skeleton
232
+ content = []
233
+ content << tag.div(class: styles[:button])
234
+ content << tag.span(t("fluxbit.skeleton.loading"), class: styles[:screen_reader])
235
+ safe_join(content)
236
+ end
237
+ end
@@ -0,0 +1,30 @@
1
+ <% if @text_outside && @text %>
2
+ <div class="<%= styles[:action][:text][:base] %>">
3
+ <span class="<%= text_classes %>"><%= @text %></span>
4
+ <% if @href %>
5
+ <%= link_to(@href, **@props) do %>
6
+ <%= icon @icon, class: icon_classes if @icon %>
7
+ <%= content if content.present? %>
8
+ <% end %>
9
+ <% else %>
10
+ <%= tag.button(**@props) do %>
11
+ <%= icon @icon, class: icon_classes if @icon %>
12
+ <%= content if content.present? %>
13
+ <% end %>
14
+ <% end %>
15
+ </div>
16
+ <% else %>
17
+ <% if @href %>
18
+ <%= link_to(@href, **@props) do %>
19
+ <%= icon @icon, class: icon_classes if @icon %>
20
+ <%= content if content.present? %>
21
+ <% end %>
22
+ <% else %>
23
+ <%= tag.button(**@props) do %>
24
+ <%= icon @icon, class: icon_classes if @icon %>
25
+ <%= content if content.present? %>
26
+ <% end %>
27
+ <% end %>
28
+ <% end %>
29
+
30
+ <%= render_popover_or_tooltip %>
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The `Fluxbit::SpeedDialActionComponent` is a component for rendering individual action items in a Speed Dial.
4
+ class Fluxbit::SpeedDialActionComponent < Fluxbit::Component
5
+ include Fluxbit::Config::SpeedDialComponent
6
+
7
+ # Initializes the SpeedDialAction component.
8
+ #
9
+ # @param [Hash] **props The properties to customize the speed dial action.
10
+ # @option props [String, Symbol] :icon (nil) The icon to display in the action button.
11
+ # @option props [String] :text (nil) The text label for the action.
12
+ # @option props [String] :tooltip (nil) The tooltip text (defaults to text if not provided).
13
+ # @option props [String] :href (nil) The URL to link to (creates an anchor tag instead of button).
14
+ # @option props [Boolean] :text_outside (false) Whether to display text outside the button.
15
+ # @option props [Boolean] :square (false) Whether to use square shape instead of rounded.
16
+ # @option props [Symbol] :tooltip_placement (:left) Tooltip placement.
17
+ # @option props [String] :remove_class ('') CSS classes to remove from the default class list.
18
+ # @option props [Hash] **props Remaining options declared as HTML attributes.
19
+ #
20
+ # @return [Fluxbit::SpeedDialActionComponent]
21
+ def initialize(**props)
22
+ super(**props.slice(:tooltip_text, :tooltip_placement, :tooltip_trigger))
23
+ @props = props
24
+
25
+ @icon = @props.delete(:icon)
26
+ @text = @props.delete(:text)
27
+ @tooltip = @props.delete(:tooltip) || @text
28
+ @href = @props.delete(:href)
29
+ @text_outside = options @props.delete(:text_outside), default: false
30
+ @square = options @props.delete(:square), default: false
31
+ @tooltip_placement = options @props.delete(:tooltip_placement), default: :left
32
+ @props[:id] ||= "speed-dial-action-#{random_id}"
33
+
34
+ # Set tooltip via parent component if provided
35
+ @tooltip_text = @tooltip if @tooltip.present?
36
+
37
+ add class: [
38
+ styles[:action][:base],
39
+ @square ? styles[:action][:shapes][:square] : styles[:action][:shapes][:rounded]
40
+ ], to: @props
41
+ @props[:type] ||= "button" unless @href
42
+
43
+ remove_class_from_props(@props)
44
+ end
45
+
46
+ def before_render
47
+ add_popover_or_tooltip
48
+ end
49
+
50
+ private
51
+
52
+ def icon_classes
53
+ styles[:action][:icon]
54
+ end
55
+
56
+ def text_classes
57
+ styles[:action][:text][:outside]
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ <div <%= tag.attributes(**@props) %> data-dial-init>
2
+ <% if top_position? %>
3
+ <button type="button" data-dial-toggle="<%= menu_id %>" aria-controls="<%= menu_id %>" aria-expanded="false" class="<%= classes trigger_classes %>">
4
+ <% if @trigger_icon.nil? %>
5
+ <%= plus_icon(class: styles[:trigger][:icon]) %>
6
+ <% else %>
7
+ <%= icon @trigger_icon, class: styles[:trigger][:icon] %>
8
+ <% end %>
9
+ <span class="<%= styles[:screen_reader] %>"><%= t("fluxbit.speed_dial.open_actions_menu") %></span>
10
+ </button>
11
+
12
+ <div id="<%= menu_id %>" class="<%= classes menu_classes %>">
13
+ <% actions.each do |action| %>
14
+ <%= action %>
15
+ <% end %>
16
+ </div>
17
+ <% else %>
18
+ <div id="<%= menu_id %>" class="<%= classes menu_classes %>">
19
+ <% actions.each do |action| %>
20
+ <%= action %>
21
+ <% end %>
22
+ </div>
23
+
24
+ <button type="button" data-dial-toggle="<%= menu_id %>" aria-controls="<%= menu_id %>" aria-expanded="false" class="<%= classes trigger_classes %>">
25
+ <% if @trigger_icon.nil? %>
26
+ <%= plus_icon(class: styles[:trigger][:icon]) %>
27
+ <% else %>
28
+ <%= icon @trigger_icon, class: styles[:trigger][:icon] %>
29
+ <% end %>
30
+ <span class="<%= styles[:screen_reader] %>"><%= t("fluxbit.speed_dial.open_actions_menu") %></span>
31
+ </button>
32
+ <% end %>
33
+ </div>
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The `Fluxbit::SpeedDialComponent` is a component for rendering customizable Speed Dial floating action buttons.
4
+ class Fluxbit::SpeedDialComponent < Fluxbit::Component
5
+ include Fluxbit::Config::SpeedDialComponent
6
+
7
+ # Slot for speed dial action items
8
+ renders_many :actions, lambda { |**props|
9
+ Fluxbit::SpeedDialActionComponent.new(
10
+ text_outside: @text_outside,
11
+ square: @square,
12
+ **props
13
+ )
14
+ }
15
+
16
+ # Initializes the SpeedDial component with various customization options.
17
+ #
18
+ # @param [Hash] **props The properties to customize the speed dial.
19
+ # @option props [Symbol] :position (:bottom_right) The position of the speed dial (:top_left, :top_right, :bottom_left, :bottom_right).
20
+ # @option props [Boolean] :square (false) Whether to use square shape instead of rounded.
21
+ # @option props [Boolean] :text_outside (false) Whether to display text outside action buttons.
22
+ # @option props [String, Symbol] :trigger_icon The icon for the trigger button.
23
+ # @option props [String] :remove_class ('') CSS classes to remove from the default class list.
24
+ # @option props [Hash] **props Remaining options declared as HTML attributes.
25
+ #
26
+ # @return [Fluxbit::SpeedDialComponent]
27
+ def initialize(**props)
28
+ super
29
+ @props = props
30
+
31
+ @position = options @props.delete(:position), collection: styles[:positions].keys, default: @@position
32
+ @square = options @props.delete(:square), default: @@square
33
+ @text_outside = options @props.delete(:text_outside), default: @@text_outside
34
+ @trigger_icon = @props.delete(:trigger_icon)
35
+ @props[:id] ||= "speed-dial-#{random_id}"
36
+
37
+ add class: [
38
+ styles[:base],
39
+ styles[:positions][@position]
40
+ ], to: @props
41
+
42
+ remove_class_from_props(@props)
43
+ end
44
+
45
+ private
46
+
47
+ def classes(class_array)
48
+ class_array.compact.join(" ")
49
+ end
50
+
51
+ def menu_id
52
+ "#{@props[:id]}-menu"
53
+ end
54
+
55
+ def trigger_classes
56
+ [
57
+ styles[:trigger][:base],
58
+ @square ? styles[:trigger][:shapes][:square] : styles[:trigger][:shapes][:rounded]
59
+ ]
60
+ end
61
+
62
+ def top_position?
63
+ @position.in?([ :top_left, :top_right ])
64
+ end
65
+
66
+ def menu_classes
67
+ [
68
+ styles[:menu][:base],
69
+ styles[:menu][:hidden],
70
+ top_position? ? styles[:menu][:spacing][:top] : styles[:menu][:spacing][:bottom]
71
+ ]
72
+ end
73
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The `Fluxbit::SpinnerComponent` is a component for rendering loading spinners.
4
+ class Fluxbit::SpinnerComponent < Fluxbit::Component
5
+ include Fluxbit::Config::SpinnerComponent
6
+
7
+ # Initializes the Spinner component with various customization options.
8
+ #
9
+ # @param [Hash] **props The properties to customize the spinner.
10
+ # @option props [Symbol] :color (:default) The color theme of the spinner (:default, :info, :success, :failure, :warning, :pink, :purple).
11
+ # @option props [Integer] :size (1) The size of the spinner (0 to 4).
12
+ # @option props [String] :label ('Loading...') The aria-label for accessibility.
13
+ # @option props [String] :remove_class ('') CSS classes to remove from the default class list.
14
+ # @option props [Hash] **props Remaining options declared as HTML attributes.
15
+ #
16
+ # @return [Fluxbit::SpinnerComponent]
17
+ def initialize(**props)
18
+ super
19
+ @props = props
20
+
21
+ @color = options @props.delete(:color), collection: styles[:colors].keys, default: @@color
22
+ @size = options @props.delete(:size), collection: (0..styles[:sizes].size - 1).to_a, default: @@size
23
+ @label = @props.delete(:label) || @@label
24
+
25
+ add class: [
26
+ styles[:base],
27
+ styles[:sizes][@size.to_i],
28
+ styles[:colors][@color]
29
+ ], to: @props
30
+
31
+ # Add accessibility attributes
32
+ @props[:role] = "status"
33
+ @props[:"aria-label"] = @label
34
+
35
+ remove_class_from_props(@props)
36
+ end
37
+
38
+ def call
39
+ tag.svg(**@props, viewBox: "0 0 100 101", fill: "none", xmlns: "http://www.w3.org/2000/svg") do
40
+ concat(
41
+ tag.path(
42
+ d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
43
+ fill: "currentColor"
44
+ )
45
+ )
46
+ concat(
47
+ tag.path(
48
+ d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
49
+ fill: "currentFill"
50
+ )
51
+ )
52
+ concat(
53
+ tag.span(@label, class: screen_reader_classes)
54
+ )
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def spinner_classes
61
+ [
62
+ styles[:base],
63
+ styles[:sizes][@size.to_i],
64
+ styles[:colors][@color]
65
+ ].compact.join(" ")
66
+ end
67
+
68
+ def screen_reader_classes
69
+ styles[:screen_reader]
70
+ end
71
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The `Fluxbit::SpinnerPercentComponent` is a component for rendering progress spinners with percentage display.
4
+ class Fluxbit::SpinnerPercentComponent < Fluxbit::Component
5
+ include Fluxbit::Config::SpinnerPercentComponent
6
+
7
+ # Initializes the SpinnerPercent component with various customization options.
8
+ #
9
+ # @param [Hash] **props The properties to customize the spinner.
10
+ # @option props [Symbol] :color (:default) The color theme of the spinner (:default, :info, :success, :failure, :warning, :pink, :purple).
11
+ # @option props [Integer] :size (1) The size of the spinner (-1 to 4).
12
+ # @option props [Integer] :percent (0) The percentage completion (0 to 100).
13
+ # @option props [String] :label ('Loading...') The aria-label for accessibility.
14
+ # @option props [Boolean] :show_percent (true) Whether to display the percentage text.
15
+ # @option props [String] :text (nil) Custom text to display instead of percentage. If provided, overrides show_percent.
16
+ # @option props [Hash] :label_html ({}) HTML attributes for the inner text element. Supports remove_class key to remove default classes.
17
+ # @option props [Boolean] :animate (false) Whether to apply rotation animation to the circle.
18
+ # @option props [Symbol] :speed (:normal) The speed of rotation animation (:slow, :normal, :fast, :very_fast).
19
+ # @option props [String] :remove_class ('') CSS classes to remove from the default class list.
20
+ # @option props [Hash] **props Remaining options declared as HTML attributes.
21
+ #
22
+ # @return [Fluxbit::SpinnerPercentComponent]
23
+ def initialize(**props)
24
+ super
25
+ @props = props
26
+
27
+ @color = options @props.delete(:color), collection: styles[:colors].keys, default: @@color
28
+ @size = options @props.delete(:size), collection: (0..styles[:sizes].count - 1).to_a, default: @@size
29
+ @percent = [ @props.delete(:percent) || @@percent, 0 ].max
30
+ @percent = [ @percent, 100 ].min
31
+ @label = @props.delete(:label) || @@label
32
+ @show_percent = @props.delete(:show_percent)
33
+ @show_percent = @@show_percent if @show_percent.nil?
34
+ @text = @props.delete(:text) || @@text
35
+ @label_html = @props.delete(:label_html) || {}
36
+ @animate = @props.delete(:animate)
37
+ @animate = @@animate if @animate.nil?
38
+ @speed = options @props.delete(:speed), collection: styles[:speeds].keys, default: @@speed
39
+
40
+ add class: [
41
+ styles[:base],
42
+ styles[:sizes][@size]
43
+ ], to: @props
44
+
45
+ # Add accessibility attributes
46
+ @props[:role] = "progressbar"
47
+ @props[:"aria-label"] = @label
48
+ @props[:"aria-valuenow"] = @percent
49
+ @props[:"aria-valuemin"] = "0"
50
+ @props[:"aria-valuemax"] = "100"
51
+
52
+ # Add Stimulus controller
53
+ @props[:data] ||= {}
54
+ @props[:data][:controller] = "fx-spinner-percent"
55
+ @props[:data][:"fx-spinner-percent-percent-value"] = @percent
56
+ @props[:data][:"fx-spinner-percent-animate-value"] = @animate
57
+ @props[:data][:"fx-spinner-percent-speed-value"] = @speed
58
+ @props[:data][:"fx-spinner-percent-has-custom-text-value"] = !@text.nil?
59
+
60
+ remove_class_from_props(@props)
61
+ end
62
+
63
+ def call
64
+ content_tag(:div, **@props) do
65
+ concat svg_content
66
+ concat text_content
67
+ concat screen_reader_content
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def container_classes
74
+ [
75
+ styles[:base],
76
+ styles[:sizes][@size]
77
+ ].compact.join(" ")
78
+ end
79
+
80
+ def background_circle_classes
81
+ styles[:colors][@color].split.first # gets "text-gray-200" part
82
+ end
83
+
84
+ def progress_circle_classes
85
+ styles[:colors][@color].split.last # gets "stroke-blue-600" part
86
+ end
87
+
88
+ def svg_classes
89
+ classes = [ styles[:sizes][@size] ]
90
+ classes << styles[:speeds][@speed] if @animate
91
+ classes.compact.join(" ")
92
+ end
93
+
94
+ def percentage_text_classes
95
+ [
96
+ styles[:percentage_text][:position],
97
+ styles[:text_colors][@color]
98
+ ].compact.join(" ")
99
+ end
100
+
101
+ def circumference
102
+ # For a circle with radius 45 (viewBox is 100x100, radius should be ~45 to fit nicely)
103
+ 2 * Math::PI * 45
104
+ end
105
+
106
+ def stroke_dasharray
107
+ circumference
108
+ end
109
+
110
+ def stroke_dashoffset
111
+ circumference - (@percent / 100.0) * circumference
112
+ end
113
+
114
+ def screen_reader_classes
115
+ styles[:screen_reader]
116
+ end
117
+
118
+ def label_text_classes
119
+ # Start with default classes
120
+ default_classes = percentage_text_classes.split(" ")
121
+
122
+ # Remove classes specified in label_html[:remove_class]
123
+ remove_class = @label_html[:remove_class] || @label_html["remove_class"]
124
+ if remove_class && !remove_class.empty?
125
+ remove_classes = remove_class.split(" ")
126
+ default_classes = default_classes - remove_classes
127
+ end
128
+
129
+ # Add custom classes from label_html[:class]
130
+ custom_classes = @label_html[:class]&.split(" ") || []
131
+
132
+ # Combine and join
133
+ (default_classes + custom_classes).uniq.join(" ")
134
+ end
135
+
136
+ def label_attrs
137
+ label_attrs = @label_html.dup
138
+ label_attrs.delete(:class)
139
+ label_attrs.delete(:remove_class)
140
+ label_attrs.delete("remove_class")
141
+ label_attrs[:class] = label_text_classes
142
+ label_attrs[:"data-fx-spinner-percent-target"] = "text"
143
+
144
+ label_attrs
145
+ end
146
+
147
+ def svg_content
148
+ tag.svg(class: "#{styles[:svg][:transform]} #{svg_classes}", viewBox: "0 0 100 100") do
149
+ concat(
150
+ tag.circle(cx: "50", cy: "50", r: "45", stroke: "currentColor",
151
+ "stroke-width": "8", fill: "transparent", class: background_circle_classes)
152
+ )
153
+ concat(
154
+ tag.circle(cx: "50", cy: "50", r: "45", stroke: "currentColor",
155
+ "stroke-width": "8", fill: "transparent", "stroke-linecap": "round",
156
+ "stroke-dasharray": stroke_dasharray, "stroke-dashoffset": stroke_dashoffset,
157
+ class: "#{progress_circle_classes} #{styles[:progress_circle][:transition]}",
158
+ "data-fx-spinner-percent-target": "progress")
159
+ )
160
+ end
161
+ end
162
+
163
+ def text_content
164
+ return "".html_safe unless @text || @show_percent
165
+
166
+ tag.div(**label_attrs) do
167
+ @text || "#{@percent}%"
168
+ end
169
+ end
170
+
171
+ def screen_reader_content
172
+ tag.span(@label, class: screen_reader_classes)
173
+ end
174
+ end