Class: Railsboot::HeadingComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/heading_component.rb

Overview

ViewComponent: renders the heading block.

Direct Known Subclasses

HeadingWithAnchorComponent

Constant Summary collapse

TAGS =

Tags.

%w[h1 h2 h3 h4 h5 h6 div span].freeze
DEFAULT_TAG =

Default tag.

"h1".freeze
SIZES =

Sizes.

%w[h1 h2 h3 h4 h5 h6].freeze
DISPLAYS =

Displays.

%w[1 2 3 4 5 6].freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag: DEFAULT_TAG, size: nil, display: nil, **html_attributes) ⇒ HeadingComponent

Returns a new instance of HeadingComponent.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/railsboot/heading_component.rb', line 14

def initialize(tag: DEFAULT_TAG, size: nil, display: nil, **html_attributes)
  @tag = fetch_or_raise(tag, TAGS)
  @size = size.to_s if size.present? && SIZES.include?(size.to_s)
  @display = display.to_s if display.present? && DISPLAYS.include?(display.to_s)
  @html_attributes = html_attributes

  @html_attributes[:tag] = @tag
  @html_attributes[:class] = class_names(
    { @size => @size.present? },
    { "display-#{@display}" => @display.present? },
    html_attributes.delete(:class)
  ).presence
end