better_ui 0.1.0 → 0.1.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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +225 -119
  4. data/app/assets/stylesheets/better_ui/application.css +0 -356
  5. data/app/components/better_ui/application/card/component.html.erb +20 -0
  6. data/app/components/better_ui/application/card/component.rb +214 -0
  7. data/app/components/better_ui/application/main/component.html.erb +9 -0
  8. data/app/components/better_ui/application/main/component.rb +123 -0
  9. data/app/components/better_ui/application/navbar/component.html.erb +92 -0
  10. data/app/components/better_ui/application/navbar/component.rb +136 -0
  11. data/app/components/better_ui/application/sidebar/component.html.erb +190 -0
  12. data/app/components/better_ui/application/sidebar/component.rb +129 -0
  13. data/app/components/better_ui/general/alert/component.html.erb +32 -0
  14. data/app/components/better_ui/general/alert/component.rb +242 -0
  15. data/app/components/better_ui/general/avatar/component.html.erb +20 -0
  16. data/app/components/better_ui/general/avatar/component.rb +301 -0
  17. data/app/components/better_ui/general/badge/component.html.erb +23 -0
  18. data/app/components/better_ui/general/badge/component.rb +248 -0
  19. data/app/components/better_ui/general/breadcrumb/component.html.erb +15 -0
  20. data/app/components/better_ui/general/breadcrumb/component.rb +187 -0
  21. data/app/components/better_ui/general/button/component.html.erb +34 -0
  22. data/app/components/better_ui/general/button/component.rb +214 -0
  23. data/app/components/better_ui/general/divider/component.html.erb +10 -0
  24. data/app/components/better_ui/general/divider/component.rb +226 -0
  25. data/app/components/better_ui/general/field/component.html.erb +27 -0
  26. data/app/components/better_ui/general/field/component.rb +37 -0
  27. data/app/components/better_ui/general/heading/component.html.erb +22 -0
  28. data/app/components/better_ui/general/heading/component.rb +257 -0
  29. data/app/components/better_ui/general/icon/component.html.erb +7 -0
  30. data/app/components/better_ui/general/icon/component.rb +239 -0
  31. data/app/components/better_ui/general/input/checkbox/component.html.erb +5 -0
  32. data/app/components/better_ui/general/input/checkbox/component.rb +238 -0
  33. data/app/components/better_ui/general/input/datetime/component.html.erb +5 -0
  34. data/app/components/better_ui/general/input/datetime/component.rb +223 -0
  35. data/app/components/better_ui/general/input/radio/component.html.erb +5 -0
  36. data/app/components/better_ui/general/input/radio/component.rb +230 -0
  37. data/app/components/better_ui/general/input/select/component.html.erb +16 -0
  38. data/app/components/better_ui/general/input/select/component.rb +184 -0
  39. data/app/components/better_ui/general/input/select/select_component.html.erb +5 -0
  40. data/app/components/better_ui/general/input/select/select_component.rb +37 -0
  41. data/app/components/better_ui/general/input/text/component.html.erb +5 -0
  42. data/app/components/better_ui/general/input/text/component.rb +171 -0
  43. data/app/components/better_ui/general/input/textarea/component.html.erb +5 -0
  44. data/app/components/better_ui/general/input/textarea/component.rb +166 -0
  45. data/app/components/better_ui/general/link/component.html.erb +18 -0
  46. data/app/components/better_ui/general/link/component.rb +258 -0
  47. data/app/components/better_ui/general/panel/component.html.erb +28 -0
  48. data/app/components/better_ui/general/panel/component.rb +249 -0
  49. data/app/components/better_ui/general/progress/component.html.erb +11 -0
  50. data/app/components/better_ui/general/progress/component.rb +160 -0
  51. data/app/components/better_ui/general/spinner/component.html.erb +35 -0
  52. data/app/components/better_ui/general/spinner/component.rb +93 -0
  53. data/app/components/better_ui/general/table/component.html.erb +5 -0
  54. data/app/components/better_ui/general/table/component.rb +217 -0
  55. data/app/components/better_ui/general/table/tbody_component.html.erb +3 -0
  56. data/app/components/better_ui/general/table/tbody_component.rb +30 -0
  57. data/app/components/better_ui/general/table/td_component.html.erb +3 -0
  58. data/app/components/better_ui/general/table/td_component.rb +44 -0
  59. data/app/components/better_ui/general/table/tfoot_component.html.erb +3 -0
  60. data/app/components/better_ui/general/table/tfoot_component.rb +28 -0
  61. data/app/components/better_ui/general/table/th_component.html.erb +6 -0
  62. data/app/components/better_ui/general/table/th_component.rb +51 -0
  63. data/app/components/better_ui/general/table/thead_component.html.erb +3 -0
  64. data/app/components/better_ui/general/table/thead_component.rb +28 -0
  65. data/app/components/better_ui/general/table/tr_component.html.erb +3 -0
  66. data/app/components/better_ui/general/table/tr_component.rb +30 -0
  67. data/app/components/better_ui/general/tag/component.html.erb +3 -0
  68. data/app/components/better_ui/general/tag/component.rb +104 -0
  69. data/app/components/better_ui/general/tooltip/component.html.erb +7 -0
  70. data/app/components/better_ui/general/tooltip/component.rb +239 -0
  71. data/app/helpers/better_ui/application/components/card/card_helper.rb +96 -0
  72. data/app/helpers/better_ui/application/components/card.rb +11 -0
  73. data/app/helpers/better_ui/application/components/main/main_helper.rb +64 -0
  74. data/app/helpers/better_ui/application/components/navbar/navbar_helper.rb +77 -0
  75. data/app/helpers/better_ui/application/components/sidebar/sidebar_helper.rb +51 -0
  76. data/app/helpers/better_ui/application_helper.rb +42 -179
  77. data/app/helpers/better_ui/general/components/alert/alert_helper.rb +57 -0
  78. data/app/helpers/better_ui/general/components/avatar/avatar_helper.rb +29 -0
  79. data/app/helpers/better_ui/general/components/badge/badge_helper.rb +53 -0
  80. data/app/helpers/better_ui/general/components/breadcrumb/breadcrumb_helper.rb +37 -0
  81. data/app/helpers/better_ui/general/components/button/button_helper.rb +65 -0
  82. data/app/helpers/better_ui/general/components/container/container_helper.rb +60 -0
  83. data/app/helpers/better_ui/general/components/divider/divider_helper.rb +63 -0
  84. data/app/helpers/better_ui/general/components/field/field_helper.rb +26 -0
  85. data/app/helpers/better_ui/general/components/heading/heading_helper.rb +72 -0
  86. data/app/helpers/better_ui/general/components/icon/icon_helper.rb +16 -0
  87. data/app/helpers/better_ui/general/components/input/checkbox/checkbox_helper.rb +81 -0
  88. data/app/helpers/better_ui/general/components/input/datetime/datetime_helper.rb +91 -0
  89. data/app/helpers/better_ui/general/components/input/radio/radio_helper.rb +79 -0
  90. data/app/helpers/better_ui/general/components/input/radio_group/radio_group_helper.rb +124 -0
  91. data/app/helpers/better_ui/general/components/input/select/select_helper.rb +70 -0
  92. data/app/helpers/better_ui/general/components/input/text/text_helper.rb +138 -0
  93. data/app/helpers/better_ui/general/components/input/textarea/textarea_helper.rb +73 -0
  94. data/app/helpers/better_ui/general/components/link/link_helper.rb +89 -0
  95. data/app/helpers/better_ui/general/components/panel/panel_helper.rb +83 -0
  96. data/app/helpers/better_ui/general/components/progress/progress_helper.rb +53 -0
  97. data/app/helpers/better_ui/general/components/spinner/spinner_helper.rb +19 -0
  98. data/app/helpers/better_ui/general/components/table/table_helper.rb +53 -0
  99. data/app/helpers/better_ui/general/components/table/tbody_helper.rb +13 -0
  100. data/app/helpers/better_ui/general/components/table/td_helper.rb +19 -0
  101. data/app/helpers/better_ui/general/components/table/tfoot_helper.rb +13 -0
  102. data/app/helpers/better_ui/general/components/table/th_helper.rb +19 -0
  103. data/app/helpers/better_ui/general/components/table/thead_helper.rb +13 -0
  104. data/app/helpers/better_ui/general/components/table/tr_helper.rb +13 -0
  105. data/app/helpers/better_ui/general/components/tag/tag_helper.rb +26 -0
  106. data/app/helpers/better_ui/general/components/tooltip/tooltip_helper.rb +60 -0
  107. data/app/views/layouts/better_ui/application.html.erb +6 -124
  108. data/config/initializers/lookbook.rb +23 -0
  109. data/config/routes.rb +0 -8
  110. data/lib/better_ui/engine.rb +5 -19
  111. data/lib/better_ui/railtie.rb +20 -0
  112. data/lib/better_ui/version.rb +1 -1
  113. data/lib/better_ui.rb +4 -20
  114. metadata +131 -28
  115. data/app/controllers/better_ui/docs_controller.rb +0 -41
  116. data/app/views/better_ui/docs/component.html.erb +0 -365
  117. data/app/views/better_ui/docs/index.html.erb +0 -100
  118. data/app/views/better_ui/docs/show.html.erb +0 -60
