Class: Pulse::ActionList::Heading

Inherits:
Component
  • Object
show all
Defined in:
app/components/pulse/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::TW_MERGE

Constants included from Pulse::AttributesHelper

Pulse::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Pulse::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

generate_id, #merge_attributes, #merge_classes

Methods included from SvgHelper

#render_svg

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from Pulse::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 %>



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

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

  @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.



17
18
19
# File 'app/components/pulse/action_list/heading.rb', line 17

def subtitle_id
  @subtitle_id
end

#title_idObject (readonly)

Returns the value of attribute title_id.



17
18
19
# File 'app/components/pulse/action_list/heading.rb', line 17

def title_id
  @title_id
end

Instance Method Details

#subtitle?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/components/pulse/action_list/heading.rb', line 47

def subtitle?
  @subtitle.present?
end