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

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/task_list.rb,
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

This is used to generate the task list component from the GDS - Components - Task list

Defined Under Namespace

Classes: Item

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the task list

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

Instance Method Summary collapse

Constructor Details

#initialize(task_list_items:, id_prefix: nil, **options) ⇒ TaskList

Returns a new instance of TaskList.

Parameters:

  • task_list_items (Array<Hash>)

    An array of task list items. See Item#initialize for details of the items in the array.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the task list HTML

  • :id_prefix (Sting)

    id prefix for the task list, defaults to ‘task-list’

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



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

def initialize(task_list_items:, id_prefix: nil, **options)
  super(**options)

  @task_list_items = task_list_items.map.with_index(1) { |task_list_item, index| Item.new(context: @context, index: index, id_prefix: id_prefix || 'task-list', **task_list_item) if task_list_item.present? }
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK task list component

Returns:

  • (ActiveSupport::SafeBuffer)


40
41
42
43
44
# File 'lib/ccs/components/govuk/task_list.rb', line 40

def render
  tag.ul(**options[:attributes]) do
    task_list_items.each { |task_list_item| concat(task_list_item.render) if task_list_item }
  end
end