Class: Avo::TabGroupComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::TabGroupComponent
- Defined in:
- app/components/avo/tab_group_component.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #active_tab ⇒ Object
- #active_tab_name ⇒ Object
- #args(tab) ⇒ Object
-
#initialize(resource:, group:, index:, form:, params:, view:) ⇒ TabGroupComponent
constructor
A new instance of TabGroupComponent.
- #render? ⇒ Boolean
- #tabs ⇒ Object
- #tabs_have_content? ⇒ Boolean
- #visible_tabs ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(resource:, group:, index:, form:, params:, view:) ⇒ TabGroupComponent
Returns a new instance of TabGroupComponent.
12 13 14 15 16 17 18 19 20 21 |
# File 'app/components/avo/tab_group_component.rb', line 12 def initialize(resource:, group:, index:, form:, params:, view:) @resource = resource @group = group @index = index @form = form @params = params @view = view @group.index = index end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
7 8 9 |
# File 'app/components/avo/tab_group_component.rb', line 7 def form @form end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
4 5 6 |
# File 'app/components/avo/tab_group_component.rb', line 4 def group @group end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
5 6 7 |
# File 'app/components/avo/tab_group_component.rb', line 5 def index @index end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
8 9 10 |
# File 'app/components/avo/tab_group_component.rb', line 8 def resource @resource end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
6 7 8 |
# File 'app/components/avo/tab_group_component.rb', line 6 def view @view end |
Instance Method Details
#active_tab ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/components/avo/tab_group_component.rb', line 47 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_name ⇒ Object
31 32 33 |
# File 'app/components/avo/tab_group_component.rb', line 31 def active_tab_name CGI.unescape(params[group_param] || group.visible_items&.first&.name) end |
#args(tab) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/components/avo/tab_group_component.rb', line 55 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
23 24 25 |
# File 'app/components/avo/tab_group_component.rb', line 23 def render? tabs_have_content? && visible_tabs.present? end |
#tabs ⇒ Object
35 36 37 38 39 |
# File 'app/components/avo/tab_group_component.rb', line 35 def tabs @group.visible_items.map do |tab| tab.hydrate(view: view) end end |
#tabs_have_content? ⇒ Boolean
27 28 29 |
# File 'app/components/avo/tab_group_component.rb', line 27 def tabs_have_content? visible_tabs.present? end |
#visible_tabs ⇒ Object
41 42 43 44 45 |
# File 'app/components/avo/tab_group_component.rb', line 41 def visible_tabs tabs.select do |tab| tab.visible? end end |