Class: Primer::SubheadComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/subhead_component.rb

Overview

Use the Subhead component for page headings.

Constant Summary

Constants included from Primer::Status::Dsl

Primer::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 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) ⇒ SubheadComponent

Returns a new instance of SubheadComponent.

Examples:

Default

<%= render(Primer::SubheadComponent.new) do |component| %>
  <% component.heading do %>
    My Heading
  <% end %>
  <% component.description do %>
    My Description
  <% end %>
<% end %>

Without border

<%= render(Primer::SubheadComponent.new(hide_border: true)) do |component| %>
  <% component.heading do %>
    My Heading
  <% end %>
  <% component.description do %>
    My Description
  <% end %>
<% end %>

With actions

<%= render(Primer::SubheadComponent.new) do |component| %>
  <% component.heading do %>
    My Heading
  <% end %>
  <% component.description do %>
    My Description
  <% end %>
  <% component.actions do %>
    <%= render(
      Primer::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 %>



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/components/primer/subhead_component.rb', line 83

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

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

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'app/components/primer/subhead_component.rb', line 97

def render?
  heading.present?
end