Sha256: ec603ca530e6c46a9fe1ada11be94d75b14d498abf422030c2edb0e2fb6f4e40

Contents?: true

Size: 1.04 KB

Versions: 87

Compression:

Stored size: 1.04 KB

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:, tabs_style:)
    @resource = resource
    @group = group
    @index = index
    @form = form
    @params = params
    @view = view
    @tabs_style = tabs_style

    @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

  def tabs_style
    @tabs_style || Avo.configuration.tabs_style
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
avo-2.53.0 app/components/avo/tab_group_component.rb
avo-2.52.0 app/components/avo/tab_group_component.rb
avo-2.49.0 app/components/avo/tab_group_component.rb
avo-2.48.0 app/components/avo/tab_group_component.rb
avo-2.47.0 app/components/avo/tab_group_component.rb
avo-2.46.0 app/components/avo/tab_group_component.rb
avo-2.45.0 app/components/avo/tab_group_component.rb
avo-2.44.0 app/components/avo/tab_group_component.rb
avo-2.43.0 app/components/avo/tab_group_component.rb
avo-2.42.2 app/components/avo/tab_group_component.rb
avo-2.42.1 app/components/avo/tab_group_component.rb
avo-2.42.0 app/components/avo/tab_group_component.rb
avo-2.41.0 app/components/avo/tab_group_component.rb
avo-2.40.0 app/components/avo/tab_group_component.rb
avo-2.39.0 app/components/avo/tab_group_component.rb
avo-2.38.0 app/components/avo/tab_group_component.rb
avo-2.37.2 app/components/avo/tab_group_component.rb
avo-2.37.1 app/components/avo/tab_group_component.rb
avo-2.37.0 app/components/avo/tab_group_component.rb
avo-2.36.3 app/components/avo/tab_group_component.rb