Class: Primer::Alpha::ActionList::Heading

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

Overview

Heading used to describe each sub list within an action list.

Constant Summary collapse

DEFAULT_SCHEME =
:subtle
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => nil,
  :filled => "ActionList-sectionDivider--filled"
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys.freeze
HEADING_MIN =
1
HEADING_MAX =
6
HEADING_LEVELS =
(HEADING_MIN..HEADING_MAX).to_a.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 Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

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(title:, heading_level: 3, scheme: DEFAULT_SCHEME, subtitle: nil, **system_arguments) ⇒ Heading

Returns a new instance of Heading.

Parameters:

  • title (String)

    Sub list title.

  • heading_level (Integer) (defaults to: 3)

    Heading level. Level 2 results in an ‘<h2>` tag, level 3 an `<h3>` tag, etc.

  • subtitle (String) (defaults to: nil)

    Optional sub list description.

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    Display a background color if scheme is ‘filled`.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/primer/alpha/action_list/heading.rb', line 25

def initialize(title:, heading_level: 3, scheme: DEFAULT_SCHEME, subtitle: nil, **system_arguments)
  raise "Heading level must be between #{HEADING_MIN} and #{HEADING_MAX}" unless HEADING_LEVELS.include?(heading_level)

  @heading_level = heading_level
  @tag = :"h#{heading_level}"
  @system_arguments = deny_tag_argument(**system_arguments)
  @title = title
  @subtitle = subtitle
  @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)
  @system_arguments[:classes] = class_names(
    "ActionList-sectionDivider",
    SCHEME_MAPPINGS[@scheme],
    @system_arguments[:classes]
  )

  @title_id = self.class.generate_id(base_name: "heading-title")
  @subtitle_id = self.class.generate_id(base_name: "heading-subtitle")
end

Instance Attribute Details

#subtitle_idObject (readonly)

Returns the value of attribute subtitle_id.



18
19
20
# File 'app/components/primer/alpha/action_list/heading.rb', line 18

def subtitle_id
  @subtitle_id
end

#title_idObject (readonly)

Returns the value of attribute title_id.



18
19
20
# File 'app/components/primer/alpha/action_list/heading.rb', line 18

def title_id
  @title_id
end

Instance Method Details

#subtitle?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/components/primer/alpha/action_list/heading.rb', line 44

def subtitle?
  @subtitle.present?
end