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,301 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Avatar
4
- class Component < ViewComponent::Base
5
- attr_reader :name, :src, :size, :shape, :status, :status_position, :theme, :style, :classes, :id
6
-
7
- # Classi base sempre presenti
8
- AVATAR_BASE_CLASSES = "relative inline-flex items-center justify-center flex-shrink-0 overflow-hidden"
9
-
10
- # Classi per elementi interni
11
- AVATAR_IMG_CLASSES = "h-full w-full object-cover"
12
- AVATAR_PLACEHOLDER_BASE_CLASSES = "flex items-center justify-center h-full w-full font-medium"
13
- AVATAR_STATUS_BASE_CLASSES = "absolute rounded-full border-2 border-white"
14
-
15
- # Dimensioni container con classi Tailwind dirette
16
- AVATAR_SIZE_CLASSES = {
17
- xxsmall: "h-5 w-5",
18
- xsmall: "h-6 w-6",
19
- small: "h-8 w-8",
20
- medium: "h-10 w-10",
21
- large: "h-12 w-12",
22
- xlarge: "h-16 w-16",
23
- xxlarge: "h-24 w-24"
24
- }
25
-
26
- # Dimensioni testo placeholder
27
- AVATAR_PLACEHOLDER_SIZE_CLASSES = {
28
- xxsmall: "text-xs",
29
- xsmall: "text-xs",
30
- small: "text-sm",
31
- medium: "text-base",
32
- large: "text-lg",
33
- xlarge: "text-xl",
34
- xxlarge: "text-2xl"
35
- }
36
-
37
- # Forme con classi Tailwind dirette
38
- AVATAR_SHAPE_CLASSES = {
39
- circle: "rounded-full",
40
- square: "rounded-none",
41
- rounded: "rounded-lg"
42
- }
43
-
44
- # Temi placeholder con classi Tailwind dirette
45
- AVATAR_PLACEHOLDER_THEME_CLASSES = {
46
- default: "bg-black text-white",
47
- white: "bg-white text-black border border-gray-300",
48
- red: "bg-red-500 text-white",
49
- rose: "bg-rose-500 text-white",
50
- orange: "bg-orange-500 text-white",
51
- green: "bg-green-500 text-white",
52
- blue: "bg-blue-500 text-white",
53
- yellow: "bg-yellow-500 text-black",
54
- violet: "bg-violet-500 text-white"
55
- }
56
-
57
- # Stati online con classi Tailwind dirette
58
- AVATAR_STATUS_THEME_CLASSES = {
59
- online: "bg-green-400",
60
- offline: "bg-gray-400",
61
- busy: "bg-red-400",
62
- away: "bg-yellow-400"
63
- }
64
-
65
- # Dimensioni indicatore stato
66
- AVATAR_STATUS_SIZE_CLASSES = {
67
- xxsmall: "h-1 w-1",
68
- xsmall: "h-1.5 w-1.5",
69
- small: "h-2 w-2",
70
- medium: "h-2.5 w-2.5",
71
- large: "h-3 w-3",
72
- xlarge: "h-3.5 w-3.5",
73
- xxlarge: "h-4 w-4"
74
- }
75
-
76
- # Posizioni dell'indicatore di stato
77
- AVATAR_STATUS_POSITION_CLASSES = {
78
- bottom_right: "bottom-0 right-0",
79
- bottom_left: "bottom-0 left-0",
80
- top_right: "top-0 right-0",
81
- top_left: "top-0 left-0"
82
- }
83
-
84
- # Stili disponibili (mantenuto per compatibilità)
85
- AVATAR_STYLE_CLASSES = {
86
- filled: "",
87
- outline: "border-2 border-gray-300",
88
- light: "opacity-75"
89
- }
90
-
91
- def initialize(
92
- name: nil,
93
- src: nil,
94
- size: :medium,
95
- shape: :circle,
96
- status: nil,
97
- status_position: :bottom_right,
98
- theme: :white,
99
- style: :filled,
100
- classes: nil,
101
- id: nil,
102
- **html_options
103
- )
104
- @name = name
105
- @src = src
106
- @size = size.to_sym
107
- @shape = shape.to_sym
108
- @status = status.present? ? status.to_sym : nil
109
- @status_position = status_position.to_sym
110
- @theme = theme.to_sym
111
- @style = style.to_sym
112
- @classes = classes
113
- @id = id
114
- @html_options = html_options
115
-
116
- validate_params
117
- end
118
-
119
- # Combina tutte le classi per il container
120
- def combined_classes
121
- [
122
- AVATAR_BASE_CLASSES,
123
- get_size_class,
124
- get_shape_class,
125
- get_style_class,
126
- @classes,
127
- @html_options[:class]
128
- ].compact.join(" ")
129
- end
130
-
131
- # Classi per il placeholder
132
- def placeholder_classes
133
- [
134
- AVATAR_PLACEHOLDER_BASE_CLASSES,
135
- get_placeholder_theme_class,
136
- get_placeholder_size_class,
137
- get_shape_class
138
- ].compact.join(" ")
139
- end
140
-
141
- # Classi per l'immagine
142
- def img_classes
143
- [
144
- AVATAR_IMG_CLASSES,
145
- get_shape_class
146
- ].compact.join(" ")
147
- end
148
-
149
- # Classi per l'indicatore di stato
150
- def status_indicator_classes
151
- [
152
- AVATAR_STATUS_BASE_CLASSES,
153
- get_status_theme_class,
154
- get_status_size_class,
155
- get_status_position_class
156
- ].compact.join(" ")
157
- end
158
-
159
- def get_size_class
160
- AVATAR_SIZE_CLASSES[@size] || AVATAR_SIZE_CLASSES[:medium]
161
- end
162
-
163
- def get_shape_class
164
- AVATAR_SHAPE_CLASSES[@shape] || AVATAR_SHAPE_CLASSES[:circle]
165
- end
166
-
167
- def get_style_class
168
- AVATAR_STYLE_CLASSES[@style] || AVATAR_STYLE_CLASSES[:filled]
169
- end
170
-
171
- def get_placeholder_theme_class
172
- AVATAR_PLACEHOLDER_THEME_CLASSES[@theme] || AVATAR_PLACEHOLDER_THEME_CLASSES[:white]
173
- end
174
-
175
- def get_placeholder_size_class
176
- AVATAR_PLACEHOLDER_SIZE_CLASSES[@size] || AVATAR_PLACEHOLDER_SIZE_CLASSES[:medium]
177
- end
178
-
179
- def get_status_theme_class
180
- AVATAR_STATUS_THEME_CLASSES[@status] || ""
181
- end
182
-
183
- def get_status_size_class
184
- AVATAR_STATUS_SIZE_CLASSES[@size] || AVATAR_STATUS_SIZE_CLASSES[:medium]
185
- end
186
-
187
- def get_status_position_class
188
- AVATAR_STATUS_POSITION_CLASSES[@status_position] || AVATAR_STATUS_POSITION_CLASSES[:bottom_right]
189
- end
190
-
191
- # Restituisce gli attributi per l'avatar
192
- def avatar_attributes
193
- attrs = {
194
- class: combined_classes,
195
- id: @id
196
- }
197
-
198
- # Aggiungi altri attributi HTML se presenti
199
- @html_options.except(:class).each do |key, value|
200
- attrs[key] = value
201
- end
202
-
203
- attrs
204
- end
205
-
206
- # Determina se mostrare l'indicatore di stato
207
- def show_status?
208
- @status.present? && AVATAR_STATUS_THEME_CLASSES.key?(@status)
209
- end
210
-
211
- # Ottiene le iniziali dal nome
212
- def initials
213
- return "" unless @name.present?
214
-
215
- words = @name.strip.split(/\s+/)
216
- if words.size >= 2
217
- "#{words[0][0]}#{words[1][0]}".upcase
218
- else
219
- @name[0..1].upcase
220
- end
221
- end
222
-
223
- # Determina se mostrare l'immagine
224
- def show_image?
225
- @src.present?
226
- end
227
-
228
- # Ottiene le dimensioni dell'avatar in pixel (per attributi width/height img)
229
- def pixel_size
230
- case @size
231
- when :xxsmall
232
- 20
233
- when :xsmall
234
- 24
235
- when :small
236
- 32
237
- when :medium
238
- 40
239
- when :large
240
- 48
241
- when :xlarge
242
- 64
243
- when :xxlarge
244
- 96
245
- else
246
- 40
247
- end
248
- end
249
-
250
- private
251
-
252
- def validate_params
253
- validate_size
254
- validate_shape
255
- validate_theme
256
- validate_style
257
- validate_status
258
- validate_status_position
259
- end
260
-
261
- def validate_size
262
- unless AVATAR_SIZE_CLASSES.keys.include?(@size)
263
- raise ArgumentError, "La dimensione deve essere una tra: #{AVATAR_SIZE_CLASSES.keys.join(', ')}"
264
- end
265
- end
266
-
267
- def validate_shape
268
- unless AVATAR_SHAPE_CLASSES.keys.include?(@shape)
269
- raise ArgumentError, "La forma deve essere una tra: #{AVATAR_SHAPE_CLASSES.keys.join(', ')}"
270
- end
271
- end
272
-
273
- def validate_theme
274
- unless AVATAR_PLACEHOLDER_THEME_CLASSES.keys.include?(@theme)
275
- raise ArgumentError, "Il tema deve essere uno tra: #{AVATAR_PLACEHOLDER_THEME_CLASSES.keys.join(', ')}"
276
- end
277
- end
278
-
279
- def validate_style
280
- unless AVATAR_STYLE_CLASSES.keys.include?(@style)
281
- raise ArgumentError, "Lo stile deve essere uno tra: #{AVATAR_STYLE_CLASSES.keys.join(', ')}"
282
- end
283
- end
284
-
285
- def validate_status
286
- return if @status.nil?
287
-
288
- unless AVATAR_STATUS_THEME_CLASSES.keys.include?(@status)
289
- raise ArgumentError, "Lo stato deve essere uno tra: #{AVATAR_STATUS_THEME_CLASSES.keys.join(', ')}"
290
- end
291
- end
292
-
293
- def validate_status_position
294
- unless AVATAR_STATUS_POSITION_CLASSES.keys.include?(@status_position)
295
- raise ArgumentError, "La posizione dello stato deve essere una tra: #{AVATAR_STATUS_POSITION_CLASSES.keys.join(', ')}"
296
- end
297
- end
298
- end
299
- end
300
- end
301
- end
@@ -1,23 +0,0 @@
1
- <span <%= tag.attributes(badge_attributes) %>>
2
- <% if @variant == :dot %>
3
- <span class="<%= dot_classes %>"></span>
4
- <% end %>
5
-
6
- <% if @icon && @icon_position == :left %>
7
- <span class="<%= icon_classes %>">
8
- <%= render_icon(@icon) %>
9
- </span>
10
- <% end %>
11
-
12
- <% if @label.present? %>
13
- <span class="<%= text_classes %>"><%= @label %></span>
14
- <% end %>
15
-
16
- <% if @icon && @icon_position == :right %>
17
- <span class="<%= icon_classes %>">
18
- <%= render_icon(@icon) %>
19
- </span>
20
- <% end %>
21
-
22
- <%= content %>
23
- </span>
@@ -1,248 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Badge
4
- class Component < ViewComponent::Base
5
- attr_reader :label, :theme, :size, :shape, :style, :variant, :icon, :icon_position, :classes, :id
6
-
7
- # Classi base sempre presenti
8
- BADGE_BASE_CLASSES = "inline-flex items-center justify-center font-medium"
9
-
10
- # Classi per elementi interni
11
- BADGE_ICON_LEFT_CLASSES = "flex-shrink-0 -ml-0.5 mr-1.5"
12
- BADGE_ICON_RIGHT_CLASSES = "flex-shrink-0 -mr-0.5 ml-1.5"
13
- BADGE_TEXT_CLASSES = "whitespace-nowrap"
14
- BADGE_DOT_CLASSES = "h-2 w-2 rounded-full mr-1.5"
15
-
16
- # Temi di badge con stile FILLED - classi Tailwind dirette
17
- BADGE_THEME_FILLED_CLASSES = {
18
- default: "bg-black text-white",
19
- white: "bg-white text-black",
20
- red: "bg-red-500 text-white",
21
- rose: "bg-rose-500 text-white",
22
- orange: "bg-orange-500 text-white",
23
- green: "bg-green-500 text-white",
24
- blue: "bg-blue-500 text-white",
25
- yellow: "bg-yellow-500 text-black",
26
- violet: "bg-violet-500 text-white",
27
- gray: "bg-gray-500 text-white"
28
- }
29
-
30
- # Temi di badge con stile OUTLINE - classi Tailwind dirette
31
- BADGE_THEME_OUTLINE_CLASSES = {
32
- default: "border border-black text-black bg-transparent",
33
- white: "border border-gray-300 text-gray-700 bg-transparent",
34
- red: "border border-red-500 text-red-500 bg-transparent",
35
- rose: "border border-rose-500 text-rose-500 bg-transparent",
36
- orange: "border border-orange-500 text-orange-500 bg-transparent",
37
- green: "border border-green-500 text-green-500 bg-transparent",
38
- blue: "border border-blue-500 text-blue-500 bg-transparent",
39
- yellow: "border border-yellow-500 text-yellow-500 bg-transparent",
40
- violet: "border border-violet-500 text-violet-500 bg-transparent",
41
- gray: "border border-gray-500 text-gray-500 bg-transparent"
42
- }
43
-
44
- # Dimensioni con classi Tailwind dirette
45
- BADGE_SIZE_CLASSES = {
46
- small: "text-xs px-2 py-0.5",
47
- medium: "text-sm px-2.5 py-0.5",
48
- large: "text-sm px-3 py-1"
49
- }
50
-
51
- # Forme con classi Tailwind dirette
52
- BADGE_SHAPE_CLASSES = {
53
- square: "rounded-md",
54
- rounded: "rounded-full"
55
- }
56
-
57
- # Colori dot per ogni tema
58
- BADGE_DOT_COLOR_CLASSES = {
59
- default: "bg-gray-500",
60
- white: "bg-gray-400",
61
- red: "bg-red-700",
62
- rose: "bg-rose-700",
63
- orange: "bg-orange-700",
64
- green: "bg-green-700",
65
- blue: "bg-blue-700",
66
- yellow: "bg-yellow-700",
67
- violet: "bg-violet-700",
68
- gray: "bg-gray-700"
69
- }
70
-
71
- # @param label [String] Testo del badge
72
- # @param theme [Symbol] default, white, red, rose, orange, green, blue, yellow, violet, gray
73
- # @param size [Symbol] small, medium, large
74
- # @param shape [Symbol] square, rounded
75
- # @param style [Symbol] filled, outline
76
- # @param variant [Symbol] nil, notification, counter, dot
77
- # @param icon [String] Nome icona (opzionale)
78
- # @param icon_position [Symbol] left, right
79
- # @param html_options [Hash] Opzioni HTML aggiuntive
80
- def initialize(
81
- label: nil,
82
- theme: :white,
83
- size: :medium,
84
- shape: :rounded,
85
- style: :filled,
86
- variant: nil,
87
- icon: nil,
88
- icon_position: :left,
89
- classes: nil,
90
- id: nil,
91
- **html_options
92
- )
93
- @label = label
94
- @theme = theme.to_sym
95
- @size = size.to_sym
96
- @shape = shape.to_sym
97
- @style = style.to_sym
98
- @variant = variant.present? ? variant.to_sym : nil
99
- @icon = icon
100
- @icon_position = icon_position.to_sym
101
- @classes = classes
102
- @id = id
103
- @html_options = html_options
104
-
105
- validate_params
106
- end
107
-
108
- # Combina tutte le classi
109
- def combined_classes
110
- [
111
- BADGE_BASE_CLASSES,
112
- get_theme_class,
113
- get_size_class,
114
- get_shape_class,
115
- @classes,
116
- @html_options[:class]
117
- ].compact.join(" ")
118
- end
119
-
120
- def get_theme_class
121
- if @style == :outline
122
- BADGE_THEME_OUTLINE_CLASSES[@theme] || BADGE_THEME_OUTLINE_CLASSES[:white]
123
- else
124
- BADGE_THEME_FILLED_CLASSES[@theme] || BADGE_THEME_FILLED_CLASSES[:white]
125
- end
126
- end
127
-
128
- def get_size_class
129
- BADGE_SIZE_CLASSES[@size] || BADGE_SIZE_CLASSES[:medium]
130
- end
131
-
132
- def get_shape_class
133
- BADGE_SHAPE_CLASSES[@shape] || BADGE_SHAPE_CLASSES[:rounded]
134
- end
135
-
136
- # Restituisce gli attributi per il badge
137
- def badge_attributes
138
- attrs = {
139
- class: combined_classes,
140
- id: @id
141
- }
142
-
143
- # Aggiungi altri attributi HTML se presenti
144
- @html_options.except(:class).each do |key, value|
145
- attrs[key] = value
146
- end
147
-
148
- attrs
149
- end
150
-
151
- def icon_classes
152
- if @icon_position == :left
153
- BADGE_ICON_LEFT_CLASSES
154
- else
155
- BADGE_ICON_RIGHT_CLASSES
156
- end
157
- end
158
-
159
- def text_classes
160
- BADGE_TEXT_CLASSES
161
- end
162
-
163
- def dot_classes
164
- [
165
- BADGE_DOT_CLASSES,
166
- get_dot_color_class
167
- ].compact.join(" ")
168
- end
169
-
170
- def get_dot_color_class
171
- BADGE_DOT_COLOR_CLASSES[@theme] || BADGE_DOT_COLOR_CLASSES[:white]
172
- end
173
-
174
- # Helper per renderizzare le icone
175
- def render_icon(icon_name)
176
- # Mappa le dimensioni del badge alle dimensioni dell'icona
177
- icon_size = case @size
178
- when :large
179
- :small
180
- when :small
181
- :tiny
182
- else
183
- :tiny
184
- end
185
-
186
- # Utilizziamo il componente Icon
187
- render BetterUi::General::IconComponent.new(
188
- name: icon_name,
189
- size: icon_size,
190
- fixed_width: true
191
- )
192
- end
193
-
194
- private
195
-
196
- def validate_params
197
- validate_theme
198
- validate_size
199
- validate_shape
200
- validate_style
201
- validate_variant
202
- validate_icon_position
203
- end
204
-
205
- def validate_theme
206
- unless BADGE_THEME_FILLED_CLASSES.keys.include?(@theme)
207
- raise ArgumentError, "Il tema deve essere uno tra: #{BADGE_THEME_FILLED_CLASSES.keys.join(', ')}"
208
- end
209
- end
210
-
211
- def validate_size
212
- unless BADGE_SIZE_CLASSES.keys.include?(@size)
213
- raise ArgumentError, "La dimensione deve essere una tra: #{BADGE_SIZE_CLASSES.keys.join(', ')}"
214
- end
215
- end
216
-
217
- def validate_shape
218
- unless BADGE_SHAPE_CLASSES.keys.include?(@shape)
219
- raise ArgumentError, "La forma deve essere una tra: #{BADGE_SHAPE_CLASSES.keys.join(', ')}"
220
- end
221
- end
222
-
223
- def validate_style
224
- valid_styles = [ :filled, :outline ]
225
- unless valid_styles.include?(@style)
226
- raise ArgumentError, "Lo stile deve essere uno tra: #{valid_styles.join(', ')}"
227
- end
228
- end
229
-
230
- def validate_variant
231
- return if @variant.nil?
232
-
233
- valid_variants = [ :notification, :counter, :dot ]
234
- unless valid_variants.include?(@variant)
235
- raise ArgumentError, "La variante deve essere una tra: #{valid_variants.join(', ')}"
236
- end
237
- end
238
-
239
- def validate_icon_position
240
- valid_positions = [ :left, :right ]
241
- unless valid_positions.include?(@icon_position)
242
- raise ArgumentError, "La posizione dell'icona deve essere una tra: #{valid_positions.join(', ')}"
243
- end
244
- end
245
- end
246
- end
247
- end
248
- end
@@ -1,15 +0,0 @@
1
- <nav <%= tag.attributes(breadcrumb_attributes) %>>
2
- <ol class="<%= BREADCRUMB_LIST_CLASSES %>">
3
- <% @items.each_with_index do |item, index| %>
4
- <li class="<%= BREADCRUMB_ITEM_CLASSES %>">
5
- <%= render link_for_item(item, active: last_item?(index)) %>
6
-
7
- <% unless last_item?(index) %>
8
- <span class="<%= separator_classes %>" aria-hidden="true">
9
- <%= separator_text %>
10
- </span>
11
- <% end %>
12
- </li>
13
- <% end %>
14
- </ol>
15
- </nav>