better_ui 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/README.md +165 -105
- data/app/components/better_ui/application/alert_component.html.erb +1 -1
- data/app/components/better_ui/application/alert_component.rb +95 -89
- data/app/components/better_ui/application/card_component.html.erb +24 -0
- data/app/components/better_ui/application/card_component.rb +53 -0
- data/app/components/better_ui/application/card_container_component.html.erb +8 -0
- data/app/components/better_ui/application/card_container_component.rb +14 -0
- data/app/components/better_ui/application/toast_component.rb +92 -57
- data/app/components/better_ui/general/avatar_component.html.erb +19 -0
- data/app/components/better_ui/general/avatar_component.rb +171 -0
- data/app/components/better_ui/general/badge_component.html.erb +19 -0
- data/app/components/better_ui/general/badge_component.rb +123 -0
- data/app/components/better_ui/general/breadcrumb_component.html.erb +7 -31
- data/app/components/better_ui/general/breadcrumb_component.rb +64 -66
- data/app/components/better_ui/general/button_component.html.erb +4 -4
- data/app/components/better_ui/general/button_component.rb +64 -95
- data/app/components/better_ui/general/heading_component.html.erb +3 -3
- data/app/components/better_ui/general/heading_component.rb +76 -70
- data/app/components/better_ui/general/icon_component.html.erb +1 -1
- data/app/components/better_ui/general/icon_component.rb +22 -23
- data/app/components/better_ui/general/link_component.html.erb +17 -0
- data/app/components/better_ui/general/link_component.rb +132 -0
- data/app/components/better_ui/general/panel_component.rb +62 -56
- data/app/components/better_ui/general/spinner_component.html.erb +15 -0
- data/app/components/better_ui/general/spinner_component.rb +79 -0
- data/app/components/better_ui/general/table_component.html.erb +56 -20
- data/app/components/better_ui/general/table_component.rb +106 -80
- data/app/components/better_ui/theme_helper.rb +77 -75
- data/app/views/components/better_ui/general/table/_custom_body_row.html.erb +17 -0
- data/app/views/components/better_ui/general/table/_custom_footer_rows.html.erb +17 -0
- data/app/views/components/better_ui/general/table/_custom_header_rows.html.erb +12 -0
- data/lib/better_ui/engine.rb +4 -10
- data/lib/better_ui/version.rb +1 -1
- data/lib/better_ui.rb +4 -0
- data/lib/generators/better_ui/stylesheet_generator.rb +96 -0
- data/lib/generators/better_ui/templates/README +56 -0
- data/lib/generators/better_ui/templates/components/_avatar.scss +151 -0
- data/lib/generators/better_ui/templates/components/_badge.scss +142 -0
- data/lib/generators/better_ui/templates/components/_breadcrumb.scss +107 -0
- data/lib/generators/better_ui/templates/components/_button.scss +106 -0
- data/lib/generators/better_ui/templates/components/_card.scss +69 -0
- data/lib/generators/better_ui/templates/components/_heading.scss +180 -0
- data/lib/generators/better_ui/templates/components/_icon.scss +90 -0
- data/lib/generators/better_ui/templates/components/_link.scss +130 -0
- data/lib/generators/better_ui/templates/components/_panel.scss +144 -0
- data/lib/generators/better_ui/templates/components/_spinner.scss +132 -0
- data/lib/generators/better_ui/templates/components/_table.scss +105 -0
- data/lib/generators/better_ui/templates/components/_variables.scss +33 -0
- data/lib/generators/better_ui/templates/components_stylesheet.scss +66 -0
- metadata +51 -22
- data/app/helpers/better_ui_application_helper.rb +0 -99
@@ -1,91 +1,95 @@
|
|
1
1
|
module BetterUi
|
2
2
|
module Application
|
3
3
|
class AlertComponent < ViewComponent::Base
|
4
|
-
attr_reader :title, :message, :variant, :icon, :dismissible, :classes, :data, :icon_position, :outline
|
4
|
+
attr_reader :title, :message, :variant, :icon, :dismissible, :classes, :data, :icon_position, :outline, :rounded
|
5
5
|
|
6
6
|
# Varianti di colore disponibili
|
7
7
|
VARIANTS = {
|
8
|
-
|
9
|
-
bg: "bg-
|
10
|
-
border: "border-
|
11
|
-
title: "text-
|
12
|
-
text: "text-
|
13
|
-
icon: "text-
|
14
|
-
close: "text-
|
15
|
-
outline_bg: "bg-white",
|
16
|
-
outline_text: "text-orange-700"
|
8
|
+
default: {
|
9
|
+
bg: "bg-black",
|
10
|
+
border: "border-gray-900",
|
11
|
+
title: "text-white",
|
12
|
+
text: "text-white",
|
13
|
+
icon: "text-white",
|
14
|
+
close: "text-white hover:bg-gray-800"
|
17
15
|
},
|
18
|
-
|
19
|
-
bg: "bg-
|
20
|
-
border: "border-
|
21
|
-
title: "text-
|
22
|
-
text: "text-
|
23
|
-
icon: "text-
|
24
|
-
close: "text-
|
25
|
-
outline_bg: "bg-white",
|
26
|
-
outline_text: "text-blue-700"
|
16
|
+
white: {
|
17
|
+
bg: "bg-white",
|
18
|
+
border: "border-gray-200",
|
19
|
+
title: "text-black",
|
20
|
+
text: "text-black",
|
21
|
+
icon: "text-black",
|
22
|
+
close: "text-black hover:bg-gray-100"
|
27
23
|
},
|
28
|
-
|
29
|
-
bg: "bg-
|
30
|
-
border: "border-
|
31
|
-
title: "text-
|
32
|
-
text: "text-
|
33
|
-
icon: "text-
|
34
|
-
close: "text-
|
35
|
-
outline_bg: "bg-white",
|
36
|
-
outline_text: "text-green-700"
|
24
|
+
red: {
|
25
|
+
bg: "bg-red-500",
|
26
|
+
border: "border-red-600",
|
27
|
+
title: "text-white",
|
28
|
+
text: "text-white",
|
29
|
+
icon: "text-white",
|
30
|
+
close: "text-white hover:bg-red-600"
|
37
31
|
},
|
38
|
-
|
39
|
-
bg: "bg-
|
40
|
-
border: "border-
|
41
|
-
title: "text-
|
42
|
-
text: "text-
|
43
|
-
icon: "text-
|
44
|
-
close: "text-
|
45
|
-
outline_bg: "bg-white",
|
46
|
-
outline_text: "text-yellow-700"
|
32
|
+
rose: {
|
33
|
+
bg: "bg-rose-500",
|
34
|
+
border: "border-rose-600",
|
35
|
+
title: "text-white",
|
36
|
+
text: "text-white",
|
37
|
+
icon: "text-white",
|
38
|
+
close: "text-white hover:bg-rose-600"
|
47
39
|
},
|
48
|
-
|
49
|
-
bg: "bg-
|
50
|
-
border: "border-
|
51
|
-
title: "text-
|
52
|
-
text: "text-
|
53
|
-
icon: "text-
|
54
|
-
close: "text-
|
55
|
-
outline_bg: "bg-white",
|
56
|
-
outline_text: "text-red-700"
|
40
|
+
orange: {
|
41
|
+
bg: "bg-orange-500",
|
42
|
+
border: "border-orange-600",
|
43
|
+
title: "text-white",
|
44
|
+
text: "text-white",
|
45
|
+
icon: "text-white",
|
46
|
+
close: "text-white hover:bg-orange-600"
|
57
47
|
},
|
58
|
-
|
59
|
-
bg: "bg-
|
60
|
-
border: "border-
|
48
|
+
green: {
|
49
|
+
bg: "bg-green-500",
|
50
|
+
border: "border-green-600",
|
61
51
|
title: "text-white",
|
62
|
-
text: "text-
|
63
|
-
icon: "text-
|
64
|
-
close: "text-
|
65
|
-
outline_bg: "bg-white",
|
66
|
-
outline_text: "text-gray-800"
|
52
|
+
text: "text-white",
|
53
|
+
icon: "text-white",
|
54
|
+
close: "text-white hover:bg-green-600"
|
67
55
|
},
|
68
|
-
|
69
|
-
bg: "bg-
|
70
|
-
border: "border-
|
71
|
-
title: "text-
|
72
|
-
text: "text-
|
73
|
-
icon: "text-
|
74
|
-
close: "text-
|
75
|
-
|
76
|
-
|
56
|
+
blue: {
|
57
|
+
bg: "bg-blue-500",
|
58
|
+
border: "border-blue-600",
|
59
|
+
title: "text-white",
|
60
|
+
text: "text-white",
|
61
|
+
icon: "text-white",
|
62
|
+
close: "text-white hover:bg-blue-600"
|
63
|
+
},
|
64
|
+
yellow: {
|
65
|
+
bg: "bg-yellow-500",
|
66
|
+
border: "border-yellow-600",
|
67
|
+
title: "text-black",
|
68
|
+
text: "text-black",
|
69
|
+
icon: "text-black",
|
70
|
+
close: "text-black hover:bg-yellow-600"
|
71
|
+
},
|
72
|
+
violet: {
|
73
|
+
bg: "bg-violet-500",
|
74
|
+
border: "border-violet-600",
|
75
|
+
title: "text-white",
|
76
|
+
text: "text-white",
|
77
|
+
icon: "text-white",
|
78
|
+
close: "text-white hover:bg-violet-600"
|
77
79
|
}
|
78
80
|
}
|
79
81
|
|
80
82
|
# Icone predefinite per ciascuna variante
|
81
83
|
DEFAULT_ICONS = {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
default: "bell",
|
85
|
+
white: "info-circle",
|
86
|
+
red: "exclamation-circle",
|
87
|
+
rose: "exclamation-circle",
|
88
|
+
orange: "bell",
|
89
|
+
green: "check-circle",
|
90
|
+
blue: "info-circle",
|
91
|
+
yellow: "exclamation-triangle",
|
92
|
+
violet: "shield-exclamation"
|
89
93
|
}
|
90
94
|
|
91
95
|
# Posizioni possibili per le icone
|
@@ -95,13 +99,14 @@ module BetterUi
|
|
95
99
|
def initialize(
|
96
100
|
title: nil,
|
97
101
|
message: nil,
|
98
|
-
variant: :
|
102
|
+
variant: :default,
|
99
103
|
icon: nil,
|
100
104
|
dismissible: false,
|
101
105
|
classes: nil,
|
102
106
|
data: {},
|
103
107
|
icon_position: :left,
|
104
|
-
outline: false
|
108
|
+
outline: false,
|
109
|
+
rounded: :sm
|
105
110
|
)
|
106
111
|
@title = title
|
107
112
|
@message = message
|
@@ -112,58 +117,59 @@ module BetterUi
|
|
112
117
|
@data = data
|
113
118
|
@icon_position = icon_position.to_sym
|
114
119
|
@outline = outline
|
120
|
+
@rounded = rounded.to_sym
|
115
121
|
end
|
116
122
|
|
117
123
|
# Genera l'icona in base alla variante se non specificata
|
118
124
|
def effective_icon
|
119
125
|
return @icon if @icon.present?
|
120
|
-
DEFAULT_ICONS[@variant]
|
126
|
+
DEFAULT_ICONS[@variant] || DEFAULT_ICONS[:default]
|
121
127
|
end
|
122
128
|
|
123
129
|
# Genera le classi per il container
|
124
130
|
def container_classes
|
125
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
131
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
126
132
|
|
127
|
-
base_classes = ["p-4 mb-4 flex"]
|
128
|
-
|
129
|
-
if @variant == :simple
|
130
|
-
base_classes << "border rounded-md"
|
131
|
-
else
|
132
|
-
base_classes << "rounded-lg border"
|
133
|
-
end
|
133
|
+
base_classes = ["p-4 mb-4 flex border"]
|
134
|
+
base_classes << get_border_radius_class
|
134
135
|
|
135
136
|
[
|
136
137
|
*base_classes,
|
137
|
-
|
138
|
+
styles[:bg],
|
138
139
|
styles[:border],
|
139
140
|
@icon_position == :top ? "flex-col" : "items-start",
|
140
141
|
@classes
|
141
142
|
].compact.join(" ")
|
142
143
|
end
|
143
144
|
|
145
|
+
# Genera il border-radius
|
146
|
+
def get_border_radius_class
|
147
|
+
ThemeHelper::BORDER_RADIUS[@rounded] || ThemeHelper::BORDER_RADIUS[:sm]
|
148
|
+
end
|
149
|
+
|
144
150
|
# Genera le classi per il titolo
|
145
151
|
def title_classes
|
146
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
152
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
147
153
|
|
148
154
|
[
|
149
|
-
|
150
|
-
|
155
|
+
"font-medium",
|
156
|
+
styles[:title]
|
151
157
|
].compact.join(" ")
|
152
158
|
end
|
153
159
|
|
154
160
|
# Genera le classi per il messaggio
|
155
161
|
def message_classes
|
156
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
162
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
157
163
|
|
158
164
|
[
|
159
165
|
"mt-1",
|
160
|
-
|
166
|
+
styles[:text]
|
161
167
|
].compact.join(" ")
|
162
168
|
end
|
163
169
|
|
164
170
|
# Genera le classi per l'icona
|
165
171
|
def icon_classes
|
166
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
172
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
167
173
|
|
168
174
|
[
|
169
175
|
"flex-shrink-0",
|
@@ -174,7 +180,7 @@ module BetterUi
|
|
174
180
|
|
175
181
|
# Genera le classi per il pulsante di chiusura
|
176
182
|
def close_button_classes
|
177
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
183
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
178
184
|
|
179
185
|
[
|
180
186
|
"ml-auto -mr-1.5 -mt-1.5 inline-flex h-8 w-8 rounded-lg p-1.5 focus:ring-2 focus:ring-gray-400",
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<div class="bui-card-base <%= get_border_radius_class %> px-4 py-5 sm:p-6">
|
2
|
+
<dt class="bui-card-title text-gray-900"><%= title %></dt>
|
3
|
+
<dd class="bui-card-body mt-1 flex items-baseline justify-between md:block lg:flex">
|
4
|
+
<div class="flex items-baseline">
|
5
|
+
<span class="bui-card-value text-indigo-600"><%= value %></span>
|
6
|
+
<span class="bui-card-value-from ml-2">from <%= value_from %></span>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="bui-card-trend <%= trend_classes %>">
|
10
|
+
<% if trend_type == :up %>
|
11
|
+
<svg class="mr-0.5 -ml-1 size-5 shrink-0 self-center <%= trend_icon_classes %>" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
12
|
+
<path fill-rule="evenodd" d="M10 17a.75.75 0 0 1-.75-.75V5.612L5.29 9.77a.75.75 0 0 1-1.08-1.04l5.25-5.5a.75.75 0 0 1 1.08 0l5.25 5.5a.75.75 0 1 1-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0 1 10 17Z" clip-rule="evenodd" />
|
13
|
+
</svg>
|
14
|
+
<span class="sr-only">Incremento di</span>
|
15
|
+
<% else %>
|
16
|
+
<svg class="mr-0.5 -ml-1 size-5 shrink-0 self-center <%= trend_icon_classes %>" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
17
|
+
<path fill-rule="evenodd" d="M10 3a.75.75 0 0 1 .75.75v10.638l3.96-4.158a.75.75 0 1 1 1.08 1.04l-5.25 5.5a.75.75 0 0 1-1.08 0l-5.25-5.5a.75.75 0 1 1 1.08-1.04l3.96 4.158V3.75A.75.75 0 0 1 10 3Z" clip-rule="evenodd" />
|
18
|
+
</svg>
|
19
|
+
<span class="sr-only">Decremento di</span>
|
20
|
+
<% end %>
|
21
|
+
<%= trend_value %>
|
22
|
+
</div>
|
23
|
+
</dd>
|
24
|
+
</div>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module Application
|
5
|
+
class CardComponent < ViewComponent::Base
|
6
|
+
attr_reader :title, :value, :value_from, :trend_value, :trend_type, :rounded
|
7
|
+
|
8
|
+
# Opzioni di bordi arrotondati standardizzati
|
9
|
+
CARD_RADIUS = {
|
10
|
+
none: 'bui-card-radius-none',
|
11
|
+
small: 'bui-card-radius-small',
|
12
|
+
medium: 'bui-card-radius-medium',
|
13
|
+
large: 'bui-card-radius-large',
|
14
|
+
full: 'bui-card-radius-full'
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
# @param title [String] Titolo della card
|
18
|
+
# @param value [String] Valore principale da visualizzare
|
19
|
+
# @param value_from [String] Valore precedente di riferimento
|
20
|
+
# @param trend_value [String] Percentuale di variazione
|
21
|
+
# @param trend_type [Symbol] Tipo di variazione (:up o :down)
|
22
|
+
# @param rounded [Symbol] Tipo di border-radius (:none, :small, :medium, :large, :full), default :small
|
23
|
+
def initialize(title:, value:, value_from:, trend_value:, trend_type: :up, rounded: :small)
|
24
|
+
@title = title
|
25
|
+
@value = value
|
26
|
+
@value_from = value_from
|
27
|
+
@trend_value = trend_value
|
28
|
+
@trend_type = trend_type.to_sym
|
29
|
+
@rounded = rounded.to_sym
|
30
|
+
end
|
31
|
+
|
32
|
+
def trend_classes
|
33
|
+
if trend_type == :up
|
34
|
+
'bg-green-500 text-white'
|
35
|
+
else
|
36
|
+
'bg-black text-white'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def trend_icon_classes
|
41
|
+
if trend_type == :up
|
42
|
+
'text-white'
|
43
|
+
else
|
44
|
+
'text-white'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_border_radius_class
|
49
|
+
CARD_RADIUS[@rounded] || CARD_RADIUS[:small]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<div>
|
2
|
+
<h3 class="text-base font-semibold text-gray-900"><%= @title %></h3>
|
3
|
+
<dl class="mt-5 grid grid-cols-1 divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow-sm md:grid-cols-3 md:divide-x md:divide-y-0">
|
4
|
+
<% cards.each do |card| %>
|
5
|
+
<%= card %>
|
6
|
+
<% end %>
|
7
|
+
</dl>
|
8
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module Application
|
5
|
+
class CardContainerComponent < ViewComponent::Base
|
6
|
+
renders_many :cards, CardComponent
|
7
|
+
|
8
|
+
# @param title [String] Titolo del container delle card
|
9
|
+
def initialize(title:)
|
10
|
+
@title = title
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,68 +1,95 @@
|
|
1
1
|
module BetterUi
|
2
2
|
module Application
|
3
3
|
class ToastComponent < ViewComponent::Base
|
4
|
-
attr_reader :title, :message, :variant, :icon, :dismissible, :classes, :data, :position, :duration, :auto_hide
|
4
|
+
attr_reader :title, :message, :variant, :icon, :dismissible, :classes, :data, :position, :duration, :auto_hide, :rounded
|
5
5
|
|
6
6
|
# Varianti di colore disponibili
|
7
7
|
VARIANTS = {
|
8
|
-
|
9
|
-
bg: "bg-
|
10
|
-
border: "border-
|
11
|
-
title: "text-
|
12
|
-
text: "text-
|
13
|
-
icon: "text-
|
14
|
-
close: "text-
|
8
|
+
default: {
|
9
|
+
bg: "bg-black",
|
10
|
+
border: "border-gray-900",
|
11
|
+
title: "text-white",
|
12
|
+
text: "text-white",
|
13
|
+
icon: "text-white",
|
14
|
+
close: "text-white hover:bg-gray-800"
|
15
|
+
},
|
16
|
+
white: {
|
17
|
+
bg: "bg-white",
|
18
|
+
border: "border-gray-200",
|
19
|
+
title: "text-black",
|
20
|
+
text: "text-black",
|
21
|
+
icon: "text-black",
|
22
|
+
close: "text-black hover:bg-gray-100"
|
15
23
|
},
|
16
|
-
|
17
|
-
bg: "bg-
|
18
|
-
border: "border-
|
19
|
-
title: "text-
|
20
|
-
text: "text-
|
21
|
-
icon: "text-
|
22
|
-
close: "text-
|
24
|
+
red: {
|
25
|
+
bg: "bg-red-500",
|
26
|
+
border: "border-red-600",
|
27
|
+
title: "text-white",
|
28
|
+
text: "text-white",
|
29
|
+
icon: "text-white",
|
30
|
+
close: "text-white hover:bg-red-600"
|
23
31
|
},
|
24
|
-
|
25
|
-
bg: "bg-
|
26
|
-
border: "border-
|
27
|
-
title: "text-
|
28
|
-
text: "text-
|
29
|
-
icon: "text-
|
30
|
-
close: "text-
|
32
|
+
rose: {
|
33
|
+
bg: "bg-rose-500",
|
34
|
+
border: "border-rose-600",
|
35
|
+
title: "text-white",
|
36
|
+
text: "text-white",
|
37
|
+
icon: "text-white",
|
38
|
+
close: "text-white hover:bg-rose-600"
|
31
39
|
},
|
32
|
-
|
33
|
-
bg: "bg-
|
34
|
-
border: "border-
|
35
|
-
title: "text-
|
36
|
-
text: "text-
|
37
|
-
icon: "text-
|
38
|
-
close: "text-
|
40
|
+
orange: {
|
41
|
+
bg: "bg-orange-500",
|
42
|
+
border: "border-orange-600",
|
43
|
+
title: "text-white",
|
44
|
+
text: "text-white",
|
45
|
+
icon: "text-white",
|
46
|
+
close: "text-white hover:bg-orange-600"
|
39
47
|
},
|
40
|
-
|
41
|
-
bg: "bg-
|
42
|
-
border: "border-
|
43
|
-
title: "text-
|
44
|
-
text: "text-
|
45
|
-
icon: "text-
|
46
|
-
close: "text-
|
48
|
+
green: {
|
49
|
+
bg: "bg-green-500",
|
50
|
+
border: "border-green-600",
|
51
|
+
title: "text-white",
|
52
|
+
text: "text-white",
|
53
|
+
icon: "text-white",
|
54
|
+
close: "text-white hover:bg-green-600"
|
47
55
|
},
|
48
|
-
|
49
|
-
bg: "bg-
|
50
|
-
border: "border-
|
56
|
+
blue: {
|
57
|
+
bg: "bg-blue-500",
|
58
|
+
border: "border-blue-600",
|
51
59
|
title: "text-white",
|
52
|
-
text: "text-
|
53
|
-
icon: "text-
|
54
|
-
close: "text-
|
60
|
+
text: "text-white",
|
61
|
+
icon: "text-white",
|
62
|
+
close: "text-white hover:bg-blue-600"
|
63
|
+
},
|
64
|
+
yellow: {
|
65
|
+
bg: "bg-yellow-500",
|
66
|
+
border: "border-yellow-600",
|
67
|
+
title: "text-black",
|
68
|
+
text: "text-black",
|
69
|
+
icon: "text-black",
|
70
|
+
close: "text-black hover:bg-yellow-600"
|
71
|
+
},
|
72
|
+
violet: {
|
73
|
+
bg: "bg-violet-500",
|
74
|
+
border: "border-violet-600",
|
75
|
+
title: "text-white",
|
76
|
+
text: "text-white",
|
77
|
+
icon: "text-white",
|
78
|
+
close: "text-white hover:bg-violet-600"
|
55
79
|
}
|
56
80
|
}
|
57
81
|
|
58
82
|
# Icone predefinite per ciascuna variante
|
59
83
|
DEFAULT_ICONS = {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
84
|
+
default: "bell",
|
85
|
+
white: "info-circle",
|
86
|
+
red: "exclamation-circle",
|
87
|
+
rose: "exclamation-circle",
|
88
|
+
orange: "bell",
|
89
|
+
green: "check-circle",
|
90
|
+
blue: "info-circle",
|
91
|
+
yellow: "exclamation-triangle",
|
92
|
+
violet: "shield-exclamation"
|
66
93
|
}
|
67
94
|
|
68
95
|
# Posizioni possibili per i toast
|
@@ -79,14 +106,15 @@ module BetterUi
|
|
79
106
|
def initialize(
|
80
107
|
title: nil,
|
81
108
|
message: nil,
|
82
|
-
variant: :
|
109
|
+
variant: :default,
|
83
110
|
icon: nil,
|
84
111
|
dismissible: true,
|
85
112
|
classes: nil,
|
86
113
|
data: {},
|
87
114
|
position: :"top-right",
|
88
115
|
duration: 5000,
|
89
|
-
auto_hide: true
|
116
|
+
auto_hide: true,
|
117
|
+
rounded: :sm
|
90
118
|
)
|
91
119
|
@title = title
|
92
120
|
@message = message
|
@@ -98,6 +126,7 @@ module BetterUi
|
|
98
126
|
@position = position.to_sym
|
99
127
|
@duration = duration
|
100
128
|
@auto_hide = auto_hide
|
129
|
+
@rounded = rounded.to_sym
|
101
130
|
|
102
131
|
# Aggiungiamo dati per il comportamento del toast
|
103
132
|
@data[:controller] = "toast" if @data[:controller].blank?
|
@@ -109,16 +138,17 @@ module BetterUi
|
|
109
138
|
# Genera l'icona in base alla variante se non specificata
|
110
139
|
def effective_icon
|
111
140
|
return @icon if @icon.present?
|
112
|
-
DEFAULT_ICONS[@variant]
|
141
|
+
DEFAULT_ICONS[@variant] || DEFAULT_ICONS[:default]
|
113
142
|
end
|
114
143
|
|
115
144
|
# Genera le classi per il container
|
116
145
|
def container_classes
|
117
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
146
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
118
147
|
position_class = POSITIONS.fetch(@position, POSITIONS[:"top-right"])
|
119
148
|
|
120
149
|
[
|
121
|
-
"fixed z-50
|
150
|
+
"fixed z-50 p-4 border shadow-lg",
|
151
|
+
get_border_radius_class,
|
122
152
|
"transform transition-transform duration-300",
|
123
153
|
"data-toast-enter-from-class='translate-y-2 opacity-0'",
|
124
154
|
"data-toast-enter-to-class='translate-y-0 opacity-100'",
|
@@ -133,9 +163,14 @@ module BetterUi
|
|
133
163
|
].compact.join(" ")
|
134
164
|
end
|
135
165
|
|
166
|
+
# Genera il border-radius
|
167
|
+
def get_border_radius_class
|
168
|
+
ThemeHelper::BORDER_RADIUS[@rounded] || ThemeHelper::BORDER_RADIUS[:sm]
|
169
|
+
end
|
170
|
+
|
136
171
|
# Genera le classi per il titolo
|
137
172
|
def title_classes
|
138
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
173
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
139
174
|
|
140
175
|
[
|
141
176
|
"font-medium",
|
@@ -145,7 +180,7 @@ module BetterUi
|
|
145
180
|
|
146
181
|
# Genera le classi per il messaggio
|
147
182
|
def message_classes
|
148
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
183
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
149
184
|
|
150
185
|
[
|
151
186
|
"mt-1",
|
@@ -155,7 +190,7 @@ module BetterUi
|
|
155
190
|
|
156
191
|
# Genera le classi per l'icona
|
157
192
|
def icon_classes
|
158
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
193
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
159
194
|
|
160
195
|
[
|
161
196
|
"flex-shrink-0",
|
@@ -166,7 +201,7 @@ module BetterUi
|
|
166
201
|
|
167
202
|
# Genera le classi per il pulsante di chiusura
|
168
203
|
def close_button_classes
|
169
|
-
styles = VARIANTS.fetch(@variant, VARIANTS[:
|
204
|
+
styles = VARIANTS.fetch(@variant, VARIANTS[:default])
|
170
205
|
|
171
206
|
[
|
172
207
|
"ml-auto -mr-1.5 -mt-1.5 inline-flex h-8 w-8 rounded-lg p-1.5 focus:ring-2 focus:ring-gray-400",
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<div <%= avatar_attributes.to_s.html_safe %>>
|
2
|
+
<% if show_image? %>
|
3
|
+
<img
|
4
|
+
src="<%= @src %>"
|
5
|
+
alt="<%= @name || 'Avatar' %>"
|
6
|
+
class="bui-avatar-image"
|
7
|
+
width="<%= pixel_size %>"
|
8
|
+
height="<%= pixel_size %>"
|
9
|
+
>
|
10
|
+
<% else %>
|
11
|
+
<div class="bui-avatar-initials">
|
12
|
+
<%= initials %>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<% if show_status? %>
|
17
|
+
<span class="<%= status_indicator_classes %>"></span>
|
18
|
+
<% end %>
|
19
|
+
</div>
|