fluxbit_view_components 0.2.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 (173) 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/check_box_component.rb +56 -0
  35. data/app/components/fluxbit/form/component.rb +27 -26
  36. data/app/components/fluxbit/form/dropzone_component.html.erb +39 -0
  37. data/app/components/fluxbit/form/dropzone_component.rb +39 -0
  38. data/app/components/fluxbit/form/field_component.rb +28 -0
  39. data/app/components/fluxbit/form/form_builder_component.rb +1 -1
  40. data/app/components/fluxbit/form/{helper_text_component.rb → help_text_component.rb} +9 -4
  41. data/app/components/fluxbit/form/label_component.rb +40 -30
  42. data/app/components/fluxbit/form/password_component.rb +247 -0
  43. data/app/components/fluxbit/form/radio_group_button_component.rb +126 -0
  44. data/app/components/fluxbit/form/range_component.rb +52 -0
  45. data/app/components/fluxbit/form/select_component.rb +185 -0
  46. data/app/components/fluxbit/form/text_field_component.rb +185 -0
  47. data/app/components/fluxbit/form/toggle_component.html.erb +23 -0
  48. data/app/components/fluxbit/form/toggle_component.rb +81 -0
  49. data/app/components/fluxbit/form/upload_image_component.html.erb +50 -0
  50. data/app/components/fluxbit/form/upload_image_component.rb +61 -0
  51. data/app/components/fluxbit/gravatar_component.rb +7 -0
  52. data/app/components/fluxbit/icon_helpers.rb +167 -0
  53. data/app/components/fluxbit/link_component.rb +42 -0
  54. data/app/components/fluxbit/modal_component.rb +28 -31
  55. data/app/components/fluxbit/pagination_component.rb +206 -0
  56. data/app/components/fluxbit/popover_component.rb +14 -14
  57. data/app/components/fluxbit/progress_component.rb +196 -0
  58. data/app/components/fluxbit/skeleton_component.rb +237 -0
  59. data/app/components/fluxbit/speed_dial_action_component.html.erb +30 -0
  60. data/app/components/fluxbit/speed_dial_action_component.rb +59 -0
  61. data/app/components/fluxbit/speed_dial_component.html.erb +33 -0
  62. data/app/components/fluxbit/speed_dial_component.rb +73 -0
  63. data/app/components/fluxbit/spinner_component.rb +71 -0
  64. data/app/components/fluxbit/spinner_percent_component.rb +174 -0
  65. data/app/components/fluxbit/stepper_component.rb +223 -0
  66. data/app/components/fluxbit/tab_component.rb +44 -25
  67. data/app/components/fluxbit/table_component.rb +186 -0
  68. data/app/components/fluxbit/table_group_component.rb +28 -0
  69. data/app/components/fluxbit/theme_button_component.rb +64 -0
  70. data/app/components/fluxbit/timeline_component.rb +63 -0
  71. data/app/components/fluxbit/timeline_item_component.html.erb +64 -0
  72. data/app/components/fluxbit/timeline_item_component.rb +78 -0
  73. data/app/components/fluxbit/tooltip_component.rb +2 -2
  74. data/app/helpers/fluxbit/components_helper.rb +93 -51
  75. data/app/helpers/fluxbit/form_builder.rb +136 -0
  76. data/app/helpers/fluxbit/view_helper.rb +71 -0
  77. data/config/locales/en.yml +37 -4
  78. data/config/locales/pt-BR.yml +36 -0
  79. data/lib/fluxbit/config/accordion_component.rb +73 -0
  80. data/lib/fluxbit/config/avatar_component.rb +11 -11
  81. data/lib/fluxbit/config/badge_component.rb +14 -11
  82. data/lib/fluxbit/config/banner_component.rb +60 -0
  83. data/lib/fluxbit/config/bottom_navigation_component.rb +74 -0
  84. data/lib/fluxbit/config/breadcrumb_component.rb +24 -0
  85. data/lib/fluxbit/config/button_component.rb +6 -4
  86. data/lib/fluxbit/config/card_component.rb +23 -12
  87. data/lib/fluxbit/config/carousel_component.rb +33 -0
  88. data/lib/fluxbit/config/drawer_component.rb +48 -0
  89. data/lib/fluxbit/config/dropdown_component.rb +29 -0
  90. data/lib/fluxbit/config/form/check_box_component.rb +19 -0
  91. data/lib/fluxbit/config/form/dropzone_component.rb +20 -0
  92. data/lib/fluxbit/config/form/{helper_text_component.rb → help_text_component.rb} +2 -2
  93. data/lib/fluxbit/config/form/label_component.rb +31 -0
  94. data/lib/fluxbit/config/form/password_component.rb +19 -0
  95. data/lib/fluxbit/config/form/radio_group_button_component.rb +24 -0
  96. data/lib/fluxbit/config/form/range_component.rb +15 -0
  97. data/lib/fluxbit/config/form/text_field_component.rb +76 -0
  98. data/lib/fluxbit/config/form/toggle_component.rb +79 -0
  99. data/lib/fluxbit/config/link_component.rb +24 -0
  100. data/lib/fluxbit/config/modal_component.rb +1 -1
  101. data/lib/fluxbit/config/pagination_component.rb +31 -0
  102. data/lib/fluxbit/config/popover_component.rb +1 -1
  103. data/lib/fluxbit/config/progress_component.rb +63 -0
  104. data/lib/fluxbit/config/skeleton_component.rb +82 -0
  105. data/lib/fluxbit/config/speed_dial_component.rb +50 -0
  106. data/lib/fluxbit/config/spinner_component.rb +30 -0
  107. data/lib/fluxbit/config/spinner_percent_component.rb +61 -0
  108. data/lib/fluxbit/config/stepper_component.rb +299 -0
  109. data/lib/fluxbit/config/tab_component.rb +6 -0
  110. data/lib/fluxbit/config/table_component.rb +75 -0
  111. data/lib/fluxbit/config/theme_button_component.rb +19 -0
  112. data/lib/fluxbit/config/timeline_component.rb +77 -0
  113. data/lib/fluxbit/view_components/engine.rb +11 -3
  114. data/lib/fluxbit/view_components/version.rb +1 -1
  115. data/lib/fluxbit/view_components.rb +27 -1
  116. data/lib/generators/fluxbit/devise_views_generator.rb +116 -0
  117. data/lib/generators/fluxbit/pagy_generator.rb +39 -0
  118. data/lib/generators/fluxbit/scaffold_generator.rb +165 -0
  119. data/lib/generators/fluxbit/templates/_alert.html.erb.tt +1 -0
  120. data/lib/generators/fluxbit/templates/_flash.html.erb.tt +15 -0
  121. data/lib/generators/fluxbit/templates/_form.html.erb.tt +38 -0
  122. data/lib/generators/fluxbit/templates/_metadata.html.erb.tt +44 -0
  123. data/lib/generators/fluxbit/templates/controller.rb.tt +406 -0
  124. data/lib/generators/fluxbit/templates/create.turbo_stream.erb.tt +7 -0
  125. data/lib/generators/fluxbit/templates/destroy.turbo_stream.erb.tt +3 -0
  126. data/lib/generators/fluxbit/templates/destroy_all.turbo_stream.erb.tt +9 -0
  127. data/lib/generators/fluxbit/templates/devise_views/confirmations/new.html.erb +11 -0
  128. data/lib/generators/fluxbit/templates/devise_views/layouts/devise.html.erb +64 -0
  129. data/lib/generators/fluxbit/templates/devise_views/mailer/confirmation_instructions.html.erb +5 -0
  130. data/lib/generators/fluxbit/templates/devise_views/mailer/email_changed.html.erb +7 -0
  131. data/lib/generators/fluxbit/templates/devise_views/mailer/password_changed.html.erb +3 -0
  132. data/lib/generators/fluxbit/templates/devise_views/mailer/reset_password_instructions.html.erb +8 -0
  133. data/lib/generators/fluxbit/templates/devise_views/mailer/unlock_instructions.html.erb +7 -0
  134. data/lib/generators/fluxbit/templates/devise_views/passwords/edit.html.erb +29 -0
  135. data/lib/generators/fluxbit/templates/devise_views/passwords/new.html.erb +11 -0
  136. data/lib/generators/fluxbit/templates/devise_views/registrations/edit.html.erb +43 -0
  137. data/lib/generators/fluxbit/templates/devise_views/registrations/new.html.erb +34 -0
  138. data/lib/generators/fluxbit/templates/devise_views/sessions/new.html.erb +15 -0
  139. data/lib/generators/fluxbit/templates/devise_views/shared/_error_messages.html.erb +14 -0
  140. data/lib/generators/fluxbit/templates/devise_views/shared/_links.html.erb +25 -0
  141. data/lib/generators/fluxbit/templates/devise_views/unlocks/new.html.erb +11 -0
  142. data/lib/generators/fluxbit/templates/edit.html.erb.tt +47 -0
  143. data/lib/generators/fluxbit/templates/fluxbit_pagy.css +27 -0
  144. data/lib/generators/fluxbit/templates/i18n.en.yml.tt +121 -0
  145. data/lib/generators/fluxbit/templates/i18n.pt-BR.yml.tt +121 -0
  146. data/lib/generators/fluxbit/templates/index.html.erb.tt +254 -0
  147. data/lib/generators/fluxbit/templates/index.json.jbuilder.tt +33 -0
  148. data/lib/generators/fluxbit/templates/new.html.erb.tt +47 -0
  149. data/lib/generators/fluxbit/templates/partial.html.erb.tt +61 -0
  150. data/lib/generators/fluxbit/templates/policy.rb.tt +36 -0
  151. data/lib/generators/fluxbit/templates/send_alert_via_drawer.erb.tt +10 -0
  152. data/lib/generators/fluxbit/templates/show.html.erb.tt +44 -0
  153. data/lib/generators/fluxbit/templates/show.json.jbuilder.tt +6 -0
  154. data/lib/generators/fluxbit/templates/update.turbo_stream.erb.tt +10 -0
  155. data/lib/generators/fluxbit/templates/update_all.turbo_stream.erb.tt +20 -0
  156. data/lib/install/install.rb +61 -3
  157. metadata +127 -35
  158. data/LICENSE.txt +0 -20
  159. data/app/components/fluxbit/form/checkbox_input_component.rb +0 -61
  160. data/app/components/fluxbit/form/datepicker_component.rb +0 -7
  161. data/app/components/fluxbit/form/radio_input_component.rb +0 -21
  162. data/app/components/fluxbit/form/range_input_component.rb +0 -51
  163. data/app/components/fluxbit/form/select_free_input_component.rb +0 -77
  164. data/app/components/fluxbit/form/select_input_component.rb +0 -21
  165. data/app/components/fluxbit/form/spacer_input_component.rb +0 -12
  166. data/app/components/fluxbit/form/text_input_component.rb +0 -225
  167. data/app/components/fluxbit/form/textarea_input_component.rb +0 -57
  168. data/app/components/fluxbit/form/toggle_input_component.rb +0 -166
  169. data/app/components/fluxbit/form/upload_image_input_component.html.erb +0 -48
  170. data/app/components/fluxbit/form/upload_image_input_component.rb +0 -61
  171. data/app/components/fluxbit/form/upload_input_component.html.erb +0 -12
  172. data/app/components/fluxbit/form/upload_input_component.rb +0 -47
  173. data/app/helpers/fluxbit/classes_helper.rb +0 -9
