Sha256: 7950d9d44ad513f27053183216c389b8a82c6a589858512b05a3f97242325614

Contents?: true

Size: 925 Bytes

Versions: 29

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

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

  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.empty?
    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

29 entries across 29 versions & 1 rubygems

Version Path
avo-2.11.2.pre.1 app/components/avo/tab_group_component.rb
avo-2.11.1.pre.3 app/components/avo/tab_group_component.rb
avo-2.11.1 app/components/avo/tab_group_component.rb
avo-2.11.1.pre.2 app/components/avo/tab_group_component.rb
avo-2.11.1.pre.1 app/components/avo/tab_group_component.rb
avo-2.11.0 app/components/avo/tab_group_component.rb
avo-2.10.3.pre.1 app/components/avo/tab_group_component.rb
avo-2.10.2 app/components/avo/tab_group_component.rb
avo-2.10.0 app/components/avo/tab_group_component.rb