Class: Primer::Alpha::Overlay::Header

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/alpha/overlay/header.rb

Overview

A ‘Overlay::Header` is a compositional component, used to render the Header of an overlay. See <%= link_to_component(Primer::Alpha::Overlay) %>.

Constant Summary collapse

DEFAULT_SIZE =
:medium
SIZE_MAPPINGS =
{
  DEFAULT_SIZE => nil,
  :large => "Overlay-header--large"
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys

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 Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::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 Primer::AttributesHelper

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

Constructor Details

#initialize(id:, title:, overlay_id: nil, subtitle: nil, size: DEFAULT_SIZE, divider: false, visually_hide_title: false, **system_arguments) ⇒ Header

Returns a new instance of Header.

Parameters:

  • title (String)

    Describes the content of the Overlay.

  • subtitle (String) (defaults to: nil)

    Provides additional context for the Overlay, also setting the ‘aria-describedby` attribute.

  • overlay_id (String) (defaults to: nil)

    Provides the id of the overlay element so the close button can close it

  • size (Symbol) (defaults to: DEFAULT_SIZE)

    The size of the Header. <%= one_of(Primer::Alpha::Overlay::Header::SIZE_OPTIONS) %>

  • divider (Boolean) (defaults to: false)

    Show a divider between the header and body.

  • visually_hide_title (Boolean) (defaults to: false)

    Visually hide the ‘title` while maintaining a label for assistive technologies.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/primer/alpha/overlay/header.rb', line 23

def initialize(
  id:,
  title:,
  overlay_id: nil,
  subtitle: nil,
  size: DEFAULT_SIZE,
  divider: false,
  visually_hide_title: false,
  **system_arguments
)
  @overlay_id = overlay_id
  @id = id
  @title = title
  @subtitle = subtitle
  @visually_hide_title = visually_hide_title
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :header
  @system_arguments[:classes] = class_names(
    "Overlay-header",
    { "Overlay-header--divided": divider },
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)],
    system_arguments[:classes]
  )
end