Class: SdrViewComponents::Elements::Tabs::TabComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Elements::Tabs::TabComponent
- Defined in:
- app/components/sdr_view_components/elements/tabs/tab_component.rb
Overview
Component for rendering a tab in a tabbed interface.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#pane_id ⇒ Object
readonly
Returns the value of attribute pane_id.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #button_classes ⇒ Object
- #classes ⇒ Object
-
#initialize(label:, id:, pane_id:, active: false, variant: :underline) ⇒ TabComponent
constructor
A new instance of TabComponent.
Methods inherited from BaseComponent
#args_for, #merge_actions, #merge_classes
Constructor Details
#initialize(label:, id:, pane_id:, active: false, variant: :underline) ⇒ TabComponent
Returns a new instance of TabComponent.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 8 def initialize(label:, id:, pane_id:, active: false, variant: :underline) @label = label @id = id @pane_id = pane_id @active = active @variant = variant raise ArgumentError, "Invalid variant: #{variant}" unless %i[underline default].include?(variant) super() end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 20 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
20 21 22 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 20 def label @label end |
#pane_id ⇒ Object (readonly)
Returns the value of attribute pane_id.
20 21 22 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 20 def pane_id @pane_id end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
20 21 22 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 20 def variant @variant end |
Instance Method Details
#active? ⇒ Boolean
22 23 24 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 22 def active? @active end |
#button_classes ⇒ Object
30 31 32 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 30 def merge_classes('nav-link', active? ? 'active' : nil) end |
#classes ⇒ Object
26 27 28 |
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 26 def classes merge_classes('nav', variant_classes) end |