Class: Yattho::Beta::Subhead

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

Overview

Use ‘Subhead` as the start of a section. The `:heading` slot will render an `<h2>` font-sized text.

  • Optionally set the ‘:description` slot to render a short description and the `:actions` slot for a related action.

  • Use a succinct, one-line description for the ‘:description` slot. For longer descriptions, omit the description slot and render a paragraph below the `Subhead`.

  • Use the actions slot to render a related action to the right of the heading. Use <%= link_to_component(Yattho::ButtonComponent) %> or <%= link_to_component(Yattho::Beta::Link) %>.

Direct Known Subclasses

SubheadComponent

Constant Summary collapse

DEFAULT_HEADING_TAG =
:div
HEADING_TAG_OPTIONS =
[DEFAULT_HEADING_TAG, :h1, :h2, :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(spacious: false, hide_border: false, **system_arguments) ⇒ Subhead

Returns a new instance of Subhead.

Examples:

Default

<%= render(Yattho::Beta::Subhead.new) do |component| %>
  <% component.with_heading(tag: :h3) do %>
    My Heading
  <% end %>
  <% component.with_description do %>
    My Description
  <% end %>
<% end %>

With dangerous heading

<%= render(Yattho::Beta::Subhead.new) do |component| %>
  <% component.with_heading(tag: :h3, danger: true) do %>
    My Heading
  <% end %>
  <% component.with_description do %>
    My Description
  <% end %>
<% end %>

With long description

<%= render(Yattho::Beta::Subhead.new) do |component| %>
  <% component.with_heading(tag: :h3) do %>
    My Heading
  <% end %>
<% end %>
<p> This is a longer description that is sitting below the Subhead. It's much longer than a description that could sit comfortably in the Subhead. </p>

Without border

<%= render(Yattho::Beta::Subhead.new(hide_border: true)) do |component| %>
  <% component.with_heading do %>
    My Heading
  <% end %>
  <% component.with_description do %>
    My Description
  <% end %>
<% end %>

With actions

<%= render(Yattho::Beta::Subhead.new) do |component| %>
  <% component.with_heading do %>
    My Heading
  <% end %>
  <% component.with_description do %>
    My Description
  <% end %>
  <% component.with_actions do %>
    <%= render(
      Yattho::ButtonComponent.new(
        tag: :a, href: "http://www.google.com", scheme: :danger
      )
    ) { "Action" } %>
  <% end %>
<% end %>

Parameters:

  • spacious (Boolean) (defaults to: false)

    Whether to add spacing to the Subhead.

  • hide_border (Boolean) (defaults to: false)

    Whether to hide the border under the heading.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/components/yattho/beta/subhead.rb', line 116

def initialize(spacious: false, hide_border: false, **system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)

  @system_arguments[:tag] = :div
  @system_arguments[:classes] =
    class_names(
      @system_arguments[:classes],
      "Subhead",
      'Subhead--spacious': spacious,
      'border-bottom-0': hide_border
    )
  @system_arguments[:mb] ||= hide_border ? 0 : nil
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'app/components/yattho/beta/subhead.rb', line 130

def render?
  heading.present?
end