@@ -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
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # The `Fluxbit::StepperComponent` is a customizable stepper component that extends `Fluxbit::Component`.
5
+ # It provides a visual representation of a multi-step process, supporting both horizontal and vertical orientations
6
+ # with various styling options including different colors and states.
7
+ #
8
+ # @example Basic usage
9
+ # = fx_stepper do |stepper|
10
+ # = stepper.with_step(title: "Step 1", state: :completed)
11
+ # = stepper.with_step(title: "Step 2", state: :active)
12
+ # = stepper.with_step(title: "Step 3")
13
+ # end
14
+ #
15
+ # @see docs/02_Components/Stepper.md For detailed documentation.
16
+ class Fluxbit::StepperComponent < Fluxbit::Component
17
+ include Fluxbit::Config::StepperComponent
18
+
19
+ renders_many :steps, lambda { |**attrs, &block|
20
+ step = Step.new(**attrs)
21
+ step.with_content(block.call) if block_given?
22
+ step
23
+ }
24
+
25
+ ##
26
+ # Initializes the stepper component with the given properties.
27
+ #
28
+ # @param [Hash] **props The properties to customize the stepper.
29
+ # @option props [Symbol] :orientation (:horizontal) The orientation of the stepper (:horizontal, :vertical).
30
+ # @option props [Symbol] :variant (:default) The variant of the stepper (:default, :progress, :detailed).
31
+ # @option props [Symbol] :color (:blue) The color theme of the active step (:blue, :green, :red, :yellow, :indigo, :purple).
32
+ # @option props [String] :remove_class ('') CSS classes to remove from the default class list.
33
+ # @option props [Hash] **props Remaining options declared as HTML attributes.
34
+ #
35
+ # @return [Fluxbit::StepperComponent]
36
+ def initialize(**props)
37
+ super
38
+ @props = props
39
+
40
+ @orientation = options @props.delete(:orientation), collection: styles[:base].keys, default: @@orientation
41
+ @variant = options @props.delete(:variant), collection: styles[:list].keys, default: @@variant
42
+ @color = options @props.delete(:color), collection: styles[:step][:default][:active].keys, default: @@color
43
+
44
+ add class: styles[:base][@orientation], to: @props, first_element: true
45
+ remove_class_from_props(@props)
46
+ end
47
+
48
+ def call
49
+ tag.div(**@props) do
50
+ tag.ol(class: styles[:list][@variant][@orientation]) do
51
+ safe_join(steps.map.with_index { |step, index| render_step(step, index) })
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def render_step(step, index)
59
+ last_step = index == steps.count - 1
60
+
61
+ content_tag(:li, class: step_item_classes) do
62
+ if @orientation == :vertical && @variant != :detailed
63
+ # Vertical layout: wrapper div for proper positioning
64
+ concat(
65
+ tag.div(class: styles[:layout][:wrapper]) do
66
+ content = []
67
+ content << tag.div(class: styles[:layout][:flex_center]) do
68
+ concat(render_step_indicator(step))
69
+ concat(render_step_content(step)) if step.title.present? || step.description.present? || step.content.present?
70
+ end
71
+ content << render_vertical_connector(step) unless last_step
72
+ safe_join(content)
73
+ end
74
+ )
75
+ elsif @orientation == :vertical && @variant == :detailed
76
+ # Detailed vertical: no connectors, just cards
77
+ concat(render_step_indicator(step))
78
+ concat(render_step_content(step)) if step.title.present? || step.description.present? || step.content.present?
79
+ else
80
+ # Horizontal layout: standard flow with connectors
81
+ concat(render_step_indicator(step))
82
+ concat(render_step_content(step)) if step.title.present? || step.description.present? || step.content.present?
83
+ concat(render_connector(step)) unless last_step
84
+ end
85
+ end
86
+ end
87
+
88
+ def step_item_classes
89
+ styles[:item][@variant][@orientation]
90
+ end
91
+
92
+ def render_step_indicator(step)
93
+ tag.div(class: step_circle_classes(step)) do
94
+ if step.icon.present?
95
+ anyicon(step.icon, class: styles[:step_icon][@variant][:completed])
96
+ elsif step.state == :completed && @variant == :progress
97
+ content_tag(:span, "✓", class: step_number_classes(step))
98
+ else
99
+ content_tag(:span, step.number || "", class: step_number_classes(step))
100
+ end
101
+ end
102
+ end
103
+
104
+ def render_step_content(step)
105
+ return "" unless step.title.present? || step.description.present? || step.content.present?
106
+
107
+ tag.div(class: styles[:content][@variant][@orientation]) do
108
+ content = []
109
+
110
+ content << tag.h3(step.title, class: step_title_classes(step)) if step.title.present?
111
+ content << tag.p(step.description, class: styles[:description]) if step.description.present?
112
+ content << step.content if step.content.present?
113
+
114
+ safe_join(content)
115
+ end
116
+ end
117
+
118
+ def render_connector(step)
119
+ return "" if @orientation == :horizontal && steps.count <= 1
120
+
121
+ connector_classes = if step.state == :completed
122
+ styles[:connector][:completed][@variant][@orientation]
123
+ elsif step.state == :active
124
+ styles[:connector][:active][@color][@variant][@orientation]
125
+ else
126
+ styles[:connector][@variant][@orientation]
127
+ end
128
+
129
+ tag.div(class: connector_classes)
130
+ end
131
+
132
+ def render_vertical_connector(step)
133
+ # Position based on variant (different circle sizes)
134
+ left_position = styles[:vertical_connector][:positions][@variant] || styles[:vertical_connector][:positions][:default]
135
+
136
+ connector_classes = [
137
+ styles[:vertical_connector][:base],
138
+ left_position,
139
+ vertical_connector_color(step)
140
+ ].compact.join(" ")
141
+
142
+ tag.div(class: connector_classes)
143
+ end
144
+
145
+ def vertical_connector_color(step)
146
+ case step.state
147
+ when :completed
148
+ styles[:vertical_connector][:colors][:completed]
149
+ when :active
150
+ styles[:vertical_connector][:colors][@color] || styles[:vertical_connector][:colors][:blue]
151
+ else
152
+ styles[:vertical_connector][:colors][:default]
153
+ end
154
+ end
155
+
156
+ def step_circle_classes(step)
157
+ case step.state
158
+ when :completed
159
+ styles[:step][@variant][:completed]
160
+ when :active
161
+ styles[:step][@variant][:active][@color]
162
+ else
163
+ styles[:step][@variant][:base]
164
+ end
165
+ end
166
+
167
+ def step_number_classes(step)
168
+ case step.state
169
+ when :completed
170
+ styles[:step_number][@variant][:completed]
171
+ when :active
172
+ styles[:step_number][@variant][:active][@color]
173
+ else
174
+ styles[:step_number][@variant][:base]
175
+ end
176
+ end
177
+
178
+ def step_title_classes(step)
179
+ case step.state
180
+ when :completed
181
+ styles[:title][:completed]
182
+ when :active
183
+ styles[:title][:active][@color]
184
+ else
185
+ styles[:title][:base]
186
+ end
187
+ end
188
+
189
+ # Nested step component
190
+ class Step < Fluxbit::Component
191
+ include Fluxbit::Config::StepperComponent
192
+
193
+ attr_reader :title, :description, :state, :number, :icon
194
+
195
+ ##
196
+ # Initializes a step item for the stepper.
197
+ #
198
+ # @param [Hash] **props The properties to customize the step.
199
+ # @option props [String] :title The title of the step.
200
+ # @option props [String] :description The description of the step.
201
+ # @option props [Symbol] :state (:pending) The state of the step (:pending, :active, :completed).
202
+ # @option props [String, Integer] :number The step number or custom text.
203
+ # @option props [String] :icon The icon name to display for completed state.
204
+ #
205
+ # @return [Fluxbit::StepperComponent::Step]
206
+ def initialize(**props)
207
+ super
208
+ @props = props
209
+
210
+ @title = @props.delete(:title)
211
+ @description = @props.delete(:description)
212
+ @state = options @props.delete(:state), collection: [ :pending, :active, :completed ], default: :pending
213
+ @number = @props.delete(:number)
214
+ @icon = @props.delete(:icon)
215
+
216
+ remove_class_from_props(@props)
217
+ end
218
+
219
+ def call
220
+ content
221
+ end
222
+ end
223
+ end
@@ -13,13 +13,24 @@ class Fluxbit::TabComponent < Fluxbit::Component
13
13
  end