@@ -0,0 +1,217 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class Component < ViewComponent::Base
5
+ attr_reader :data, :headers, :caption, :striped, :hoverable, :bordered, :compact, :minimal, :footer,
6
+ :header_rows_partial, :body_row_partial, :footer_rows_partial, :thead_partial, :tfoot_partial
7
+
8
+ # Classi base sempre presenti
9
+ TABLE_BASE_CLASSES = "w-full table-auto border-collapse"
10
+
11
+ # Temi di colore con classi Tailwind dirette
12
+ TABLE_THEME = {
13
+ default: "bg-gray-50 text-gray-900",
14
+ white: "bg-white text-gray-900",
15
+ red: "bg-red-50 text-red-900",
16
+ rose: "bg-rose-50 text-rose-900",
17
+ orange: "bg-orange-50 text-orange-900",
18
+ green: "bg-green-50 text-green-900",
19
+ blue: "bg-blue-50 text-blue-900",
20
+ yellow: "bg-yellow-50 text-yellow-900",
21
+ violet: "bg-violet-50 text-violet-900"
22
+ }.freeze
23
+
24
+ # Opzioni di bordi arrotondati con classi Tailwind dirette
25
+ TABLE_RADIUS = {
26
+ none: "rounded-none",
27
+ small: "rounded-md",
28
+ medium: "rounded-lg",
29
+ large: "rounded-xl",
30
+ full: "rounded-full"
31
+ }.freeze
32
+
33
+
34
+ # Classi per container
35
+ CONTAINER_BASE_CLASSES = "overflow-x-auto"
36
+
37
+ # Classi per elementi della tabella
38
+ THEAD_CLASSES = "bg-gray-100 border-b border-gray-200"
39
+ TBODY_CLASSES = ""
40
+ TFOOT_CLASSES = "bg-gray-50 border-t border-gray-200"
41
+ TR_CLASSES = "border-b border-gray-100 hover:bg-gray-50"
42
+ TH_CLASSES = "px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
43
+ TD_CLASSES = "px-4 py-3 text-sm text-gray-900"
44
+ TF_CLASSES = "px-4 py-3 text-sm font-medium text-gray-900"
45
+ CAPTION_CLASSES = "mb-2 text-sm text-gray-600 text-left"
46
+
47
+ def initialize(
48
+ data: nil,
49
+ headers: nil,
50
+ caption: nil,
51
+ theme: :default,
52
+ radius: :small,
53
+ striped: false,
54
+ hoverable: false,
55
+ bordered: false,
56
+ compact: false,
57
+ minimal: false,
58
+ footer: nil,
59
+ header_rows_partial: nil,
60
+ body_row_partial: nil,
61
+ footer_rows_partial: nil,
62
+ thead_partial: nil,
63
+ tfoot_partial: nil,
64
+ **html_options
65
+ )
66
+ @data = data || []
67
+ @headers = headers
68
+ @caption = caption
69
+ @theme = theme.to_sym
70
+ @radius = radius.to_sym
71
+ # Flag boolean combinabili
72
+ @striped = !!striped
73
+ @hoverable = !!hoverable
74
+ @bordered = !!bordered
75
+ @compact = !!compact
76
+ @minimal = !!minimal
77
+ @footer = footer.is_a?(Array) ? footer : nil
78
+ @header_rows_partial = header_rows_partial
79
+ @body_row_partial = body_row_partial
80
+ @footer_rows_partial = footer_rows_partial
81
+ @thead_partial = thead_partial
82
+ @tfoot_partial = tfoot_partial
83
+ @html_options = html_options
84
+
85
+ validate_params
86
+ end
87
+
88
+ # Combina tutte le classi per la tabella
89
+ def combined_classes
90
+ [
91
+ TABLE_BASE_CLASSES,
92
+ get_theme_class,
93
+ @bordered ? "border border-gray-200" : nil,
94
+ @striped ? "[&_tbody_tr:nth-child(odd)]:bg-gray-50" : nil,
95
+ @hoverable ? "[&_tbody_tr]:hover:bg-gray-50" : nil,
96
+ @compact ? "[&_td]:py-1 [&_th]:py-1" : nil,
97
+ @minimal ? "border-0" : nil,
98
+ @html_options[:class]
99
+ ].compact.join(" ")
100
+ end
101
+
102
+ # Restituisce gli attributi HTML per la tabella
103
+ def table_attributes
104
+ attrs = @html_options.except(:class)
105
+ attrs[:class] = combined_classes
106
+ attrs
107
+ end
108
+
109
+ # Combina le classi per il container
110
+ def table_container_classes
111
+ [
112
+ CONTAINER_BASE_CLASSES,
113
+ get_radius_class
114
+ ].compact.join(" ")
115
+ end
116
+
117
+ # Restituisce gli attributi HTML per il container
118
+ def container_attributes
119
+ {
120
+ class: table_container_classes
121
+ }
122
+ end
123
+
124
+ def get_radius_class
125
+ TABLE_RADIUS[@radius] || TABLE_RADIUS[:small]
126
+ end
127
+
128
+ def get_theme_class
129
+ TABLE_THEME[@theme] || TABLE_THEME[:default]
130
+ end
131
+
132
+
133
+ def caption_classes
134
+ CAPTION_CLASSES
135
+ end
136
+
137
+ def thead_classes
138
+ THEAD_CLASSES
139
+ end
140
+
141
+ def tbody_classes
142
+ TBODY_CLASSES
143
+ end
144
+
145
+ def tfoot_classes
146
+ TFOOT_CLASSES
147
+ end
148
+
149
+ def tr_classes(index)
150
+ TR_CLASSES
151
+ end
152
+
153
+ def th_classes
154
+ TH_CLASSES
155
+ end
156
+
157
+ def td_classes
158
+ TD_CLASSES
159
+ end
160
+
161
+ def tf_classes
162
+ TF_CLASSES
163
+ end
164
+
165
+ def headers_for_display
166
+ return @headers if @headers.present?
167
+ return [] if @data.empty?
168
+
169
+ case first_item = @data.first
170
+ when Hash
171
+ first_item.keys
172
+ when ->(item) { item.respond_to?(:attributes) }
173
+ first_item.attributes.keys - %w[id created_at updated_at]
174
+ else
175
+ []
176
+ end
177
+ end
178
+
179
+ # Ottiene il valore di una cella in modo consistente
180
+ def get_cell_value(row, header)
181
+ if row.is_a?(Hash)
182
+ row[header.to_s] || row[header.to_sym] || "—"
183
+ elsif row.respond_to?(header.to_sym)
184
+ row.send(header.to_sym)
185
+ elsif row.is_a?(Array) && headers_for_display.index(header)
186
+ row[headers_for_display.index(header)] || "—"
187
+ else
188
+ "—"
189
+ end
190
+ end
191
+
192
+ def render?
193
+ true
194
+ end
195
+
196
+ private
197
+
198
+ def validate_params
199
+ validate_theme
200
+ validate_radius
201
+ end
202
+
203
+ def validate_theme
204
+ unless TABLE_THEME.keys.include?(@theme)
205
+ raise ArgumentError, "Il tema deve essere uno tra: #{TABLE_THEME.keys.join(', ')}"
206
+ end
207
+ end
208
+
209
+ def validate_radius
210
+ unless TABLE_RADIUS.keys.include?(@radius)
211
+ raise ArgumentError, "Il radius deve essere uno tra: #{TABLE_RADIUS.keys.join(', ')}"
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,3 @@
1
+ <tbody <%= tag.attributes(tbody_attributes) %>>
2
+ <%= content %>
3
+ </tbody>
@@ -0,0 +1,30 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class TbodyComponent < ViewComponent::Base
5
+ attr_reader :theme, :striped, :hoverable
6
+
7
+ def initialize(theme: :default, striped: false, hoverable: false, **html_options)
8
+ @theme = theme.to_sym
9
+ @striped = !!striped
10
+ @hoverable = !!hoverable
11
+ @html_options = html_options
12
+ end
13
+
14
+ def tbody_classes
15
+ [
16
+ @striped ? "[&_tr:nth-child(odd)]:bg-gray-50" : nil,
17
+ @hoverable ? "[&_tr]:hover:bg-gray-50" : nil,
18
+ @html_options[:class]
19
+ ].compact.join(" ")
20
+ end
21
+
22
+ def tbody_attributes
23
+ attrs = @html_options.except(:class)
24
+ attrs[:class] = tbody_classes
25
+ attrs
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ <td <%= tag.attributes(td_attributes) %>>
2
+ <%= content %>
3
+ </td>
@@ -0,0 +1,44 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class TdComponent < ViewComponent::Base
5
+ attr_reader :theme, :align, :compact
6
+
7
+ def initialize(theme: :default, align: :left, compact: false, **html_options)
8
+ @theme = theme.to_sym
9
+ @align = align.to_sym
10
+ @compact = !!compact
11
+ @html_options = html_options
12
+ end
13
+
14
+ def td_classes
15
+ [
16
+ "px-4 py-3 text-sm text-gray-900",
17
+ alignment_class,
18
+ @compact ? "py-1" : nil,
19
+ @html_options[:class]
20
+ ].compact.join(" ")
21
+ end
22
+
23
+ def td_attributes
24
+ attrs = @html_options.except(:class)
25
+ attrs[:class] = td_classes
26
+ attrs
27
+ end
28
+
29
+ private
30
+
31
+ def alignment_class
32
+ case @align
33
+ when :center
34
+ "text-center"
35
+ when :right
36
+ "text-right"
37
+ else
38
+ "text-left"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ <tfoot <%= tag.attributes(tfoot_attributes) %>>
2
+ <%= content %>
3
+ </tfoot>
@@ -0,0 +1,28 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class TfootComponent < ViewComponent::Base
5
+ attr_reader :theme, :bordered
6
+
7
+ def initialize(theme: :default, bordered: false, **html_options)
8
+ @theme = theme.to_sym
9
+ @bordered = !!bordered
10
+ @html_options = html_options
11
+ end
12
+
13
+ def tfoot_classes
14
+ [
15
+ "bg-gray-50 border-t border-gray-200",
16
+ @html_options[:class]
17
+ ].compact.join(" ")
18
+ end
19
+
20
+ def tfoot_attributes
21
+ attrs = @html_options.except(:class)
22
+ attrs[:class] = tfoot_classes
23
+ attrs
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ <th <%= tag.attributes(th_attributes) %>>
2
+ <%= content %>
3
+ <% if @sortable %>
4
+ <span class="ml-1 text-gray-400"><%= sort_icon %></span>
5
+ <% end %>
6
+ </th>
@@ -0,0 +1,51 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class ThComponent < ViewComponent::Base
5
+ attr_reader :theme, :sortable, :sorted, :sort_direction, :scope
6
+
7
+ def initialize(
8
+ theme: :default,
9
+ sortable: false,
10
+ sorted: false,
11
+ sort_direction: :asc,
12
+ scope: "col",
13
+ **html_options
14
+ )
15
+ @theme = theme.to_sym
16
+ @sortable = !!sortable
17
+ @sorted = !!sorted
18
+ @sort_direction = sort_direction.to_sym
19
+ @scope = scope
20
+ @html_options = html_options
21
+ end
22
+
23
+ def th_classes
24
+ [
25
+ "px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",
26
+ @sortable ? "cursor-pointer hover:bg-gray-200" : nil,
27
+ @sorted ? "bg-gray-200" : nil,
28
+ @html_options[:class]
29
+ ].compact.join(" ")
30
+ end
31
+
32
+ def th_attributes
33
+ attrs = @html_options.except(:class)
34
+ attrs[:class] = th_classes
35
+ attrs[:scope] = @scope
36
+ attrs
37
+ end
38
+
39
+ def sort_icon
40
+ return unless @sortable
41
+
42
+ if @sorted
43
+ @sort_direction == :asc ? "↑" : "↓"
44
+ else
45
+ "↕"
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ <thead <%= tag.attributes(thead_attributes) %>>
2
+ <%= content %>
3
+ </thead>
@@ -0,0 +1,28 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class TheadComponent < ViewComponent::Base
5
+ attr_reader :theme, :bordered
6
+
7
+ def initialize(theme: :default, bordered: false, **html_options)
8
+ @theme = theme.to_sym
9
+ @bordered = !!bordered
10
+ @html_options = html_options
11
+ end
12
+
13
+ def thead_classes
14
+ [
15
+ "bg-gray-100 border-b border-gray-200",
16
+ @html_options[:class]
17
+ ].compact.join(" ")
18
+ end
19
+
20
+ def thead_attributes
21
+ attrs = @html_options.except(:class)
22
+ attrs[:class] = thead_classes
23
+ attrs
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ <tr <%= tag.attributes(tr_attributes) %>>
2
+ <%= content %>
3
+ </tr>
@@ -0,0 +1,30 @@
1
+ module BetterUi
2
+ module General
3
+ module Table
4
+ class TrComponent < ViewComponent::Base
5
+ attr_reader :theme, :highlighted, :striped_index
6
+
7
+ def initialize(theme: :default, highlighted: false, striped_index: nil, **html_options)
8
+ @theme = theme.to_sym
9
+ @highlighted = !!highlighted
10
+ @striped_index = striped_index
11
+ @html_options = html_options
12
+ end
13
+
14
+ def tr_classes
15
+ [
16
+ "border-b border-gray-100",
17
+ @highlighted ? "bg-blue-50" : nil,
18
+ @html_options[:class]
19
+ ].compact.join(" ")
20
+ end
21
+
22
+ def tr_attributes
23
+ attrs = @html_options.except(:class)
24
+ attrs[:class] = tr_classes
25
+ attrs
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ <span class="<%= tag_classes %>">
2
+ <%= text %>
3
+ </span>
@@ -0,0 +1,104 @@
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
@@ -0,0 +1,7 @@
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>