better_ui 0.6.0 → 0.7.1

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 (198) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +257 -212
  3. data/Rakefile +11 -2
  4. data/app/components/better_ui/action_messages_component/action_messages_component.html.erb +48 -0
  5. data/app/components/better_ui/action_messages_component.rb +544 -0
  6. data/app/components/better_ui/application_component.rb +66 -0
  7. data/app/components/better_ui/button_component/button_component.html.erb +31 -0
  8. data/app/components/better_ui/button_component.rb +307 -0
  9. data/app/components/better_ui/card_component/card_component.html.erb +17 -0
  10. data/app/components/better_ui/card_component.rb +460 -0
  11. data/app/components/better_ui/drawer/header_component/header_component.html.erb +24 -0
  12. data/app/components/better_ui/drawer/header_component.rb +238 -0
  13. data/app/components/better_ui/drawer/layout_component/layout_component.html.erb +44 -0
  14. data/app/components/better_ui/drawer/layout_component.rb +270 -0
  15. data/app/components/better_ui/drawer/nav_group_component/nav_group_component.html.erb +10 -0
  16. data/app/components/better_ui/drawer/nav_group_component.rb +155 -0
  17. data/app/components/better_ui/drawer/nav_item_component/nav_item_component.html.erb +13 -0
  18. data/app/components/better_ui/drawer/nav_item_component.rb +225 -0
  19. data/app/components/better_ui/drawer/sidebar_component/sidebar_component.html.erb +17 -0
  20. data/app/components/better_ui/drawer/sidebar_component.rb +263 -0
  21. data/app/components/better_ui/forms/base_component.rb +450 -0
  22. data/app/components/better_ui/forms/checkbox_component/checkbox_component.html.erb +28 -0
  23. data/app/components/better_ui/forms/checkbox_component.rb +419 -0
  24. data/app/components/better_ui/forms/checkbox_group_component/checkbox_group_component.html.erb +40 -0
  25. data/app/components/better_ui/forms/checkbox_group_component.rb +363 -0
  26. data/app/components/better_ui/forms/number_input_component/number_input_component.html.erb +40 -0
  27. data/app/components/better_ui/forms/number_input_component.rb +320 -0
  28. data/app/components/better_ui/forms/password_input_component/password_input_component.html.erb +71 -0
  29. data/app/components/better_ui/forms/password_input_component.rb +206 -0
  30. data/app/components/better_ui/forms/text_input_component/text_input_component.html.erb +40 -0
  31. data/app/components/better_ui/forms/text_input_component.rb +258 -0
  32. data/app/components/better_ui/forms/textarea_component/textarea_component.html.erb +40 -0
  33. data/app/components/better_ui/forms/textarea_component.rb +329 -0
  34. data/app/form_builders/better_ui/ui_form_builder.rb +467 -0
  35. data/app/helpers/better_ui/application_helper.rb +325 -58
  36. data/app/views/layouts/better_ui/application.html.erb +1 -1
  37. data/config/routes.rb +1 -0
  38. data/lib/better_ui/engine.rb +34 -5
  39. data/lib/better_ui/version.rb +1 -1
  40. data/lib/better_ui.rb +32 -5
  41. data/lib/generators/better_ui/install/USAGE +44 -0
  42. data/lib/generators/better_ui/install/install_generator.rb +87 -0
  43. data/lib/generators/better_ui/install/templates/better_ui_theme.css.tt +280 -0
  44. data/lib/tasks/better_ui_tasks.rake +39 -4
  45. metadata +55 -203
  46. data/app/components/better_ui/application/card/component.html.erb +0 -20
  47. data/app/components/better_ui/application/card/component.rb +0 -214
  48. data/app/components/better_ui/application/main/component.html.erb +0 -9
  49. data/app/components/better_ui/application/main/component.rb +0 -123
  50. data/app/components/better_ui/application/navbar/component.html.erb +0 -92
  51. data/app/components/better_ui/application/navbar/component.rb +0 -136
  52. data/app/components/better_ui/application/sidebar/component.html.erb +0 -249
  53. data/app/components/better_ui/application/sidebar/component.rb +0 -187
  54. data/app/components/better_ui/general/accordion/component.html.erb +0 -5
  55. data/app/components/better_ui/general/accordion/component.rb +0 -92
  56. data/app/components/better_ui/general/accordion/item_component.html.erb +0 -12
  57. data/app/components/better_ui/general/accordion/item_component.rb +0 -176
  58. data/app/components/better_ui/general/alert/component.html.erb +0 -32
  59. data/app/components/better_ui/general/alert/component.rb +0 -242
  60. data/app/components/better_ui/general/avatar/component.html.erb +0 -20
  61. data/app/components/better_ui/general/avatar/component.rb +0 -301
  62. data/app/components/better_ui/general/badge/component.html.erb +0 -23
  63. data/app/components/better_ui/general/badge/component.rb +0 -248
  64. data/app/components/better_ui/general/breadcrumb/component.html.erb +0 -15
  65. data/app/components/better_ui/general/breadcrumb/component.rb +0 -187
  66. data/app/components/better_ui/general/button/component.html.erb +0 -34
  67. data/app/components/better_ui/general/button/component.rb +0 -214
  68. data/app/components/better_ui/general/divider/component.html.erb +0 -10
  69. data/app/components/better_ui/general/divider/component.rb +0 -226
  70. data/app/components/better_ui/general/dropdown/component.html.erb +0 -28
  71. data/app/components/better_ui/general/dropdown/component.rb +0 -192
  72. data/app/components/better_ui/general/dropdown/divider_component.html.erb +0 -1
  73. data/app/components/better_ui/general/dropdown/divider_component.rb +0 -41
  74. data/app/components/better_ui/general/dropdown/item_component.html.erb +0 -6
  75. data/app/components/better_ui/general/dropdown/item_component.rb +0 -119
  76. data/app/components/better_ui/general/field/component.html.erb +0 -27
  77. data/app/components/better_ui/general/field/component.rb +0 -37
  78. data/app/components/better_ui/general/grid/cell_component.html.erb +0 -3
  79. data/app/components/better_ui/general/grid/cell_component.rb +0 -390
  80. data/app/components/better_ui/general/grid/component.html.erb +0 -3
  81. data/app/components/better_ui/general/grid/component.rb +0 -301
  82. data/app/components/better_ui/general/heading/component.html.erb +0 -22
  83. data/app/components/better_ui/general/heading/component.rb +0 -257
  84. data/app/components/better_ui/general/icon/component.html.erb +0 -7
  85. data/app/components/better_ui/general/icon/component.rb +0 -240
  86. data/app/components/better_ui/general/input/checkbox/component.html.erb +0 -5
  87. data/app/components/better_ui/general/input/checkbox/component.rb +0 -238
  88. data/app/components/better_ui/general/input/datetime/component.html.erb +0 -5
  89. data/app/components/better_ui/general/input/datetime/component.rb +0 -223
  90. data/app/components/better_ui/general/input/pin/component.html.erb +0 -1
  91. data/app/components/better_ui/general/input/pin/component.rb +0 -201
  92. data/app/components/better_ui/general/input/radio/component.html.erb +0 -5
  93. data/app/components/better_ui/general/input/radio/component.rb +0 -230
  94. data/app/components/better_ui/general/input/rating/component.html.erb +0 -4
  95. data/app/components/better_ui/general/input/rating/component.rb +0 -272
  96. data/app/components/better_ui/general/input/select/component.html.erb +0 -78
  97. data/app/components/better_ui/general/input/select/component.rb +0 -249
  98. data/app/components/better_ui/general/input/select/select_component.html.erb +0 -5
  99. data/app/components/better_ui/general/input/select/select_component.rb +0 -37
  100. data/app/components/better_ui/general/input/text/component.html.erb +0 -5
  101. data/app/components/better_ui/general/input/text/component.rb +0 -171
  102. data/app/components/better_ui/general/input/textarea/component.html.erb +0 -5
  103. data/app/components/better_ui/general/input/textarea/component.rb +0 -166
  104. data/app/components/better_ui/general/input/toggle/component.html.erb +0 -5
  105. data/app/components/better_ui/general/input/toggle/component.rb +0 -242
  106. data/app/components/better_ui/general/link/component.html.erb +0 -18
  107. data/app/components/better_ui/general/link/component.rb +0 -258
  108. data/app/components/better_ui/general/modal/component.html.erb +0 -5
  109. data/app/components/better_ui/general/modal/component.rb +0 -47
  110. data/app/components/better_ui/general/modal/modal_component.html.erb +0 -52
  111. data/app/components/better_ui/general/modal/modal_component.rb +0 -160
  112. data/app/components/better_ui/general/pagination/component.html.erb +0 -85
  113. data/app/components/better_ui/general/pagination/component.rb +0 -216
  114. data/app/components/better_ui/general/panel/component.html.erb +0 -28
  115. data/app/components/better_ui/general/panel/component.rb +0 -249
  116. data/app/components/better_ui/general/progress/component.html.erb +0 -11
  117. data/app/components/better_ui/general/progress/component.rb +0 -160
  118. data/app/components/better_ui/general/spinner/component.html.erb +0 -35
  119. data/app/components/better_ui/general/spinner/component.rb +0 -93
  120. data/app/components/better_ui/general/table/component.html.erb +0 -5
  121. data/app/components/better_ui/general/table/component.rb +0 -217
  122. data/app/components/better_ui/general/table/tbody_component.html.erb +0 -3
  123. data/app/components/better_ui/general/table/tbody_component.rb +0 -30
  124. data/app/components/better_ui/general/table/td_component.html.erb +0 -3
  125. data/app/components/better_ui/general/table/td_component.rb +0 -44
  126. data/app/components/better_ui/general/table/tfoot_component.html.erb +0 -3
  127. data/app/components/better_ui/general/table/tfoot_component.rb +0 -28
  128. data/app/components/better_ui/general/table/th_component.html.erb +0 -6
  129. data/app/components/better_ui/general/table/th_component.rb +0 -51
  130. data/app/components/better_ui/general/table/thead_component.html.erb +0 -3
  131. data/app/components/better_ui/general/table/thead_component.rb +0 -28
  132. data/app/components/better_ui/general/table/tr_component.html.erb +0 -3
  133. data/app/components/better_ui/general/table/tr_component.rb +0 -30
  134. data/app/components/better_ui/general/tabs/component.html.erb +0 -11
  135. data/app/components/better_ui/general/tabs/component.rb +0 -120
  136. data/app/components/better_ui/general/tabs/panel_component.html.erb +0 -3
  137. data/app/components/better_ui/general/tabs/panel_component.rb +0 -37
  138. data/app/components/better_ui/general/tabs/tab_component.html.erb +0 -13
  139. data/app/components/better_ui/general/tabs/tab_component.rb +0 -111
  140. data/app/components/better_ui/general/tag/component.html.erb +0 -3
  141. data/app/components/better_ui/general/tag/component.rb +0 -104
  142. data/app/components/better_ui/general/text/component.html.erb +0 -1
  143. data/app/components/better_ui/general/text/component.rb +0 -194
  144. data/app/components/better_ui/general/tooltip/component.html.erb +0 -7
  145. data/app/components/better_ui/general/tooltip/component.rb +0 -239
  146. data/app/helpers/better_ui/application/components/card/card_helper.rb +0 -96
  147. data/app/helpers/better_ui/application/components/card.rb +0 -11
  148. data/app/helpers/better_ui/application/components/main/main_helper.rb +0 -64
  149. data/app/helpers/better_ui/application/components/navbar/navbar_helper.rb +0 -77
  150. data/app/helpers/better_ui/application/components/sidebar/sidebar_helper.rb +0 -51
  151. data/app/helpers/better_ui/general/components/accordion/accordion_helper.rb +0 -73
  152. data/app/helpers/better_ui/general/components/alert/alert_helper.rb +0 -57
  153. data/app/helpers/better_ui/general/components/avatar/avatar_helper.rb +0 -29
  154. data/app/helpers/better_ui/general/components/badge/badge_helper.rb +0 -53
  155. data/app/helpers/better_ui/general/components/breadcrumb/breadcrumb_helper.rb +0 -37
  156. data/app/helpers/better_ui/general/components/button/button_helper.rb +0 -65
  157. data/app/helpers/better_ui/general/components/container/container_helper.rb +0 -60
  158. data/app/helpers/better_ui/general/components/divider/divider_helper.rb +0 -63
  159. data/app/helpers/better_ui/general/components/dropdown/divider_helper.rb +0 -32
  160. data/app/helpers/better_ui/general/components/dropdown/dropdown_helper.rb +0 -88
  161. data/app/helpers/better_ui/general/components/dropdown/item_helper.rb +0 -68
  162. data/app/helpers/better_ui/general/components/field/field_helper.rb +0 -26
  163. data/app/helpers/better_ui/general/components/grid/grid_helper.rb +0 -145
  164. data/app/helpers/better_ui/general/components/heading/heading_helper.rb +0 -72
  165. data/app/helpers/better_ui/general/components/icon/icon_helper.rb +0 -16
  166. data/app/helpers/better_ui/general/components/input/checkbox/checkbox_helper.rb +0 -81
  167. data/app/helpers/better_ui/general/components/input/datetime/datetime_helper.rb +0 -91
  168. data/app/helpers/better_ui/general/components/input/pin/pin_helper.rb +0 -76
  169. data/app/helpers/better_ui/general/components/input/radio/radio_helper.rb +0 -79
  170. data/app/helpers/better_ui/general/components/input/radio_group/radio_group_helper.rb +0 -124
  171. data/app/helpers/better_ui/general/components/input/rating/rating_helper.rb +0 -70
  172. data/app/helpers/better_ui/general/components/input/select/select_helper.rb +0 -86
  173. data/app/helpers/better_ui/general/components/input/text/text_helper.rb +0 -138
  174. data/app/helpers/better_ui/general/components/input/textarea/textarea_helper.rb +0 -73
  175. data/app/helpers/better_ui/general/components/input/toggle/toggle_helper.rb +0 -77
  176. data/app/helpers/better_ui/general/components/link/link_helper.rb +0 -89
  177. data/app/helpers/better_ui/general/components/modal/modal_helper.rb +0 -85
  178. data/app/helpers/better_ui/general/components/pagination/pagination_helper.rb +0 -82
  179. data/app/helpers/better_ui/general/components/panel/panel_helper.rb +0 -83
  180. data/app/helpers/better_ui/general/components/progress/progress_helper.rb +0 -53
  181. data/app/helpers/better_ui/general/components/spinner/spinner_helper.rb +0 -19
  182. data/app/helpers/better_ui/general/components/table/table_helper.rb +0 -53
  183. data/app/helpers/better_ui/general/components/table/tbody_helper.rb +0 -13
  184. data/app/helpers/better_ui/general/components/table/td_helper.rb +0 -19
  185. data/app/helpers/better_ui/general/components/table/tfoot_helper.rb +0 -13
  186. data/app/helpers/better_ui/general/components/table/th_helper.rb +0 -19
  187. data/app/helpers/better_ui/general/components/table/thead_helper.rb +0 -13
  188. data/app/helpers/better_ui/general/components/table/tr_helper.rb +0 -13
  189. data/app/helpers/better_ui/general/components/tabs/panel_helper.rb +0 -62
  190. data/app/helpers/better_ui/general/components/tabs/tab_helper.rb +0 -55
  191. data/app/helpers/better_ui/general/components/tabs/tabs_helper.rb +0 -95
  192. data/app/helpers/better_ui/general/components/tag/tag_helper.rb +0 -26
  193. data/app/helpers/better_ui/general/components/text/text_helper.rb +0 -83
  194. data/app/helpers/better_ui/general/components/tooltip/tooltip_helper.rb +0 -60
  195. data/app/jobs/better_ui/application_job.rb +0 -4
  196. data/app/mailers/better_ui/application_mailer.rb +0 -6
  197. data/config/initializers/lookbook.rb +0 -23
  198. data/lib/better_ui/railtie.rb +0 -20
