Class: SdrViewComponents::TabForm::TabComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::TabForm::TabComponent
- 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
-
#active_tab_name ⇒ Object
Returns the value of attribute active_tab_name.
-
#tab_name ⇒ Object
readonly
Returns the value of attribute tab_name.
Instance Method Summary collapse
- #classes ⇒ Object
-
#data ⇒ Object
Callers can pass their own
data:(e.g. anaction: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. - #id ⇒ Object
-
#initialize(label:, tab_name:, mark_required: false, data: {}) ⇒ TabComponent
constructor
A new instance of TabComponent.
- #label ⇒ Object
- #mark_required? ⇒ Boolean
- #pane_id ⇒ Object
- #selected? ⇒ Boolean
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_name ⇒ Object
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_name ⇒ Object (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
#classes ⇒ Object
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 |
#data ⇒ Object
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 |
#id ⇒ Object
27 28 29 |
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 27 def id "#{tab_name}-tab" end |
#label ⇒ Object
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
35 36 37 |
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 35 def mark_required? @mark_required end |
#pane_id ⇒ Object
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
19 20 21 |
# File 'app/components/sdr_view_components/tab_form/tab_component.rb', line 19 def selected? tab_name == active_tab_name end |