Class: CCS::Components::GovUK::Tabs::Panel

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/tabs/panel.rb

Overview

GOV.UK Tabs panel

The individual tab panels

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(index:, id_prefix:, content: nil, text: nil, **options) ⇒ Panel

Returns a new instance of Panel.

Parameters:

  • index (Integer)

    the index of the tab panel

  • id_prefix (Integer)

    prefix used for the id of a panel if no id is specified

  • content (ActiveSupport::SafeBuffer) (defaults to: nil)

    HTML to use as content for the tab panel

  • text (String) (defaults to: nil)

    if :content is blank then this is the text used for the tab panel

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



35
36
37
38
39
40
41
42
43
# File 'lib/ccs/components/govuk/tabs/panel.rb', line 35

def initialize(index:, id_prefix:, content: nil, text: nil, **options)
  super(**options)
  @options[:attributes][:class] = "govuk-tabs__panel #{'govuk-tabs__panel--hidden' if index > 1}".rstrip
  @options[:attributes][:id] ||= "#{id_prefix}-#{index}"

  @index = index
  @content = content
  @text = text
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Tabs panel

Returns:

  • (ActiveSupport::SafeBuffer)


49
50
51
52
53
# File 'lib/ccs/components/govuk/tabs/panel.rb', line 49

def render
  tag.div(**options[:attributes]) do
    content || tag.p(text, class: 'govuk-body')
  end
end