Class: SdrViewComponents::Elements::Tabs::TabComponent

Inherits:
BaseComponent
  • Object
show all
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

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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

#idObject (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

#labelObject (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_idObject (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

#variantObject (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

Returns:

  • (Boolean)


22
23
24
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 22

def active?
  @active
end

#button_classesObject



30
31
32
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 30

def button_classes
  merge_classes('nav-link', active? ? 'active' : nil)
end

#classesObject



26
27
28
# File 'app/components/sdr_view_components/elements/tabs/tab_component.rb', line 26

def classes
  merge_classes('nav', variant_classes)
end