Class: Fluxbit::BottomNavigationComponent::Item

Inherits:
Component
  • Object
show all
Includes:
Config::BottomNavigationComponent
Defined in:
app/components/fluxbit/bottom_navigation_component.rb

Overview

Item component for bottom navigation

Constant Summary

Constants inherited from Component

Component::ComponentObj

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props, &block) ⇒ Item

Initializes the item component.

Parameters:

  • **props (Hash)

    The properties to customize the item.

  • props (Hash)

    a customizable set of options

Options Hash (**props):

  • :href (String)

    The URL the item links to.

  • :icon (String)

    The icon to display.

  • :active (Boolean) — default: false

    Whether the item is currently active.

  • :tooltip_text (String)

    Tooltip text to display on hover.

  • :sr_only (Boolean) — default: false

    Show text for screen readers only.

  • :parent_config (Fluxbit::BottomNavigationComponent)

    Parent component configuration.

  • :parent_variant (Symbol)

    Parent component variant.

  • **props (Hash)

    Remaining options declared as HTML attributes.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/components/fluxbit/bottom_navigation_component.rb', line 145

def initialize(**props, &block)
  super(**props, &block)
  @props = props
  @parent_config = @props.delete(:parent_config)
  @parent_variant = @props.delete(:parent_variant) || :default

  @href = @props.delete(:href) || "#"
  @icon = @props.delete(:icon)
  @active = options(@props.delete(:active), default: false)
  @tooltip_text = @props.delete(:tooltip_text)
  @sr_only = options(@props.delete(:sr_only), default: @parent_variant == :app_bar)

  add(class: styles[:item][:base], to: @props, first_element: true)
  add(class: styles[:item][:active], to: @props) if @active
  add(class: styles[:item][:inactive], to: @props) unless @active

  @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
end

Instance Method Details

#callObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'app/components/fluxbit/bottom_navigation_component.rb', line 164

def call
  setup_data_attributes

  button_content = tag.button(type: "button", **@props) do
    concat(render_icon) if @icon
    concat(tag.span(content, class: text_classes))
  end

  if @tooltip_text
    safe_join([button_content, render_tooltip])
  else
    button_content
  end
end