Class: Pulse::NavList::Heading

Inherits:
Component
  • Object
show all
Defined in:
app/components/pulse/nav_list/heading.rb

Overview

The heading placed above a NavList's items.

See <%= link_to_component(NavList) %> for usage examples.

Constant Summary

Constants inherited from Component

Component::TW_MERGE

Constants included from AttributesHelper

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

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

Constructor Details

#initialize(title:, id: self.class.generate_id, heading_level: 2, **system_arguments) ⇒ Heading

Returns a new instance of Heading.

Parameters:

  • title (String)

    The text content of the heading.

  • id (String) (defaults to: self.class.generate_id)

    The value of the ID HTML attribute. Auto-generated by default.

  • heading_level (Integer) (defaults to: 2)

    The heading level, i.e. 2 for an <h2>, 3 for an <h3>, etc.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



15
16
17
18
19
20
21
# File 'app/components/pulse/nav_list/heading.rb', line 15

def initialize(title:, id: self.class.generate_id, heading_level: 2,
               **system_arguments)
  @title = title
  @id = id
  @heading_level = heading_level
  @system_arguments = system_arguments
end

Instance Attribute Details

#heading_levelObject (readonly)

Returns the value of attribute heading_level.



9
10
11
# File 'app/components/pulse/nav_list/heading.rb', line 9

def heading_level
  @heading_level
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'app/components/pulse/nav_list/heading.rb', line 9

def id
  @id
end

#system_argumentsObject (readonly)

Returns the value of attribute system_arguments.



9
10
11
# File 'app/components/pulse/nav_list/heading.rb', line 9

def system_arguments
  @system_arguments
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'app/components/pulse/nav_list/heading.rb', line 9

def title
  @title
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/pulse/nav_list/heading.rb', line 23

def call
  render(
    Pulse::Text.new(
      type: :body4,
      tag: :"h#{heading_level}",
      id:,
      classes: 'pulse-ml-2 pulse-mb-4',
      **system_arguments
    ).with_content(title)
  )
end