Class: Primer::SubheadComponent

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

Overview

Use the Subhead component for page headings.

Defined Under Namespace

Classes: Actions, Description, Heading

Constant Summary

Constants inherited from Component

Component::STATUSES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

status

Methods included from ViewHelper

#primer

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

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.slot(:heading) do %>
    My Heading
  <% end %>
  <% component.slot(:description) do %>
    My Description
  <% end %>
<% end %>

Without border

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

With actions

<%= render(Primer::SubheadComponent.new) do |component| %>
  <% component.slot(:heading) do %>
    My Heading
  <% end %>
  <% component.slot(:description) do %>
    My Description
  <% end %>
  <% component.slot(:actions) do %>
    <%= render(
      Primer::ButtonComponent.new(
        tag: :a, href: "http://www.google.com", button_type: :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 %>



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/components/primer/subhead_component.rb', line 52

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)


66
67
68
# File 'app/components/primer/subhead_component.rb', line 66

def render?
  heading.present?
end