Class: CCS::Components::GovUK::SummaryList::Action::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/summary_list/action/link.rb

Overview

GOV.UK Summary list action link

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the summary list action link

{ class: 'govuk-link' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text:, href:, visually_hidden_text: nil, card_title: nil, **options) ⇒ Link

Returns a new instance of Link.

Parameters:

  • text (String)

    the text for the action link

  • href (String)

    the href for the action link

  • visually_hidden_text (String) (defaults to: nil)

    optional visually hidden text for the action link

  • card_title (String) (defaults to: nil)

    card title text for the action link

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the summary list action link HTML

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



35
36
37
38
39
40
41
42
# File 'lib/ccs/components/govuk/summary_list/action/link.rb', line 35

def initialize(text:, href:, visually_hidden_text: nil, card_title: nil, **options)
  super(**options)

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

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Summary list action link

Returns:

  • (ActiveSupport::SafeBuffer)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ccs/components/govuk/summary_list/action/link.rb', line 48

def render
  link_to(href, **@options[:attributes]) do
    concat(text)
    if visually_hidden_text.present? || card_title.present?
      concat(tag.span(class: 'govuk-visually-hidden') do
        if visually_hidden_text
          concat(' ')
          concat(visually_hidden_text)
        end
        if card_title
          concat(' ')
          concat("(#{card_title})")
        end
      end)
    end
  end
end