Class: BetterUi::General::Link::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Link::Component
- Defined in:
- app/components/better_ui/general/link/component.rb
Constant Summary collapse
- LINK_BASE_CLASSES =
Classi base sempre presenti
"transition-colors duration-200 no-underline"
- LINK_THEME_CLASSES =
Temi con classi Tailwind dirette - LOGICA CORRETTA
{ default: "text-white hover:text-gray-300", # Bianco per sfondi scuri white: "text-gray-900 hover:text-gray-700", # Nero per sfondi chiari red: "text-red-500 hover:text-red-600", rose: "text-rose-500 hover:text-rose-600", orange: "text-orange-500 hover:text-orange-600", green: "text-green-500 hover:text-green-600", blue: "text-blue-500 hover:text-blue-600", yellow: "text-yellow-600 hover:text-yellow-700", violet: "text-violet-500 hover:text-violet-600" }
- LINK_ORIENTATION_CLASSES =
Orientamenti con classi Tailwind dirette
{ horizontal: "inline-flex items-center", vertical: "flex flex-col items-center" }
- LINK_STYLE_CLASSES =
Stili con classi Tailwind dirette
{ default: "", underline: "underline", bold: "font-bold", text: "no-underline" }
- LINK_SIZE_CLASSES =
Dimensioni con classi Tailwind dirette
{ extra_small: "text-xs", small: "text-sm", medium: "text-base", large: "text-lg" }
- LINK_STATE_CLASSES =
Stati con classi Tailwind dirette
{ normal: "", active: "font-semibold", disabled: "opacity-50 cursor-not-allowed pointer-events-none" }
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Determina se è un link attivo/corrente.
-
#combined_classes ⇒ Object
Combina tutte le classi CSS.
-
#disabled? ⇒ Boolean
Determina se è disabilitato.
-
#element_attributes ⇒ Object
Restituisce gli attributi per il link/span.
-
#icon_classes ⇒ Object
Classi per l’icona con dimensionamento proporzionale.
-
#initialize(label:, href: nil, theme: :white, orientation: :horizontal, style: :default, size: :medium, icon: nil, active: false, disabled: false, data: {}, method: nil, target: nil, **html_options) ⇒ Component
constructor
A new instance of Component.
-
#link? ⇒ Boolean
Determina se è un link o solo testo.
-
#render_icon ⇒ Object
Renderizza l’icona.
-
#show_icon? ⇒ Boolean
Determina se mostrare l’icona.
-
#text_classes ⇒ Object
Classi per il testo.
Constructor Details
#initialize(label:, href: nil, theme: :white, orientation: :horizontal, style: :default, size: :medium, icon: nil, active: false, disabled: false, data: {}, method: nil, target: nil, **html_options) ⇒ Component
Returns a new instance of Component.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/components/better_ui/general/link/component.rb', line 65 def initialize( label:, href: nil, theme: :white, orientation: :horizontal, style: :default, size: :medium, icon: nil, active: false, disabled: false, data: {}, method: nil, target: nil, ** ) @label = label @href = href @theme = theme.to_sym @orientation = orientation.to_sym @style = style.to_sym @size = size.to_sym @icon = icon @active = active @disabled = disabled @data = data || {} @method = method @target = target @html_options = validate_params end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def active @active end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def data @data end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def disabled @disabled end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def href @href end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def icon @icon end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def label @label end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def method @method end |
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def orientation @orientation end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def size @size end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def style @style end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def target @target end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
5 6 7 |
# File 'app/components/better_ui/general/link/component.rb', line 5 def theme @theme end |
Instance Method Details
#active? ⇒ Boolean
Determina se è un link attivo/corrente
98 99 100 |
# File 'app/components/better_ui/general/link/component.rb', line 98 def active? @active end |
#combined_classes ⇒ Object
Combina tutte le classi CSS
113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/components/better_ui/general/link/component.rb', line 113 def combined_classes [ LINK_BASE_CLASSES, get_theme_class, get_orientation_class, get_style_class, get_size_class, get_state_class, @html_options[:class] ].compact.join(" ") end |
#disabled? ⇒ Boolean
Determina se è disabilitato
103 104 105 |
# File 'app/components/better_ui/general/link/component.rb', line 103 def disabled? @disabled end |
#element_attributes ⇒ Object
Restituisce gli attributi per il link/span
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/components/better_ui/general/link/component.rb', line 161 def element_attributes attrs = @html_options.except(:class) attrs[:class] = combined_classes if link? # Attributi specifici per i link if @method.present? attrs[:data] = @data.merge(turbo_method: @method) elsif @data.present? attrs[:data] = @data end attrs[:target] = @target if @target.present? attrs[:aria] ||= {} attrs[:aria][:current] = "page" if active? else # Attributi per span (testo semplice o disabilitato) attrs[:aria] ||= {} attrs[:aria][:disabled] = true if disabled? end attrs end |
#icon_classes ⇒ Object
Classi per l’icona con dimensionamento proporzionale
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/components/better_ui/general/link/component.rb', line 126 def icon_classes return "" unless @icon.present? # Definisce spacing e dimensioni icona basate su size base_spacing = case @orientation when :horizontal "mr-2" when :vertical "mb-1" else "mr-2" end icon_size = case @size when :extra_small "w-3 h-3" when :small "w-4 h-4" when :medium "w-5 h-5" when :large "w-6 h-6" else "w-5 h-5" end "#{base_spacing} #{icon_size} inline-block" end |
#link? ⇒ Boolean
Determina se è un link o solo testo
108 109 110 |
# File 'app/components/better_ui/general/link/component.rb', line 108 def link? @href.present? && !@disabled end |
#render_icon ⇒ Object
Renderizza l’icona
191 192 193 194 195 196 197 198 199 |
# File 'app/components/better_ui/general/link/component.rb', line 191 def render_icon return nil unless show_icon? if @icon.is_a?(String) render BetterUi::General::IconComponent.new(name: @icon) else @icon # Assumiamo che sia già un componente renderizzato end end |
#show_icon? ⇒ Boolean
Determina se mostrare l’icona
186 187 188 |
# File 'app/components/better_ui/general/link/component.rb', line 186 def show_icon? @icon.present? end |
#text_classes ⇒ Object
Classi per il testo
156 157 158 |
# File 'app/components/better_ui/general/link/component.rb', line 156 def text_classes "inline-block" end |