@@ -1,22 +0,0 @@
1
- <%# Template per il heading %>
2
- <div class="<%= container_classes %>">
3
- <%= tag.public_send(heading_tag, **heading_attributes) do %>
4
- <% if show_icon? %>
5
- <span class="<%= icon_classes %>">
6
- <%= render BetterUi::General::Icon::Component.new(name: @icon) %>
7
- </span>
8
- <% end %>
9
-
10
- <span><%= content %></span>
11
- <% end %>
12
-
13
- <% if show_subtitle? %>
14
- <div class="<%= subtitle_classes %>">
15
- <%= @subtitle %>
16
- </div>
17
- <% end %>
18
-
19
- <% if show_divider? %>
20
- <div class="<%= divider_classes %>"></div>
21
- <% end %>
22
- </div>
@@ -1,257 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Heading
4
- class Component < ViewComponent::Base
5
- attr_reader :level, :theme, :align, :size, :style, :icon, :subtitle, :with_divider
6
-
7
- # Classi base sempre presenti
8
- HEADING_BASE_CLASSES = "font-bold leading-tight"
9
-
10
- # Temi con classi Tailwind dirette - LOGICA CORRETTA
11
- HEADING_THEME_CLASSES = {
12
- default: "text-white", # Testo bianco (per sfondi scuri)
13
- white: "text-gray-900", # Testo nero (per sfondi chiari)
14
- red: "text-red-500",
15
- rose: "text-rose-500",
16
- orange: "text-orange-500",
17
- green: "text-green-500",
18
- blue: "text-blue-500",
19
- yellow: "text-yellow-600",
20
- violet: "text-violet-500",
21
- purple: "text-purple-500"
22
- }
23
-
24
- # Allineamenti con classi Tailwind dirette
25
- HEADING_ALIGN_CLASSES = {
26
- left: "text-left",
27
- center: "text-center",
28
- right: "text-right"
29
- }
30
-
31
- # Dimensioni base (verranno combinate con level)
32
- HEADING_SIZE_CLASSES = {
33
- small: {
34
- 1 => "text-2xl sm:text-3xl",
35
- 2 => "text-xl sm:text-2xl",
36
- 3 => "text-lg sm:text-xl",
37
- 4 => "text-base sm:text-lg",
38
- 5 => "text-sm sm:text-base",
39
- 6 => "text-xs sm:text-sm"
40
- },
41
- medium: {
42
- 1 => "text-3xl sm:text-4xl",
43
- 2 => "text-2xl sm:text-3xl",
44
- 3 => "text-xl sm:text-2xl",
45
- 4 => "text-lg sm:text-xl",
46
- 5 => "text-base sm:text-lg",
47
- 6 => "text-sm sm:text-base"
48
- },
49
- large: {
50
- 1 => "text-4xl sm:text-5xl",
51
- 2 => "text-3xl sm:text-4xl",
52
- 3 => "text-2xl sm:text-3xl",
53
- 4 => "text-xl sm:text-2xl",
54
- 5 => "text-lg sm:text-xl",
55
- 6 => "text-base sm:text-lg"
56
- }
57
- }
58
-
59
- # Stili con classi Tailwind dirette
60
- HEADING_STYLE_CLASSES = {
61
- normal: "",
62
- bold: "font-extrabold",
63
- italic: "italic",
64
- underline: "underline"
65
- }
66
-
67
- # Temi per subtitle - LOGICA CORRETTA
68
- HEADING_SUBTITLE_THEME_CLASSES = {
69
- default: "text-gray-300", # Testo grigio chiaro (per sfondi scuri)
70
- white: "text-gray-600", # Testo grigio scuro (per sfondi chiari)
71
- red: "text-red-400",
72
- rose: "text-rose-400",
73
- orange: "text-orange-400",
74
- green: "text-green-400",
75
- blue: "text-blue-400",
76
- yellow: "text-yellow-500",
77
- violet: "text-violet-400"
78
- }
79
-
80
- # Temi per divider - LOGICA CORRETTA
81
- HEADING_DIVIDER_THEME_CLASSES = {
82
- default: "border-gray-700", # Bordo grigio scuro (per sfondi scuri)
83
- white: "border-gray-200", # Bordo grigio chiaro (per sfondi chiari)
84
- red: "border-red-200",
85
- rose: "border-rose-200",
86
- orange: "border-orange-200",
87
- green: "border-green-200",
88
- blue: "border-blue-200",
89
- yellow: "border-yellow-200",
90
- violet: "border-violet-200"
91
- }
92
-
93
- # @param level [Integer] livello del heading (1-6)
94
- # @param theme [Symbol] tema del colore (:default, :white, etc.)
95
- # @param align [Symbol] allineamento (:left, :center, :right)
96
- # @param size [Symbol] dimensione (:small, :medium, :large)
97
- # @param style [Symbol] stile (:normal, :bold, :italic, :underline)
98
- # @param icon [String] icona opzionale
99
- # @param subtitle [String] sottotitolo opzionale
100
- # @param with_divider [Boolean] mostra linea divisoria
101
- # @param html_options [Hash] opzioni HTML per il container
102
- def initialize(
103
- level: 2,
104
- theme: :white,
105
- align: :left,
106
- size: :medium,
107
- style: :normal,
108
- icon: nil,
109
- subtitle: nil,
110
- with_divider: false,
111
- **html_options
112
- )
113
- @level = level.to_i.clamp(1, 6)
114
- @theme = theme.to_sym
115
- @align = align.to_sym
116
- @size = size.to_sym
117
- @style = style.to_sym
118
- @icon = icon
119
- @subtitle = subtitle
120
- @with_divider = with_divider
121
- @html_options = html_options
122
-
123
- validate_params
124
- end
125
-
126
- # Combina tutte le classi per il heading
127
- def heading_classes
128
- [
129
- HEADING_BASE_CLASSES,
130
- get_theme_class,
131
- get_align_class,
132
- get_size_class,
133
- get_style_class,
134
- @html_options[:class]
135
- ].compact.join(" ")
136
- end
137
-
138
- # Classi per il container principale
139
- def container_classes
140
- "mb-4"
141
- end
142
-
143
- # Classi per il subtitle
144
- def subtitle_classes
145
- return "" unless @subtitle.present?
146
-
147
- [
148
- "mt-1 text-sm",
149
- get_subtitle_theme_class,
150
- get_align_class
151
- ].compact.join(" ")
152
- end
153
-
154
- # Classi per il divider
155
- def divider_classes
156
- return "" unless @with_divider
157
-
158
- [
159
- "mt-2 border-t",
160
- get_divider_theme_class
161
- ].compact.join(" ")
162
- end
163
-
164
- # Classi per l'icona
165
- def icon_classes
166
- return "" unless @icon.present?
167
- "mr-2 inline-block"
168
- end
169
-
170
- # Restituisce gli attributi HTML per il heading
171
- def heading_attributes
172
- attrs = @html_options.except(:class)
173
- attrs[:class] = heading_classes
174
- attrs
175
- end
176
-
177
- # Tag del heading basato sul level
178
- def heading_tag
179
- "h#{@level}"
180
- end
181
-
182
- # Determina se mostrare l'icona
183
- def show_icon?
184
- @icon.present?
185
- end
186
-
187
- # Determina se mostrare il subtitle
188
- def show_subtitle?
189
- @subtitle.present?
190
- end
191
-
192
- # Determina se mostrare il divider
193
- def show_divider?
194
- @with_divider
195
- end
196
-
197
- private
198
-
199
- def get_theme_class
200
- HEADING_THEME_CLASSES[@theme] || HEADING_THEME_CLASSES[:white]
201
- end
202
-
203
- def get_align_class
204
- HEADING_ALIGN_CLASSES[@align] || HEADING_ALIGN_CLASSES[:left]
205
- end
206
-
207
- def get_size_class
208
- size_map = HEADING_SIZE_CLASSES[@size] || HEADING_SIZE_CLASSES[:medium]
209
- size_map[@level] || size_map[2]
210
- end
211
-
212
- def get_style_class
213
- HEADING_STYLE_CLASSES[@style] || HEADING_STYLE_CLASSES[:normal]
214
- end
215
-
216
- def get_subtitle_theme_class
217
- HEADING_SUBTITLE_THEME_CLASSES[@theme] || HEADING_SUBTITLE_THEME_CLASSES[:white]
218
- end
219
-
220
- def get_divider_theme_class
221
- HEADING_DIVIDER_THEME_CLASSES[@theme] || HEADING_DIVIDER_THEME_CLASSES[:white]
222
- end
223
-
224
- def validate_params
225
- validate_theme
226
- validate_align
227
- validate_size
228
- validate_style
229
- end
230
-
231
- def validate_theme
232
- unless HEADING_THEME_CLASSES.keys.include?(@theme)
233
- raise ArgumentError, "Il tema deve essere uno tra: #{HEADING_THEME_CLASSES.keys.join(', ')}"
234
- end
235
- end
236
-
237
- def validate_align
238
- unless HEADING_ALIGN_CLASSES.keys.include?(@align)
239
- raise ArgumentError, "L'allineamento deve essere uno tra: #{HEADING_ALIGN_CLASSES.keys.join(', ')}"
240
- end
241
- end
242
-
243
- def validate_size
244
- unless HEADING_SIZE_CLASSES.keys.include?(@size)
245
- raise ArgumentError, "La dimensione deve essere una tra: #{HEADING_SIZE_CLASSES.keys.join(', ')}"
246
- end
247
- end
248
-
249
- def validate_style
250
- unless HEADING_STYLE_CLASSES.keys.include?(@style)
251
- raise ArgumentError, "Lo stile deve essere uno tra: #{HEADING_STYLE_CLASSES.keys.join(', ')}"
252
- end
253
- end
254
- end
255
- end
256
- end
257
- end
@@ -1,7 +0,0 @@
1
- <% if href.present? %>
2
- <%= tag.a(**icon_attributes) do %>
3
- <i class="<%= fa_class_name %> <%= icon_classes %>"></i>
4
- <% end %>
5
- <% else %>
6
- <i class="<%= fa_class_name %> <%= icon_classes %>"></i>
7
- <% end %>
@@ -1,240 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Icon
4
- class Component < ViewComponent::Base
5
- # Classi base per l'icona con nomenclatura BEM
6
- ICON_BASE_CLASSES = "bui-icon inline-flex items-center justify-center"
7
-
8
- # Dimensioni dell'icona (standardizzate: small, medium, large)
9
- ICON_SIZE_CLASSES = {
10
- small: "bui-icon--small w-4 h-4 text-sm",
11
- medium: "bui-icon--medium w-5 h-5 text-base",
12
- large: "bui-icon--large w-6 h-6 text-lg",
13
- xlarge: "bui-icon--large w-7 h-7 text-xl"
14
- }.freeze
15
-
16
- # Temi dell'icona con colori coerenti
17
- ICON_THEME_CLASSES = {
18
- default: "bui-icon--default text-gray-600",
19
- white: "bui-icon--white text-white",
20
- red: "bui-icon--red text-red-600",
21
- rose: "bui-icon--rose text-rose-600",
22
- orange: "bui-icon--orange text-orange-600",
23
- green: "bui-icon--green text-green-600",
24
- blue: "bui-icon--blue text-blue-600",
25
- yellow: "bui-icon--yellow text-yellow-600",
26
- violet: "bui-icon--violet text-violet-600",
27
- purple: "bui-icon--purple text-purple-600"
28
- }.freeze
29
-
30
- # Animazioni disponibili
31
- ICON_ANIMATION_CLASSES = {
32
- spin: "bui-icon--spin animate-spin",
33
- pulse: "bui-icon--pulse animate-pulse"
34
- }.freeze
35
-
36
- # Trasformazioni disponibili
37
- ICON_ROTATION_CLASSES = {
38
- 90 => "bui-icon--rotate-90 transform rotate-90",
39
- 180 => "bui-icon--rotate-180 transform rotate-180",
40
- 270 => "bui-icon--rotate-270 transform rotate-270"
41
- }.freeze
42
-
43
- ICON_FLIP_CLASSES = {
44
- horizontal: "bui-icon--flip-h transform scale-x-[-1]",
45
- vertical: "bui-icon--flip-v transform scale-y-[-1]",
46
- both: "bui-icon--flip-both transform scale-[-1]"
47
- }.freeze
48
-
49
- # Bordo e larghezza fissa
50
- ICON_BORDER_CLASSES = "bui-icon--border border border-current rounded-full p-1"
51
- ICON_FIXED_WIDTH_CLASSES = "bui-icon--fixed-width w-5"
52
-
53
- attr_reader :name, :style, :size, :theme, :spin, :pulse, :border, :fixed_width,
54
- :rotation, :flip, :classes, :id, :href, :method, :target, :html_options
55
-
56
- # @param name [String] Nome dell'icona (richiesto)
57
- # @param style [Symbol] Stile dell'icona (:solid, :regular, :brands)
58
- # @param size [Symbol] Dimensione (:small, :medium, :large)
59
- # @param theme [Symbol] Tema colore (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)
60
- # @param spin [Boolean] Rotazione continua
61
- # @param pulse [Boolean] Animazione pulsazione
62
- # @param border [Boolean] Mostra bordo attorno all'icona
63
- # @param fixed_width [Boolean] Larghezza fissa per allineamento
64
- # @param rotation [Integer] Rotazione in gradi (0, 90, 180, 270)
65
- # @param flip [Symbol] Tipo di flip (:horizontal, :vertical, :both)
66
- # @param classes [String] Classi CSS aggiuntive
67
- # @param id [String] ID HTML
68
- # @param href [String] URL per l'icona
69
- # @param html_options [Hash] Attributi HTML aggiuntivi
70
- def initialize(
71
- name:,
72
- style: :solid,
73
- size: :medium,
74
- theme: :default,
75
- spin: false,
76
- pulse: false,
77
- border: false,
78
- fixed_width: false,
79
- rotation: nil,
80
- flip: nil,
81
- classes: nil,
82
- id: nil,
83
- href: nil,
84
- method: nil,
85
- target: nil,
86
- **html_options
87
- )
88
- @name = name
89
- @style = style.to_sym
90
- @size = size.to_sym
91
- @theme = theme.to_sym
92
- @spin = spin
93
- @pulse = pulse
94
- @border = border
95
- @fixed_width = fixed_width
96
- @rotation = rotation&.to_i
97
- @flip = flip&.to_sym
98
- @classes = classes
99
- @id = id
100
- @href = href
101
- @method = method
102
- @target = target
103
- @html_options = html_options
104
-
105
- validate_params!
106
- end
107
-
108
- # Genera le classi CSS complete per l'icona
109
- def icon_classes
110
- classes = [
111
- ICON_BASE_CLASSES,
112
- size_classes,
113
- theme_classes,
114
- animation_classes,
115
- transformation_classes,
116
- border_classes,
117
- fixed_width_classes,
118
- @classes
119
- ].compact.join(" ")
120
- end
121
-
122
- # Attributi HTML per l'elemento icona
123
- def icon_attributes
124
- attrs = {
125
- class: icon_classes,
126
- id: @id,
127
- href: @href,
128
- target: @target,
129
- **@html_options
130
- }.compact
131
-
132
- # Handle method for Turbo
133
- if @method.present?
134
- attrs[:data] ||= {}
135
- attrs[:data][:turbo_method] = @method
136
- end
137
-
138
- attrs
139
- end
140
-
141
- # Nome completo della classe FontAwesome basato su stile
142
- def fa_class_name
143
- prefix = case @style
144
- when :solid then "fas"
145
- when :regular then "far"
146
- when :brands then "fab"
147
- else "fas"
148
- end
149
-
150
- "#{prefix} fa-#{@name}"
151
- end
152
-
153
- # Verifica se il componente deve essere renderizzato
154
- def render?
155
- @name.present?
156
- end
157
-
158
- private
159
-
160
- def validate_params!
161
- validate_name!
162
- validate_style!
163
- validate_size!
164
- validate_theme!
165
- validate_rotation!
166
- validate_flip!
167
- end
168
-
169
- def validate_name!
170
- raise ArgumentError, "Il nome dell'icona è richiesto" if @name.blank?
171
- end
172
-
173
- def validate_style!
174
- valid_styles = [ :solid, :regular, :brands ]
175
- unless valid_styles.include?(@style)
176
- raise ArgumentError, "Lo stile deve essere uno tra: #{valid_styles.join(', ')}"
177
- end
178
- end
179
-
180
- def validate_size!
181
- unless ICON_SIZE_CLASSES.key?(@size)
182
- valid_sizes = ICON_SIZE_CLASSES.keys
183
- raise ArgumentError, "La dimensione deve essere una tra: #{valid_sizes.join(', ')}"
184
- end
185
- end
186
-
187
- def validate_theme!
188
- unless ICON_THEME_CLASSES.key?(@theme)
189
- valid_themes = ICON_THEME_CLASSES.keys
190
- raise ArgumentError, "Il tema deve essere uno tra: #{valid_themes.join(', ')}"
191
- end
192
- end
193
-
194
- def validate_rotation!
195
- if @rotation && !ICON_ROTATION_CLASSES.key?(@rotation)
196
- valid_rotations = ICON_ROTATION_CLASSES.keys
197
- raise ArgumentError, "La rotazione deve essere una tra: #{valid_rotations.join(', ')}"
198
- end
199
- end
200
-
201
- def validate_flip!
202
- if @flip && !ICON_FLIP_CLASSES.key?(@flip)
203
- valid_flips = ICON_FLIP_CLASSES.keys
204
- raise ArgumentError, "Il flip deve essere uno tra: #{valid_flips.join(', ')}"
205
- end
206
- end
207
-
208
- def size_classes
209
- ICON_SIZE_CLASSES[@size]
210
- end
211
-
212
- def theme_classes
213
- ICON_THEME_CLASSES[@theme]
214
- end
215
-
216
- def animation_classes
217
- animations = []
218
- animations << ICON_ANIMATION_CLASSES[:spin] if @spin
219
- animations << ICON_ANIMATION_CLASSES[:pulse] if @pulse
220
- animations.join(" ")
221
- end
222
-
223
- def transformation_classes
224
- transformations = []
225
- transformations << ICON_ROTATION_CLASSES[@rotation] if @rotation
226
- transformations << ICON_FLIP_CLASSES[@flip] if @flip
227
- transformations.join(" ")
228
- end
229
-
230
- def border_classes
231
- @border ? ICON_BORDER_CLASSES : nil
232
- end
233
-
234
- def fixed_width_classes
235
- @fixed_width ? ICON_FIXED_WIDTH_CLASSES : nil
236
- end
237
- end
238
- end
239
- end
240
- end
@@ -1,5 +0,0 @@
1
- <% if @label.present? %>
2
- <%= render_checkbox_with_label %>
3
- <% else %>
4
- <%= input_tag %>
5
- <% end %>