Class: Avo::TabGroupComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/avo/tab_group_component.rb

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Method Summary collapse

Methods inherited from BaseComponent

#has_with_trial

Methods included from Concerns::FindAssociationField

#find_association_field

Instance Method Details

#active_tabObject



41
42
43
44
45
46
47
# File 'app/components/avo/tab_group_component.rb', line 41

def active_tab
  return if group.visible_items.blank?

  group.visible_items.find do |tab|
    tab.name.to_s == active_tab_name.to_s
  end
end

#active_tab_nameObject



25
26
27
# File 'app/components/avo/tab_group_component.rb', line 25

def active_tab_name
  CGI.unescape(params[group_param] || group.visible_items&.first&.name)
end

#after_initializeObject



13
14
15
# File 'app/components/avo/tab_group_component.rb', line 13

def after_initialize
  group.index = index
end

#args(tab) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/avo/tab_group_component.rb', line 49

def args(tab)
  {
    # Hide the turbo frames that aren't in the current tab
    # This way we can lazy load the un-selected tabs on the show view
    class: "block #{'hidden' unless tab.name == active_tab_name}",
    data: {
      # Add a marker to know if we already loaded a turbo frame
      loaded: tab.name == active_tab_name,
      tabs_target: :tabPanel,
      tab_id: tab.name,
    }
  }
end

#render?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/avo/tab_group_component.rb', line 17

def render?
  tabs_have_content? && visible_tabs.present?
end

#tabsObject



29
30
31
32
33
# File 'app/components/avo/tab_group_component.rb', line 29

def tabs
  @group.visible_items.map do |tab|
    tab.hydrate(view: view)
  end
end

#tabs_have_content?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/components/avo/tab_group_component.rb', line 21

def tabs_have_content?
  visible_tabs.present?
end

#visible_tabsObject



35
36
37
38
39
# File 'app/components/avo/tab_group_component.rb', line 35

def visible_tabs
  tabs.select do |tab|
    tab.visible?
  end
end