better_ui 0.6.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 (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 +52 -200
  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,176 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BetterUi
4
- module General
5
- module Accordion
6
- class ItemComponent < ViewComponent::Base
7
- ITEM_THEME = {
8
- default: 'border-gray-200 bg-white',
9
- white: 'border-gray-100 bg-white',
10
- blue: 'border-blue-200 bg-blue-50',
11
- red: 'border-red-200 bg-red-50',
12
- green: 'border-green-200 bg-green-50',
13
- yellow: 'border-yellow-200 bg-yellow-50',
14
- violet: 'border-violet-200 bg-violet-50',
15
- orange: 'border-orange-200 bg-orange-50',
16
- rose: 'border-rose-200 bg-rose-50'
17
- }.freeze
18
-
19
- ITEM_HEADER_THEME = {
20
- default: 'text-gray-900 hover:bg-gray-50',
21
- white: 'text-gray-900 hover:bg-gray-50',
22
- blue: 'text-blue-900 hover:bg-blue-100',
23
- red: 'text-red-900 hover:bg-red-100',
24
- green: 'text-green-900 hover:bg-green-100',
25
- yellow: 'text-yellow-900 hover:bg-yellow-100',
26
- violet: 'text-violet-900 hover:bg-violet-100',
27
- orange: 'text-orange-900 hover:bg-orange-100',
28
- rose: 'text-rose-900 hover:bg-rose-100'
29
- }.freeze
30
-
31
- ITEM_SIZE_HEADER = {
32
- small: 'text-sm px-4 py-3',
33
- medium: 'text-base px-5 py-4',
34
- large: 'text-lg px-6 py-5'
35
- }.freeze
36
-
37
- ITEM_SIZE_CONTENT = {
38
- small: 'px-4 py-3',
39
- medium: 'px-5 py-4',
40
- large: 'px-6 py-5'
41
- }.freeze
42
-
43
- ITEM_SIZE_ICON = {
44
- small: 'w-4 h-4',
45
- medium: 'w-5 h-5',
46
- large: 'w-6 h-6'
47
- }.freeze
48
-
49
- def initialize(title:, expanded: false, disabled: false, icon: 'chevron-down',
50
- theme: :default, size: :medium, classes: '', **options)
51
- @title = title
52
- @expanded = expanded
53
- @disabled = disabled
54
- @icon = icon
55
- @theme = theme
56
- @size = size
57
- @classes = classes
58
- @options = options
59
-
60
- validate_params
61
- end
62
-
63
- private
64
-
65
- attr_reader :title, :expanded, :disabled, :icon, :theme, :size, :classes, :options
66
-
67
- def validate_params
68
- validate_theme
69
- validate_size
70
-
71
- raise ArgumentError, 'title cannot be blank' if title.blank?
72
- end
73
-
74
- def validate_theme
75
- return if ITEM_THEME.key?(theme)
76
-
77
- raise ArgumentError, "Invalid theme: #{theme}. Must be one of #{ITEM_THEME.keys}"
78
- end
79
-
80
- def validate_size
81
- return if ITEM_SIZE_HEADER.key?(size)
82
-
83
- raise ArgumentError, "Invalid size: #{size}. Must be one of #{ITEM_SIZE_HEADER.keys}"
84
- end
85
-
86
- def unique_id
87
- @unique_id ||= "accordion-item-#{SecureRandom.hex(4)}"
88
- end
89
-
90
- def content_id
91
- "#{unique_id}-content"
92
- end
93
-
94
- def header_id
95
- "#{unique_id}-header"
96
- end
97
-
98
- # Attributi per il wrapper dell'item
99
- def item_attributes
100
- base_classes = [
101
- 'bui-accordion-item',
102
- ITEM_THEME[theme],
103
- classes
104
- ].compact.join(' ')
105
-
106
- {
107
- class: base_classes,
108
- 'data-bui-accordion-target': 'item'
109
- }.merge(options)
110
- end
111
-
112
- # Attributi per il button header
113
- def header_attributes
114
- base_classes = [
115
- 'bui-accordion-header',
116
- 'w-full flex items-center justify-between text-left font-medium transition-colors duration-200',
117
- ITEM_SIZE_HEADER[size],
118
- ITEM_HEADER_THEME[theme],
119
- disabled? ? 'cursor-not-allowed opacity-50' : 'cursor-pointer'
120
- ].compact.join(' ')
121
-
122
- {
123
- class: base_classes,
124
- type: 'button',
125
- id: header_id,
126
- 'aria-expanded': expanded,
127
- 'aria-controls': content_id,
128
- 'data-action': 'click->bui-accordion#toggle',
129
- 'data-bui-accordion-target': 'trigger',
130
- disabled: disabled
131
- }
132
- end
133
-
134
- # Attributi per il contenuto
135
- def content_attributes
136
- base_classes = [
137
- 'bui-accordion-content',
138
- 'transition-all duration-300 ease-in-out overflow-hidden',
139
- ITEM_SIZE_CONTENT[size],
140
- expanded? ? 'block' : 'hidden'
141
- ].compact.join(' ')
142
-
143
- {
144
- class: base_classes,
145
- id: content_id,
146
- 'aria-labelledby': header_id,
147
- 'data-bui-accordion-target': 'content'
148
- }
149
- end
150
-
151
- # Attributi per l'icona
152
- def icon_attributes
153
- base_classes = [
154
- 'bui-accordion-icon',
155
- 'transition-transform duration-200',
156
- ITEM_SIZE_ICON[size],
157
- expanded? ? 'rotate-180' : ''
158
- ].compact.join(' ')
159
-
160
- {
161
- class: base_classes,
162
- 'data-bui-accordion-target': 'icon'
163
- }
164
- end
165
-
166
- def disabled?
167
- disabled
168
- end
169
-
170
- def expanded?
171
- expanded
172
- end
173
- end
174
- end
175
- end
176
- end
@@ -1,32 +0,0 @@
1
- <div <%= tag.attributes(alert_attributes) %>>
2
- <% if (@icon.blank? ? default_icon : @icon) && @icon_position == :left %>
3
- <div class="<%= get_icon_classes %> <%= get_icon_theme_class %>">
4
- <%= render BetterUi::General::Icon::Component.new(name: @icon.blank? ? default_icon : @icon) %>
5
- </div>
6
- <% end %>
7
-
8
- <div class="<%= get_content_classes %>">
9
- <% if @title.present? %>
10
- <div class="<%= ALERT_TITLE_CLASSES %>"><%= @title %></div>
11
- <% end %>
12
- <div class="<%= ALERT_MESSAGE_CLASSES %>">
13
- <% if @html_content %>
14
- <%= raw @message %>
15
- <% else %>
16
- <%= @message %>
17
- <% end %>
18
- </div>
19
- </div>
20
-
21
- <% if (@icon.blank? ? default_icon : @icon) && @icon_position == :right %>
22
- <div class="<%= get_icon_classes %> <%= get_icon_theme_class %>">
23
- <%= render BetterUi::General::Icon::Component.new(name: @icon.blank? ? default_icon : @icon) %>
24
- </div>
25
- <% end %>
26
-
27
- <% if @dismissible %>
28
- <button type="button" class="<%= get_close_classes %>" aria-label="Chiudi">
29
- <%= render BetterUi::General::Icon::Component.new(name: "x", size: :sm) %>
30
- </button>
31
- <% end %>
32
- </div>
@@ -1,242 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Alert
4
- class Component < ViewComponent::Base
5
- # Classi base sempre presenti
6
- ALERT_BASE_CLASSES = "flex p-4 mb-4 border"
7
-
8
- # Classi per elementi interni
9
- ALERT_ICON_CLASSES = "flex-shrink-0 mr-3 w-5 h-5"
10
- ALERT_ICON_RIGHT_CLASSES = "flex-shrink-0 ml-3 mr-0"
11
- ALERT_CONTENT_CLASSES = "flex-1"
12
- ALERT_TITLE_CLASSES = "font-medium mb-1"
13
- ALERT_MESSAGE_CLASSES = "text-sm"
14
- ALERT_CLOSE_CLASSES = "ml-auto -my-1.5 -mr-1.5 p-1.5 rounded-md focus:ring-2 focus:ring-offset-2 hover:bg-gray-100"
15
-
16
- # Temi di alert con classi Tailwind dirette
17
- ALERT_THEME_CLASSES = {
18
- default: "bg-black text-white border-gray-900",
19
- white: "bg-white text-black border-gray-200",
20
- red: "bg-red-500 text-white border-red-600",
21
- rose: "bg-rose-500 text-white border-rose-600",
22
- orange: "bg-orange-500 text-white border-orange-600",
23
- green: "bg-green-500 text-white border-green-600",
24
- blue: "bg-blue-500 text-white border-blue-600",
25
- yellow: "bg-yellow-500 text-black border-yellow-600",
26
- violet: "bg-violet-500 text-white border-violet-600"
27
- }
28
-
29
- # Colori icone per ogni tema
30
- ALERT_ICON_THEME_CLASSES = {
31
- default: "text-white",
32
- white: "text-black",
33
- red: "text-white",
34
- rose: "text-white",
35
- orange: "text-white",
36
- green: "text-white",
37
- blue: "text-white",
38
- yellow: "text-black",
39
- violet: "text-white"
40
- }
41
-
42
- # Colori close button per ogni tema
43
- ALERT_CLOSE_THEME_CLASSES = {
44
- default: "text-white focus:ring-gray-600",
45
- white: "text-black focus:ring-gray-400",
46
- red: "text-white focus:ring-red-400",
47
- rose: "text-white focus:ring-rose-400",
48
- orange: "text-white focus:ring-orange-400",
49
- green: "text-white focus:ring-green-400",
50
- blue: "text-white focus:ring-blue-400",
51
- yellow: "text-black focus:ring-yellow-400",
52
- violet: "text-white focus:ring-violet-400"
53
- }
54
-
55
- # Border radius con classi Tailwind dirette
56
- ALERT_RADIUS_CLASSES = {
57
- none: "rounded-none",
58
- small: "rounded-sm",
59
- medium: "rounded-md",
60
- large: "rounded-lg",
61
- full: "rounded-full"
62
- }
63
-
64
- # Classi per layout quando icon è a destra
65
- ALERT_ICON_RIGHT_LAYOUT_CLASSES = "flex-row-reverse"
66
- ALERT_CONTENT_RIGHT_CLASSES = "text-right"
67
-
68
- # Classi per alert dismissible
69
- ALERT_DISMISSIBLE_CLASSES = "pr-12 relative"
70
- ALERT_CLOSE_POSITION_CLASSES = "absolute right-4 top-4"
71
-
72
- # Livelli di importanza con attributi ARIA
73
- IMPORTANCE_LEVELS = {
74
- high: { role: "alert", "aria-live": "assertive" },
75
- medium: { role: "status", "aria-live": "polite" },
76
- low: { role: "status", "aria-live": "polite" }
77
- }
78
-
79
- # @param title [String] titolo dell'alert (opzionale)
80
- # @param message [String] contenuto dell'alert
81
- # @param theme [Symbol] :default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet
82
- # @param icon [String] nome dell'icona (opzionale)
83
- # @param icon_position [Symbol] :left, :right posizione dell'icona
84
- # @param dismissible [Boolean] se l'alert può essere chiuso
85
- # @param rounded [Symbol] :none, :small, :medium, :large, :full arrotondamento degli angoli
86
- # @param importance [Symbol] :high, :medium, :low livello di importanza per accessibilità
87
- # @param html_content [Boolean] se il messaggio contiene HTML
88
- # @param classes [String] classi CSS aggiuntive
89
- # @param html_options [Hash] opzioni HTML per il container
90
- def initialize(
91
- title: nil,
92
- message: nil,
93
- theme: :white,
94
- icon: nil,
95
- icon_position: :left,
96
- dismissible: false,
97
- rounded: :medium,
98
- importance: :medium,
99
- html_content: false,
100
- classes: nil,
101
- **html_options
102
- )
103
- @title = title
104
- @message = message
105
- @theme = theme.to_sym
106
- @icon = icon
107
- @icon_position = icon_position.to_sym
108
- @dismissible = dismissible
109
- @rounded = rounded.to_sym
110
- @importance = importance.to_sym
111
- @html_content = html_content
112
- @classes = classes
113
- @html_options = html_options
114
-
115
- validate_params
116
- end
117
-
118
- def default_icon
119
- case @theme
120
- when :default then "bell"
121
- when :white then "information-circle"
122
- when :red, :rose then "exclamation-circle"
123
- when :orange then "bell"
124
- when :green then "check-circle"
125
- when :blue then "information-circle"
126
- when :yellow then "exclamation-triangle"
127
- when :violet then "shield-exclamation"
128
- else "information-circle"
129
- end
130
- end
131
-
132
- # Combina tutte le classi
133
- def combined_classes
134
- [
135
- ALERT_BASE_CLASSES,
136
- get_theme_class,
137
- get_border_radius_class,
138
- get_icon_position_class,
139
- @dismissible ? ALERT_DISMISSIBLE_CLASSES : nil,
140
- @classes,
141
- @html_options[:class]
142
- ].compact.join(" ")
143
- end
144
-
145
- # Restituisce gli attributi per l'alert
146
- def alert_attributes
147
- attrs = {
148
- class: combined_classes
149
- }
150
-
151
- # Aggiungi attributi ARIA in base al livello di importanza
152
- importance_attrs = IMPORTANCE_LEVELS[@importance] || IMPORTANCE_LEVELS[:medium]
153
- importance_attrs.each do |key, value|
154
- attrs[key] = value
155
- end
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
- # Genera le classi del tema
166
- def get_theme_class
167
- ALERT_THEME_CLASSES[@theme] || ALERT_THEME_CLASSES[:white]
168
- end
169
-
170
- # Genera le classi per il border radius
171
- def get_border_radius_class
172
- ALERT_RADIUS_CLASSES[@rounded] || ALERT_RADIUS_CLASSES[:medium]
173
- end
174
-
175
- # Genera la classe per la posizione dell'icona (layout)
176
- def get_icon_position_class
177
- @icon_position == :right ? ALERT_ICON_RIGHT_LAYOUT_CLASSES : nil
178
- end
179
-
180
- # Genera le classi per l'icona
181
- def get_icon_classes
182
- if @icon_position == :right
183
- ALERT_ICON_RIGHT_CLASSES
184
- else
185
- ALERT_ICON_CLASSES
186
- end
187
- end
188
-
189
- # Genera le classi per il contenuto
190
- def get_content_classes
191
- if @icon_position == :right
192
- [ ALERT_CONTENT_CLASSES, ALERT_CONTENT_RIGHT_CLASSES ].join(" ")
193
- else
194
- ALERT_CONTENT_CLASSES
195
- end
196
- end
197
-
198
- # Genera le classi per l'icona del tema
199
- def get_icon_theme_class
200
- ALERT_ICON_THEME_CLASSES[@theme] || ALERT_ICON_THEME_CLASSES[:white]
201
- end
202
-
203
- # Genera le classi per il close button
204
- def get_close_classes
205
- base_classes = ALERT_CLOSE_CLASSES
206
- theme_classes = ALERT_CLOSE_THEME_CLASSES[@theme] || ALERT_CLOSE_THEME_CLASSES[:white]
207
- position_classes = @dismissible ? ALERT_CLOSE_POSITION_CLASSES : nil
208
-
209
- [ base_classes, theme_classes, position_classes ].compact.join(" ")
210
- end
211
-
212
- private
213
-
214
- def validate_params
215
- # Validazione tema
216
- valid_themes = ALERT_THEME_CLASSES.keys
217
- unless valid_themes.include?(@theme)
218
- raise ArgumentError, "Il tema deve essere uno tra: #{valid_themes.join(', ')}"
219
- end
220
-
221
- # Validazione border radius
222
- valid_radius = ALERT_RADIUS_CLASSES.keys
223
- unless valid_radius.include?(@rounded)
224
- raise ArgumentError, "Il border radius deve essere uno tra: #{valid_radius.join(', ')}"
225
- end
226
-
227
- # Validazione posizione icona
228
- valid_positions = [ :left, :right ]
229
- unless valid_positions.include?(@icon_position)
230
- raise ArgumentError, "La posizione dell'icona deve essere una tra: #{valid_positions.join(', ')}"
231
- end
232
-
233
- # Validazione livello di importanza
234
- valid_importance = IMPORTANCE_LEVELS.keys
235
- unless valid_importance.include?(@importance)
236
- raise ArgumentError, "Il livello di importanza deve essere uno tra: #{valid_importance.join(', ')}"
237
- end
238
- end
239
- end
240
- end
241
- end
242
- end
@@ -1,20 +0,0 @@
1
- <%# Template per l'avatar %>
2
- <%= tag.div(**avatar_attributes) do %>
3
- <% if show_image? %>
4
- <%= tag.img(
5
- src: @src,
6
- alt: @name || 'Avatar',
7
- class: img_classes,
8
- width: pixel_size,
9
- height: pixel_size
10
- ) %>
11
- <% else %>
12
- <%= tag.div(class: placeholder_classes) do %>
13
- <%= initials %>
14
- <% end %>
15
- <% end %>
16
-
17
- <% if show_status? %>
18
- <%= tag.span(class: status_indicator_classes) %>
19
- <% end %>
20
- <% end %>