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,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BetterUi
4
- module General
5
- module Tabs
6
- class TabComponent < ViewComponent::Base
7
- include BetterUi::General::Components::Icon::IconHelper
8
-
9
- TAB_THEME_ACTIVE = {
10
- default: 'bg-white text-gray-900 shadow-sm',
11
- blue: 'bg-blue-600 text-white',
12
- red: 'bg-red-600 text-white',
13
- green: 'bg-green-600 text-white',
14
- yellow: 'bg-yellow-600 text-white',
15
- violet: 'bg-violet-600 text-white',
16
- orange: 'bg-orange-600 text-white',
17
- rose: 'bg-rose-600 text-white',
18
- white: 'bg-white text-gray-900'
19
- }.freeze
20
-
21
- TAB_THEME_INACTIVE = {
22
- default: 'text-gray-500 hover:text-gray-700',
23
- blue: 'text-blue-600 hover:text-blue-700',
24
- red: 'text-red-600 hover:text-red-700',
25
- green: 'text-green-600 hover:text-green-700',
26
- yellow: 'text-yellow-600 hover:text-yellow-700',
27
- violet: 'text-violet-600 hover:text-violet-700',
28
- orange: 'text-orange-600 hover:text-orange-700',
29
- rose: 'text-rose-600 hover:text-rose-700',
30
- white: 'text-gray-600 hover:text-gray-700'
31
- }.freeze
32
-
33
- TAB_SIZE = {
34
- small: 'px-3 py-1.5 text-sm',
35
- medium: 'px-4 py-2 text-base',
36
- large: 'px-6 py-3 text-lg'
37
- }.freeze
38
-
39
- def initialize(text:, target:, active: false, icon: nil, disabled: false, badge: nil,
40
- theme: :default, size: :medium, classes: '', **options)
41
- @text = text
42
- @target = target
43
- @active = active
44
- @icon = icon
45
- @disabled = disabled
46
- @badge = badge
47
- @theme = theme
48
- @size = size
49
- @classes = classes
50
- @options = options
51
-
52
- validate_params
53
- end
54
-
55
- private
56
-
57
- attr_reader :text, :target, :active, :icon, :disabled, :badge, :theme, :size, :classes, :options
58
-
59
- def validate_params
60
- validate_theme
61
- validate_size
62
- end
63
-
64
- def validate_theme
65
- return if TAB_THEME_ACTIVE.key?(theme)
66
-
67
- raise ArgumentError, "Invalid theme: #{theme}. Must be one of #{TAB_THEME_ACTIVE.keys}"
68
- end
69
-
70
- def validate_size
71
- return if TAB_SIZE.key?(size)
72
-
73
- raise ArgumentError, "Invalid size: #{size}. Must be one of #{TAB_SIZE.keys}"
74
- end
75
-
76
- def tab_attributes
77
- theme_classes = active ? TAB_THEME_ACTIVE[theme] : TAB_THEME_INACTIVE[theme]
78
-
79
- base_classes = [
80
- 'inline-flex items-center justify-center gap-2 font-medium rounded-md transition-colors',
81
- 'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500',
82
- TAB_SIZE[size],
83
- theme_classes,
84
- disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',
85
- classes
86
- ].compact.join(' ')
87
-
88
- {
89
- class: base_classes,
90
- role: 'tab',
91
- 'aria-selected': active.to_s,
92
- 'aria-controls': target,
93
- 'data-bui-tabs-target': 'tab',
94
- 'data-target': target,
95
- 'data-action': disabled ? '' : 'click->bui-tabs#switchTab keydown->bui-tabs#keydown',
96
- tabindex: active ? '0' : '-1',
97
- id: "tab-#{target}"
98
- }.merge(options)
99
- end
100
-
101
- def has_icon?
102
- icon.present?
103
- end
104
-
105
- def has_badge?
106
- badge.present?
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,3 +0,0 @@
1
- <span class="<%= tag_classes %>">
2
- <%= text %>
3
- </span>
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BetterUi
4
- module General
5
- module Tag
6
- class Component < ViewComponent::Base
7
- def initialize(text:, theme: :white, size: :medium, style: :filled, **options)
8
- @text = text
9
- @theme = theme.to_sym
10
- @size = size.to_sym
11
- @style = style.to_sym
12
- @options = options
13
- end
14
-
15
- private
16
-
17
- attr_reader :text, :theme, :size, :style, :options
18
-
19
- def tag_classes
20
- base_classes = %w[
21
- inline-flex
22
- items-center
23
- justify-center
24
- font-medium
25
- transition-colors
26
- duration-200
27
- bui-tag
28
- ]
29
-
30
- base_classes.concat(size_classes)
31
- base_classes.concat(theme_classes)
32
- base_classes.concat(style_classes)
33
- base_classes.join(" ")
34
- end
35
-
36
- def size_classes
37
- case size
38
- when :small
39
- %w[text-xs px-2 py-1 rounded]
40
- when :large
41
- %w[text-base px-4 py-2 rounded-lg]
42
- else # :medium
43
- %w[text-sm px-3 py-1.5 rounded-md]
44
- end
45
- end
46
-
47
- def theme_classes
48
- case theme
49
- when :default
50
- %w[bg-gray-100 text-gray-800]
51
- when :red
52
- %w[bg-red-100 text-red-800]
53
- when :rose
54
- %w[bg-rose-100 text-rose-800]
55
- when :orange
56
- %w[bg-orange-100 text-orange-800]
57
- when :green
58
- %w[bg-green-100 text-green-800]
59
- when :blue
60
- %w[bg-blue-100 text-blue-800]
61
- when :yellow
62
- %w[bg-yellow-100 text-yellow-800]
63
- when :violet
64
- %w[bg-violet-100 text-violet-800]
65
- else # :white
66
- %w[bg-white text-gray-700 border border-gray-200]
67
- end
68
- end
69
-
70
- def style_classes
71
- case style
72
- when :outline
73
- outline_theme_classes
74
- else # :filled
75
- []
76
- end
77
- end
78
-
79
- def outline_theme_classes
80
- case theme
81
- when :default
82
- %w[bg-transparent border-gray-300 text-gray-700 hover:bg-gray-50]
83
- when :red
84
- %w[bg-transparent border-red-300 text-red-700 hover:bg-red-50]
85
- when :rose
86
- %w[bg-transparent border-rose-300 text-rose-700 hover:bg-rose-50]
87
- when :orange
88
- %w[bg-transparent border-orange-300 text-orange-700 hover:bg-orange-50]
89
- when :green
90
- %w[bg-transparent border-green-300 text-green-700 hover:bg-green-50]
91
- when :blue
92
- %w[bg-transparent border-blue-300 text-blue-700 hover:bg-blue-50]
93
- when :yellow
94
- %w[bg-transparent border-yellow-300 text-yellow-700 hover:bg-yellow-50]
95
- when :violet
96
- %w[bg-transparent border-violet-300 text-violet-700 hover:bg-violet-50]
97
- else # :white
98
- %w[bg-transparent border-gray-300 text-gray-700 hover:bg-gray-50]
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
@@ -1 +0,0 @@
1
- <%= tag.span(text_content, **text_attributes) %>
@@ -1,194 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BetterUi
4
- module General
5
- module Text
6
- class Component < ViewComponent::Base
7
- attr_reader :text, :theme, :size, :align, :weight, :style, :classes, :html_options
8
-
9
- # Classi base sempre presenti
10
- TEXT_BASE_CLASSES = "block"
11
-
12
- # Temi colore con classi Tailwind dirette
13
- TEXT_THEME_CLASSES = {
14
- default: "text-gray-900", # Testo nero standard
15
- white: "text-white", # Testo bianco
16
- red: "text-red-600",
17
- rose: "text-rose-600",
18
- orange: "text-orange-600",
19
- green: "text-green-600",
20
- blue: "text-blue-600",
21
- yellow: "text-yellow-600",
22
- violet: "text-violet-600",
23
- purple: "text-purple-600",
24
- gray: "text-gray-600",
25
- muted: "text-gray-500"
26
- }.freeze
27
-
28
- # Dimensioni con classi Tailwind dirette
29
- TEXT_SIZE_CLASSES = {
30
- xs: "text-xs",
31
- small: "text-sm",
32
- medium: "text-base",
33
- large: "text-lg",
34
- xl: "text-xl",
35
- "2xl": "text-2xl"
36
- }.freeze
37
-
38
- # Allineamenti con classi Tailwind dirette
39
- TEXT_ALIGN_CLASSES = {
40
- left: "text-left",
41
- center: "text-center",
42
- right: "text-right",
43
- justify: "text-justify"
44
- }.freeze
45
-
46
- # Peso font con classi Tailwind dirette
47
- TEXT_WEIGHT_CLASSES = {
48
- thin: "font-thin",
49
- light: "font-light",
50
- normal: "font-normal",
51
- medium: "font-medium",
52
- semibold: "font-semibold",
53
- bold: "font-bold",
54
- extrabold: "font-extrabold"
55
- }.freeze
56
-
57
- # Stili con classi Tailwind dirette
58
- TEXT_STYLE_CLASSES = {
59
- normal: "",
60
- italic: "italic",
61
- underline: "underline",
62
- line_through: "line-through"
63
- }.freeze
64
-
65
- # @param text [String] testo da mostrare (opzionale se si usa blocco)
66
- # @param theme [Symbol] tema del colore (:default, :white, :red, :blue, etc.)
67
- # @param size [Symbol] dimensione (:xs, :small, :medium, :large, :xl, :"2xl")
68
- # @param align [Symbol] allineamento (:left, :center, :right, :justify)
69
- # @param weight [Symbol] peso font (:thin, :light, :normal, :medium, :semibold, :bold, :extrabold)
70
- # @param style [Symbol] stile (:normal, :italic, :underline, :line_through)
71
- # @param classes [String] classi CSS aggiuntive
72
- # @param html_options [Hash] opzioni HTML aggiuntive
73
- def initialize(
74
- text: nil,
75
- theme: :default,
76
- size: :medium,
77
- align: :left,
78
- weight: :normal,
79
- style: :normal,
80
- classes: '',
81
- **html_options
82
- )
83
- @text = text
84
- @theme = theme.to_sym
85
- @size = size.to_sym
86
- @align = align.to_sym
87
- @weight = weight.to_sym
88
- @style = style.to_sym
89
- @classes = classes
90
- @html_options = html_options
91
-
92
- validate_params
93
- super()
94
- end
95
-
96
- # Combina tutte le classi CSS
97
- def combined_classes
98
- [
99
- TEXT_BASE_CLASSES,
100
- get_theme_classes,
101
- get_size_classes,
102
- get_align_classes,
103
- get_weight_classes,
104
- get_style_classes,
105
- @classes,
106
- @html_options[:class]
107
- ].compact.join(" ")
108
- end
109
-
110
- # Attributi HTML per l'elemento
111
- def text_attributes
112
- attrs = @html_options.except(:class)
113
- attrs[:class] = combined_classes
114
- attrs
115
- end
116
-
117
- # Determina se il componente ha contenuto da renderizzare
118
- def render?
119
- @text.present? || content.present?
120
- end
121
-
122
- # Contenuto da mostrare (testo diretto o contenuto blocco)
123
- def text_content
124
- @text.present? ? @text : content
125
- end
126
-
127
- private
128
-
129
- def validate_params
130
- validate_theme
131
- validate_size
132
- validate_align
133
- validate_weight
134
- validate_style
135
- end
136
-
137
- def validate_theme
138
- unless TEXT_THEME_CLASSES.key?(@theme)
139
- valid_themes = TEXT_THEME_CLASSES.keys
140
- raise ArgumentError, "Il tema deve essere uno tra: #{valid_themes.join(', ')}"
141
- end
142
- end
143
-
144
- def validate_size
145
- unless TEXT_SIZE_CLASSES.key?(@size)
146
- valid_sizes = TEXT_SIZE_CLASSES.keys
147
- raise ArgumentError, "La dimensione deve essere una tra: #{valid_sizes.join(', ')}"
148
- end
149
- end
150
-
151
- def validate_align
152
- unless TEXT_ALIGN_CLASSES.key?(@align)
153
- valid_aligns = TEXT_ALIGN_CLASSES.keys
154
- raise ArgumentError, "L'allineamento deve essere uno tra: #{valid_aligns.join(', ')}"
155
- end
156
- end
157
-
158
- def validate_weight
159
- unless TEXT_WEIGHT_CLASSES.key?(@weight)
160
- valid_weights = TEXT_WEIGHT_CLASSES.keys
161
- raise ArgumentError, "Il peso deve essere uno tra: #{valid_weights.join(', ')}"
162
- end
163
- end
164
-
165
- def validate_style
166
- unless TEXT_STYLE_CLASSES.key?(@style)
167
- valid_styles = TEXT_STYLE_CLASSES.keys
168
- raise ArgumentError, "Lo stile deve essere uno tra: #{valid_styles.join(', ')}"
169
- end
170
- end
171
-
172
- def get_theme_classes
173
- TEXT_THEME_CLASSES[@theme]
174
- end
175
-
176
- def get_size_classes
177
- TEXT_SIZE_CLASSES[@size]
178
- end
179
-
180
- def get_align_classes
181
- TEXT_ALIGN_CLASSES[@align]
182
- end
183
-
184
- def get_weight_classes
185
- TEXT_WEIGHT_CLASSES[@weight]
186
- end
187
-
188
- def get_style_classes
189
- TEXT_STYLE_CLASSES[@style]
190
- end
191
- end
192
- end
193
- end
194
- end
@@ -1,7 +0,0 @@
1
- <div <%= tag.attributes(tooltip_attributes) %>>
2
- <%= content %>
3
- <div class="<%= bubble_classes %>">
4
- <%= @text %>
5
- <div class="<%= arrow_classes %>"></div>
6
- </div>
7
- </div>
@@ -1,239 +0,0 @@
1
- module BetterUi
2
- module General
3
- module Tooltip
4
- class Component < ViewComponent::Base
5
- # Classi base sempre presenti
6
- TOOLTIP_BASE_CLASSES = "relative inline-block"
7
-
8
- # Classi base per il bubble del tooltip
9
- TOOLTIP_BUBBLE_BASE_CLASSES = "absolute z-50 px-2 py-1 text-sm rounded shadow-lg opacity-0 pointer-events-none transition-opacity duration-200"
10
-
11
- # Classi per la visibilità su hover
12
- TOOLTIP_HOVER_CLASSES = "group-hover:opacity-100"
13
-
14
- # Posizioni del tooltip con classi Tailwind dirette
15
- TOOLTIP_POSITIONS = {
16
- top: "bottom-full left-1/2 transform -translate-x-1/2 mb-2",
17
- right: "left-full top-1/2 transform -translate-y-1/2 ml-2",
18
- bottom: "top-full left-1/2 transform -translate-x-1/2 mt-2",
19
- left: "right-full top-1/2 transform -translate-y-1/2 mr-2"
20
- }
21
-
22
- # Dimensioni del tooltip con classi Tailwind dirette
23
- TOOLTIP_SIZES = {
24
- small: "px-1.5 py-0.5 text-xs",
25
- medium: "px-2 py-1 text-sm",
26
- large: "px-3 py-2 text-base"
27
- }
28
-
29
- # Temi di tooltip con classi Tailwind dirette - Stile filled
30
- TOOLTIP_FILLED_THEMES = {
31
- default: "bg-gray-900 text-white",
32
- white: "bg-white text-gray-900 border border-gray-200",
33
- red: "bg-red-600 text-white",
34
- rose: "bg-rose-600 text-white",
35
- orange: "bg-orange-600 text-white",
36
- green: "bg-green-600 text-white",
37
- blue: "bg-blue-600 text-white",
38
- yellow: "bg-yellow-600 text-white",
39
- violet: "bg-violet-600 text-white"
40
- }
41
-
42
- # Temi di tooltip con classi Tailwind dirette - Stile outline
43
- TOOLTIP_OUTLINE_THEMES = {
44
- default: "bg-white text-gray-900 border border-gray-900",
45
- white: "bg-gray-50 text-gray-900 border border-gray-300",
46
- red: "bg-white text-red-600 border border-red-600",
47
- rose: "bg-white text-rose-600 border border-rose-600",
48
- orange: "bg-white text-orange-600 border border-orange-600",
49
- green: "bg-white text-green-600 border border-green-600",
50
- blue: "bg-white text-blue-600 border border-blue-600",
51
- yellow: "bg-white text-yellow-600 border border-yellow-600",
52
- violet: "bg-white text-violet-600 border border-violet-600"
53
- }
54
-
55
- # Classi per le frecce del tooltip - Filled
56
- TOOLTIP_ARROW_BASE_CLASSES = "absolute w-2 h-2 transform rotate-45"
57
-
58
- TOOLTIP_ARROW_POSITIONS = {
59
- top: "top-full left-1/2 -translate-x-1/2 -mt-1",
60
- right: "right-full top-1/2 -translate-y-1/2 -mr-1",
61
- bottom: "bottom-full left-1/2 -translate-x-1/2 -mb-1",
62
- left: "left-full top-1/2 -translate-y-1/2 -ml-1"
63
- }
64
-
65
- TOOLTIP_ARROW_FILLED_THEMES = {
66
- default: "bg-gray-900",
67
- white: "bg-white border border-gray-200",
68
- red: "bg-red-600",
69
- rose: "bg-rose-600",
70
- orange: "bg-orange-600",
71
- green: "bg-green-600",
72
- blue: "bg-blue-600",
73
- yellow: "bg-yellow-600",
74
- violet: "bg-violet-600"
75
- }
76
-
77
- TOOLTIP_ARROW_OUTLINE_THEMES = {
78
- default: "bg-white border border-gray-900",
79
- white: "bg-gray-50 border border-gray-300",
80
- red: "bg-white border border-red-600",
81
- rose: "bg-white border border-rose-600",
82
- orange: "bg-white border border-orange-600",
83
- green: "bg-white border border-green-600",
84
- blue: "bg-white border border-blue-600",
85
- yellow: "bg-white border border-yellow-600",
86
- violet: "bg-white border border-violet-600"
87
- }
88
-
89
- # @param text [String] testo del tooltip
90
- # @param theme [Symbol] :default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet
91
- # @param position [Symbol] :top, :right, :bottom, :left posizione del tooltip
92
- # @param size [Symbol] :small, :medium, :large dimensione del tooltip
93
- # @param style [Symbol] :filled, :outline stile del tooltip
94
- # @param classes [String] classi CSS aggiuntive per il container
95
- # @param html_options [Hash] opzioni HTML per il container
96
- def initialize(
97
- text: nil,
98
- theme: :white,
99
- position: :top,
100
- size: :medium,
101
- style: :filled,
102
- classes: nil,
103
- **html_options
104
- )
105
- @text = text
106
- @theme = theme.to_sym
107
- @position = position.to_sym
108
- @size = size.to_sym
109
- @style = style.to_sym
110
- @classes = classes
111
- @html_options = html_options
112
-
113
- validate_params
114
- end
115
-
116
- # Combina tutte le classi per il container
117
- def combined_classes
118
- [
119
- TOOLTIP_BASE_CLASSES,
120
- "group", # Necessario per il trigger hover
121
- @classes,
122
- @html_options[:class]
123
- ].compact.join(" ")
124
- end
125
-
126
- # Combina tutte le classi per il bubble del tooltip
127
- def bubble_classes
128
- [
129
- TOOLTIP_BUBBLE_BASE_CLASSES,
130
- get_position_class,
131
- get_size_class,
132
- get_theme_class,
133
- TOOLTIP_HOVER_CLASSES
134
- ].compact.join(" ")
135
- end
136
-
137
- # Combina tutte le classi per la freccia del tooltip
138
- def arrow_classes
139
- [
140
- TOOLTIP_ARROW_BASE_CLASSES,
141
- get_arrow_position_class,
142
- get_arrow_theme_class
143
- ].compact.join(" ")
144
- end
145
-
146
- # Restituisce gli attributi per il container del tooltip
147
- def tooltip_attributes
148
- attrs = {
149
- class: combined_classes,
150
- role: "tooltip",
151
- "data-tooltip": @text
152
- }
153
-
154
- # Aggiungi altri attributi HTML se presenti
155
- @html_options.except(:class).each do |key, value|
156
- attrs[key] = value
157
- end
158
-
159
- attrs
160
- end
161
-
162
- # Genera le classi per la posizione
163
- def get_position_class
164
- TOOLTIP_POSITIONS[@position] || TOOLTIP_POSITIONS[:top]
165
- end
166
-
167
- # Genera le classi per la dimensione
168
- def get_size_class
169
- TOOLTIP_SIZES[@size] || TOOLTIP_SIZES[:medium]
170
- end
171
-
172
- # Genera le classi per il tema
173
- def get_theme_class
174
- if @style == :outline
175
- TOOLTIP_OUTLINE_THEMES[@theme] || TOOLTIP_OUTLINE_THEMES[:white]
176
- else
177
- TOOLTIP_FILLED_THEMES[@theme] || TOOLTIP_FILLED_THEMES[:white]
178
- end
179
- end
180
-
181
- # Genera le classi per la posizione della freccia
182
- def get_arrow_position_class
183
- TOOLTIP_ARROW_POSITIONS[@position] || TOOLTIP_ARROW_POSITIONS[:top]
184
- end
185
-
186
- # Genera le classi per il tema della freccia
187
- def get_arrow_theme_class
188
- if @style == :outline
189
- TOOLTIP_ARROW_OUTLINE_THEMES[@theme] || TOOLTIP_ARROW_OUTLINE_THEMES[:white]
190
- else
191
- TOOLTIP_ARROW_FILLED_THEMES[@theme] || TOOLTIP_ARROW_FILLED_THEMES[:white]
192
- end
193
- end
194
-
195
- # Verifica se il componente deve essere renderizzato
196
- def render?
197
- @text.present? && content.present?
198
- end
199
-
200
- private
201
-
202
- def validate_params
203
- validate_theme
204
- validate_position
205
- validate_size
206
- validate_style
207
- end
208
-
209
- def validate_theme
210
- valid_themes = TOOLTIP_FILLED_THEMES.keys
211
- unless valid_themes.include?(@theme)
212
- raise ArgumentError, "Il tema deve essere uno tra: #{valid_themes.join(', ')}"
213
- end
214
- end
215
-
216
- def validate_position
217
- valid_positions = TOOLTIP_POSITIONS.keys
218
- unless valid_positions.include?(@position)
219
- raise ArgumentError, "La posizione deve essere una tra: #{valid_positions.join(', ')}"
220
- end
221
- end
222
-
223
- def validate_size
224
- valid_sizes = TOOLTIP_SIZES.keys
225
- unless valid_sizes.include?(@size)
226
- raise ArgumentError, "La dimensione deve essere una tra: #{valid_sizes.join(', ')}"
227
- end
228
- end
229
-
230
- def validate_style
231
- valid_styles = [ :filled, :outline ]
232
- unless valid_styles.include?(@style)
233
- raise ArgumentError, "Lo stile deve essere uno tra: #{valid_styles.join(', ')}"
234
- end
235
- end
236
- end
237
- end
238
- end
239
- end