Class: GovukComponent::TabComponent::Tab
- Defined in:
- app/components/govuk_component/tab_component.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#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
-
#initialize(label:, text: nil, id: 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, id: nil, classes: [], html_attributes: {}) ⇒ Tab
Returns a new instance of Tab.
24 25 26 27 28 29 30 |
# File 'app/components/govuk_component/tab_component.rb', line 24 def initialize(label:, text: nil, id: nil, classes: [], html_attributes: {}) @label = label @text = h(text) @id = id || label.parameterize super(classes:, html_attributes:) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'app/components/govuk_component/tab_component.rb', line 22 def id @id end |
#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
54 55 56 |
# File 'app/components/govuk_component/tab_component.rb', line 54 def call content || text || fail(ArgumentError, "no text or content") end |
#combined_attributes(i) ⇒ Object
50 51 52 |
# File 'app/components/govuk_component/tab_component.rb', line 50 def combined_attributes(i) html_attributes.deep_merge_html_attributes({ class: hidden_class(i) }).deep_tidy_html_attributes end |
#default_attributes ⇒ Object
46 47 48 |
# File 'app/components/govuk_component/tab_component.rb', line 46 def default_attributes { id:, class: "#{brand}-tabs__panel" } end |
#hidden_class(i = nil) ⇒ Object
32 33 34 35 36 |
# File 'app/components/govuk_component/tab_component.rb', line 32 def hidden_class(i = nil) return [] if i&.zero? ["#{brand}-tabs__panel--hidden"] end |
#li_classes(i = nil) ⇒ Object
38 39 40 |
# File 'app/components/govuk_component/tab_component.rb', line 38 def li_classes(i = nil) class_names("#{brand}-tabs__list-item", "#{brand}-tabs__list-item--selected" => i&.zero?).split end |
#li_link ⇒ Object
42 43 44 |
# File 'app/components/govuk_component/tab_component.rb', line 42 def li_link link_to(label, "#" + id, class: "#{brand}-tabs__tab") end |