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,187 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Breadcrumb
4
- class Component < ViewComponent::Base
5
- attr_reader :items, :separator, :size, :theme, :classes, :html_options
6
-
7
- # Classi base sempre presenti
8
- BREADCRUMB_BASE_CLASSES = "flex items-center flex-wrap"
9
-
10
- # Classi per lista e items
11
- BREADCRUMB_LIST_CLASSES = "flex flex-wrap items-center"
12
- BREADCRUMB_ITEM_CLASSES = "flex items-center"
13
-
14
- # Temi di breadcrumb con classi Tailwind dirette
15
- BREADCRUMB_THEME_CLASSES = {
16
- default: "text-white",
17
- white: "text-black",
18
- red: "text-white",
19
- rose: "text-white",
20
- orange: "text-white",
21
- green: "text-white",
22
- blue: "text-white",
23
- yellow: "text-black",
24
- violet: "text-white",
25
- gray: "text-gray-900"
26
- }
27
-
28
- # Classi per separatori con temi
29
- BREADCRUMB_SEPARATOR_THEME_CLASSES = {
30
- default: "text-gray-500",
31
- white: "text-gray-400",
32
- red: "text-red-300",
33
- rose: "text-rose-300",
34
- orange: "text-orange-300",
35
- green: "text-green-300",
36
- blue: "text-blue-300",
37
- yellow: "text-yellow-600",
38
- violet: "text-violet-300",
39
- gray: "text-gray-500"
40
- }
41
-
42
- # Dimensioni con classi Tailwind dirette
43
- BREADCRUMB_SIZE_CLASSES = {
44
- extra_small: "text-[0.65rem]",
45
- small: "text-xs",
46
- medium: "text-sm",
47
- large: "text-base"
48
- }
49
-
50
- # Separatori predefiniti
51
- BREADCRUMB_SEPARATOR_TYPES = {
52
- slash: "/",
53
- chevron: "›",
54
- arrow: "→",
55
- dot: "•",
56
- pipe: "|"
57
- }
58
-
59
- # Inizializzazione del componente
60
- def initialize(
61
- items: [],
62
- separator: :chevron,
63
- theme: :white,
64
- size: :medium,
65
- classes: nil,
66
- **html_options
67
- )
68
- @items = items || []
69
- @separator = separator.to_sym
70
- @theme = theme.to_sym
71
- @size = size.to_sym
72
- @classes = classes
73
- @html_options = html_options
74
-
75
- validate_params
76
- end
77
-
78
- # Restituisce il separatore come stringa
79
- def separator_text
80
- if BREADCRUMB_SEPARATOR_TYPES.key?(@separator)
81
- BREADCRUMB_SEPARATOR_TYPES[@separator]
82
- else
83
- @separator.to_s
84
- end
85
- end
86
-
87
- # Genera le classi per il container
88
- def container_classes
89
- [
90
- BREADCRUMB_BASE_CLASSES,
91
- get_theme_class,
92
- get_size_class,
93
- @classes,
94
- @html_options[:class]
95
- ].compact.join(" ")
96
- end
97
-
98
- # Verifica se un item è l'ultimo (attivo)
99
- def last_item?(index)
100
- index == @items.length - 1
101
- end
102
-
103
- # Crea un componente link per l'item
104
- def link_for_item(item, active: false)
105
- label = item.is_a?(Hash) ? item[:label] : item.to_s
106
- href = item.is_a?(Hash) ? item[:url] : nil
107
- icon = item.is_a?(Hash) ? item[:icon] : nil
108
-
109
- BetterUi::General::Link::Component.new(
110
- label: label,
111
- href: href,
112
- theme: @theme,
113
- size: @size,
114
- icon: icon,
115
- active: active
116
- )
117
- end
118
-
119
- # Restituisce gli attributi per il breadcrumb
120
- def breadcrumb_attributes
121
- attrs = {
122
- "aria-label": "Breadcrumb",
123
- class: container_classes
124
- }
125
-
126
- # Aggiungi altri attributi HTML se presenti
127
- @html_options.except(:class).each do |key, value|
128
- attrs[key] = value
129
- end
130
-
131
- attrs
132
- end
133
-
134
- # Restituisce le classi CSS per il separatore
135
- def separator_classes
136
- [
137
- "mx-2",
138
- get_separator_theme_class
139
- ].compact.join(" ")
140
- end
141
-
142
- def get_separator_theme_class
143
- BREADCRUMB_SEPARATOR_THEME_CLASSES[@theme] || BREADCRUMB_SEPARATOR_THEME_CLASSES[:white]
144
- end
145
-
146
- # Verifica se rendere il componente
147
- def render?
148
- @items.present? && @items.length > 0
149
- end
150
-
151
- private
152
-
153
- def get_theme_class
154
- BREADCRUMB_THEME_CLASSES[@theme] || BREADCRUMB_THEME_CLASSES[:white]
155
- end
156
-
157
- def get_size_class
158
- BREADCRUMB_SIZE_CLASSES[@size] || BREADCRUMB_SIZE_CLASSES[:medium]
159
- end
160
-
161
- def validate_params
162
- validate_theme
163
- validate_size
164
- validate_separator
165
- end
166
-
167
- def validate_theme
168
- unless BREADCRUMB_THEME_CLASSES.keys.include?(@theme)
169
- raise ArgumentError, "Il tema deve essere uno tra: #{BREADCRUMB_THEME_CLASSES.keys.join(', ')}"
170
- end
171
- end
172
-
173
- def validate_size
174
- unless BREADCRUMB_SIZE_CLASSES.keys.include?(@size)
175
- raise ArgumentError, "La dimensione deve essere una tra: #{BREADCRUMB_SIZE_CLASSES.keys.join(', ')}"
176
- end
177
- end
178
-
179
- def validate_separator
180
- return if !@separator.is_a?(Symbol) || BREADCRUMB_SEPARATOR_TYPES.keys.include?(@separator)
181
-
182
- raise ArgumentError, "Il separatore predefinito deve essere uno tra: #{BREADCRUMB_SEPARATOR_TYPES.keys.join(', ')}"
183
- end
184
- end
185
- end
186
- end
187
- end
@@ -1,34 +0,0 @@
1
- <%# Template per il bottone %>
2
- <% if link? %>
3
- <%= link_to @href, **link_attributes do %>
4
- <% if @icon && @icon_position == :left %>
5
- <span class="flex-shrink-0<%= @text.present? ? ' mr-2' : '' %>"><%= render_icon(@icon) %></span>
6
- <% end %>
7
-
8
- <% if @text %>
9
- <span class="flex-grow"><%= @text %></span>
10
- <% end %>
11
-
12
- <% if @icon && @icon_position == :right %>
13
- <span class="flex-shrink-0<%= @text.present? ? ' ml-2' : '' %>"><%= render_icon(@icon) %></span>
14
- <% end %>
15
-
16
- <%= content %>
17
- <% end %>
18
- <% else %>
19
- <%= tag.button(**button_attributes) do %>
20
- <% if @icon && @icon_position == :left %>
21
- <span class="flex-shrink-0<%= @text.present? ? ' mr-2' : '' %>"><%= render_icon(@icon) %></span>
22
- <% end %>
23
-
24
- <% if @text %>
25
- <span class="flex-grow"><%= @text %></span>
26
- <% end %>
27
-
28
- <% if @icon && @icon_position == :right %>
29
- <span class="flex-shrink-0<%= @text.present? ? ' ml-2' : '' %>"><%= render_icon(@icon) %></span>
30
- <% end %>
31
-
32
- <%= content %>
33
- <% end %>
34
- <% end %>
@@ -1,214 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Button
4
- class Component < ViewComponent::Base
5
- attr_reader :text, :theme, :size, :full_width, :disabled,
6
- :icon, :icon_position, :href, :method, :data, :classes, :id, :rounded, :button_type, :html_options
7
-
8
- # Classi base sempre presenti
9
- BUTTON_BASE_CLASSES = "inline-flex items-center justify-center font-medium transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2"
10
-
11
- # Temi di bottoni con classi Tailwind dirette
12
- BUTTON_THEME = {
13
- default: "bg-black text-white hover:bg-gray-900 focus:ring-gray-900",
14
- white: "bg-white text-black border border-gray-300 hover:bg-gray-50 focus:ring-gray-400",
15
- red: "bg-red-500 text-white hover:bg-red-600 focus:ring-red-500",
16
- rose: "bg-rose-500 text-white hover:bg-rose-600 focus:ring-rose-500",
17
- orange: "bg-orange-500 text-white hover:bg-orange-600 focus:ring-orange-500",
18
- green: "bg-green-500 text-white hover:bg-green-600 focus:ring-green-500",
19
- blue: "bg-blue-500 text-white hover:bg-blue-600 focus:ring-blue-500",
20
- yellow: "bg-yellow-500 text-black hover:bg-yellow-600 focus:ring-yellow-500",
21
- violet: "bg-violet-500 text-white hover:bg-violet-600 focus:ring-violet-500",
22
- purple: "bg-purple-500 text-white hover:bg-purple-600 focus:ring-purple-500"
23
- }
24
-
25
- # Dimensioni con classi Tailwind dirette
26
- BUTTON_SIZES = {
27
- small: "px-2.5 py-1.5 text-xs",
28
- medium: "px-4 py-2 text-sm",
29
- large: "px-6 py-3 text-base"
30
- }
31
-
32
- # Border radius con classi Tailwind dirette
33
- BUTTON_RADIUS = {
34
- none: "rounded-none",
35
- small: "rounded-md",
36
- medium: "rounded-lg",
37
- large: "rounded-xl",
38
- full: "rounded-full"
39
- }
40
-
41
- # Inizializzazione del componente
42
- def initialize(
43
- text: nil,
44
- theme: :white,
45
- size: :medium,
46
- full_width: false,
47
- disabled: false,
48
- icon: nil,
49
- icon_position: :left,
50
- href: nil,
51
- method: nil,
52
- data: {},
53
- classes: nil,
54
- id: nil,
55
- rounded: :medium,
56
- button_type: :button,
57
- **html_options
58
- )
59
- @text = text
60
- @theme = theme.to_sym
61
- @size = size.to_sym
62
- @full_width = full_width
63
- @disabled = disabled
64
- @icon = icon
65
- @icon_position = icon_position.to_sym
66
- @href = href
67
- @method = method
68
- @data = data
69
- @classes = classes
70
- @id = id
71
- @rounded = rounded.to_sym
72
- @button_type = button_type.to_sym
73
- @html_options = html_options
74
-
75
- validate_params
76
- end
77
-
78
- # Determina se il bottone è un link o un button
79
- def link?
80
- @href.present?
81
- end
82
-
83
- # Combina tutte le classi
84
- def combined_classes
85
- [
86
- BUTTON_BASE_CLASSES,
87
- get_button_type_classes,
88
- get_button_size_classes,
89
- get_border_radius_class,
90
- @full_width ? "w-full" : nil,
91
- @disabled ? "opacity-50 cursor-not-allowed" : nil,
92
- @classes,
93
- @html_options[:class]
94
- ].compact.join(" ")
95
- end
96
-
97
- def get_button_type_classes
98
- BUTTON_THEME[@theme] || BUTTON_THEME[:white]
99
- end
100
-
101
- def get_border_radius_class
102
- BUTTON_RADIUS[@rounded] || BUTTON_RADIUS[:medium]
103
- end
104
-
105
- def get_button_size_classes
106
- BUTTON_SIZES[@size] || BUTTON_SIZES[:medium]
107
- end
108
-
109
- # Restituisce gli attributi per il bottone
110
- def button_attributes
111
- attrs = {
112
- class: combined_classes,
113
- type: button_type,
114
- id: @id
115
- }
116
-
117
- attrs[:disabled] = true if @disabled
118
- attrs[:data] = @data if @data.present?
119
-
120
- # Aggiungi altri attributi HTML se presenti
121
- @html_options.except(:class).each do |key, value|
122
- attrs[key] = value
123
- end
124
-
125
- attrs
126
- end
127
-
128
- # Restituisce gli attributi per il link
129
- def link_attributes
130
- attrs = {
131
- class: combined_classes,
132
- id: @id
133
- }
134
-
135
- attrs[:data] = @data.merge(turbo_method: @method) if @method.present?
136
- attrs[:data] = @data if @data.present? && !@method.present?
137
- attrs[:href] = @disabled ? nil : @href
138
- attrs[:role] = "button"
139
- attrs[:tabindex] = @disabled ? "-1" : "0"
140
- attrs[:aria] = { disabled: @disabled } if @disabled
141
-
142
- # Aggiungi altri attributi HTML se presenti
143
- @html_options.except(:class).each do |key, value|
144
- attrs[key] = value
145
- end
146
-
147
- attrs
148
- end
149
-
150
- def button_type
151
- @button_type || "button"
152
- end
153
-
154
- # Helper per renderizzare le icone
155
- def render_icon(icon_name)
156
- # Mappa le dimensioni del bottone alle dimensioni dell'icona
157
- icon_size = case @size
158
- when :large
159
- :large
160
- when :small
161
- :small
162
- else
163
- :medium
164
- end
165
-
166
- # Utilizziamo il componente Icon
167
- render BetterUi::General::Icon::Component.new(
168
- name: icon_name,
169
- size: icon_size,
170
- fixed_width: true
171
- )
172
- end
173
-
174
- # Verifica se rendere il componente
175
- def render?
176
- @text.present? || @icon.present? || content.present?
177
- end
178
-
179
- private
180
-
181
- def validate_params
182
- validate_theme
183
- validate_size
184
- validate_icon_position
185
- validate_rounded
186
- end
187
-
188
- def validate_theme
189
- unless BUTTON_THEME.keys.include?(@theme)
190
- raise ArgumentError, "Il tema deve essere uno tra: #{BUTTON_THEME.keys.join(', ')}"
191
- end
192
- end
193
-
194
- def validate_size
195
- unless BUTTON_SIZES.keys.include?(@size)
196
- raise ArgumentError, "La dimensione deve essere una tra: #{BUTTON_SIZES.keys.join(', ')}"
197
- end
198
- end
199
-
200
- def validate_icon_position
201
- unless [ :left, :right ].include?(@icon_position)
202
- raise ArgumentError, "La posizione dell'icona deve essere :left o :right"
203
- end
204
- end
205
-
206
- def validate_rounded
207
- unless BUTTON_RADIUS.keys.include?(@rounded)
208
- raise ArgumentError, "Il bordo deve essere uno tra: #{BUTTON_RADIUS.keys.join(', ')}"
209
- end
210
- end
211
- end
212
- end
213
- end
214
- end
@@ -1,10 +0,0 @@
1
- <%# Template per il divider %>
2
- <% if show_label? %>
3
- <%= tag.div(**divider_attributes) do %>
4
- <div class="<%= label_line_classes %>"></div>
5
- <span class="<%= label_classes %>"><%= @label %></span>
6
- <div class="<%= label_line_classes %>"></div>
7
- <% end %>
8
- <% else %>
9
- <%= tag.div(**divider_attributes) %>
10
- <% end %>
@@ -1,226 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Divider
4
- class Component < ViewComponent::Base
5
- attr_reader :theme, :orientation, :style, :size, :label, :height, :classes
6
-
7
- # Classi base sempre presenti
8
- DIVIDER_BASE_CLASSES = "my-4"
9
-
10
- # Temi con classi Tailwind dirette - LOGICA CORRETTA
11
- DIVIDER_THEME_CLASSES = {
12
- default: "border-white", # Bordo bianco (per sfondi scuri)
13
- white: "border-gray-300", # Bordo grigio (per sfondi chiari)
14
- red: "border-red-500",
15
- rose: "border-rose-500",
16
- orange: "border-orange-500",
17
- green: "border-green-500",
18
- blue: "border-blue-500",
19
- yellow: "border-yellow-500",
20
- violet: "border-violet-500"
21
- }
22
-
23
- # Orientamento con classi Tailwind dirette
24
- DIVIDER_ORIENTATION_CLASSES = {
25
- horizontal: "w-full border-t",
26
- vertical: "h-full border-l"
27
- }
28
-
29
- # Stili di linea con classi Tailwind dirette
30
- DIVIDER_STYLE_CLASSES = {
31
- solid: "border-solid",
32
- dashed: "border-dashed",
33
- dotted: "border-dotted",
34
- double: "border-double"
35
- }
36
-
37
- # Dimensioni con classi Tailwind dirette
38
- DIVIDER_SIZE_CLASSES = {
39
- thin: {
40
- horizontal: "border-t",
41
- vertical: "border-l"
42
- },
43
- medium: {
44
- horizontal: "border-t-2",
45
- vertical: "border-l-2"
46
- },
47
- thick: {
48
- horizontal: "border-t-4",
49
- vertical: "border-l-4"
50
- }
51
- }
52
-
53
- # Classi per label con classi Tailwind dirette - LOGICA CORRETTA
54
- DIVIDER_LABEL_THEME_CLASSES = {
55
- default: "text-white bg-transparent px-3", # Testo bianco trasparente (per sfondi scuri)
56
- white: "text-gray-900 bg-white px-3", # Testo nero su bianco (per sfondi chiari)
57
- red: "text-red-500 bg-white px-3",
58
- rose: "text-rose-500 bg-white px-3",
59
- orange: "text-orange-500 bg-white px-3",
60
- green: "text-green-500 bg-white px-3",
61
- blue: "text-blue-500 bg-white px-3",
62
- yellow: "text-yellow-600 bg-white px-3",
63
- violet: "text-violet-500 bg-white px-3"
64
- }
65
-
66
- # @param theme [Symbol] tema del divider (:default, :white, etc.)
67
- # @param orientation [Symbol] orientamento del divider (:horizontal, :vertical)
68
- # @param style [Symbol] stile della linea (:solid, :dashed, :dotted, :double)
69
- # @param size [Symbol] dimensione della linea (:thin, :medium, :thick)
70
- # @param label [String] testo opzionale da mostrare al centro del divider
71
- # @param height [String] altezza per divider verticale (es. "100px", "100%")
72
- # @param classes [String] classi CSS aggiuntive
73
- # @param html_options [Hash] opzioni HTML per il container
74
- def initialize(
75
- theme: :white,
76
- orientation: :horizontal,
77
- style: :solid,
78
- size: :medium,
79
- label: nil,
80
- height: nil,
81
- classes: nil,
82
- **html_options
83
- )
84
- @theme = theme.to_sym
85
- @orientation = orientation.to_sym
86
- @style = style.to_sym
87
- @size = size.to_sym
88
- @label = label
89
- @height = height
90
- @classes = classes
91
- @html_options = html_options
92
-
93
- validate_params
94
- end
95
-
96
- # Combina tutte le classi per il container
97
- def combined_classes
98
- base_classes = []
99
-
100
- if @label.present? && @orientation == :horizontal
101
- # Per divider con label orizzontale: flex layout
102
- base_classes = [
103
- "flex items-center text-center",
104
- get_theme_class,
105
- get_style_class
106
- ]
107
- else
108
- # Per divider normale
109
- base_classes = [
110
- DIVIDER_BASE_CLASSES,
111
- get_orientation_class,
112
- get_theme_class,
113
- get_style_class,
114
- get_size_class
115
- ]
116
- end
117
-
118
- [ *base_classes, @classes, @html_options[:class] ].compact.join(" ")
119
- end
120
-
121
- # Classi per il label
122
- def label_classes
123
- return "" unless @label.present?
124
-
125
- [
126
- "relative z-10 text-sm font-medium",
127
- get_label_theme_class
128
- ].compact.join(" ")
129
- end
130
-
131
- # Classi per le linee before/after quando c'è un label
132
- def label_line_classes
133
- return "" unless @label.present? && @orientation == :horizontal
134
-
135
- [
136
- "flex-1 h-px",
137
- get_theme_class,
138
- get_style_class
139
- ].compact.join(" ")
140
- end
141
-
142
- # Genera gli attributi di stile inline necessari
143
- def inline_styles
144
- return nil unless @orientation == :vertical && @height.present?
145
- "height: #{@height};"
146
- end
147
-
148
- # Restituisce gli attributi per il divider
149
- def divider_attributes
150
- attrs = {
151
- class: combined_classes
152
- }
153
-
154
- # Aggiungi stile inline se presente
155
- attrs[:style] = inline_styles if inline_styles.present?
156
-
157
- # Aggiungi altri attributi HTML se presenti
158
- @html_options.except(:class).each do |key, value|
159
- attrs[key] = value
160
- end
161
-
162
- attrs
163
- end
164
-
165
- # Determina se mostrare il label
166
- def show_label?
167
- @label.present? && @orientation == :horizontal
168
- end
169
-
170
- private
171
-
172
- def get_theme_class
173
- DIVIDER_THEME_CLASSES[@theme] || DIVIDER_THEME_CLASSES[:white]
174
- end
175
-
176
- def get_orientation_class
177
- DIVIDER_ORIENTATION_CLASSES[@orientation] || DIVIDER_ORIENTATION_CLASSES[:horizontal]
178
- end
179
-
180
- def get_style_class
181
- DIVIDER_STYLE_CLASSES[@style] || DIVIDER_STYLE_CLASSES[:solid]
182
- end
183
-
184
- def get_size_class
185
- size_map = DIVIDER_SIZE_CLASSES[@size] || DIVIDER_SIZE_CLASSES[:medium]
186
- size_map[@orientation] || size_map[:horizontal]
187
- end
188
-
189
- def get_label_theme_class
190
- DIVIDER_LABEL_THEME_CLASSES[@theme] || DIVIDER_LABEL_THEME_CLASSES[:white]
191
- end
192
-
193
- def validate_params
194
- validate_theme
195
- validate_orientation
196
- validate_style
197
- validate_size
198
- end
199
-
200
- def validate_theme
201
- unless DIVIDER_THEME_CLASSES.keys.include?(@theme)
202
- raise ArgumentError, "Il tema deve essere uno tra: #{DIVIDER_THEME_CLASSES.keys.join(', ')}"
203
- end
204
- end
205
-
206
- def validate_orientation
207
- unless DIVIDER_ORIENTATION_CLASSES.keys.include?(@orientation)
208
- raise ArgumentError, "L'orientamento deve essere uno tra: #{DIVIDER_ORIENTATION_CLASSES.keys.join(', ')}"
209
- end
210
- end
211
-
212
- def validate_style
213
- unless DIVIDER_STYLE_CLASSES.keys.include?(@style)
214
- raise ArgumentError, "Lo stile deve essere uno tra: #{DIVIDER_STYLE_CLASSES.keys.join(', ')}"
215
- end
216
- end
217
-
218
- def validate_size
219
- unless DIVIDER_SIZE_CLASSES.keys.include?(@size)
220
- raise ArgumentError, "La dimensione deve essere una tra: #{DIVIDER_SIZE_CLASSES.keys.join(', ')}"
221
- end
222
- end
223
- end
224
- end
225
- end
226
- end
@@ -1,28 +0,0 @@
1
- <div class="relative <%= @classes %> <%= fullwidth_classes %>"
2
- data-controller="bui-dropdown"
3
- data-bui-dropdown-open-value="false"
4
- data-bui-dropdown-selectable-value="<%= @selectable.to_s %>"
5
- <%= tag.attributes(@html_options.except(:class)) %>>
6
-
7
- <button type="button"
8
- class="items-center border font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors <%= dynamic_trigger_classes %> <%= fullwidth_classes %>"
9
- data-bui-dropdown-target="trigger"
10
- data-action="click->bui-dropdown#toggle keydown->bui-dropdown#keydown"
11
- aria-expanded="false"
12
- aria-haspopup="true">
13
- <%= @trigger %>
14
- <% if @show_chevron %>
15
- <%= bui_icon("chevron-down", size: :small, classes: "ml-2 -mr-1") %>
16
- <% end %>
17
- </button>
18
-
19
- <div class="absolute z-[1000] my-2 origin-top-right bg-white border border-gray-200 shadow-lg focus:outline-none <%= dynamic_menu_classes %> <%= fullwidth_classes %>"
20
- data-bui-dropdown-target="menu"
21
- role="menu"
22
- aria-orientation="vertical"
23
- style="display: none;">
24
- <div class="py-1" role="none" data-action="click->bui-dropdown#itemClick">
25
- <%= content %>
26
- </div>
27
- </div>
28
- </div>