Class: SdrViewComponents::Elements::HeadingComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Elements::HeadingComponent
- Defined in:
- app/components/sdr_view_components/elements/heading_component.rb
Overview
Applies an h# component with the expected styling.
Instance Method Summary collapse
-
#call ⇒ Object
Renders the component without the need for a .erb partial.
- #classes ⇒ Object
-
#initialize(level:, text: nil, variant: nil, classes: []) ⇒ HeadingComponent
constructor
A new instance of HeadingComponent.
Methods inherited from BaseComponent
#args_for, #merge_actions, #merge_classes
Constructor Details
#initialize(level:, text: nil, variant: nil, classes: []) ⇒ HeadingComponent
Returns a new instance of HeadingComponent.
7 8 9 10 11 12 13 14 15 |
# File 'app/components/sdr_view_components/elements/heading_component.rb', line 7 def initialize(level:, text: nil, variant: nil, classes: []) raise ArgumentError, 'Invalid level' unless %i[h1 h2 h3 h4 h5 h6].include?(level.to_sym) @level = level @variant = variant @classes = classes @text = text # Provide text or content super() end |
Instance Method Details
#call ⇒ Object
Renders the component without the need for a .erb partial.
22 23 24 25 26 27 28 |
# File 'app/components/sdr_view_components/elements/heading_component.rb', line 22 def call return unless tag.respond_to?(@level) tag.public_send(@level, class: classes) do @text || content end end |
#classes ⇒ Object
17 18 19 |
# File 'app/components/sdr_view_components/elements/heading_component.rb', line 17 def classes merge_classes(variant_class, @classes) end |