Class: GovukComponent::TabComponent::Tab

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/tab_component.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Attributes included from GovukComponent::Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Methods included from GovukComponent::Traits::CustomClasses

#classes

Methods included from Govuk::Components::Helpers::CssUtilities

#combine_classes

Constructor Details

#initialize(label:, text: nil, classes: [], html_attributes: {}) ⇒ Tab

Returns a new instance of Tab.



22
23
24
25
26
27
# File 'app/components/govuk_component/tab_component.rb', line 22

def initialize(label:, text: nil, classes: [], html_attributes: {})
  super(classes: classes, html_attributes: html_attributes)

  @label = label
  @text  = text
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



20
21
22
# File 'app/components/govuk_component/tab_component.rb', line 20

def label
  @label
end

#textObject (readonly)

Returns the value of attribute text.



20
21
22
# File 'app/components/govuk_component/tab_component.rb', line 20

def text
  @text
end

Instance Method Details

#callObject



51
52
53
# File 'app/components/govuk_component/tab_component.rb', line 51

def call
  content || text || fail(ArgumentError, "no text or content")
end

#default_classesObject



47
48
49
# File 'app/components/govuk_component/tab_component.rb', line 47

def default_classes
  %w(govuk-tabs__panel)
end

#hidden_class(i = nil) ⇒ Object



33
34
35
# File 'app/components/govuk_component/tab_component.rb', line 33

def hidden_class(i = nil)
  %(govuk-tabs__panel--hidden) unless i&.zero?
end

#id(prefix: nil) ⇒ Object



29
30
31
# File 'app/components/govuk_component/tab_component.rb', line 29

def id(prefix: nil)
  [prefix, label.parameterize].join
end

#li_classes(i = nil) ⇒ Object



37
38
39
40
41
# File 'app/components/govuk_component/tab_component.rb', line 37

def li_classes(i = nil)
  %w(govuk-tabs__list-item).tap do |c|
    c.append("govuk-tabs__list-item--selected") if i&.zero?
  end
end


43
44
45
# File 'app/components/govuk_component/tab_component.rb', line 43

def li_link
  link_to(label, id(prefix: '#'), class: "govuk-tabs__tab")
end