Class: BetterUi::General::Breadcrumb::Component

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/breadcrumb/component.rb

Constant Summary collapse

"flex items-center flex-wrap"
"flex flex-wrap items-center"
"flex items-center"
{
  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"
}
{
  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"
}
{
  extra_small: "text-[0.65rem]",
  small: "text-xs",
  medium: "text-sm",
  large: "text-base"
}
{
  slash: "/",
  chevron: "›",
  arrow: "→",
  dot: "•",
  pipe: "|"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

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,
  **html_options
)
  @items = items || []
  @separator = separator.to_sym
  @theme = theme.to_sym
  @size = size.to_sym
  @classes = classes
  @html_options = html_options

  validate_params
end

Instance Attribute Details

#classesObject (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_optionsObject (readonly)

Returns the value of attribute html_options.



5
6
7
# File 'app/components/better_ui/general/breadcrumb/component.rb', line 5

def html_options
  @html_options
end

#itemsObject (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

#separatorObject (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

#sizeObject (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

#themeObject (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

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 breadcrumb_attributes
  attrs = {
    "aria-label": "Breadcrumb",
    class: container_classes
  }

  # Aggiungi altri attributi HTML se presenti
  @html_options.except(:class).each do |key, value|
    attrs[key] = value
  end

  attrs
end

#container_classesObject

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,
    @html_options[:class]
  ].compact.join(" ")
end

#get_separator_theme_classObject



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

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_classesObject

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_textObject

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