14
14
  }
15
15
 
16
+ # Initializes the Tab component with the given properties.
17
+ #
18
+ # @param [Hash] props The properties to customize the Tab component.
19
+ # @option props [Symbol] :variant (:default) The variant style (:default, :underline, :pills, :full_width).
20
+ # @option props [Symbol] :color (:blue) The color theme for active tabs.
21
+ # @option props [Boolean] :vertical (false) Whether tabs should be displayed vertically.
22
+ # @option props [Symbol] :tab_panel (:default) The style for tab panels (:default, :none).
23
+ # @option props [Symbol] :align (:left) Horizontal alignment of tabs (:left, :center, :right). Only applies to horizontal tabs.
24
+ # @option props [Hash] :ul_html ({}) HTML attributes to apply to the ul element.
25
+ # @option props [Hash] **props Remaining options declared as HTML attributes, applied to the tab container.
16
26
  def initialize(**props)
17
27
  @variant = (props.delete(:variant) || @@variant).to_sym
18
28
  @color = props.delete(:color) || @@color
19
29
  @vertical = props.delete(:vertical) || @@vertical
20
30
  @tab_panel = (props.delete(:tab_panel) || @@tab_panel).to_sym
31
+ @align = (props.delete(:align) || @@align).to_sym
21
32
  @tabs_group = []
