Class: Railsboot::HeadingComponent

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

Constant Summary collapse

TAGS =
["h1", "h2", "h3", "h4", "h5", "h6", "div", "span"].freeze
DEFAULT_TAG =
"h1".freeze
SIZES =
["h1", "h2", "h3", "h4", "h5", "h6"].freeze
DISPLAYS =
["1", "2", "3", "4", "5", "6"].freeze

Constants inherited from Component

Component::COLORS, Component::DEFAULT_COLOR

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HeadingComponent.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/components/railsboot/heading_component.rb', line 8

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