better_ui 0.3.0 → 0.6.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/app/components/better_ui/application/main/component.html.erb +1 -1
- data/app/components/better_ui/application/sidebar/component.html.erb +25 -3
- data/app/components/better_ui/application/sidebar/component.rb +62 -5
- data/app/components/better_ui/general/button/component.html.erb +8 -8
- data/app/components/better_ui/general/button/component.rb +11 -11
- data/app/components/better_ui/general/dropdown/component.html.erb +7 -4
- data/app/components/better_ui/general/dropdown/component.rb +23 -1
- data/app/components/better_ui/general/field/component.html.erb +3 -3
- data/app/components/better_ui/general/field/component.rb +3 -3
- data/app/components/better_ui/general/grid/cell_component.html.erb +3 -0
- data/app/components/better_ui/general/grid/cell_component.rb +390 -0
- data/app/components/better_ui/general/grid/component.html.erb +3 -0
- data/app/components/better_ui/general/grid/component.rb +301 -0
- data/app/components/better_ui/general/heading/component.html.erb +1 -1
- data/app/components/better_ui/general/icon/component.rb +2 -1
- data/app/components/better_ui/general/input/checkbox/component.rb +10 -10
- data/app/components/better_ui/general/input/pin/component.html.erb +1 -0
- data/app/components/better_ui/general/input/pin/component.rb +201 -0
- data/app/components/better_ui/general/input/radio/component.rb +10 -10
- data/app/components/better_ui/general/input/rating/component.html.erb +4 -0
- data/app/components/better_ui/general/input/rating/component.rb +272 -0
- data/app/components/better_ui/general/input/select/component.html.erb +76 -14
- data/app/components/better_ui/general/input/select/component.rb +166 -101
- data/app/components/better_ui/general/input/toggle/component.html.erb +5 -0
- data/app/components/better_ui/general/input/toggle/component.rb +242 -0
- data/app/components/better_ui/general/link/component.rb +1 -1
- data/app/components/better_ui/general/text/component.html.erb +1 -0
- data/app/components/better_ui/general/text/component.rb +194 -0
- data/app/helpers/better_ui/application_helper.rb +7 -0
- data/app/helpers/better_ui/general/components/button/button_helper.rb +6 -6
- data/app/helpers/better_ui/general/components/dropdown/dropdown_helper.rb +9 -0
- data/app/helpers/better_ui/general/components/dropdown/item_helper.rb +13 -7
- data/app/helpers/better_ui/general/components/field/field_helper.rb +4 -4
- data/app/helpers/better_ui/general/components/grid/grid_helper.rb +145 -0
- data/app/helpers/better_ui/general/components/input/pin/pin_helper.rb +76 -0
- data/app/helpers/better_ui/general/components/input/rating/rating_helper.rb +70 -0
- data/app/helpers/better_ui/general/components/input/select/select_helper.rb +47 -31
- data/app/helpers/better_ui/general/components/input/toggle/toggle_helper.rb +77 -0
- data/app/helpers/better_ui/general/components/text/text_helper.rb +83 -0
- data/lib/better_ui/version.rb +1 -1
- data/lib/better_ui.rb +1 -0
- metadata +19 -4
- data/app/helpers/better_ui/general/components/accordion.rb +0 -11
- data/app/helpers/better_ui/general/components/modal.rb +0 -11
@@ -0,0 +1,194 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module General
|
5
|
+
module Text
|
6
|
+
class Component < ViewComponent::Base
|
7
|
+
attr_reader :text, :theme, :size, :align, :weight, :style, :classes, :html_options
|
8
|
+
|
9
|
+
# Classi base sempre presenti
|
10
|
+
TEXT_BASE_CLASSES = "block"
|
11
|
+
|
12
|
+
# Temi colore con classi Tailwind dirette
|
13
|
+
TEXT_THEME_CLASSES = {
|
14
|
+
default: "text-gray-900", # Testo nero standard
|
15
|
+
white: "text-white", # Testo bianco
|
16
|
+
red: "text-red-600",
|
17
|
+
rose: "text-rose-600",
|
18
|
+
orange: "text-orange-600",
|
19
|
+
green: "text-green-600",
|
20
|
+
blue: "text-blue-600",
|
21
|
+
yellow: "text-yellow-600",
|
22
|
+
violet: "text-violet-600",
|
23
|
+
purple: "text-purple-600",
|
24
|
+
gray: "text-gray-600",
|
25
|
+
muted: "text-gray-500"
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
# Dimensioni con classi Tailwind dirette
|
29
|
+
TEXT_SIZE_CLASSES = {
|
30
|
+
xs: "text-xs",
|
31
|
+
small: "text-sm",
|
32
|
+
medium: "text-base",
|
33
|
+
large: "text-lg",
|
34
|
+
xl: "text-xl",
|
35
|
+
"2xl": "text-2xl"
|
36
|
+
}.freeze
|
37
|
+
|
38
|
+
# Allineamenti con classi Tailwind dirette
|
39
|
+
TEXT_ALIGN_CLASSES = {
|
40
|
+
left: "text-left",
|
41
|
+
center: "text-center",
|
42
|
+
right: "text-right",
|
43
|
+
justify: "text-justify"
|
44
|
+
}.freeze
|
45
|
+
|
46
|
+
# Peso font con classi Tailwind dirette
|
47
|
+
TEXT_WEIGHT_CLASSES = {
|
48
|
+
thin: "font-thin",
|
49
|
+
light: "font-light",
|
50
|
+
normal: "font-normal",
|
51
|
+
medium: "font-medium",
|
52
|
+
semibold: "font-semibold",
|
53
|
+
bold: "font-bold",
|
54
|
+
extrabold: "font-extrabold"
|
55
|
+
}.freeze
|
56
|
+
|
57
|
+
# Stili con classi Tailwind dirette
|
58
|
+
TEXT_STYLE_CLASSES = {
|
59
|
+
normal: "",
|
60
|
+
italic: "italic",
|
61
|
+
underline: "underline",
|
62
|
+
line_through: "line-through"
|
63
|
+
}.freeze
|
64
|
+
|
65
|
+
# @param text [String] testo da mostrare (opzionale se si usa blocco)
|
66
|
+
# @param theme [Symbol] tema del colore (:default, :white, :red, :blue, etc.)
|
67
|
+
# @param size [Symbol] dimensione (:xs, :small, :medium, :large, :xl, :"2xl")
|
68
|
+
# @param align [Symbol] allineamento (:left, :center, :right, :justify)
|
69
|
+
# @param weight [Symbol] peso font (:thin, :light, :normal, :medium, :semibold, :bold, :extrabold)
|
70
|
+
# @param style [Symbol] stile (:normal, :italic, :underline, :line_through)
|
71
|
+
# @param classes [String] classi CSS aggiuntive
|
72
|
+
# @param html_options [Hash] opzioni HTML aggiuntive
|
73
|
+
def initialize(
|
74
|
+
text: nil,
|
75
|
+
theme: :default,
|
76
|
+
size: :medium,
|
77
|
+
align: :left,
|
78
|
+
weight: :normal,
|
79
|
+
style: :normal,
|
80
|
+
classes: '',
|
81
|
+
**html_options
|
82
|
+
)
|
83
|
+
@text = text
|
84
|
+
@theme = theme.to_sym
|
85
|
+
@size = size.to_sym
|
86
|
+
@align = align.to_sym
|
87
|
+
@weight = weight.to_sym
|
88
|
+
@style = style.to_sym
|
89
|
+
@classes = classes
|
90
|
+
@html_options = html_options
|
91
|
+
|
92
|
+
validate_params
|
93
|
+
super()
|
94
|
+
end
|
95
|
+
|
96
|
+
# Combina tutte le classi CSS
|
97
|
+
def combined_classes
|
98
|
+
[
|
99
|
+
TEXT_BASE_CLASSES,
|
100
|
+
get_theme_classes,
|
101
|
+
get_size_classes,
|
102
|
+
get_align_classes,
|
103
|
+
get_weight_classes,
|
104
|
+
get_style_classes,
|
105
|
+
@classes,
|
106
|
+
@html_options[:class]
|
107
|
+
].compact.join(" ")
|
108
|
+
end
|
109
|
+
|
110
|
+
# Attributi HTML per l'elemento
|
111
|
+
def text_attributes
|
112
|
+
attrs = @html_options.except(:class)
|
113
|
+
attrs[:class] = combined_classes
|
114
|
+
attrs
|
115
|
+
end
|
116
|
+
|
117
|
+
# Determina se il componente ha contenuto da renderizzare
|
118
|
+
def render?
|
119
|
+
@text.present? || content.present?
|
120
|
+
end
|
121
|
+
|
122
|
+
# Contenuto da mostrare (testo diretto o contenuto blocco)
|
123
|
+
def text_content
|
124
|
+
@text.present? ? @text : content
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def validate_params
|
130
|
+
validate_theme
|
131
|
+
validate_size
|
132
|
+
validate_align
|
133
|
+
validate_weight
|
134
|
+
validate_style
|
135
|
+
end
|
136
|
+
|
137
|
+
def validate_theme
|
138
|
+
unless TEXT_THEME_CLASSES.key?(@theme)
|
139
|
+
valid_themes = TEXT_THEME_CLASSES.keys
|
140
|
+
raise ArgumentError, "Il tema deve essere uno tra: #{valid_themes.join(', ')}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def validate_size
|
145
|
+
unless TEXT_SIZE_CLASSES.key?(@size)
|
146
|
+
valid_sizes = TEXT_SIZE_CLASSES.keys
|
147
|
+
raise ArgumentError, "La dimensione deve essere una tra: #{valid_sizes.join(', ')}"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def validate_align
|
152
|
+
unless TEXT_ALIGN_CLASSES.key?(@align)
|
153
|
+
valid_aligns = TEXT_ALIGN_CLASSES.keys
|
154
|
+
raise ArgumentError, "L'allineamento deve essere uno tra: #{valid_aligns.join(', ')}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def validate_weight
|
159
|
+
unless TEXT_WEIGHT_CLASSES.key?(@weight)
|
160
|
+
valid_weights = TEXT_WEIGHT_CLASSES.keys
|
161
|
+
raise ArgumentError, "Il peso deve essere uno tra: #{valid_weights.join(', ')}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def validate_style
|
166
|
+
unless TEXT_STYLE_CLASSES.key?(@style)
|
167
|
+
valid_styles = TEXT_STYLE_CLASSES.keys
|
168
|
+
raise ArgumentError, "Lo stile deve essere uno tra: #{valid_styles.join(', ')}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_theme_classes
|
173
|
+
TEXT_THEME_CLASSES[@theme]
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_size_classes
|
177
|
+
TEXT_SIZE_CLASSES[@size]
|
178
|
+
end
|
179
|
+
|
180
|
+
def get_align_classes
|
181
|
+
TEXT_ALIGN_CLASSES[@align]
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_weight_classes
|
185
|
+
TEXT_WEIGHT_CLASSES[@weight]
|
186
|
+
end
|
187
|
+
|
188
|
+
def get_style_classes
|
189
|
+
TEXT_STYLE_CLASSES[@style]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -24,6 +24,10 @@ module BetterUi
|
|
24
24
|
include General::Components::Spinner::SpinnerHelper
|
25
25
|
include General::Components::Tag::TagHelper
|
26
26
|
include General::Components::Tooltip::TooltipHelper
|
27
|
+
include General::Components::Field::FieldHelper
|
28
|
+
include General::Components::Grid::GridHelper
|
29
|
+
include General::Components::Text::TextHelper
|
30
|
+
include General::Components::Dropdown::DropdownHelper
|
27
31
|
|
28
32
|
include General::Components::Table::TableHelper
|
29
33
|
include General::Components::Table::TbodyHelper
|
@@ -45,6 +49,9 @@ module BetterUi
|
|
45
49
|
include General::Components::Input::Select::SelectHelper
|
46
50
|
include General::Components::Input::Text::TextHelper
|
47
51
|
include General::Components::Input::Textarea::TextareaHelper
|
52
|
+
include General::Components::Input::Toggle::ToggleHelper
|
53
|
+
include General::Components::Input::Rating::RatingHelper
|
54
|
+
include General::Components::Input::Pin::PinHelper
|
48
55
|
|
49
56
|
# Application Components
|
50
57
|
include Application::Components::Main::MainHelper
|
@@ -5,8 +5,8 @@ module BetterUi
|
|
5
5
|
module ButtonHelper
|
6
6
|
# Helper per renderizzare un bottone
|
7
7
|
#
|
8
|
-
# @param
|
9
|
-
# @param
|
8
|
+
# @param text [String] Testo del bottone (argomento posizionale)
|
9
|
+
# @param theme [Symbol] Tema del bottone (:default, :white, :red, etc.)
|
10
10
|
# @param size [Symbol] Dimensione del bottone (:small, :medium, :large)
|
11
11
|
# @param full_width [Boolean] Larghezza completa
|
12
12
|
# @param disabled [Boolean] Stato disabilitato
|
@@ -23,8 +23,8 @@ module BetterUi
|
|
23
23
|
#
|
24
24
|
# @return [String] HTML del bottone
|
25
25
|
def bui_button(
|
26
|
-
|
27
|
-
|
26
|
+
text = nil,
|
27
|
+
theme: :white,
|
28
28
|
size: :medium,
|
29
29
|
full_width: false,
|
30
30
|
disabled: false,
|
@@ -41,8 +41,8 @@ module BetterUi
|
|
41
41
|
&block
|
42
42
|
)
|
43
43
|
render BetterUi::General::Button::Component.new(
|
44
|
-
|
45
|
-
|
44
|
+
text: text,
|
45
|
+
theme: theme,
|
46
46
|
size: size,
|
47
47
|
full_width: full_width,
|
48
48
|
disabled: disabled,
|
@@ -14,6 +14,9 @@ module BetterUi
|
|
14
14
|
# @param size [Symbol] La dimensione del trigger (:small, :medium, :large)
|
15
15
|
# @param rounded [Symbol] Il border radius (:none, :small, :medium, :large, :full)
|
16
16
|
# @param animation [Symbol] Il tipo di animazione (:fade, :slide, :none)
|
17
|
+
# @param fullwidth [Boolean] Se il trigger deve occupare tutta la larghezza disponibile
|
18
|
+
# @param show_chevron [Boolean] Se mostrare l'icona chevron automatica
|
19
|
+
# @param selectable [Boolean] Se il dropdown deve aggiornare il trigger con la selezione
|
17
20
|
# @param classes [String] Classi CSS aggiuntive
|
18
21
|
# @param options [Hash] Attributi HTML aggiuntivi
|
19
22
|
# @param block [Proc] Il contenuto del menu dropdown
|
@@ -57,6 +60,9 @@ module BetterUi
|
|
57
60
|
size: :medium,
|
58
61
|
rounded: :medium,
|
59
62
|
animation: :fade,
|
63
|
+
fullwidth: false,
|
64
|
+
show_chevron: true,
|
65
|
+
selectable: false,
|
60
66
|
classes: '',
|
61
67
|
**options,
|
62
68
|
&block
|
@@ -68,6 +74,9 @@ module BetterUi
|
|
68
74
|
size: size,
|
69
75
|
rounded: rounded,
|
70
76
|
animation: animation,
|
77
|
+
fullwidth: fullwidth,
|
78
|
+
show_chevron: show_chevron,
|
79
|
+
selectable: selectable,
|
71
80
|
classes: classes,
|
72
81
|
**options
|
73
82
|
), &block
|
@@ -20,22 +20,25 @@ module BetterUi
|
|
20
20
|
# @return [String] Il markup HTML dell'elemento dropdown
|
21
21
|
#
|
22
22
|
# @example Uso base
|
23
|
-
# <%= bui_dropdown_item(
|
23
|
+
# <%= bui_dropdown_item("Modifica") %>
|
24
24
|
#
|
25
25
|
# @example Con icona
|
26
|
-
# <%= bui_dropdown_item(
|
26
|
+
# <%= bui_dropdown_item("Elimina", icon: "trash") %>
|
27
27
|
#
|
28
28
|
# @example Come link
|
29
|
-
# <%= bui_dropdown_item(
|
29
|
+
# <%= bui_dropdown_item("Profilo", href: "/profile", icon: "user") %>
|
30
30
|
#
|
31
31
|
# @example Con tema colorato
|
32
|
-
# <%= bui_dropdown_item(
|
32
|
+
# <%= bui_dropdown_item("Azione pericolosa", theme: :red, icon: "trash") %>
|
33
33
|
#
|
34
34
|
# @example Disabilitato
|
35
|
-
# <%= bui_dropdown_item(
|
35
|
+
# <%= bui_dropdown_item("Non disponibile", disabled: true) %>
|
36
|
+
#
|
37
|
+
# @example Uso con sintassi keyword (backward compatible)
|
38
|
+
# <%= bui_dropdown_item(text: "Modifica legacy") %>
|
36
39
|
#
|
37
40
|
def bui_dropdown_item(
|
38
|
-
text
|
41
|
+
text = nil,
|
39
42
|
icon: nil,
|
40
43
|
href: nil,
|
41
44
|
theme: :default,
|
@@ -44,8 +47,11 @@ module BetterUi
|
|
44
47
|
classes: '',
|
45
48
|
**options
|
46
49
|
)
|
50
|
+
# Supporta sia sintassi posizionale che keyword per backward compatibility
|
51
|
+
item_text = text || options.delete(:text)
|
52
|
+
|
47
53
|
render BetterUi::General::Dropdown::ItemComponent.new(
|
48
|
-
text:
|
54
|
+
text: item_text,
|
49
55
|
icon: icon,
|
50
56
|
href: href,
|
51
57
|
theme: theme,
|
@@ -3,15 +3,15 @@ module BetterUi
|
|
3
3
|
module Components
|
4
4
|
module Field
|
5
5
|
module FieldHelper
|
6
|
-
# @param
|
6
|
+
# @param text [String] Testo della label (argomento posizionale)
|
7
7
|
# @param name [String] Nome del campo
|
8
8
|
# @param required [Boolean] Se il campo è obbligatorio
|
9
9
|
# @param error [String] Messaggio di errore
|
10
10
|
# @param help_text [String] Testo di aiuto
|
11
11
|
# @return [BetterUi::General::FieldComponent] Componente del campo
|
12
|
-
def bui_field(
|
12
|
+
def bui_field(text = nil, name:, required: false, error: nil, help_text: nil, id: nil, &block)
|
13
13
|
render BetterUi::General::Field::Component.new(
|
14
|
-
|
14
|
+
text: text,
|
15
15
|
name: name,
|
16
16
|
required: required,
|
17
17
|
error: error,
|
@@ -23,4 +23,4 @@ module BetterUi
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module General
|
5
|
+
module Components
|
6
|
+
module Grid
|
7
|
+
module GridHelper
|
8
|
+
# Helper per creare un contenitore grid CSS
|
9
|
+
#
|
10
|
+
# @param cols [Integer, Hash] Numero colonne (1-12, :auto, :none) o hash responsive {sm: 1, md: 2, lg: 3, xl: 4}
|
11
|
+
# @param rows [Integer, Hash, nil] Numero righe (1-6, :auto, :none) o hash responsive
|
12
|
+
# @param gap [Symbol, Hash] Spaziatura (:none, :small, :medium, :large) o hash responsive
|
13
|
+
# @param flow [Symbol] Direzione flusso (:row, :col, :row_dense, :col_dense)
|
14
|
+
# @param align_items [Symbol, nil] Allineamento verticale (:start, :center, :end, :stretch)
|
15
|
+
# @param justify_items [Symbol, nil] Allineamento orizzontale (:start, :center, :end, :stretch)
|
16
|
+
# @param classes [String] Classi CSS aggiuntive
|
17
|
+
# @param id [String, nil] ID elemento
|
18
|
+
# @param options [Hash] Attributi HTML aggiuntivi
|
19
|
+
# @param block [Proc] Blocco contenente le celle grid
|
20
|
+
#
|
21
|
+
# @return [String] HTML del grid container
|
22
|
+
#
|
23
|
+
# @example Uso base
|
24
|
+
# <%= bui_grid(cols: 3, gap: :medium) do %>
|
25
|
+
# <%= content %>
|
26
|
+
# <% end %>
|
27
|
+
#
|
28
|
+
# @example Con responsive
|
29
|
+
# <%= bui_grid(cols: {sm: 1, md: 2, lg: 3, xl: 4}, gap: :large) do %>
|
30
|
+
# <%= content %>
|
31
|
+
# <% end %>
|
32
|
+
#
|
33
|
+
# @example Con righe e allineamento
|
34
|
+
# <%= bui_grid(cols: 2, rows: 3, gap: :medium, align_items: :center) do %>
|
35
|
+
# <%= content %>
|
36
|
+
# <% end %>
|
37
|
+
#
|
38
|
+
# @example Con flow e justify
|
39
|
+
# <%= bui_grid(cols: 4, flow: :col, justify_items: :center) do %>
|
40
|
+
# <%= content %>
|
41
|
+
# <% end %>
|
42
|
+
#
|
43
|
+
# @example Con attributi HTML aggiuntivi
|
44
|
+
# <%= bui_grid(cols: 3, id: "main-grid", data: {testid: "grid"}) do %>
|
45
|
+
# <%= content %>
|
46
|
+
# <% end %>
|
47
|
+
def bui_grid(
|
48
|
+
cols: 1,
|
49
|
+
rows: nil,
|
50
|
+
gap: :medium,
|
51
|
+
flow: :row,
|
52
|
+
align_items: nil,
|
53
|
+
justify_items: nil,
|
54
|
+
classes: '',
|
55
|
+
id: nil,
|
56
|
+
**options,
|
57
|
+
&block
|
58
|
+
)
|
59
|
+
render BetterUi::General::Grid::Component.new(
|
60
|
+
cols: cols,
|
61
|
+
rows: rows,
|
62
|
+
gap: gap,
|
63
|
+
flow: flow,
|
64
|
+
align_items: align_items,
|
65
|
+
justify_items: justify_items,
|
66
|
+
classes: classes,
|
67
|
+
id: id,
|
68
|
+
**options
|
69
|
+
), &block
|
70
|
+
end
|
71
|
+
|
72
|
+
# Helper per creare una cella grid con controllo posizionamento
|
73
|
+
#
|
74
|
+
# @param col [Integer, Hash, nil] Span colonne (1-12, :auto, :full) o hash responsive {sm: 1, md: 2, lg: 3}
|
75
|
+
# @param row [Integer, Hash, nil] Span righe (1-6, :auto, :full) o hash responsive
|
76
|
+
# @param col_start [Integer, Hash, nil] Posizione inizio colonna (1-13, :auto) o hash responsive
|
77
|
+
# @param col_end [Integer, Hash, nil] Posizione fine colonna (1-13, :auto) o hash responsive
|
78
|
+
# @param row_start [Integer, Hash, nil] Posizione inizio riga (1-7, :auto) o hash responsive
|
79
|
+
# @param row_end [Integer, Hash, nil] Posizione fine riga (1-7, :auto) o hash responsive
|
80
|
+
# @param justify_self [Symbol, nil] Allineamento orizzontale cella (:auto, :start, :center, :end, :stretch)
|
81
|
+
# @param align_self [Symbol, nil] Allineamento verticale cella (:auto, :start, :center, :end, :stretch)
|
82
|
+
# @param classes [String] Classi CSS aggiuntive
|
83
|
+
# @param id [String, nil] ID elemento
|
84
|
+
# @param options [Hash] Attributi HTML aggiuntivi
|
85
|
+
# @param block [Proc] Blocco contenente il contenuto della cella
|
86
|
+
#
|
87
|
+
# @return [String] HTML della grid cell
|
88
|
+
#
|
89
|
+
# @example Uso base
|
90
|
+
# <%= bui_grid_cell do %>
|
91
|
+
# <div>Contenuto cella</div>
|
92
|
+
# <% end %>
|
93
|
+
#
|
94
|
+
# @example Con span colonne
|
95
|
+
# <%= bui_grid_cell(col: 2) do %>
|
96
|
+
# <div>Cella che occupa 2 colonne</div>
|
97
|
+
# <% end %>
|
98
|
+
#
|
99
|
+
# @example Con responsive
|
100
|
+
# <%= bui_grid_cell(col: {sm: 1, md: 2, lg: 3}) do %>
|
101
|
+
# <div>Cella responsive</div>
|
102
|
+
# <% end %>
|
103
|
+
#
|
104
|
+
# @example Con posizionamento specifico
|
105
|
+
# <%= bui_grid_cell(col_start: 2, col_end: 4) do %>
|
106
|
+
# <div>Cella dalla colonna 2 alla 4</div>
|
107
|
+
# <% end %>
|
108
|
+
#
|
109
|
+
# @example Con allineamento
|
110
|
+
# <%= bui_grid_cell(col: 2, justify_self: :center, align_self: :start) do %>
|
111
|
+
# <div>Cella centrata orizzontalmente</div>
|
112
|
+
# <% end %>
|
113
|
+
def bui_grid_cell(
|
114
|
+
col: nil,
|
115
|
+
row: nil,
|
116
|
+
col_start: nil,
|
117
|
+
col_end: nil,
|
118
|
+
row_start: nil,
|
119
|
+
row_end: nil,
|
120
|
+
justify_self: nil,
|
121
|
+
align_self: nil,
|
122
|
+
classes: '',
|
123
|
+
id: nil,
|
124
|
+
**options,
|
125
|
+
&block
|
126
|
+
)
|
127
|
+
render BetterUi::General::Grid::CellComponent.new(
|
128
|
+
col: col,
|
129
|
+
row: row,
|
130
|
+
col_start: col_start,
|
131
|
+
col_end: col_end,
|
132
|
+
row_start: row_start,
|
133
|
+
row_end: row_end,
|
134
|
+
justify_self: justify_self,
|
135
|
+
align_self: align_self,
|
136
|
+
classes: classes,
|
137
|
+
id: id,
|
138
|
+
**options
|
139
|
+
), &block
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module General
|
5
|
+
module Components
|
6
|
+
module Input
|
7
|
+
module Pin
|
8
|
+
module PinHelper
|
9
|
+
# Renderizza un componente Pin/OTP Input per inserimento codici di verifica numerici.
|
10
|
+
#
|
11
|
+
# @param name [String] Nome del campo pin (obbligatorio)
|
12
|
+
# @param value [String] Valore del pin preimpostato
|
13
|
+
# @param length [Integer] Numero di campi pin (4-8, default: 6)
|
14
|
+
# @param placeholder [String] Placeholder per campi vuoti (default: '•')
|
15
|
+
# @param required [Boolean] Se il campo è obbligatorio
|
16
|
+
# @param disabled [Boolean] Se il campo è disabilitato
|
17
|
+
# @param theme [Symbol] Tema del componente (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)
|
18
|
+
# @param size [Symbol] Dimensione del componente (:small, :medium, :large)
|
19
|
+
# @param form [ActionView::Helpers::FormBuilder, nil] Form builder Rails opzionale
|
20
|
+
# @param classes [String] Classi CSS aggiuntive
|
21
|
+
# @param options [Hash] Opzioni aggiuntive per attributi HTML
|
22
|
+
#
|
23
|
+
# @return [String] HTML del componente Pin renderizzato
|
24
|
+
#
|
25
|
+
# @example Uso base per codice OTP
|
26
|
+
# <%= bui_input_pin(name: 'verification_code') %>
|
27
|
+
#
|
28
|
+
# @example Con lunghezza personalizzata e tema
|
29
|
+
# <%= bui_input_pin(name: 'pin_code', length: 4, theme: :blue, size: :large) %>
|
30
|
+
#
|
31
|
+
# @example Con Rails form builder
|
32
|
+
# <%= form_with model: @user do |form| %>
|
33
|
+
# <%= bui_input_pin(name: :otp_code, form: form, value: @user.otp_code) %>
|
34
|
+
# <% end %>
|
35
|
+
#
|
36
|
+
# @example Con validazione e attributi personalizzati
|
37
|
+
# <%= bui_input_pin(
|
38
|
+
# name: 'sms_code',
|
39
|
+
# length: 6,
|
40
|
+
# required: true,
|
41
|
+
# placeholder: '_',
|
42
|
+
# theme: :green,
|
43
|
+
# classes: 'my-custom-class',
|
44
|
+
# id: 'sms-verification'
|
45
|
+
# ) %>
|
46
|
+
#
|
47
|
+
# @example Per codice bancario a 8 cifre
|
48
|
+
# <%= bui_input_pin(
|
49
|
+
# name: 'bank_code',
|
50
|
+
# length: 8,
|
51
|
+
# theme: :violet,
|
52
|
+
# size: :small,
|
53
|
+
# placeholder: '0'
|
54
|
+
# ) %>
|
55
|
+
def bui_input_pin(name:, value: '', length: 6, placeholder: '•', required: false, disabled: false,
|
56
|
+
theme: :default, size: :medium, form: nil, classes: '', **options)
|
57
|
+
render BetterUi::General::Input::Pin::Component.new(
|
58
|
+
name: name,
|
59
|
+
value: value,
|
60
|
+
length: length,
|
61
|
+
placeholder: placeholder,
|
62
|
+
required: required,
|
63
|
+
disabled: disabled,
|
64
|
+
theme: theme,
|
65
|
+
size: size,
|
66
|
+
form: form,
|
67
|
+
classes: classes,
|
68
|
+
**options
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterUi
|
4
|
+
module General
|
5
|
+
module Components
|
6
|
+
module Input
|
7
|
+
module Rating
|
8
|
+
module RatingHelper
|
9
|
+
# Renderizza un componente Rating (Input) interattivo con stelle per valutazioni e feedback.
|
10
|
+
#
|
11
|
+
# @param name [String] Nome del campo rating (obbligatorio se non readonly)
|
12
|
+
# @param value [Float, Integer] Valore del rating attuale (0.0 - max_stars)
|
13
|
+
# @param max_stars [Integer] Numero massimo di stelle (default: 5)
|
14
|
+
# @param readonly [Boolean] Se il rating è in sola lettura
|
15
|
+
# @param half_stars [Boolean] Se supportare mezze stelle
|
16
|
+
# @param theme [Symbol] Tema del componente (:default, :yellow, :orange, :red, :pink, :purple, :blue, :green, :gray)
|
17
|
+
# @param size [Symbol] Dimensione del componente (:small, :medium, :large)
|
18
|
+
# @param show_value [Boolean] Se mostrare il valore numerico accanto alle stelle
|
19
|
+
# @param form [ActionView::Helpers::FormBuilder, nil] Form builder Rails opzionale
|
20
|
+
# @param classes [String] Classi CSS aggiuntive
|
21
|
+
# @param options [Hash] Opzioni aggiuntive per attributi HTML
|
22
|
+
#
|
23
|
+
# @return [String] HTML del componente Rating renderizzato
|
24
|
+
#
|
25
|
+
# @example Uso base per inserimento rating
|
26
|
+
# <%= bui_input_rating(name: 'review_rating') %>
|
27
|
+
#
|
28
|
+
# @example Rating read-only per visualizzazione
|
29
|
+
# <%= bui_input_rating(value: 4.5, readonly: true, show_value: true) %>
|
30
|
+
#
|
31
|
+
# @example Con tema e dimensioni personalizzate
|
32
|
+
# <%= bui_input_rating(name: 'quality', theme: :orange, size: :large, max_stars: 10) %>
|
33
|
+
#
|
34
|
+
# @example Con Rails form builder
|
35
|
+
# <%= form_with model: @review do |form| %>
|
36
|
+
# <%= bui_input_rating(name: :rating, form: form, value: @review.rating, show_value: true) %>
|
37
|
+
# <% end %>
|
38
|
+
#
|
39
|
+
# @example Rating con mezze stelle e valore preimpostato
|
40
|
+
# <%= bui_input_rating(
|
41
|
+
# name: 'service_rating',
|
42
|
+
# value: 3.5,
|
43
|
+
# half_stars: true,
|
44
|
+
# theme: :green,
|
45
|
+
# size: :medium,
|
46
|
+
# show_value: true
|
47
|
+
# ) %>
|
48
|
+
def bui_input_rating(name: nil, value: 0, max_stars: 5, readonly: false, half_stars: true,
|
49
|
+
theme: :default, size: :medium, show_value: false, form: nil,
|
50
|
+
classes: '', **options)
|
51
|
+
render BetterUi::General::Input::Rating::Component.new(
|
52
|
+
name: name,
|
53
|
+
value: value,
|
54
|
+
max_stars: max_stars,
|
55
|
+
readonly: readonly,
|
56
|
+
half_stars: half_stars,
|
57
|
+
theme: theme,
|
58
|
+
size: size,
|
59
|
+
show_value: show_value,
|
60
|
+
form: form,
|
61
|
+
classes: classes,
|
62
|
+
**options
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|