Sha256: de559e8e546f1078c9b9467f526125d745ac55598c671904965e80bffbabed6e

Contents?: true

Size: 950 Bytes

Versions: 55

Compression:

Stored size: 950 Bytes

Contents

# frozen_string_literal: true

class Avo::TabGroupComponent < Avo::BaseComponent
  attr_reader :group
  attr_reader :index
  attr_reader :view
  attr_reader :form
  attr_reader :resource

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

    @group.index = index
  end

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

  def tabs_have_content?
    visible_tabs.present?
  end

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

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

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

  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
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
avo-3.0.1.beta23 app/components/avo/tab_group_component.rb
avo-3.0.1.beta20 app/components/avo/tab_group_component.rb
avo-3.0.1.beta21 app/components/avo/tab_group_component.rb
avo-3.0.1.beta17 app/components/avo/tab_group_component.rb
avo-3.0.1.beta22 app/components/avo/tab_group_component.rb
avo-3.0.1.beta18 app/components/avo/tab_group_component.rb
avo-3.0.1.beta19 app/components/avo/tab_group_component.rb
avo-3.0.1.beta24 app/components/avo/tab_group_component.rb
avo-3.0.1.beta15 app/components/avo/tab_group_component.rb
avo-3.0.1.beta16 app/components/avo/tab_group_component.rb
avo-3.0.1.beta14 app/components/avo/tab_group_component.rb
avo-3.0.1.beta12 app/components/avo/tab_group_component.rb
avo-3.0.1.beta13 app/components/avo/tab_group_component.rb
avo-3.0.1.beta10 app/components/avo/tab_group_component.rb
avo-3.0.1.beta11 app/components/avo/tab_group_component.rb
avo-3.0.0.pre19 app/components/avo/tab_group_component.rb
avo-3.0.1.beta8 app/components/avo/tab_group_component.rb
avo-3.0.1.beta9 app/components/avo/tab_group_component.rb
avo-3.0.1.beta6 app/components/avo/tab_group_component.rb
avo-3.0.1.beta7 app/components/avo/tab_group_component.rb