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

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

Overview

GOV.UK Task list item

The individual list item for the task list

Defined Under Namespace

Classes: Status, Title

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the task list item

{ class: 'govuk-task-list__item' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(title:, status:, index:, id_prefix:, hint_text: nil, **options) ⇒ Item

Returns a new instance of Item.

Parameters:

  • title (Hash)

    options for the item title. See Title#initialize for details of title.

  • status (Hash)

    options for the item status. See Status#initialize for details of status.

  • index (Integer)

    the index of the item

  • id_prefix (String)

    the id prefix for the task list

  • hint_text (String) (defaults to: nil)

    optional hint text for the item

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the task list item HTML



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

def initialize(title:, status:, index:, id_prefix:, hint_text: nil, **options)
  super(**options)
  @options[:attributes][:class] << ' govuk-task-list__item--with-link' if title[:href]

  @id_prefix = "#{id_prefix}-#{index}"
  @title = Title.new(context: @context, id_prefix: @id_prefix, hint_text: hint_text, **title)
  @hint_text = hint_text
  @status = Status.new(context: @context, id_prefix: @id_prefix, **status)
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Task list item

Returns:

  • (ActiveSupport::SafeBuffer)


58
59
60
61
62
63
64
65
66
# File 'lib/ccs/components/govuk/task_list/item.rb', line 58

def render
  tag.li(class: options[:attributes][:class]) do
    concat(tag.div(class: 'govuk-task-list__name-and-hint') do
      concat(title.render)
      concat(tag.div(hint_text, class: 'govuk-task-list__hint', id: "#{id_prefix}-hint")) if hint_text
    end)
    concat(status.render)
  end
end