Class: CCS::Components::GovUK::TaskList::Item::Title

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/task_list/item/title.rb

Overview

GOV.UK Task list item title

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(text:, id_prefix:, href: nil, hint_text: nil, **options) ⇒ Title

Returns a new instance of Title.

Parameters:

  • text (String)

    the text for the title

  • id_prefix (String)

    the id prefix for the task list item

  • href (String) (defaults to: nil)

    optional link for the title

  • hint_text (String) (defaults to: nil)

    flag to indicate if there is a hint

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the task list item title HTML



30
31
32
33
34
35
36
# File 'lib/ccs/components/govuk/task_list/item/title.rb', line 30

def initialize(text:, id_prefix:, href: nil, hint_text: nil, **options)
  super(**options)
  @options[:attributes][:aria] = { describedby: (hint_text ? "#{id_prefix}-hint " : '') + "#{id_prefix}-status" } if href

  @text = text
  @href = href
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Task list item title

Returns:

  • (ActiveSupport::SafeBuffer)


42
43
44
45
46
47
48
# File 'lib/ccs/components/govuk/task_list/item/title.rb', line 42

def render
  if href
    link_to(text, href, class: "govuk-link govuk-task-list__link #{@options[:attributes][:class]}".rstrip, aria: { describedby: @options[:attributes][:aria][:describedby] })
  else
    tag.div(text, class: @options[:attributes][:class])
  end
end