Class: Primer::Beta::Subhead

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/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(Primer::ButtonComponent) %> or <%= link_to_component(Primer::Beta::Link) %>.

Constant Summary collapse

DEFAULT_HEADING_TAG =
:div
HEADING_TAG_OPTIONS =
[DEFAULT_HEADING_TAG, :h1, :h2, :h3, :h4, :h5, :h6].freeze
DEFAULT_HEADING_SIZE =
:large
HEADING_SIZE_MAP =
{
  DEFAULT_HEADING_SIZE => "Subhead-heading--large",
  :medium => "Subhead-heading--medium"
}.freeze
HEADING_SIZE_OPTIONS =
HEADING_SIZE_MAP.keys.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

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

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

Methods included from AttributesHelper

#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Constructor Details

#initialize(spacious: false, hide_border: false, **system_arguments) ⇒ Subhead

Returns a new instance of Subhead.

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 %>



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/components/primer/beta/subhead.rb', line 69

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)


83
84
85
# File 'app/components/primer/beta/subhead.rb', line 83

def render?
  heading.present?
end