better_ui_tmp 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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +211 -0
- data/Rakefile +8 -0
- data/app/assets/builds/application.js +1 -0
- data/app/assets/builds/better_ui.css +1 -0
- data/app/assets/stylesheets/better_ui.scss +3 -0
- data/app/components/better_ui/application/main/component.html.erb +5 -0
- data/app/components/better_ui/application/main/component.rb +99 -0
- data/app/components/better_ui/application/navbar/component.html.erb +219 -0
- data/app/components/better_ui/application/navbar/component.rb +148 -0
- data/app/components/better_ui/application/sidebar/component.html.erb +184 -0
- data/app/components/better_ui/application/sidebar/component.rb +129 -0
- data/app/components/better_ui/general/alert/component.html.erb +32 -0
- data/app/components/better_ui/general/alert/component.rb +242 -0
- data/app/components/better_ui/general/avatar/component.html.erb +20 -0
- data/app/components/better_ui/general/avatar/component.rb +301 -0
- data/app/components/better_ui/general/badge/component.html.erb +23 -0
- data/app/components/better_ui/general/badge/component.rb +248 -0
- data/app/components/better_ui/general/breadcrumb/component.html.erb +15 -0
- data/app/components/better_ui/general/breadcrumb/component.rb +186 -0
- data/app/components/better_ui/general/button/component.html.erb +34 -0
- data/app/components/better_ui/general/button/component.rb +214 -0
- data/app/components/better_ui/general/card/component.html.erb +21 -0
- data/app/components/better_ui/general/card/component.rb +37 -0
- data/app/components/better_ui/general/container/component.html.erb +8 -0
- data/app/components/better_ui/general/container/component.rb +158 -0
- data/app/components/better_ui/general/divider/component.html.erb +10 -0
- data/app/components/better_ui/general/divider/component.rb +226 -0
- data/app/components/better_ui/general/heading/component.html.erb +22 -0
- data/app/components/better_ui/general/heading/component.rb +257 -0
- data/app/components/better_ui/general/icon/component.html.erb +1 -0
- data/app/components/better_ui/general/icon/component.rb +222 -0
- data/app/components/better_ui/general/link/component.html.erb +18 -0
- data/app/components/better_ui/general/link/component.rb +255 -0
- data/app/components/better_ui/general/panel/component.html.erb +28 -0
- data/app/components/better_ui/general/panel/component.rb +249 -0
- data/app/components/better_ui/general/progress/component.html.erb +11 -0
- data/app/components/better_ui/general/progress/component.rb +160 -0
- data/app/components/better_ui/general/spinner/component.html.erb +35 -0
- data/app/components/better_ui/general/spinner/component.rb +93 -0
- data/app/components/better_ui/general/table/component.html.erb +5 -0
- data/app/components/better_ui/general/table/component.rb +217 -0
- data/app/components/better_ui/general/table/tbody_component.html.erb +3 -0
- data/app/components/better_ui/general/table/tbody_component.rb +30 -0
- data/app/components/better_ui/general/table/td_component.html.erb +3 -0
- data/app/components/better_ui/general/table/td_component.rb +44 -0
- data/app/components/better_ui/general/table/tfoot_component.html.erb +3 -0
- data/app/components/better_ui/general/table/tfoot_component.rb +28 -0
- data/app/components/better_ui/general/table/th_component.html.erb +6 -0
- data/app/components/better_ui/general/table/th_component.rb +51 -0
- data/app/components/better_ui/general/table/thead_component.html.erb +3 -0
- data/app/components/better_ui/general/table/thead_component.rb +28 -0
- data/app/components/better_ui/general/table/tr_component.html.erb +3 -0
- data/app/components/better_ui/general/table/tr_component.rb +30 -0
- data/app/components/better_ui/general/tag/component.html.erb +3 -0
- data/app/components/better_ui/general/tag/component.rb +104 -0
- data/app/components/better_ui/general/tooltip/component.html.erb +7 -0
- data/app/components/better_ui/general/tooltip/component.rb +239 -0
- data/app/controllers/better_ui/application_controller.rb +5 -0
- data/app/helpers/better_ui/application/components/main/main_helper.rb +42 -0
- data/app/helpers/better_ui/application/components/main.rb +13 -0
- data/app/helpers/better_ui/application/components/navbar/navbar_helper.rb +51 -0
- data/app/helpers/better_ui/application/components/navbar.rb +13 -0
- data/app/helpers/better_ui/application/components/sidebar/sidebar_helper.rb +51 -0
- data/app/helpers/better_ui/application/components/sidebar.rb +13 -0
- data/app/helpers/better_ui/application_helper.rb +10 -0
- data/app/helpers/better_ui/form_helper.rb +5 -0
- data/app/helpers/better_ui/general/components/alert/alert_helper.rb +29 -0
- data/app/helpers/better_ui/general/components/alert.rb +13 -0
- data/app/helpers/better_ui/general/components/avatar/avatar_helper.rb +29 -0
- data/app/helpers/better_ui/general/components/avatar.rb +13 -0
- data/app/helpers/better_ui/general/components/badge/badge_helper.rb +53 -0
- data/app/helpers/better_ui/general/components/badge.rb +13 -0
- data/app/helpers/better_ui/general/components/breadcrumb/breadcrumb_helper.rb +37 -0
- data/app/helpers/better_ui/general/components/breadcrumb.rb +13 -0
- data/app/helpers/better_ui/general/components/button/button_helper.rb +65 -0
- data/app/helpers/better_ui/general/components/button.rb +13 -0
- data/app/helpers/better_ui/general/components/card/card_helper.rb +37 -0
- data/app/helpers/better_ui/general/components/card.rb +13 -0
- data/app/helpers/better_ui/general/components/container/container_helper.rb +60 -0
- data/app/helpers/better_ui/general/components/container.rb +13 -0
- data/app/helpers/better_ui/general/components/divider/divider_helper.rb +63 -0
- data/app/helpers/better_ui/general/components/divider.rb +13 -0
- data/app/helpers/better_ui/general/components/heading/heading_helper.rb +72 -0
- data/app/helpers/better_ui/general/components/heading.rb +13 -0
- data/app/helpers/better_ui/general/components/icon/icon_helper.rb +16 -0
- data/app/helpers/better_ui/general/components/icon.rb +13 -0
- data/app/helpers/better_ui/general/components/link/link_helper.rb +89 -0
- data/app/helpers/better_ui/general/components/link.rb +13 -0
- data/app/helpers/better_ui/general/components/panel/panel_helper.rb +83 -0
- data/app/helpers/better_ui/general/components/panel.rb +13 -0
- data/app/helpers/better_ui/general/components/progress/progress_helper.rb +53 -0
- data/app/helpers/better_ui/general/components/progress.rb +11 -0
- data/app/helpers/better_ui/general/components/spinner/spinner_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/spinner.rb +10 -0
- data/app/helpers/better_ui/general/components/table/table_helper.rb +13 -0
- data/app/helpers/better_ui/general/components/table/tbody_helper.rb +13 -0
- data/app/helpers/better_ui/general/components/table/td_helper.rb +19 -0
- data/app/helpers/better_ui/general/components/table/tfoot_helper.rb +13 -0
- data/app/helpers/better_ui/general/components/table/th_helper.rb +19 -0
- data/app/helpers/better_ui/general/components/table/thead_helper.rb +13 -0
- data/app/helpers/better_ui/general/components/table/tr_helper.rb +13 -0
- data/app/helpers/better_ui/general/components/table.rb +25 -0
- data/app/helpers/better_ui/general/components/tag/tag_helper.rb +26 -0
- data/app/helpers/better_ui/general/components/tag.rb +15 -0
- data/app/helpers/better_ui/general/components/tooltip/tooltip_helper.rb +60 -0
- data/app/helpers/better_ui/general/components/tooltip.rb +13 -0
- data/app/helpers/better_ui/general_helper.rb +24 -0
- data/app/helpers/better_ui_helper.rb +16 -0
- data/app/javascript/application.js +1 -0
- data/app/jobs/better_ui/application_job.rb +4 -0
- data/app/mailers/better_ui/application_mailer.rb +6 -0
- data/app/models/better_ui/application_record.rb +5 -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/app/views/layouts/component_preview.html.erb +32 -0
- data/config/initializers/lookbook.rb +23 -0
- data/config/routes.rb +3 -0
- data/lib/better_ui/engine.rb +109 -0
- data/lib/better_ui/version.rb +3 -0
- data/lib/better_ui.rb +37 -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/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
- data/lib/tasks/better_ui_tasks.rake +4 -0
- metadata +260 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
<%# Template for card component %>
|
2
|
+
|
3
|
+
<%= tag.div(**html_attributes) do %>
|
4
|
+
<% if header? %>
|
5
|
+
<div class="bui-card__header">
|
6
|
+
<%= header %>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% if body? %>
|
11
|
+
<div class="bui-card__body">
|
12
|
+
<%= body %>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<% if footer? %>
|
17
|
+
<div class="bui-card__footer">
|
18
|
+
<%= footer %>
|
19
|
+
</div>
|
20
|
+
<% end %>
|
21
|
+
<% end %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module General
|
5
|
+
module Card
|
6
|
+
class Component < ViewComponent::Base
|
7
|
+
renders_one :header
|
8
|
+
renders_one :body
|
9
|
+
renders_one :footer
|
10
|
+
|
11
|
+
def initialize(theme: :white, style: :default, padding: :medium, radius: :medium, **options)
|
12
|
+
@theme = theme
|
13
|
+
@style = style
|
14
|
+
@padding = padding
|
15
|
+
@radius = radius
|
16
|
+
@options = options
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def html_attributes
|
22
|
+
{
|
23
|
+
class: class_names(
|
24
|
+
"bui-card",
|
25
|
+
"bui-card--theme-#{@theme}",
|
26
|
+
"bui-card--style-#{@style}",
|
27
|
+
"bui-card--padding-#{@padding}",
|
28
|
+
"bui-card--radius-#{@radius}",
|
29
|
+
@options[:class]
|
30
|
+
),
|
31
|
+
**@options.except(:class)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module BetterUi
|
2
|
+
module General
|
3
|
+
module Container
|
4
|
+
class Component < ViewComponent::Base
|
5
|
+
attr_reader :html_content, :fluid, :max_width, :padding, :background, :border, :shadow, :classes
|
6
|
+
|
7
|
+
# Classi base sempre presenti
|
8
|
+
CONTAINER_BASE_CLASSES = "mx-auto"
|
9
|
+
|
10
|
+
# Larghezze massime con classi Tailwind dirette
|
11
|
+
CONTAINER_MAX_WIDTH_CLASSES = {
|
12
|
+
sm: "max-w-screen-sm",
|
13
|
+
md: "max-w-screen-md",
|
14
|
+
lg: "max-w-screen-lg",
|
15
|
+
xl: "max-w-screen-xl",
|
16
|
+
xxl: "max-w-screen-2xl"
|
17
|
+
}
|
18
|
+
|
19
|
+
# Padding con classi Tailwind dirette
|
20
|
+
CONTAINER_PADDING_CLASSES = {
|
21
|
+
none: "p-0",
|
22
|
+
small: "p-2",
|
23
|
+
medium: "p-4",
|
24
|
+
large: "p-6"
|
25
|
+
}
|
26
|
+
|
27
|
+
# Background con classi Tailwind dirette
|
28
|
+
CONTAINER_BACKGROUND_CLASSES = {
|
29
|
+
white: "bg-white",
|
30
|
+
light: "bg-gray-50",
|
31
|
+
dark: "bg-gray-900",
|
32
|
+
transparent: "bg-transparent"
|
33
|
+
}
|
34
|
+
|
35
|
+
# Border con classi Tailwind dirette
|
36
|
+
CONTAINER_BORDER_CLASSES = {
|
37
|
+
none: "border-0",
|
38
|
+
small: "border",
|
39
|
+
medium: "border-2",
|
40
|
+
large: "border-4"
|
41
|
+
}
|
42
|
+
|
43
|
+
# Shadow con classi Tailwind dirette
|
44
|
+
CONTAINER_SHADOW_CLASSES = {
|
45
|
+
none: "shadow-none",
|
46
|
+
small: "shadow-sm",
|
47
|
+
medium: "shadow",
|
48
|
+
large: "shadow-lg"
|
49
|
+
}
|
50
|
+
|
51
|
+
# @param html_content [String] contenuto HTML del container (opzionale)
|
52
|
+
# @param fluid [Boolean] se il container deve essere fluid (full width)
|
53
|
+
# @param max_width [Symbol] larghezza massima del container (:sm, :md, :lg, :xl, :xxl)
|
54
|
+
# @param padding [Symbol] padding interno (:none, :small, :medium, :large)
|
55
|
+
# @param background [Symbol] colore di sfondo (:white, :light, :dark, :transparent)
|
56
|
+
# @param border [Symbol] bordo del container (:none, :small, :medium, :large)
|
57
|
+
# @param shadow [Symbol] ombra del container (:none, :small, :medium, :large)
|
58
|
+
# @param html_options [Hash] opzioni HTML aggiuntive
|
59
|
+
def initialize(
|
60
|
+
html_content: nil,
|
61
|
+
fluid: false,
|
62
|
+
max_width: :lg,
|
63
|
+
padding: :medium,
|
64
|
+
background: :white,
|
65
|
+
border: false,
|
66
|
+
shadow: :none,
|
67
|
+
classes: nil,
|
68
|
+
**html_options
|
69
|
+
)
|
70
|
+
@html_content = html_content
|
71
|
+
@fluid = fluid
|
72
|
+
@max_width = max_width.to_sym
|
73
|
+
@padding = padding.to_sym
|
74
|
+
@background = background.to_sym
|
75
|
+
@border = border
|
76
|
+
@shadow = shadow
|
77
|
+
@html_options = html_options
|
78
|
+
@classes = classes
|
79
|
+
|
80
|
+
validate_params
|
81
|
+
end
|
82
|
+
|
83
|
+
# Combina tutte le classi CSS per il container
|
84
|
+
def combined_classes
|
85
|
+
[
|
86
|
+
CONTAINER_BASE_CLASSES,
|
87
|
+
get_max_width_class,
|
88
|
+
get_padding_class,
|
89
|
+
get_background_class,
|
90
|
+
get_border_class,
|
91
|
+
get_shadow_class,
|
92
|
+
@classes,
|
93
|
+
@html_options[:class]
|
94
|
+
].compact.join(" ")
|
95
|
+
end
|
96
|
+
|
97
|
+
# Restituisce gli attributi HTML per il container
|
98
|
+
def container_attributes
|
99
|
+
attrs = @html_options.except(:class)
|
100
|
+
attrs[:class] = combined_classes
|
101
|
+
attrs
|
102
|
+
end
|
103
|
+
|
104
|
+
# Determina se il container deve essere renderizzato
|
105
|
+
def render?
|
106
|
+
@html_content.present? || content.present?
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def get_max_width_class
|
112
|
+
return "" if @fluid
|
113
|
+
CONTAINER_MAX_WIDTH_CLASSES[@max_width] || CONTAINER_MAX_WIDTH_CLASSES[:lg]
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_padding_class
|
117
|
+
CONTAINER_PADDING_CLASSES[@padding] || CONTAINER_PADDING_CLASSES[:medium]
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_background_class
|
121
|
+
CONTAINER_BACKGROUND_CLASSES[@background] || CONTAINER_BACKGROUND_CLASSES[:white]
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_border_class
|
125
|
+
CONTAINER_BORDER_CLASSES[@border] || CONTAINER_BORDER_CLASSES[:none]
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_shadow_class
|
129
|
+
CONTAINER_SHADOW_CLASSES[@shadow] || CONTAINER_SHADOW_CLASSES[:none]
|
130
|
+
end
|
131
|
+
|
132
|
+
def validate_params
|
133
|
+
validate_max_width
|
134
|
+
validate_padding
|
135
|
+
validate_background
|
136
|
+
end
|
137
|
+
|
138
|
+
def validate_max_width
|
139
|
+
unless CONTAINER_MAX_WIDTH_CLASSES.keys.include?(@max_width)
|
140
|
+
raise ArgumentError, "La larghezza massima deve essere una tra: #{CONTAINER_MAX_WIDTH_CLASSES.keys.join(', ')}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def validate_padding
|
145
|
+
unless CONTAINER_PADDING_CLASSES.keys.include?(@padding)
|
146
|
+
raise ArgumentError, "Il padding deve essere uno tra: #{CONTAINER_PADDING_CLASSES.keys.join(', ')}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def validate_background
|
151
|
+
unless CONTAINER_BACKGROUND_CLASSES.keys.include?(@background)
|
152
|
+
raise ArgumentError, "Il background deve essere uno tra: #{CONTAINER_BACKGROUND_CLASSES.keys.join(', ')}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%# Template per il divider %>
|
2
|
+
<% if show_label? %>
|
3
|
+
<%= tag.div(**divider_attributes) do %>
|
4
|
+
<div class="<%= label_line_classes %>"></div>
|
5
|
+
<span class="<%= label_classes %>"><%= @label %></span>
|
6
|
+
<div class="<%= label_line_classes %>"></div>
|
7
|
+
<% end %>
|
8
|
+
<% else %>
|
9
|
+
<%= tag.div(**divider_attributes) %>
|
10
|
+
<% end %>
|
@@ -0,0 +1,226 @@
|
|
1
|
+
module BetterUi
|
2
|
+
module General
|
3
|
+
module Divider
|
4
|
+
class Component < ViewComponent::Base
|
5
|
+
attr_reader :theme, :orientation, :style, :size, :label, :height, :classes
|
6
|
+
|
7
|
+
# Classi base sempre presenti
|
8
|
+
DIVIDER_BASE_CLASSES = "my-4"
|
9
|
+
|
10
|
+
# Temi con classi Tailwind dirette - LOGICA CORRETTA
|
11
|
+
DIVIDER_THEME_CLASSES = {
|
12
|
+
default: "border-white", # Bordo bianco (per sfondi scuri)
|
13
|
+
white: "border-gray-300", # Bordo grigio (per sfondi chiari)
|
14
|
+
red: "border-red-500",
|
15
|
+
rose: "border-rose-500",
|
16
|
+
orange: "border-orange-500",
|
17
|
+
green: "border-green-500",
|
18
|
+
blue: "border-blue-500",
|
19
|
+
yellow: "border-yellow-500",
|
20
|
+
violet: "border-violet-500"
|
21
|
+
}
|
22
|
+
|
23
|
+
# Orientamento con classi Tailwind dirette
|
24
|
+
DIVIDER_ORIENTATION_CLASSES = {
|
25
|
+
horizontal: "w-full border-t",
|
26
|
+
vertical: "h-full border-l"
|
27
|
+
}
|
28
|
+
|
29
|
+
# Stili di linea con classi Tailwind dirette
|
30
|
+
DIVIDER_STYLE_CLASSES = {
|
31
|
+
solid: "border-solid",
|
32
|
+
dashed: "border-dashed",
|
33
|
+
dotted: "border-dotted",
|
34
|
+
double: "border-double"
|
35
|
+
}
|
36
|
+
|
37
|
+
# Dimensioni con classi Tailwind dirette
|
38
|
+
DIVIDER_SIZE_CLASSES = {
|
39
|
+
thin: {
|
40
|
+
horizontal: "border-t",
|
41
|
+
vertical: "border-l"
|
42
|
+
},
|
43
|
+
medium: {
|
44
|
+
horizontal: "border-t-2",
|
45
|
+
vertical: "border-l-2"
|
46
|
+
},
|
47
|
+
thick: {
|
48
|
+
horizontal: "border-t-4",
|
49
|
+
vertical: "border-l-4"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
# Classi per label con classi Tailwind dirette - LOGICA CORRETTA
|
54
|
+
DIVIDER_LABEL_THEME_CLASSES = {
|
55
|
+
default: "text-white bg-transparent px-3", # Testo bianco trasparente (per sfondi scuri)
|
56
|
+
white: "text-gray-900 bg-white px-3", # Testo nero su bianco (per sfondi chiari)
|
57
|
+
red: "text-red-500 bg-white px-3",
|
58
|
+
rose: "text-rose-500 bg-white px-3",
|
59
|
+
orange: "text-orange-500 bg-white px-3",
|
60
|
+
green: "text-green-500 bg-white px-3",
|
61
|
+
blue: "text-blue-500 bg-white px-3",
|
62
|
+
yellow: "text-yellow-600 bg-white px-3",
|
63
|
+
violet: "text-violet-500 bg-white px-3"
|
64
|
+
}
|
65
|
+
|
66
|
+
# @param theme [Symbol] tema del divider (:default, :white, etc.)
|
67
|
+
# @param orientation [Symbol] orientamento del divider (:horizontal, :vertical)
|
68
|
+
# @param style [Symbol] stile della linea (:solid, :dashed, :dotted, :double)
|
69
|
+
# @param size [Symbol] dimensione della linea (:thin, :medium, :thick)
|
70
|
+
# @param label [String] testo opzionale da mostrare al centro del divider
|
71
|
+
# @param height [String] altezza per divider verticale (es. "100px", "100%")
|
72
|
+
# @param classes [String] classi CSS aggiuntive
|
73
|
+
# @param html_options [Hash] opzioni HTML per il container
|
74
|
+
def initialize(
|
75
|
+
theme: :white,
|
76
|
+
orientation: :horizontal,
|
77
|
+
style: :solid,
|
78
|
+
size: :medium,
|
79
|
+
label: nil,
|
80
|
+
height: nil,
|
81
|
+
classes: nil,
|
82
|
+
**html_options
|
83
|
+
)
|
84
|
+
@theme = theme.to_sym
|
85
|
+
@orientation = orientation.to_sym
|
86
|
+
@style = style.to_sym
|
87
|
+
@size = size.to_sym
|
88
|
+
@label = label
|
89
|
+
@height = height
|
90
|
+
@classes = classes
|
91
|
+
@html_options = html_options
|
92
|
+
|
93
|
+
validate_params
|
94
|
+
end
|
95
|
+
|
96
|
+
# Combina tutte le classi per il container
|
97
|
+
def combined_classes
|
98
|
+
base_classes = []
|
99
|
+
|
100
|
+
if @label.present? && @orientation == :horizontal
|
101
|
+
# Per divider con label orizzontale: flex layout
|
102
|
+
base_classes = [
|
103
|
+
"flex items-center text-center",
|
104
|
+
get_theme_class,
|
105
|
+
get_style_class
|
106
|
+
]
|
107
|
+
else
|
108
|
+
# Per divider normale
|
109
|
+
base_classes = [
|
110
|
+
DIVIDER_BASE_CLASSES,
|
111
|
+
get_orientation_class,
|
112
|
+
get_theme_class,
|
113
|
+
get_style_class,
|
114
|
+
get_size_class
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
[*base_classes, @classes, @html_options[:class]].compact.join(" ")
|
119
|
+
end
|
120
|
+
|
121
|
+
# Classi per il label
|
122
|
+
def label_classes
|
123
|
+
return "" unless @label.present?
|
124
|
+
|
125
|
+
[
|
126
|
+
"relative z-10 text-sm font-medium",
|
127
|
+
get_label_theme_class
|
128
|
+
].compact.join(" ")
|
129
|
+
end
|
130
|
+
|
131
|
+
# Classi per le linee before/after quando c'è un label
|
132
|
+
def label_line_classes
|
133
|
+
return "" unless @label.present? && @orientation == :horizontal
|
134
|
+
|
135
|
+
[
|
136
|
+
"flex-1 h-px",
|
137
|
+
get_theme_class,
|
138
|
+
get_style_class
|
139
|
+
].compact.join(" ")
|
140
|
+
end
|
141
|
+
|
142
|
+
# Genera gli attributi di stile inline necessari
|
143
|
+
def inline_styles
|
144
|
+
return nil unless @orientation == :vertical && @height.present?
|
145
|
+
"height: #{@height};"
|
146
|
+
end
|
147
|
+
|
148
|
+
# Restituisce gli attributi per il divider
|
149
|
+
def divider_attributes
|
150
|
+
attrs = {
|
151
|
+
class: combined_classes
|
152
|
+
}
|
153
|
+
|
154
|
+
# Aggiungi stile inline se presente
|
155
|
+
attrs[:style] = inline_styles if inline_styles.present?
|
156
|
+
|
157
|
+
# Aggiungi altri attributi HTML se presenti
|
158
|
+
@html_options.except(:class).each do |key, value|
|
159
|
+
attrs[key] = value
|
160
|
+
end
|
161
|
+
|
162
|
+
attrs
|
163
|
+
end
|
164
|
+
|
165
|
+
# Determina se mostrare il label
|
166
|
+
def show_label?
|
167
|
+
@label.present? && @orientation == :horizontal
|
168
|
+
end
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
def get_theme_class
|
173
|
+
DIVIDER_THEME_CLASSES[@theme] || DIVIDER_THEME_CLASSES[:white]
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_orientation_class
|
177
|
+
DIVIDER_ORIENTATION_CLASSES[@orientation] || DIVIDER_ORIENTATION_CLASSES[:horizontal]
|
178
|
+
end
|
179
|
+
|
180
|
+
def get_style_class
|
181
|
+
DIVIDER_STYLE_CLASSES[@style] || DIVIDER_STYLE_CLASSES[:solid]
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_size_class
|
185
|
+
size_map = DIVIDER_SIZE_CLASSES[@size] || DIVIDER_SIZE_CLASSES[:medium]
|
186
|
+
size_map[@orientation] || size_map[:horizontal]
|
187
|
+
end
|
188
|
+
|
189
|
+
def get_label_theme_class
|
190
|
+
DIVIDER_LABEL_THEME_CLASSES[@theme] || DIVIDER_LABEL_THEME_CLASSES[:white]
|
191
|
+
end
|
192
|
+
|
193
|
+
def validate_params
|
194
|
+
validate_theme
|
195
|
+
validate_orientation
|
196
|
+
validate_style
|
197
|
+
validate_size
|
198
|
+
end
|
199
|
+
|
200
|
+
def validate_theme
|
201
|
+
unless DIVIDER_THEME_CLASSES.keys.include?(@theme)
|
202
|
+
raise ArgumentError, "Il tema deve essere uno tra: #{DIVIDER_THEME_CLASSES.keys.join(', ')}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def validate_orientation
|
207
|
+
unless DIVIDER_ORIENTATION_CLASSES.keys.include?(@orientation)
|
208
|
+
raise ArgumentError, "L'orientamento deve essere uno tra: #{DIVIDER_ORIENTATION_CLASSES.keys.join(', ')}"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def validate_style
|
213
|
+
unless DIVIDER_STYLE_CLASSES.keys.include?(@style)
|
214
|
+
raise ArgumentError, "Lo stile deve essere uno tra: #{DIVIDER_STYLE_CLASSES.keys.join(', ')}"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def validate_size
|
219
|
+
unless DIVIDER_SIZE_CLASSES.keys.include?(@size)
|
220
|
+
raise ArgumentError, "La dimensione deve essere una tra: #{DIVIDER_SIZE_CLASSES.keys.join(', ')}"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%# Template per il heading %>
|
2
|
+
<div class="<%= container_classes %>">
|
3
|
+
<%= tag.public_send(heading_tag, **heading_attributes) do %>
|
4
|
+
<% if show_icon? %>
|
5
|
+
<span class="<%= icon_classes %>">
|
6
|
+
<%= render BetterUi::General::IconComponent.new(name: @icon) %>
|
7
|
+
</span>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<span><%= content %></span>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<% if show_subtitle? %>
|
14
|
+
<div class="<%= subtitle_classes %>">
|
15
|
+
<%= @subtitle %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% if show_divider? %>
|
20
|
+
<div class="<%= divider_classes %>"></div>
|
21
|
+
<% end %>
|
22
|
+
</div>
|