Class: Jav::TabGroupComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#has_with_trial

Constructor Details

#initialize(resource:, group:, index:, form:, params:, view:, tabs_style:) ⇒ TabGroupComponent

Returns a new instance of TabGroupComponent.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/components/jav/tab_group_component.rb', line 6

def initialize(resource:, group:, index:, form:, params:, view:, tabs_style:)
  super
  @resource = resource
  @group = group
  @index = index
  @form = form
  @params = params
  @view = view
  @tabs_style = tabs_style

  @group.index = index
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



4
5
6
# File 'app/components/jav/tab_group_component.rb', line 4

def form
  @form
end

#groupObject (readonly)

Returns the value of attribute group.



4
5
6
# File 'app/components/jav/tab_group_component.rb', line 4

def group
  @group
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'app/components/jav/tab_group_component.rb', line 4

def index
  @index
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'app/components/jav/tab_group_component.rb', line 4

def resource
  @resource
end

#viewObject (readonly)

Returns the value of attribute view.



4
5
6
# File 'app/components/jav/tab_group_component.rb', line 4

def view
  @view
end

Instance Method Details

#active_tabObject



41
42
43
44
45
46
47
# File 'app/components/jav/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



27
28
29
# File 'app/components/jav/tab_group_component.rb', line 27

def active_tab_name
  params[:active_tab_name] || group.visible_items&.first&.name
end

#render?Boolean

Returns:



19
20
21
# File 'app/components/jav/tab_group_component.rb', line 19

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

#tabsObject



31
32
33
34
35
# File 'app/components/jav/tab_group_component.rb', line 31

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

#tabs_have_content?Boolean

Returns:



23
24
25
# File 'app/components/jav/tab_group_component.rb', line 23

def tabs_have_content?
  visible_tabs.present?
end

#tabs_styleObject



49
50
51
# File 'app/components/jav/tab_group_component.rb', line 49

def tabs_style
  @tabs_style || Jav.configuration.tabs_style
end

#visible_tabsObject



37
38
39
# File 'app/components/jav/tab_group_component.rb', line 37

def visible_tabs
  tabs.select(&:visible?)
end