22
- @ul_props = props.delete(:ul_props) || {}
33
+ @ul_html = props.delete(:ul_html) || {}
23
34
  @props = props
24
35
  @vertical = false if @variant == :full_width
25
36
  super
@@ -31,7 +42,7 @@ class Fluxbit::TabComponent < Fluxbit::Component
31
42
  add class: styles[:div][@vertical ? :vertical : :horizontal], to: @props, first_element: true
32
43
 
33
44
  if @has_panels
34
- content_tag :div, **@props do
45
+ tag.div(**@props) do
35
46
  concat(render_tab_list)
36
47
  concat(render_tab_panels)
37
48
  end
@@ -43,21 +54,22 @@ class Fluxbit::TabComponent < Fluxbit::Component
43
54
  private
44
55
 
45
56
  def render_tab_list
46
- add class: styles[:tab_list][:ul][@vertical ? :vertical : :horizontal], to: @ul_props, first_element: true
47
- add class: styles[:tab_list][:variant][variant], to: @ul_props
48
- @ul_props[:role] = "tablist"
57
+ add class: styles[:tab_list][:ul][@vertical ? :vertical : :horizontal], to: @ul_html, first_element: true
58
+ add class: styles[:tab_list][:variant][variant], to: @ul_html
59
+ add class: styles[:tab_list][:align][@align], to: @ul_html unless @vertical
60
+ @ul_html[:role] = "tablist"
49
61
 
