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: [], **options) ⇒ HeadingComponent
constructor
A new instance of HeadingComponent.
Methods inherited from BaseComponent
#args_for, #mark_label_required, #merge_actions, #merge_classes
Constructor Details
#initialize(level:, text: nil, variant: nil, classes: [], **options) ⇒ HeadingComponent
Returns a new instance of HeadingComponent.
7 8 9 10 11 12 13 14 15 16 |
# 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 @options = super() end |
Instance Method Details
#call ⇒ Object
Renders the component without the need for a .erb partial.
23 24 25 26 27 28 29 |
# File 'app/components/sdr_view_components/elements/heading_component.rb', line 23 def call return unless tag.respond_to?(@level) tag.public_send(@level, class: classes, **@options) do @text || content end end |
#classes ⇒ Object
18 19 20 |
# File 'app/components/sdr_view_components/elements/heading_component.rb', line 18 def classes merge_classes(variant_class, @classes) end |