Class: SdrViewComponents::TabForm::PaneComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/tab_form/pane_component.rb

Overview

Component for a tab pane in a SdrViewComponents::TabForm::TabListComponent. Based on https://getbootstrap.com/docs/5.3/components/navs-tabs/#javascript-behavior

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #mark_label_required, #merge_actions, #merge_classes

Constructor Details

#initialize(tab_name:, label: nil, help_text: nil, tooltip: nil, pane_header_class: 'pane-header', mark_required: false) ⇒ PaneComponent

rubocop:disable Metrics/ParameterLists



13
14
15
16
17
18
19
20
21
22
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 13

def initialize(tab_name:, label: nil, help_text: nil, tooltip: nil, pane_header_class: 'pane-header', # rubocop:disable Metrics/ParameterLists
               mark_required: false)
  @tab_name = tab_name
  @label = label
  @help_text = help_text
  @tooltip = tooltip
  @pane_header_class = pane_header_class
  @mark_required = mark_required
  super()
end

Instance Attribute Details

#active_tab_nameObject

Returns the value of attribute active_tab_name.



11
12
13
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 11

def active_tab_name
  @active_tab_name
end

#help_textObject (readonly)

Returns the value of attribute help_text.



24
25
26
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 24

def help_text
  @help_text
end

#pane_header_classObject (readonly)

Returns the value of attribute pane_header_class.



24
25
26
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 24

def pane_header_class
  @pane_header_class
end

#tab_nameObject (readonly)

Returns the value of attribute tab_name.



24
25
26
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 24

def tab_name
  @tab_name
end

#tooltipObject (readonly)

Returns the value of attribute tooltip.



24
25
26
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 24

def tooltip
  @tooltip
end

Instance Method Details

#classesObject



40
41
42
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 40

def classes
  merge_classes(%w[tab-pane fade h-100], selected? ? 'show active' : nil)
end

#idObject



44
45
46
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 44

def id
  "#{tab_name}-pane"
end

#labelObject



34
35
36
37
38
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 34

def label
  return unless @label

  mark_label_required(label: @label, mark_required: mark_required?)
end

#mark_required?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 30

def mark_required?
  @mark_required
end

#selected?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 26

def selected?
  tab_name == active_tab_name
end

#tab_idObject



48
49
50
# File 'app/components/sdr_view_components/tab_form/pane_component.rb', line 48

def tab_id
  "#{tab_name}-tab"
end