Class: BetterUi::General::Breadcrumb::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Breadcrumb::Component
- Defined in:
- app/components/better_ui/general/breadcrumb/component.rb
Constant Summary collapse
- BREADCRUMB_BASE_CLASSES =
Classi base sempre presenti
"flex items-center flex-wrap"
- BREADCRUMB_LIST_CLASSES =
Classi per lista e items
"flex flex-wrap items-center"
- BREADCRUMB_ITEM_CLASSES =
"flex items-center"
- BREADCRUMB_THEME_CLASSES =
Temi di breadcrumb con classi Tailwind dirette
{ default: "text-white", white: "text-black", red: "text-white", rose: "text-white", orange: "text-white", green: "text-white", blue: "text-white", yellow: "text-black", violet: "text-white", gray: "text-gray-900" }
- BREADCRUMB_SEPARATOR_THEME_CLASSES =
Classi per separatori con temi
{ default: "text-gray-500", white: "text-gray-400", red: "text-red-300", rose: "text-rose-300", orange: "text-orange-300", green: "text-green-300", blue: "text-blue-300", yellow: "text-yellow-600", violet: "text-violet-300", gray: "text-gray-500" }
- BREADCRUMB_SIZE_CLASSES =
Dimensioni con classi Tailwind dirette
{ extra_small: "text-[0.65rem]", small: "text-xs", medium: "text-sm", large: "text-base" }
- BREADCRUMB_SEPARATOR_TYPES =
Separatori predefiniti
{ slash: "/", chevron: "›", arrow: "→", dot: "•", pipe: "|" }
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#breadcrumb_attributes ⇒ Object
Restituisce gli attributi per il breadcrumb.
-
#container_classes ⇒ Object
Genera le classi per il container.
- #get_separator_theme_class ⇒ Object
-
#initialize(items: [], separator: :chevron, theme: :white, size: :medium, classes: nil, **html_options) ⇒ Component
constructor
Inizializzazione del componente.
-
#last_item?(index) ⇒ Boolean
Verifica se un item è l’ultimo (attivo).
-
#link_for_item(item, active: false) ⇒ Object
Crea un componente link per l’item.
-
#render? ⇒ Boolean
Verifica se rendere il componente.
-
#separator_classes ⇒ Object
Restituisce le classi CSS per il separatore.
-
#separator_text ⇒ Object
Restituisce il separatore come stringa.
Constructor Details
#initialize(items: [], separator: :chevron, theme: :white, size: :medium, classes: nil, **html_options) ⇒ Component
Inizializzazione del componente
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 60 def initialize( items: [], separator: :chevron, theme: :white, size: :medium, classes: nil, ** ) @items = items || [] @separator = separator.to_sym @theme = theme.to_sym @size = size.to_sym @classes = classes = validate_params end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
5 6 7 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5 def classes @classes end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
5 6 7 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5 def end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
5 6 7 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5 def items @items end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
5 6 7 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5 def separator @separator end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5 def size @size end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
5 6 7 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5 def theme @theme end |
Instance Method Details
#breadcrumb_attributes ⇒ Object
Restituisce gli attributi per il breadcrumb
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 120 def attrs = { "aria-label": "Breadcrumb", class: container_classes } # Aggiungi altri attributi HTML se presenti .except(:class).each do |key, value| attrs[key] = value end attrs end |
#container_classes ⇒ Object
Genera le classi per il container
88 89 90 91 92 93 94 95 96 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 88 def container_classes [ BREADCRUMB_BASE_CLASSES, get_theme_class, get_size_class, @classes, [:class] ].compact.join(" ") end |
#get_separator_theme_class ⇒ Object
142 143 144 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 142 def get_separator_theme_class BREADCRUMB_SEPARATOR_THEME_CLASSES[@theme] || BREADCRUMB_SEPARATOR_THEME_CLASSES[:white] end |
#last_item?(index) ⇒ Boolean
Verifica se un item è l’ultimo (attivo)
99 100 101 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 99 def last_item?(index) index == @items.length - 1 end |
#link_for_item(item, active: false) ⇒ Object
Crea un componente link per l’item
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 104 def link_for_item(item, active: false) label = item.is_a?(Hash) ? item[:label] : item.to_s href = item.is_a?(Hash) ? item[:url] : nil icon = item.is_a?(Hash) ? item[:icon] : nil BetterUi::General::Link::Component.new( label: label, href: href, theme: @theme, size: @size, icon: icon, active: active ) end |
#render? ⇒ Boolean
Verifica se rendere il componente
147 148 149 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 147 def render? @items.present? && @items.length > 0 end |
#separator_classes ⇒ Object
Restituisce le classi CSS per il separatore
135 136 137 138 139 140 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 135 def separator_classes [ "mx-2", get_separator_theme_class ].compact.join(" ") end |
#separator_text ⇒ Object
Restituisce il separatore come stringa
79 80 81 82 83 84 85 |
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 79 def separator_text if BREADCRUMB_SEPARATOR_TYPES.key?(@separator) BREADCRUMB_SEPARATOR_TYPES[@separator] else @separator.to_s end end |