better_ui 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/README.md +141 -189
- data/app/assets/stylesheets/better_ui/_base.scss +9 -0
- data/app/assets/stylesheets/better_ui/_components.scss +2 -0
- data/app/assets/stylesheets/better_ui/_utilities.scss +14 -0
- data/app/assets/stylesheets/better_ui/application.css +3 -1
- data/app/assets/stylesheets/better_ui/components/_avatar.scss +200 -0
- data/app/assets/stylesheets/better_ui/components/_badge.scss +154 -0
- data/app/assets/stylesheets/better_ui/components/_breadcrumb.scss +106 -0
- data/app/assets/stylesheets/better_ui/components/_button.scss +105 -0
- data/app/assets/stylesheets/better_ui/components/_card.scss +60 -0
- data/app/assets/stylesheets/better_ui/components/_heading.scss +81 -0
- data/app/assets/stylesheets/better_ui/components/_icon.scss +134 -0
- data/app/assets/stylesheets/better_ui/components/_index.scss +17 -0
- data/app/assets/stylesheets/better_ui/components/_link.scss +100 -0
- data/app/assets/stylesheets/better_ui/components/_panel.scss +104 -0
- data/app/assets/stylesheets/better_ui/components/_spinner.scss +129 -0
- data/app/assets/stylesheets/better_ui/components/_table.scss +156 -0
- data/app/assets/stylesheets/better_ui/components/_variables.scss +1 -0
- data/app/assets/stylesheets/better_ui.scss +4 -0
- 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 +135 -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 +6 -6
- data/app/components/better_ui/general/button_component.rb +62 -95
- data/app/components/better_ui/general/heading_component.html.erb +1 -25
- data/app/components/better_ui/general/heading_component.rb +20 -113
- data/app/components/better_ui/general/icon_component.rb +37 -61
- 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 +51 -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 +89 -87
- data/app/helpers/better_ui/general/components/avatar_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/badge_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/breadcrumb_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/button_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/heading_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/icon_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/link_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/panel_helper.rb +16 -0
- data/app/helpers/better_ui/general/components/spinner_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/table_helper.rb +17 -0
- data/app/helpers/better_ui/general_helper.rb +15 -0
- data/app/helpers/better_ui_helper.rb +12 -0
- 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/config/routes.rb +2 -13
- data/lib/better_ui/engine.rb +66 -16
- data/lib/better_ui/version.rb +1 -1
- data/lib/better_ui.rb +12 -0
- data/lib/generators/better_ui/install_generator.rb +103 -0
- data/lib/generators/better_ui/stylesheet_generator.rb +159 -0
- data/lib/generators/better_ui/templates/README +125 -0
- data/lib/generators/better_ui/templates/components/_avatar.scss +200 -0
- data/lib/generators/better_ui/templates/components/_badge.scss +154 -0
- data/lib/generators/better_ui/templates/components/_breadcrumb.scss +106 -0
- data/lib/generators/better_ui/templates/components/_button.scss +109 -0
- data/lib/generators/better_ui/templates/components/_card.scss +60 -0
- data/lib/generators/better_ui/templates/components/_heading.scss +81 -0
- data/lib/generators/better_ui/templates/components/_icon.scss +134 -0
- data/lib/generators/better_ui/templates/components/_index.scss +17 -0
- data/lib/generators/better_ui/templates/components/_link.scss +100 -0
- data/lib/generators/better_ui/templates/components/_panel.scss +104 -0
- data/lib/generators/better_ui/templates/components/_spinner.scss +129 -0
- data/lib/generators/better_ui/templates/components/_table.scss +156 -0
- data/lib/generators/better_ui/templates/components/_variables.scss +0 -0
- data/lib/generators/better_ui/templates/components_stylesheet.scss +35 -0
- data/lib/generators/better_ui/templates/index.scss +18 -0
- data/lib/generators/better_ui/templates/initializer.rb +41 -0
- metadata +120 -49
- data/app/assets/javascripts/better_ui/controllers/navbar_controller.js +0 -138
- data/app/assets/javascripts/better_ui/controllers/sidebar_controller.js +0 -211
- data/app/assets/javascripts/better_ui/controllers/toast_controller.js +0 -161
- data/app/assets/javascripts/better_ui/index.js +0 -159
- data/app/assets/javascripts/better_ui/toast_manager.js +0 -77
- data/app/components/better_ui/theme_helper.rb +0 -169
- data/app/controllers/better_ui/docs_controller.rb +0 -34
- data/app/helpers/better_ui_application_helper.rb +0 -99
@@ -1,46 +1,55 @@
|
|
1
1
|
module BetterUi
|
2
2
|
module General
|
3
3
|
class ButtonComponent < ViewComponent::Base
|
4
|
-
attr_reader :label, :type, :size, :
|
5
|
-
:icon, :icon_position, :href, :method, :data, :classes, :id
|
4
|
+
attr_reader :label, :type, :size, :full_width, :disabled,
|
5
|
+
:icon, :icon_position, :href, :method, :data, :classes, :id, :rounded
|
6
6
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
# Temi di bottoni disponibili con classi CSS personalizzate
|
8
|
+
BUTTON_THEME = {
|
9
|
+
default: "bui-button--default",
|
10
|
+
white: "bui-button--white",
|
11
|
+
red: "bui-button--red",
|
12
|
+
rose: "bui-button--rose",
|
13
|
+
orange: "bui-button--orange",
|
14
|
+
green: "bui-button--green",
|
15
|
+
blue: "bui-button--blue",
|
16
|
+
yellow: "bui-button--yellow",
|
17
|
+
violet: "bui-button--violet"
|
17
18
|
}
|
18
19
|
|
19
|
-
#
|
20
|
-
OUTLINE_BUTTON_TYPES = {
|
21
|
-
primary: "bg-transparent text-blue-600 border-blue-600 border hover:text-white hover:bg-blue-600",
|
22
|
-
secondary: "bg-transparent text-gray-800 border-gray-200 border hover:text-white hover:bg-gray-200",
|
23
|
-
success: "bg-transparent text-green-600 border-green-600 border hover:text-white hover:bg-green-600",
|
24
|
-
danger: "bg-transparent text-red-600 border-red-600 border hover:text-white hover:bg-red-600",
|
25
|
-
warning: "bg-transparent text-yellow-500 border-yellow-500 border hover:text-white hover:bg-yellow-500",
|
26
|
-
info: "bg-transparent text-sky-500 border-sky-500 border hover:text-white hover:bg-sky-500",
|
27
|
-
light: "bg-transparent text-gray-800 border-gray-300 border hover:text-gray-900 hover:bg-gray-100",
|
28
|
-
dark: "bg-transparent text-gray-800 border-gray-800 border hover:text-white hover:bg-gray-800"
|
29
|
-
}
|
30
|
-
|
31
|
-
# Dimensioni disponibili
|
20
|
+
# Dimensioni disponibili con classi CSS personalizzate
|
32
21
|
BUTTON_SIZES = {
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
small: "bui-button--small",
|
23
|
+
medium: "bui-button--medium",
|
24
|
+
large: "bui-button--large"
|
25
|
+
}
|
26
|
+
|
27
|
+
# Border radius disponibili con classi CSS personalizzate
|
28
|
+
BUTTON_RADIUS = {
|
29
|
+
none: "bui-button--radius-none",
|
30
|
+
small: "bui-button--radius-small",
|
31
|
+
medium: "bui-button--radius-medium",
|
32
|
+
large: "bui-button--radius-large",
|
33
|
+
full: "bui-button--radius-full"
|
34
|
+
}
|
35
|
+
|
36
|
+
# Stati e comportamenti del bottone
|
37
|
+
BUTTON_STATES = {
|
38
|
+
disabled: "bui-button--disabled",
|
39
|
+
full_width: "bui-button--full-width"
|
40
|
+
}
|
41
|
+
|
42
|
+
# Layout e stili comuni
|
43
|
+
BUTTON_LAYOUT = {
|
44
|
+
default: "bui-btn-layout-default",
|
45
|
+
focus: "bui-btn-focus"
|
36
46
|
}
|
37
47
|
|
38
48
|
# Inizializzazione del componente
|
39
49
|
def initialize(
|
40
50
|
label: nil,
|
41
|
-
type: :
|
42
|
-
size: :
|
43
|
-
outline: false,
|
51
|
+
type: :default,
|
52
|
+
size: :medium,
|
44
53
|
full_width: false,
|
45
54
|
disabled: false,
|
46
55
|
icon: nil,
|
@@ -49,12 +58,12 @@ module BetterUi
|
|
49
58
|
method: nil,
|
50
59
|
data: {},
|
51
60
|
classes: nil,
|
52
|
-
id: nil
|
61
|
+
id: nil,
|
62
|
+
rounded: :small
|
53
63
|
)
|
54
64
|
@label = label
|
55
65
|
@type = type.to_sym
|
56
66
|
@size = size.to_sym
|
57
|
-
@outline = outline
|
58
67
|
@full_width = full_width
|
59
68
|
@disabled = disabled
|
60
69
|
@icon = icon
|
@@ -64,6 +73,7 @@ module BetterUi
|
|
64
73
|
@data = data
|
65
74
|
@classes = classes
|
66
75
|
@id = id
|
76
|
+
@rounded = rounded.to_sym
|
67
77
|
end
|
68
78
|
|
69
79
|
# Determina se il bottone è un link o un button
|
@@ -74,79 +84,26 @@ module BetterUi
|
|
74
84
|
# Combina tutte le classi
|
75
85
|
def combined_classes
|
76
86
|
[
|
77
|
-
"
|
78
|
-
|
87
|
+
"bui-button", # Classe base per tutti i bottoni
|
88
|
+
get_border_radius_class,
|
79
89
|
get_button_type_classes,
|
80
90
|
get_button_size_classes,
|
81
|
-
@full_width ?
|
82
|
-
@disabled ?
|
91
|
+
@full_width ? BUTTON_STATES[:full_width] : "",
|
92
|
+
@disabled ? BUTTON_STATES[:disabled] : "",
|
83
93
|
@classes
|
84
94
|
].compact.join(" ")
|
85
95
|
end
|
86
96
|
|
87
97
|
def get_button_type_classes
|
88
|
-
|
89
|
-
get_outline_button_classes
|
90
|
-
else
|
91
|
-
get_solid_button_classes
|
92
|
-
end
|
98
|
+
BUTTON_THEME[@type] || BUTTON_THEME[:default]
|
93
99
|
end
|
94
100
|
|
95
|
-
def
|
96
|
-
|
97
|
-
when :primary
|
98
|
-
"bg-orange-500 text-white hover:bg-orange-600 focus:ring-orange-500"
|
99
|
-
when :secondary
|
100
|
-
"bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-300"
|
101
|
-
when :success
|
102
|
-
"bg-green-500 text-white hover:bg-green-600 focus:ring-green-500"
|
103
|
-
when :danger
|
104
|
-
"bg-red-500 text-white hover:bg-red-600 focus:ring-red-500"
|
105
|
-
when :warning
|
106
|
-
"bg-amber-500 text-white hover:bg-amber-600 focus:ring-amber-500"
|
107
|
-
when :info
|
108
|
-
"bg-blue-500 text-white hover:bg-blue-600 focus:ring-blue-500"
|
109
|
-
when :light
|
110
|
-
"bg-white text-gray-800 border border-gray-300 hover:bg-gray-100 focus:ring-gray-300"
|
111
|
-
when :dark
|
112
|
-
"bg-gray-800 text-white hover:bg-gray-900 focus:ring-gray-800"
|
113
|
-
else
|
114
|
-
"bg-orange-500 text-white hover:bg-orange-600 focus:ring-orange-500"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def get_outline_button_classes
|
119
|
-
case @type
|
120
|
-
when :primary
|
121
|
-
"bg-transparent text-orange-500 border-2 border-orange-500 hover:bg-orange-50 focus:ring-orange-500"
|
122
|
-
when :secondary
|
123
|
-
"bg-transparent text-gray-800 border-2 border-gray-300 hover:bg-gray-50 focus:ring-gray-300"
|
124
|
-
when :success
|
125
|
-
"bg-transparent text-green-500 border-2 border-green-500 hover:bg-green-50 focus:ring-green-500"
|
126
|
-
when :danger
|
127
|
-
"bg-transparent text-red-500 border-2 border-red-500 hover:bg-red-50 focus:ring-red-500"
|
128
|
-
when :warning
|
129
|
-
"bg-transparent text-amber-500 border-2 border-amber-500 hover:bg-amber-50 focus:ring-amber-500"
|
130
|
-
when :info
|
131
|
-
"bg-transparent text-blue-500 border-2 border-blue-500 hover:bg-blue-50 focus:ring-blue-500"
|
132
|
-
when :light
|
133
|
-
"bg-transparent text-gray-800 border-2 border-gray-300 hover:bg-gray-50 focus:ring-gray-300"
|
134
|
-
when :dark
|
135
|
-
"bg-transparent text-gray-800 border-2 border-gray-800 hover:bg-gray-50 focus:ring-gray-800"
|
136
|
-
else
|
137
|
-
"bg-transparent text-orange-500 border-2 border-orange-500 hover:bg-orange-50 focus:ring-orange-500"
|
138
|
-
end
|
101
|
+
def get_border_radius_class
|
102
|
+
BUTTON_RADIUS[@rounded] || BUTTON_RADIUS[:small]
|
139
103
|
end
|
140
104
|
|
141
105
|
def get_button_size_classes
|
142
|
-
|
143
|
-
when :sm
|
144
|
-
"py-1 px-2.5 text-xs"
|
145
|
-
when :lg
|
146
|
-
"py-2.5 px-6 text-base"
|
147
|
-
else # :md
|
148
|
-
"py-2 px-4 text-sm"
|
149
|
-
end
|
106
|
+
BUTTON_SIZES[@size] || BUTTON_SIZES[:medium]
|
150
107
|
end
|
151
108
|
|
152
109
|
# Restituisce gli attributi per il bottone
|
@@ -181,10 +138,20 @@ module BetterUi
|
|
181
138
|
|
182
139
|
# Helper per renderizzare le icone
|
183
140
|
def render_icon(icon_name)
|
141
|
+
# Mappa le dimensioni del bottone alle dimensioni dell'icona
|
142
|
+
icon_size = case @size
|
143
|
+
when :large
|
144
|
+
:large
|
145
|
+
when :small
|
146
|
+
:small
|
147
|
+
else
|
148
|
+
:medium
|
149
|
+
end
|
150
|
+
|
184
151
|
# Utilizziamo il componente Icon
|
185
152
|
render BetterUi::General::IconComponent.new(
|
186
153
|
name: icon_name,
|
187
|
-
size:
|
154
|
+
size: icon_size,
|
188
155
|
fixed_width: true
|
189
156
|
)
|
190
157
|
end
|
@@ -1,25 +1 @@
|
|
1
|
-
|
2
|
-
<%# Utilizzo di tag heading dinamico in base al livello specificato %>
|
3
|
-
<<%= "h#{@level}" %> class="<%= heading_classes %>">
|
4
|
-
<% if @icon.present? %>
|
5
|
-
<span class="inline-flex items-center">
|
6
|
-
<span class="mr-2">
|
7
|
-
<%= render BetterUi::General::IconComponent.new(name: @icon) %>
|
8
|
-
</span>
|
9
|
-
<%= @text || content %>
|
10
|
-
</span>
|
11
|
-
<% else %>
|
12
|
-
<%= @text || content %>
|
13
|
-
<% end %>
|
14
|
-
</<%= "h#{@level}" %>>
|
15
|
-
|
16
|
-
<% if @subtitle.present? %>
|
17
|
-
<div class="<%= subtitle_classes %>">
|
18
|
-
<%= @subtitle %>
|
19
|
-
</div>
|
20
|
-
<% end %>
|
21
|
-
|
22
|
-
<% if @with_divider %>
|
23
|
-
<div class="<%= divider_classes %>"></div>
|
24
|
-
<% end %>
|
25
|
-
</div>
|
1
|
+
<%= content_tag("h#{@level}", content, class: heading_classes) %>
|
@@ -1,142 +1,49 @@
|
|
1
1
|
module BetterUi
|
2
2
|
module General
|
3
3
|
class HeadingComponent < ViewComponent::Base
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :level, :variant, :align, :classes
|
5
5
|
|
6
6
|
# Varianti di colore disponibili
|
7
|
-
|
8
|
-
default:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
},
|
18
|
-
success: {
|
19
|
-
heading: "text-green-700",
|
20
|
-
subtitle: "text-green-500",
|
21
|
-
divider: "border-green-300"
|
22
|
-
},
|
23
|
-
warning: {
|
24
|
-
heading: "text-yellow-700",
|
25
|
-
subtitle: "text-yellow-500",
|
26
|
-
divider: "border-yellow-300"
|
27
|
-
},
|
28
|
-
danger: {
|
29
|
-
heading: "text-red-700",
|
30
|
-
subtitle: "text-red-500",
|
31
|
-
divider: "border-red-300"
|
32
|
-
},
|
33
|
-
info: {
|
34
|
-
heading: "text-blue-700",
|
35
|
-
subtitle: "text-blue-500",
|
36
|
-
divider: "border-blue-300"
|
37
|
-
},
|
38
|
-
light: {
|
39
|
-
heading: "text-gray-100",
|
40
|
-
subtitle: "text-gray-300",
|
41
|
-
divider: "border-gray-700"
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
# Dimensioni disponibili
|
46
|
-
SIZES = {
|
47
|
-
xs: {
|
48
|
-
heading: "text-lg",
|
49
|
-
subtitle: "text-sm"
|
50
|
-
},
|
51
|
-
sm: {
|
52
|
-
heading: "text-xl",
|
53
|
-
subtitle: "text-base"
|
54
|
-
},
|
55
|
-
md: {
|
56
|
-
heading: "text-2xl",
|
57
|
-
subtitle: "text-lg"
|
58
|
-
},
|
59
|
-
lg: {
|
60
|
-
heading: "text-3xl",
|
61
|
-
subtitle: "text-xl"
|
62
|
-
},
|
63
|
-
xl: {
|
64
|
-
heading: "text-4xl",
|
65
|
-
subtitle: "text-2xl"
|
66
|
-
},
|
67
|
-
xxl: {
|
68
|
-
heading: "text-5xl",
|
69
|
-
subtitle: "text-3xl"
|
70
|
-
}
|
7
|
+
HEADER_THEME = {
|
8
|
+
default: "bui-heading--default",
|
9
|
+
white: "bui-heading--white",
|
10
|
+
red: "bui-heading--red",
|
11
|
+
rose: "bui-heading--rose",
|
12
|
+
orange: "bui-heading--orange",
|
13
|
+
green: "bui-heading--green",
|
14
|
+
blue: "bui-heading--blue",
|
15
|
+
yellow: "bui-heading--yellow",
|
16
|
+
violet: "bui-heading--violet"
|
71
17
|
}
|
72
18
|
|
73
19
|
# Allineamenti disponibili
|
74
|
-
|
75
|
-
left: "
|
76
|
-
center: "
|
77
|
-
right: "
|
20
|
+
HEADER_ALIGNMENTS = {
|
21
|
+
left: "bui-heading--left",
|
22
|
+
center: "bui-heading--center",
|
23
|
+
right: "bui-heading--right"
|
78
24
|
}
|
79
25
|
|
80
|
-
# Inizializzazione del componente
|
81
26
|
def initialize(
|
82
|
-
text: nil,
|
83
27
|
level: 2,
|
84
28
|
variant: :default,
|
85
|
-
size: :md,
|
86
29
|
align: :left,
|
87
|
-
classes: nil
|
88
|
-
icon: nil,
|
89
|
-
subtitle: nil,
|
90
|
-
with_divider: false
|
30
|
+
classes: nil
|
91
31
|
)
|
92
|
-
@text = text
|
93
32
|
@level = level.to_i.clamp(1, 6)
|
94
33
|
@variant = variant.to_sym
|
95
|
-
@size = size.to_sym
|
96
34
|
@align = align.to_sym
|
97
35
|
@classes = classes
|
98
|
-
@icon = icon
|
99
|
-
@subtitle = subtitle
|
100
|
-
@with_divider = with_divider
|
101
36
|
end
|
102
37
|
|
103
|
-
# Genera le classi per l'heading
|
104
38
|
def heading_classes
|
105
39
|
[
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
40
|
+
"bui-heading",
|
41
|
+
"bui-heading--#{@level}",
|
42
|
+
HEADER_THEME.fetch(@variant, HEADER_THEME[:default]),
|
43
|
+
HEADER_ALIGNMENTS.fetch(@align, HEADER_ALIGNMENTS[:left]),
|
110
44
|
@classes
|
111
45
|
].compact.join(" ")
|
112
46
|
end
|
113
|
-
|
114
|
-
# Genera le classi per il sottotitolo
|
115
|
-
def subtitle_classes
|
116
|
-
[
|
117
|
-
VARIANTS.fetch(@variant, VARIANTS[:default])[:subtitle],
|
118
|
-
SIZES.fetch(@size, SIZES[:md])[:subtitle],
|
119
|
-
ALIGNMENTS.fetch(@align, ALIGNMENTS[:left]),
|
120
|
-
"mt-1"
|
121
|
-
].compact.join(" ")
|
122
|
-
end
|
123
|
-
|
124
|
-
# Genera le classi per il divisore
|
125
|
-
def divider_classes
|
126
|
-
[
|
127
|
-
"border-t",
|
128
|
-
"mt-2",
|
129
|
-
VARIANTS.fetch(@variant, VARIANTS[:default])[:divider]
|
130
|
-
].compact.join(" ")
|
131
|
-
end
|
132
|
-
|
133
|
-
# Genera le classi per il container
|
134
|
-
def container_classes
|
135
|
-
[
|
136
|
-
"mb-4",
|
137
|
-
@with_divider ? "pb-2" : ""
|
138
|
-
].compact.join(" ")
|
139
|
-
end
|
140
47
|
end
|
141
48
|
end
|
142
49
|
end
|
@@ -2,97 +2,73 @@ module BetterUi
|
|
2
2
|
module General
|
3
3
|
class IconComponent < ViewComponent::Base
|
4
4
|
# Dimensioni disponibili
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
ICON_SIZES = {
|
6
|
+
xsmall: "bui-icon--xs",
|
7
|
+
tiny: "bui-icon--xs",
|
8
|
+
small: "bui-icon--sm",
|
9
|
+
medium: "bui-icon--md",
|
10
|
+
large: "bui-icon--lg",
|
11
|
+
xlarge: "bui-icon--xl"
|
12
12
|
}
|
13
13
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
# Colori disponibili
|
15
|
+
ICON_THEMES = {
|
16
|
+
default: "bui-icon--default",
|
17
|
+
white: "bui-icon--white",
|
18
|
+
red: "bui-icon--red",
|
19
|
+
rose: "bui-icon--rose",
|
20
|
+
orange: "bui-icon--orange",
|
21
|
+
green: "bui-icon--green",
|
22
|
+
blue: "bui-icon--blue",
|
23
|
+
yellow: "bui-icon--yellow",
|
24
|
+
violet: "bui-icon--violet"
|
21
25
|
}
|
22
26
|
|
23
27
|
# Inizializzazione del componente
|
24
28
|
def initialize(
|
25
29
|
name:,
|
26
|
-
size: :
|
27
|
-
|
30
|
+
size: :medium,
|
31
|
+
color: :default,
|
28
32
|
fixed_width: false,
|
29
33
|
spin: false,
|
30
34
|
pulse: false,
|
31
|
-
|
32
|
-
|
33
|
-
rotation: nil,
|
35
|
+
solid: false,
|
36
|
+
solid_color: false,
|
34
37
|
classes: nil
|
35
38
|
)
|
36
39
|
@name = name.to_s.gsub('_', '-') # Convertiamo da snake_case a kebab-case per Font Awesome
|
37
40
|
@size = size.to_sym
|
38
|
-
@
|
41
|
+
@color = color.to_sym
|
39
42
|
@fixed_width = fixed_width
|
40
43
|
@spin = spin
|
41
44
|
@pulse = pulse
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@rotation = rotation
|
45
|
+
@solid = solid
|
46
|
+
@solid_color = solid_color
|
45
47
|
@classes = classes
|
46
48
|
end
|
47
49
|
|
48
|
-
# Classe CSS per
|
49
|
-
def
|
50
|
-
|
50
|
+
# Classe CSS per il colore
|
51
|
+
def color_class
|
52
|
+
ICON_THEMES[@color] || ICON_THEMES[:default]
|
51
53
|
end
|
52
54
|
|
53
55
|
# Classe CSS per la dimensione
|
54
56
|
def size_class
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
# Classe per rotazione
|
59
|
-
def rotation_class
|
60
|
-
return "" unless @rotation
|
61
|
-
"fa-rotate-#{@rotation}"
|
62
|
-
end
|
63
|
-
|
64
|
-
# Classe per rovesciamento
|
65
|
-
def flip_class
|
66
|
-
return "" unless @flip
|
67
|
-
"fa-flip-#{@flip}"
|
68
|
-
end
|
69
|
-
|
70
|
-
# Classi per animazioni
|
71
|
-
def animation_classes
|
72
|
-
classes = []
|
73
|
-
classes << "fa-spin" if @spin
|
74
|
-
classes << "fa-pulse" if @pulse
|
75
|
-
classes.join(" ")
|
76
|
-
end
|
77
|
-
|
78
|
-
# Classi per caratteristiche aggiuntive
|
79
|
-
def feature_classes
|
80
|
-
classes = []
|
81
|
-
classes << "fa-fw" if @fixed_width
|
82
|
-
classes << "fa-border" if @border
|
83
|
-
classes.join(" ")
|
57
|
+
ICON_SIZES[@size] || ICON_SIZES[:medium]
|
84
58
|
end
|
85
59
|
|
86
60
|
# Combinazione di tutte le classi
|
87
61
|
def combined_classes
|
88
62
|
[
|
89
|
-
|
90
|
-
"fa-#{@name}",
|
63
|
+
"bui-icon",
|
64
|
+
"fa-#{@name}", # Questa classe deve rimanere specifica di Font Awesome
|
91
65
|
size_class,
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
66
|
+
color_class,
|
67
|
+
@fixed_width ? "bui-icon--fixed-width" : nil,
|
68
|
+
@spin ? "bui-icon--spin" : nil,
|
69
|
+
@pulse ? "bui-icon--pulse" : nil,
|
70
|
+
@solid ? "bui-icon--solid" : nil,
|
71
|
+
@solid_color ? "bui-icon--solid-primary" : nil,
|
96
72
|
@classes
|
97
73
|
].reject(&:blank?).join(" ")
|
98
74
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% if link? %>
|
2
|
+
<%= link_to href, **link_attributes do %>
|
3
|
+
<% if render_icon %>
|
4
|
+
<span class="bui-link__icon"><%= render_icon %></span>
|
5
|
+
<% end %>
|
6
|
+
<span class="bui-link__text"><%= label %></span>
|
7
|
+
<%= content if content.present? %>
|
8
|
+
<% end %>
|
9
|
+
<% else %>
|
10
|
+
<span class="<%= component_classes %>" <%= "aria-current='page'" if active? %>>
|
11
|
+
<% if render_icon %>
|
12
|
+
<span class="bui-link__icon"><%= render_icon %></span>
|
13
|
+
<% end %>
|
14
|
+
<span class="bui-link__text"><%= label %></span>
|
15
|
+
<%= content if content.present? %>
|
16
|
+
</span>
|
17
|
+
<% end %>
|