Class: SdrViewComponents::TabForm::TabComponent

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

Overview

Component for a tab in a SdrViewComponents::TabForm::TabListComponent.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #mark_label_required, #merge_actions, #merge_classes

Constructor Details

#initialize(label:, tab_name:, mark_required: false, data: {}) ⇒ TabComponent

Returns a new instance of TabComponent.



9
10
11
12
13
14
15
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 9

def initialize(label:, tab_name:, mark_required: false, data: {})
  @label = label
  @tab_name = tab_name
  @mark_required = mark_required
  @data = data
  super()
end

Instance Attribute Details

#active_tab_nameObject

Returns the value of attribute active_tab_name.



7
8
9
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 7

def active_tab_name
  @active_tab_name
end

#tab_nameObject (readonly)

Returns the value of attribute tab_name.



17
18
19
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 17

def tab_name
  @tab_name
end

Instance Method Details

#classesObject



23
24
25
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 23

def classes
  merge_classes('nav-link w-100', selected? ? 'active' : nil)
end

#dataObject

Callers can pass their own data: (e.g. an action: to wire up other Stimulus controllers); it's merged with the data this component needs to function as a Bootstrap tab wired to TabListComponent's sdr-tab-error controller.



46
47
48
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 46

def data
  { bs_toggle: 'tab', bs_target: "##{pane_id}", sdr_tab_error_target: 'tab' }.merge(@data)
end

#idObject



27
28
29
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 27

def id
  "#{tab_name}-tab"
end

#labelObject



39
40
41
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 39

def label
  mark_label_required(label: @label, mark_required: mark_required?, hidden_label: 'contains required fields')
end

#mark_required?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 35

def mark_required?
  @mark_required
end

#pane_idObject



31
32
33
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 31

def pane_id
  "#{tab_name}-pane"
end

#selected?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 19

def selected?
  tab_name == active_tab_name
end