Class: GovukComponent::TaskListComponent::ItemComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/task_list_component/item_component.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(title: nil, href: nil, hint: nil, count: nil, id_prefix: nil, status: {}, classes: [], html_attributes: {}) ⇒ ItemComponent

Returns a new instance of ItemComponent.



31
32
33
34
35
36
37
38
39
40
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 31

def initialize(title: nil, href: nil, hint: nil, count: nil, id_prefix: nil, status: {}, classes: [], html_attributes: {})
  @raw_title  = title
  @href       = href
  @hint       = hint
  @raw_status = status
  @id_prefix  = id_prefix
  @count      = count

  super(classes:, html_attributes:)
end

Instance Attribute Details

#count=(value) ⇒ Object (writeonly)

Sets the attribute count

Parameters:

  • value

    the value to set the attribute count to.



29
30
31
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 29

def count=(value)
  @count = value
end

#hintObject (readonly)

Returns the value of attribute hint.



28
29
30
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 28

def hint
  @hint
end

#hrefObject (readonly)

Returns the value of attribute href.



28
29
30
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 28

def href
  @href
end

#raw_statusObject (readonly)

Returns the value of attribute raw_status.



28
29
30
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 28

def raw_status
  @raw_status
end

#raw_titleObject (readonly)

Returns the value of attribute raw_title.



28
29
30
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 28

def raw_title
  @raw_title
end

Instance Method Details

#callObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/govuk_component/task_list_component/item_component.rb', line 42

def call
  if href.presence && status_content.cannot_start_yet
    fail(ArgumentError, "item cannot have a href with status where cannot_start_yet: true")
  end

  adjusted_html_attributes = if href.present? || title&.href.present?
                               html_attributes_with_link_class
                             else
                               html_attributes
                             end

  tag.li(safe_join([title_content, status_content].compact), **adjusted_html_attributes)
end