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
{ 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.
64 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 |
# File 'app/components/better_ui/general/link/component.rb', line 64 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 = 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
97 98 99 |
# File 'app/components/better_ui/general/link/component.rb', line 97 def active? @active end |
#combined_classes ⇒ Object
Combina tutte le classi CSS
112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/components/better_ui/general/link/component.rb', line 112 def combined_classes [ LINK_BASE_CLASSES, get_theme_class, get_orientation_class, get_style_class, get_size_class, get_state_class, [:class] ].compact.join(" ") end |
#disabled? ⇒ Boolean
Determina se è disabilitato
102 103 104 |
# File 'app/components/better_ui/general/link/component.rb', line 102 def disabled? @disabled end |
#element_attributes ⇒ Object
Restituisce gli attributi per il link/span
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/components/better_ui/general/link/component.rb', line 158 def element_attributes attrs = .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
125 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 |
# File 'app/components/better_ui/general/link/component.rb', line 125 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 :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
107 108 109 |
# File 'app/components/better_ui/general/link/component.rb', line 107 def link? @href.present? && !@disabled end |
#render_icon ⇒ Object
Renderizza l’icona
188 189 190 191 192 193 194 195 196 |
# File 'app/components/better_ui/general/link/component.rb', line 188 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
183 184 185 |
# File 'app/components/better_ui/general/link/component.rb', line 183 def show_icon? @icon.present? end |
#text_classes ⇒ Object
Classi per il testo
153 154 155 |
# File 'app/components/better_ui/general/link/component.rb', line 153 def text_classes "inline-block" end |