Class: GovukComponent::SummaryListComponent::ActionComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/summary_list_component/action_component.rb

Defined Under Namespace

Classes: VisuallyHiddenDefaultNilClass

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(href: nil, text: 'Change', visually_hidden_text: VisuallyHiddenDefaultNilClass, classes: [], html_attributes: {}) ⇒ ActionComponent

Returns a new instance of ActionComponent.



6
7
8
9
10
11
12
13
14
15
16
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 6

def initialize(href: nil, text: 'Change', visually_hidden_text: VisuallyHiddenDefaultNilClass, classes: [], html_attributes: {})
  if config.require_summary_list_action_visually_hidden_text && visually_hidden_text == VisuallyHiddenDefaultNilClass
    fail(ArgumentError, "missing keyword: visually_hidden_text")
  end

  super(classes: classes, html_attributes: html_attributes)

  @href                 = href
  @text                 = text
  @visually_hidden_text = visually_hidden_text
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 4

def attributes
  @attributes
end

#classesObject (readonly)

Returns the value of attribute classes.



4
5
6
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 4

def classes
  @classes
end

#hrefObject (readonly)

Returns the value of attribute href.



4
5
6
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 4

def href
  @href
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 4

def text
  @text
end

#visually_hidden_textObject (readonly)

Returns the value of attribute visually_hidden_text.



4
5
6
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 4

def visually_hidden_text
  @visually_hidden_text
end

Instance Method Details

#callObject



22
23
24
25
26
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 22

def call
  link_to(href, **html_attributes) do
    safe_join([action_text, visually_hidden_span].compact, " ")
  end
end

#render?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/components/govuk_component/summary_list_component/action_component.rb', line 18

def render?
  href.present?
end