better_ui 0.3.0 → 0.7.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 (183) 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 -51
  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 -4
  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 +52 -185
  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 -227
  53. data/app/components/better_ui/application/sidebar/component.rb +0 -130
  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 -25
  71. data/app/components/better_ui/general/dropdown/component.rb +0 -170
  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/heading/component.html.erb +0 -22
  79. data/app/components/better_ui/general/heading/component.rb +0 -257
  80. data/app/components/better_ui/general/icon/component.html.erb +0 -7
  81. data/app/components/better_ui/general/icon/component.rb +0 -239
  82. data/app/components/better_ui/general/input/checkbox/component.html.erb +0 -5
  83. data/app/components/better_ui/general/input/checkbox/component.rb +0 -238
  84. data/app/components/better_ui/general/input/datetime/component.html.erb +0 -5
  85. data/app/components/better_ui/general/input/datetime/component.rb +0 -223
  86. data/app/components/better_ui/general/input/radio/component.html.erb +0 -5
  87. data/app/components/better_ui/general/input/radio/component.rb +0 -230
  88. data/app/components/better_ui/general/input/select/component.html.erb +0 -16
  89. data/app/components/better_ui/general/input/select/component.rb +0 -184
  90. data/app/components/better_ui/general/input/select/select_component.html.erb +0 -5
  91. data/app/components/better_ui/general/input/select/select_component.rb +0 -37
  92. data/app/components/better_ui/general/input/text/component.html.erb +0 -5
  93. data/app/components/better_ui/general/input/text/component.rb +0 -171
  94. data/app/components/better_ui/general/input/textarea/component.html.erb +0 -5
  95. data/app/components/better_ui/general/input/textarea/component.rb +0 -166
  96. data/app/components/better_ui/general/link/component.html.erb +0 -18
  97. data/app/components/better_ui/general/link/component.rb +0 -258
  98. data/app/components/better_ui/general/modal/component.html.erb +0 -5
  99. data/app/components/better_ui/general/modal/component.rb +0 -47
  100. data/app/components/better_ui/general/modal/modal_component.html.erb +0 -52
  101. data/app/components/better_ui/general/modal/modal_component.rb +0 -160
  102. data/app/components/better_ui/general/pagination/component.html.erb +0 -85
  103. data/app/components/better_ui/general/pagination/component.rb +0 -216
  104. data/app/components/better_ui/general/panel/component.html.erb +0 -28
  105. data/app/components/better_ui/general/panel/component.rb +0 -249
  106. data/app/components/better_ui/general/progress/component.html.erb +0 -11
  107. data/app/components/better_ui/general/progress/component.rb +0 -160
  108. data/app/components/better_ui/general/spinner/component.html.erb +0 -35
  109. data/app/components/better_ui/general/spinner/component.rb +0 -93
  110. data/app/components/better_ui/general/table/component.html.erb +0 -5
  111. data/app/components/better_ui/general/table/component.rb +0 -217
  112. data/app/components/better_ui/general/table/tbody_component.html.erb +0 -3
  113. data/app/components/better_ui/general/table/tbody_component.rb +0 -30
  114. data/app/components/better_ui/general/table/td_component.html.erb +0 -3
  115. data/app/components/better_ui/general/table/td_component.rb +0 -44
  116. data/app/components/better_ui/general/table/tfoot_component.html.erb +0 -3
  117. data/app/components/better_ui/general/table/tfoot_component.rb +0 -28
  118. data/app/components/better_ui/general/table/th_component.html.erb +0 -6
  119. data/app/components/better_ui/general/table/th_component.rb +0 -51
  120. data/app/components/better_ui/general/table/thead_component.html.erb +0 -3
  121. data/app/components/better_ui/general/table/thead_component.rb +0 -28
  122. data/app/components/better_ui/general/table/tr_component.html.erb +0 -3
  123. data/app/components/better_ui/general/table/tr_component.rb +0 -30
  124. data/app/components/better_ui/general/tabs/component.html.erb +0 -11
  125. data/app/components/better_ui/general/tabs/component.rb +0 -120
  126. data/app/components/better_ui/general/tabs/panel_component.html.erb +0 -3
  127. data/app/components/better_ui/general/tabs/panel_component.rb +0 -37
  128. data/app/components/better_ui/general/tabs/tab_component.html.erb +0 -13
  129. data/app/components/better_ui/general/tabs/tab_component.rb +0 -111
  130. data/app/components/better_ui/general/tag/component.html.erb +0 -3
  131. data/app/components/better_ui/general/tag/component.rb +0 -104
  132. data/app/components/better_ui/general/tooltip/component.html.erb +0 -7
  133. data/app/components/better_ui/general/tooltip/component.rb +0 -239
  134. data/app/helpers/better_ui/application/components/card/card_helper.rb +0 -96
  135. data/app/helpers/better_ui/application/components/card.rb +0 -11
  136. data/app/helpers/better_ui/application/components/main/main_helper.rb +0 -64
  137. data/app/helpers/better_ui/application/components/navbar/navbar_helper.rb +0 -77
  138. data/app/helpers/better_ui/application/components/sidebar/sidebar_helper.rb +0 -51
  139. data/app/helpers/better_ui/general/components/accordion/accordion_helper.rb +0 -73
  140. data/app/helpers/better_ui/general/components/accordion.rb +0 -11
  141. data/app/helpers/better_ui/general/components/alert/alert_helper.rb +0 -57
  142. data/app/helpers/better_ui/general/components/avatar/avatar_helper.rb +0 -29
  143. data/app/helpers/better_ui/general/components/badge/badge_helper.rb +0 -53
  144. data/app/helpers/better_ui/general/components/breadcrumb/breadcrumb_helper.rb +0 -37
  145. data/app/helpers/better_ui/general/components/button/button_helper.rb +0 -65
  146. data/app/helpers/better_ui/general/components/container/container_helper.rb +0 -60
  147. data/app/helpers/better_ui/general/components/divider/divider_helper.rb +0 -63
  148. data/app/helpers/better_ui/general/components/dropdown/divider_helper.rb +0 -32
  149. data/app/helpers/better_ui/general/components/dropdown/dropdown_helper.rb +0 -79
  150. data/app/helpers/better_ui/general/components/dropdown/item_helper.rb +0 -62
  151. data/app/helpers/better_ui/general/components/field/field_helper.rb +0 -26
  152. data/app/helpers/better_ui/general/components/heading/heading_helper.rb +0 -72
  153. data/app/helpers/better_ui/general/components/icon/icon_helper.rb +0 -16
  154. data/app/helpers/better_ui/general/components/input/checkbox/checkbox_helper.rb +0 -81
  155. data/app/helpers/better_ui/general/components/input/datetime/datetime_helper.rb +0 -91
  156. data/app/helpers/better_ui/general/components/input/radio/radio_helper.rb +0 -79
  157. data/app/helpers/better_ui/general/components/input/radio_group/radio_group_helper.rb +0 -124
  158. data/app/helpers/better_ui/general/components/input/select/select_helper.rb +0 -70
  159. data/app/helpers/better_ui/general/components/input/text/text_helper.rb +0 -138
  160. data/app/helpers/better_ui/general/components/input/textarea/textarea_helper.rb +0 -73
  161. data/app/helpers/better_ui/general/components/link/link_helper.rb +0 -89
  162. data/app/helpers/better_ui/general/components/modal/modal_helper.rb +0 -85
  163. data/app/helpers/better_ui/general/components/modal.rb +0 -11
  164. data/app/helpers/better_ui/general/components/pagination/pagination_helper.rb +0 -82
  165. data/app/helpers/better_ui/general/components/panel/panel_helper.rb +0 -83
  166. data/app/helpers/better_ui/general/components/progress/progress_helper.rb +0 -53
  167. data/app/helpers/better_ui/general/components/spinner/spinner_helper.rb +0 -19
  168. data/app/helpers/better_ui/general/components/table/table_helper.rb +0 -53
  169. data/app/helpers/better_ui/general/components/table/tbody_helper.rb +0 -13
  170. data/app/helpers/better_ui/general/components/table/td_helper.rb +0 -19
  171. data/app/helpers/better_ui/general/components/table/tfoot_helper.rb +0 -13
  172. data/app/helpers/better_ui/general/components/table/th_helper.rb +0 -19
  173. data/app/helpers/better_ui/general/components/table/thead_helper.rb +0 -13
  174. data/app/helpers/better_ui/general/components/table/tr_helper.rb +0 -13
  175. data/app/helpers/better_ui/general/components/tabs/panel_helper.rb +0 -62
  176. data/app/helpers/better_ui/general/components/tabs/tab_helper.rb +0 -55
  177. data/app/helpers/better_ui/general/components/tabs/tabs_helper.rb +0 -95
  178. data/app/helpers/better_ui/general/components/tag/tag_helper.rb +0 -26
  179. data/app/helpers/better_ui/general/components/tooltip/tooltip_helper.rb +0 -60
  180. data/app/jobs/better_ui/application_job.rb +0 -4
  181. data/app/mailers/better_ui/application_mailer.rb +0 -6
  182. data/config/initializers/lookbook.rb +0 -23
  183. data/lib/better_ui/railtie.rb +0 -20