50
62
  if @has_panels
51
- @ul_props[:data] = {
63
+ @ul_html[:data] = {
52
64
  "tabs-toggle": "##{fx_id}-content",
53
65
  "tabs-active-classes": styles[:tab_list][:tab_item][:variant][variant][:active][@color],
54
66
  "tabs-inactive-classes": styles[:tab_list][:tab_item][:variant][variant][:inactive]
55
67
  }
56
68
  end
57
69
 
58
- @ul_props[:id] = fx_id
70
+ @ul_html[:id] = fx_id
59
71
 
60
- content_tag :ul, **@ul_props do
72
+ tag.ul(**@ul_html) do
61
73
  safe_join(@tabs_group.map.with_index { |tab, index| render_tab(tab, index) })
62
74
  end
63
75
  end
@@ -102,41 +114,48 @@ class Fluxbit::TabComponent < Fluxbit::Component
102
114
  tab.props.delete :"aria-controls"
103
115
  end
104
116
 
105
- li_props = tab.props.delete(:li_props) || {}
106
- li_props[:role] = "presentation"
107
- li_props[:id] = "#{fx_id}-#{index}-li"
108
- add class: styles[:tab_list][:li], to: li_props, first_element: true
117
+ li_html = tab.props.delete(:li_html) || {}
118
+ li_html[:role] = "presentation"
119
+ li_html[:id] = "#{fx_id}-#{index}-li"
120
+ add class: styles[:tab_list][:li], to: li_html, first_element: true
109
121
 
110
- content_tag :li, **li_props do
111
- content_tag :a, **tab.props do
122
+ tag.li(**li_html) do
123
+ tag.a(**tab.props) do
112
124
  concat(render_icon(tab_icon)) if tab_icon
113
- concat(content_tag(:span, tab_title))
125
+ concat(tag.span(tab_title))
114
126
  end
115
127
  end
116
128
  end
117
129
 
118
130
  def render_icon(icon)
119
- if icon.include?('class="')
120
- icon.gsub("class=\"", "class=\"#{styles[:tab_list][:tab_item][:icon]} ")
131
+ return "" if icon.blank?
132
+
133
+ modified = if icon.include?('class="')
134
+ icon.gsub('class="', "class=\"#{styles[:tab_list][:tab_item][:icon]} ")
121
135
  else
122
136
  icon.gsub("<svg", "<svg class=\"#{styles[:tab_list][:tab_item][:icon]}\"")
123
- end.html_safe
137
+ end
138
+
139
+ allowed_tags = %w[svg path circle rect line polyline polygon g defs title use]
140
+ allowed_attrs = %w[class fill stroke stroke-width stroke-linecap stroke-linejoin width height viewBox xmlns x y d points cx cy r x1 y1 x2 y2 href aria-hidden]
141
+
142
+ view_context.sanitize(modified, tags: allowed_tags, attributes: allowed_attrs)
124
143
  end
125
144
 
126
145
  def render_tab_panels
127
- content_tag :div, id: "##{fx_id}-content", class: styles[:tabpanel_container][@vertical ? :vertical : :horizontal] do
146
+ tag.div(id: "##{fx_id}-content", class: styles[:tabpanel_container][@vertical ? :vertical : :horizontal]) do
128
147
  safe_join(@tabs_group.map.with_index { |tab, index| render_tabpanel(tab, index) })
129
148
  end
130
149
  end
131
150
 
132
151
  def render_tabpanel(tab, index)
133
- content_props = tab.props[:content_props] || {}
134
- add class: styles[:tabpanel][@vertical ? :vertical : :horizontal][@tab_panel][tab.props[:active] ? :active : :inactive], to: content_props, first_element: true
152
+ content_html = tab.props[:content_html] || {}
153
+ add class: styles[:tabpanel][@vertical ? :vertical : :horizontal][@tab_panel][tab.props[:active] ? :active : :inactive], to: content_html, first_element: true
135
154
 
136
- content_props[:id] = "#{fx_id}-tabpanel-#{index}"
137
- content_props[:role] = "tabpanel"
138
- content_props[:"aria-labelledby"] = "#{fx_id}-#{index}"
155
+ content_html[:id] = "#{fx_id}-tabpanel-#{index}"
156
+ content_html[:role] = "tabpanel"
157
+ content_html[:"aria-labelledby"] = "#{fx_id}-#{index}"
139
158
 
140
- content_tag :div, tab.content, **content_props
159
+ tag.div(tab.content, **content_html)
141
160
  end
142
161
  end