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
Instance Method Summary collapse
- #call ⇒ Object
- #combined_attributes(i) ⇒ Object
- #default_attributes ⇒ 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 inherited from Base
Constructor Details
#initialize(label:, text: nil, classes: [], html_attributes: {}) ⇒ Tab
Returns a new instance of Tab.
24 25 26 27 28 29 |
# File 'app/components/govuk_component/tab_component.rb', line 24 def initialize(label:, text: nil, classes: [], html_attributes: {}) @label = label @text = h(text) super(classes: classes, html_attributes: html_attributes) end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
22 23 24 |
# File 'app/components/govuk_component/tab_component.rb', line 22 def label @label end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
22 23 24 |
# File 'app/components/govuk_component/tab_component.rb', line 22 def text @text end |
Instance Method Details
#call ⇒ Object
57 58 59 |
# File 'app/components/govuk_component/tab_component.rb', line 57 def call content || text || fail(ArgumentError, "no text or content") end |
#combined_attributes(i) ⇒ Object
53 54 55 |
# File 'app/components/govuk_component/tab_component.rb', line 53 def combined_attributes(i) html_attributes.deep_merge_html_attributes({ class: hidden_class(i) }).deep_tidy_html_attributes end |
#default_attributes ⇒ Object
49 50 51 |
# File 'app/components/govuk_component/tab_component.rb', line 49 def default_attributes { id: id, class: "#{brand}-tabs__panel" } end |
#hidden_class(i = nil) ⇒ Object
35 36 37 38 39 |
# File 'app/components/govuk_component/tab_component.rb', line 35 def hidden_class(i = nil) return [] if i&.zero? ["#{brand}-tabs__panel--hidden"] end |
#id(prefix: nil) ⇒ Object
31 32 33 |
# File 'app/components/govuk_component/tab_component.rb', line 31 def id(prefix: nil) [prefix, label.parameterize].join end |
#li_classes(i = nil) ⇒ Object
41 42 43 |
# File 'app/components/govuk_component/tab_component.rb', line 41 def li_classes(i = nil) class_names("#{brand}-tabs__list-item", "#{brand}-tabs__list-item--selected" => i&.zero?).split end |
#li_link ⇒ Object
45 46 47 |
# File 'app/components/govuk_component/tab_component.rb', line 45 def li_link link_to(label, id(prefix: '#'), class: "#{brand}-tabs__tab") end |