@@ -1,258 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Link
4
- class Component < ViewComponent::Base
5
- attr_reader :label, :href, :theme, :orientation, :style, :size, :icon, :active, :disabled, :data, :method, :target
6
-
7
- # Classi base sempre presenti
8
- LINK_BASE_CLASSES = "transition-colors duration-200 no-underline"
9
-
10
- # Temi con classi Tailwind dirette - LOGICA CORRETTA
11
- LINK_THEME_CLASSES = {
12
- default: "text-white hover:text-gray-300", # Bianco per sfondi scuri
13
- white: "text-gray-900 hover:text-gray-700", # Nero per sfondi chiari
14
- red: "text-red-500 hover:text-red-600",
15
- rose: "text-rose-500 hover:text-rose-600",
16
- orange: "text-orange-500 hover:text-orange-600",
17
- green: "text-green-500 hover:text-green-600",
18
- blue: "text-blue-500 hover:text-blue-600",
19
- yellow: "text-yellow-600 hover:text-yellow-700",
20
- violet: "text-violet-500 hover:text-violet-600"
21
- }
22
-
23
- # Orientamenti con classi Tailwind dirette
24
- LINK_ORIENTATION_CLASSES = {
25
- horizontal: "inline-flex items-center",
26
- vertical: "flex flex-col items-center"
27
- }
28
-
29
- # Stili con classi Tailwind dirette
30
- LINK_STYLE_CLASSES = {
31
- default: "",
32
- underline: "underline",
33
- bold: "font-bold",
34
- text: "no-underline"
35
- }
36
-
37
- # Dimensioni con classi Tailwind dirette
38
- LINK_SIZE_CLASSES = {
39
- extra_small: "text-[0.65rem]",
40
- small: "text-sm",
41
- medium: "text-base",
42
- large: "text-lg"
43
- }
44
-
45
- # Stati con classi Tailwind dirette
46
- LINK_STATE_CLASSES = {
47
- normal: "",
48
- active: "font-semibold",
49
- disabled: "opacity-50 cursor-not-allowed pointer-events-none"
50
- }
51
-
52
- # @param label [String] testo del link
53
- # @param href [String] URL di destinazione (nil per semplice testo)
54
- # @param theme [Symbol] tema del colore (:default, :white, etc.)
55
- # @param orientation [Symbol] orientamento (:horizontal, :vertical)
56
- # @param style [Symbol] stile (:default, :underline, :bold, :text)
57
- # @param size [Symbol] dimensione (:extra_small, :small, :medium, :large)
58
- # @param icon [String] icona opzionale
59
- # @param active [Boolean] stato attivo del link
60
- # @param disabled [Boolean] stato disabilitato del link
61
- # @param data [Hash] attributi data
62
- # @param method [Symbol] metodo HTTP (per Turbo)
63
- # @param target [String] target del link
64
- # @param html_options [Hash] opzioni HTML aggiuntive
65
- def initialize(
66
- label:,
67
- href: nil,
68
- theme: :white,
69
- orientation: :horizontal,
70
- style: :default,
71
- size: :medium,
72
- icon: nil,
73
- active: false,
74
- disabled: false,
75
- data: {},
76
- method: nil,
77
- target: nil,
78
- **html_options
79
- )
80
- @label = label
81
- @href = href
82
- @theme = theme.to_sym
83
- @orientation = orientation.to_sym
84
- @style = style.to_sym
85
- @size = size.to_sym
86
- @icon = icon
87
- @active = active
88
- @disabled = disabled
89
- @data = data || {}
90
- @method = method
91
- @target = target
92
- @html_options = html_options
93
-
94
- validate_params
95
- end
96
-
97
- # Determina se è un link attivo/corrente
98
- def active?
99
- @active
100
- end
101
-
102
- # Determina se è disabilitato
103
- def disabled?
104
- @disabled
105
- end
106
-
107
- # Determina se è un link o solo testo
108
- def link?
109
- @href.present? && !@disabled
110
- end
111
-
112
- # Combina tutte le classi CSS
113
- def combined_classes
114
- [
115
- LINK_BASE_CLASSES,
116
- get_theme_class,
117
- get_orientation_class,
118
- get_style_class,
119
- get_size_class,
120
- get_state_class,
121
- @html_options[:class]
122
- ].compact.join(" ")
123
- end
124
-
125
- # Classi per l'icona con dimensionamento proporzionale
126
- def icon_classes
127
- return "" unless @icon.present?
128
-
129
- # Definisce spacing e dimensioni icona basate su size
130
- base_spacing = case @orientation
131
- when :horizontal
132
- "mr-2"
133
- when :vertical
134
- "mb-1"
135
- else
136
- "mr-2"
137
- end
138
-
139
- icon_size = case @size
140
- when :extra_small
141
- "w-3 h-3"
142
- when :small
143
- "w-4 h-4"
144
- when :medium
145
- "w-5 h-5"
146
- when :large
147
- "w-6 h-6"
148
- else
149
- "w-5 h-5"
150
- end
151
-
152
- "#{base_spacing} #{icon_size} inline-block"
153
- end
154
-
155
- # Classi per il testo
156
- def text_classes
157
- "inline-block"
158
- end
159
-
160
- # Restituisce gli attributi per il link/span
161
- def element_attributes
162
- attrs = @html_options.except(:class)
163
- attrs[:class] = combined_classes
164
-
165
- if link?
166
- # Attributi specifici per i link
167
- if @method.present?
168
- attrs[:data] = @data.merge(turbo_method: @method)
169
- elsif @data.present?
170
- attrs[:data] = @data
171
- end
172
-
173
- attrs[:target] = @target if @target.present?
174
- attrs[:aria] ||= {}
175
- attrs[:aria][:current] = "page" if active?
176
- else
177
- # Attributi per span (testo semplice o disabilitato)
178
- attrs[:aria] ||= {}
179
- attrs[:aria][:disabled] = true if disabled?
180
- end
181
-
182
- attrs
183
- end
184
-
185
- # Determina se mostrare l'icona
186
- def show_icon?
187
- @icon.present?
188
- end
189
-
190
- # Renderizza l'icona
191
- def render_icon
192
- return nil unless show_icon?
193
-
194
- if @icon.is_a?(String)
195
- render BetterUi::General::IconComponent.new(name: @icon)
196
- else
197
- @icon # Assumiamo che sia già un componente renderizzato
198
- end
199
- end
200
-
201
- private
202
-
203
- def get_theme_class
204
- LINK_THEME_CLASSES[@theme] || LINK_THEME_CLASSES[:white]
205
- end
206
-
207
- def get_orientation_class
208
- LINK_ORIENTATION_CLASSES[@orientation] || LINK_ORIENTATION_CLASSES[:horizontal]
209
- end
210
-
211
- def get_style_class
212
- LINK_STYLE_CLASSES[@style] || LINK_STYLE_CLASSES[:default]
213
- end
214
-
215
- def get_size_class
216
- LINK_SIZE_CLASSES[@size] || LINK_SIZE_CLASSES[:medium]
217
- end
218
-
219
- def get_state_class
220
- return LINK_STATE_CLASSES[:disabled] if disabled?
221
- return LINK_STATE_CLASSES[:active] if active?
222
- LINK_STATE_CLASSES[:normal]
223
- end
224
-
225
- def validate_params
226
- validate_theme
227
- validate_orientation
228
- validate_style
229
- validate_size
230
- end
231
-
232
- def validate_theme
233
- unless LINK_THEME_CLASSES.keys.include?(@theme)
234
- raise ArgumentError, "Il tema deve essere uno tra: #{LINK_THEME_CLASSES.keys.join(', ')}"
235
- end
236
- end
237
-
238
- def validate_orientation
239
- unless LINK_ORIENTATION_CLASSES.keys.include?(@orientation)
240
- raise ArgumentError, "L'orientamento deve essere uno tra: #{LINK_ORIENTATION_CLASSES.keys.join(', ')}"
241
- end
242
- end
243
-
244
- def validate_style
245
- unless LINK_STYLE_CLASSES.keys.include?(@style)
246
- raise ArgumentError, "Lo stile deve essere uno tra: #{LINK_STYLE_CLASSES.keys.join(', ')}"
247
- end
248
- end
249
-
250
- def validate_size
251
- unless LINK_SIZE_CLASSES.keys.include?(@size)
252
- raise ArgumentError, "La dimensione deve essere una tra: #{LINK_SIZE_CLASSES.keys.join(', ')}"
253
- end
254
- end
255
- end
256
- end
257
- end
258
- end
@@ -1,5 +0,0 @@
1
- <%# Wrapper component con controller Stimulus e slots %>
2
- <div <%= tag.attributes(wrapper_attributes) %>>
3
- <%= trigger %>
4
- <%= modal %>
5
- </div>
@@ -1,47 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Modal
4
- class Component < ViewComponent::Base
5
- renders_one :trigger
6
- renders_one :modal
7
-
8
- attr_reader :close_on_backdrop, :close_on_escape, :lock_scroll, :classes, :html_options
9
-
10
-
11
-
12
- # Inizializzazione del wrapper component
13
- def initialize(
14
- close_on_backdrop: true,
15
- close_on_escape: true,
16
- lock_scroll: true,
17
- classes: nil,
18
- **html_options
19
- )
20
- @close_on_backdrop = close_on_backdrop
21
- @close_on_escape = close_on_escape
22
- @lock_scroll = lock_scroll
23
- @classes = classes
24
- @html_options = html_options
25
- end
26
-
27
- # Combina tutte le classi per il wrapper
28
- def wrapper_classes
29
- [@classes, @html_options[:class]].compact.join(" ")
30
- end
31
-
32
- # Restituisce gli attributi per il wrapper principale (con controller Stimulus)
33
- def wrapper_attributes
34
- {
35
- class: wrapper_classes,
36
- 'data-controller': 'bui-modal',
37
- 'data-bui-modal-close-on-backdrop-value': close_on_backdrop,
38
- 'data-bui-modal-close-on-escape-value': close_on_escape,
39
- 'data-bui-modal-lock-scroll-value': lock_scroll
40
- }.merge(@html_options.except(:class))
41
- end
42
-
43
-
44
- end
45
- end
46
- end
47
- end
@@ -1,52 +0,0 @@
1
- <%# Template per il modal content %>
2
- <% if @backdrop %>
3
- <%= tag.div **backdrop_attributes do %>
4
- <%= tag.div **container_attributes do %>
5
- <%# Header del modal %>
6
- <%= tag.div **header_attributes do %>
7
- <h3 class="text-lg font-semibold" id="modal-title"><%= @title %></h3>
8
- <% if @closable %>
9
- <%= helpers.bui_button(
10
- label: "Chiudi",
11
- icon: "x-mark",
12
- type: :white,
13
- size: :small,
14
- data: [
15
- { name: 'bui-modal-target', value: 'closeButton' },
16
- { name: 'action', value: 'click->bui-modal#closeButtonClicked' }
17
- ]
18
- ) %>
19
- <% end %>
20
- <% end %>
21
-
22
- <%# Body del modal %>
23
- <div class="p-6">
24
- <%= content %>
25
- </div>
26
- <% end %>
27
- <% end %>
28
- <% else %>
29
- <%= tag.div **container_attributes do %>
30
- <%# Header del modal %>
31
- <%= tag.div **header_attributes do %>
32
- <h3 class="text-lg font-semibold" id="modal-title"><%= @title %></h3>
33
- <% if @closable %>
34
- <%= helpers.bui_button(
35
- label: "Chiudi",
36
- icon: "x-mark",
37
- type: :white,
38
- size: :small,
39
- data: [
40
- { name: 'bui-modal-target', value: 'closeButton' },
41
- { name: 'action', value: 'click->bui-modal#closeButtonClicked' }
42
- ]
43
- ) %>
44
- <% end %>
45
- <% end %>
46
-
47
- <%# Body del modal %>
48
- <div class="p-6">
49
- <%= content %>
50
- </div>
51
- <% end %>
52
- <% end %>
@@ -1,160 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Modal
4
- class ModalComponent < ViewComponent::Base
5
- attr_reader :title, :theme, :size, :backdrop, :closable, :classes, :html_options
6
-
7
- # Classi base sempre presenti per il backdrop
8
- MODAL_BACKDROP_CLASSES = "fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50"
9
-
10
- # Classi base per il contenitore del modal
11
- MODAL_CONTAINER_CLASSES = "relative bg-white shadow-xl w-full"
12
-
13
- # Temi dell'header del modal con classi Tailwind dirette
14
- MODAL_THEME = {
15
- default: "bg-gray-50 border-b border-gray-200 text-gray-900",
16
- white: "bg-white border-b border-gray-200 text-gray-900",
17
- red: "bg-red-50 border-b border-red-200 text-red-900",
18
- rose: "bg-rose-50 border-b border-rose-200 text-rose-900",
19
- orange: "bg-orange-50 border-b border-orange-200 text-orange-900",
20
- green: "bg-green-50 border-b border-green-200 text-green-900",
21
- blue: "bg-blue-50 border-b border-blue-200 text-blue-900",
22
- yellow: "bg-yellow-50 border-b border-yellow-200 text-yellow-900",
23
- violet: "bg-violet-50 border-b border-violet-200 text-violet-900"
24
- }
25
-
26
- # Dimensioni con classi Tailwind dirette
27
- MODAL_SIZES = {
28
- small: "max-w-sm",
29
- medium: "max-w-md",
30
- large: "max-w-2xl"
31
- }
32
-
33
- # Border radius con classi Tailwind dirette
34
- MODAL_ROUNDED = {
35
- none: "rounded-none",
36
- small: "rounded-md",
37
- medium: "rounded-lg",
38
- large: "rounded-xl",
39
- full: "rounded-full"
40
- }
41
-
42
- # Inizializzazione del modal component
43
- def initialize(
44
- title:,
45
- theme: :default,
46
- size: :medium,
47
- rounded: :medium,
48
- backdrop: true,
49
- closable: true,
50
- classes: nil,
51
- **html_options
52
- )
53
- @title = title
54
- @theme = theme.to_sym
55
- @size = size.to_sym
56
- @rounded = rounded.to_sym
57
- @backdrop = backdrop
58
- @closable = closable
59
- @classes = classes
60
- @html_options = html_options
61
-
62
- validate_params
63
- end
64
-
65
- # Combina tutte le classi per il backdrop
66
- def backdrop_classes
67
- MODAL_BACKDROP_CLASSES
68
- end
69
-
70
- # Combina tutte le classi per il contenitore
71
- def container_classes
72
- [
73
- MODAL_CONTAINER_CLASSES,
74
- get_modal_size_classes,
75
- get_modal_rounded_classes,
76
- @classes,
77
- @html_options[:class]
78
- ].compact.join(" ")
79
- end
80
-
81
- # Combina tutte le classi per l'header
82
- def header_classes
83
- [
84
- "flex items-center justify-between p-6",
85
- get_modal_theme_classes
86
- ].compact.join(" ")
87
- end
88
-
89
- def get_modal_theme_classes
90
- MODAL_THEME[@theme] || MODAL_THEME[:default]
91
- end
92
-
93
- def get_modal_size_classes
94
- MODAL_SIZES[@size] || MODAL_SIZES[:medium]
95
- end
96
-
97
- def get_modal_rounded_classes
98
- MODAL_ROUNDED[@rounded] || MODAL_ROUNDED[:medium]
99
- end
100
-
101
- # Restituisce gli attributi per il backdrop
102
- def backdrop_attributes
103
- {
104
- class: backdrop_classes,
105
- 'data-bui-modal-target': 'backdrop'
106
- }
107
- end
108
-
109
- # Restituisce gli attributi per il contenitore
110
- def container_attributes
111
- {
112
- class: container_classes,
113
- role: "dialog",
114
- "aria-modal": "true",
115
- "aria-labelledby": "modal-title",
116
- 'data-bui-modal-target': 'container'
117
- }
118
- end
119
-
120
- # Restituisce gli attributi per l'header
121
- def header_attributes
122
- {
123
- class: header_classes
124
- }
125
- end
126
-
127
- # Verifica se rendere il componente
128
- def render?
129
- @title.present?
130
- end
131
-
132
- private
133
-
134
- def validate_params
135
- validate_theme
136
- validate_size
137
- validate_rounded
138
- end
139
-
140
- def validate_theme
141
- unless MODAL_THEME.keys.include?(@theme)
142
- raise ArgumentError, "Il tema deve essere uno tra: #{MODAL_THEME.keys.join(', ')}"
143
- end
144
- end
145
-
146
- def validate_size
147
- unless MODAL_SIZES.keys.include?(@size)
148
- raise ArgumentError, "La dimensione deve essere una tra: #{MODAL_SIZES.keys.join(', ')}"
149
- end
150
- end
151
-
152
- def validate_rounded
153
- unless MODAL_ROUNDED.keys.include?(@rounded)
154
- raise ArgumentError, "Il border radius deve essere uno tra: #{MODAL_ROUNDED.keys.join(', ')}"
155
- end
156
- end
157
- end
158
- end
159
- end
160
- end
@@ -1,85 +0,0 @@
1
- <% if should_show_pagination? %>
2
- <nav aria-label="Pagination" class="flex items-center justify-between">
3
-
4
- <!-- Info testo opzionale -->
5
- <% if show_info %>
6
- <div class="hidden sm:block">
7
- <p class="text-sm text-gray-700"><%= info_text %></p>
8
- </div>
9
- <% end %>
10
-
11
- <!-- Controlli paginazione -->
12
- <div class="<%= container_classes %>">
13
-
14
- <!-- Pulsante Previous -->
15
- <% if previous_page %>
16
- <a href="<%= build_url(previous_page) %>"
17
- class="<%= page_link_classes(previous_page) %> rounded-l-md"
18
- aria-label="Pagina precedente">
19
- <span class="sr-only">Precedente</span>
20
- <%= bui_icon(name: "chevron-left", size: :medium) %>
21
- </a>
22
- <% else %>
23
- <span class="<%= disabled_classes %> rounded-l-md" aria-label="Pagina precedente">
24
- <span class="sr-only">Precedente</span>
25
- <%= bui_icon(name: "chevron-left", size: :medium) %>
26
- </span>
27
- <% end %>
28
-
29
- <!-- Prima pagina se necessaria -->
30
- <% if show_left_ellipsis? %>
31
- <a href="<%= build_url(1) %>" class="<%= page_link_classes(1) %>">1</a>
32
- <span class="<%= disabled_classes %>">...</span>
33
- <% end %>
34
-
35
- <!-- Range pagine -->
36
- <% page_range.each do |page_num| %>
37
- <% if page_num == current_page %>
38
- <span aria-current="page" class="<%= page_link_classes(page_num) %>">
39
- <%= page_num %>
40
- </span>
41
- <% else %>
42
- <a href="<%= build_url(page_num) %>"
43
- class="<%= page_link_classes(page_num) %>"
44
- aria-label="Vai alla pagina <%= page_num %>">
45
- <%= page_num %>
46
- </a>
47
- <% end %>
48
- <% end %>
49
-
50
- <!-- Ultima pagina se necessaria -->
51
- <% if show_right_ellipsis? %>
52
- <span class="<%= disabled_classes %>">...</span>
53
- <a href="<%= build_url(total_pages) %>" class="<%= page_link_classes(total_pages) %>">
54
- <%= total_pages %>
55
- </a>
56
- <% end %>
57
-
58
- <!-- Pulsante Next -->
59
- <% if next_page %>
60
- <a href="<%= build_url(next_page) %>"
61
- class="<%= page_link_classes(next_page) %> rounded-r-md"
62
- aria-label="Pagina successiva">
63
- <span class="sr-only">Successiva</span>
64
- <%= bui_icon(name: "chevron-right", size: :medium) %>
65
- </a>
66
- <% else %>
67
- <span class="<%= disabled_classes %> rounded-r-md" aria-label="Pagina successiva">
68
- <span class="sr-only">Successiva</span>
69
- <%= bui_icon(name: "chevron-right", size: :medium) %>
70
- </span>
71
- <% end %>
72
-
73
- </div>
74
-
75
- <!-- Info mobile -->
76
- <% if show_info %>
77
- <div class="flex flex-1 justify-between sm:hidden">
78
- <span class="text-sm text-gray-700">
79
- Pagina <%= current_page %> di <%= total_pages %>
80
- </span>
81
- </div>
82
- <% end %>
83
-
84
- </nav>
85
- <% end %>