Class: Yattho::Beta::Heading

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/heading.rb

Overview

‘Heading` should be used to communicate page organization and hierarchy.

  • Set tag to one of ‘:h1`, `:h2`, `:h3`, `:h4`, `:h5`, `:h6` based on what is appropriate for the page context.

  • Use ‘Heading` as the title of a section or sub section.

  • Do not use ‘Heading` for styling alone. For simply styling text, consider using <%= link_to_component(Yattho::Beta::Text) %> with relevant <%= link_to_typography_docs %> such as `font_size` and `font_weight`.

  • Do not jump heading levels. For instance, do not follow a ‘<h1>` with an `<h3>`. Heading levels should increase by one in ascending order.

Constant Summary collapse

TAG_FALLBACK =
:h2
TAG_OPTIONS =
[:h1, TAG_FALLBACK, :h3, :h4, :h5, :h6].freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(tag:, **system_arguments) ⇒ Heading

Returns a new instance of Heading.

Examples:

Default

<%= render(Yattho::Beta::Heading.new(tag: :h1)) { "H1 Text" } %>
<%= render(Yattho::Beta::Heading.new(tag: :h2)) { "H2 Text" } %>
<%= render(Yattho::Beta::Heading.new(tag: :h3)) { "H3 Text" } %>
<%= render(Yattho::Beta::Heading.new(tag: :h4)) { "H4 Text" } %>
<%= render(Yattho::Beta::Heading.new(tag: :h5)) { "H5 Text" } %>
<%= render(Yattho::Beta::Heading.new(tag: :h6)) { "H6 Text" } %>

Parameters:

  • tag (String)

    <%= one_of(Yattho::Beta::Heading::TAG_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



36
37
38
39
# File 'app/components/yattho/beta/heading.rb', line 36

def initialize(tag:, **system_arguments)
  @system_arguments = system_arguments
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_FALLBACK)
end

Instance Method Details

#callObject



41
42
43
# File 'app/components/yattho/beta/heading.rb', line 41

def call
  render(Yattho::BaseComponent.new(**@system_arguments)) { content }
end