Class: GovukComponent::TabComponent::Tab
- Defined in:
- app/components/govuk_component/tab_component.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Attributes inherited from Base
Attributes included from GovukComponent::Traits::CustomHtmlAttributes
Instance Method Summary collapse
- #call ⇒ Object
- #default_classes ⇒ Object
- #hidden_class(i = nil) ⇒ Object
- #id(prefix: nil) ⇒ Object
-
#initialize(label:, text: nil, classes: [], html_attributes: {}) ⇒ Tab
constructor
A new instance of Tab.
- #li_classes(i = nil) ⇒ Object
- #li_link ⇒ Object
Methods included from GovukComponent::Traits::CustomClasses
Methods included from Govuk::Components::Helpers::CssUtilities
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
#label ⇒ Object (readonly)
Returns the value of attribute label.
20 21 22 |
# File 'app/components/govuk_component/tab_component.rb', line 20 def label @label end |
#text ⇒ Object (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
#call ⇒ Object
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_classes ⇒ Object
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 |
#li_link ⇒ Object
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 |