Class: CCS::Components::GovUK::CookieBanner::Action

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

Overview

GOV.UK Cookie Banner Action

The individual cookie banner action. It defaults to creating button unless a href is set which will create a link

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the cookie banner action

{ class: 'govuk-link' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text:, href: nil) ⇒ Action

the action will be rendered as a button

Parameters:

  • text (String)

    the button or link text

  • href (String) (defaults to: nil)

    the href for a link

  • options (Hash)

    options that will be used in customising the HTML



34
35
36
37
38
39
# File 'lib/ccs/components/govuk/cookie_banner/action.rb', line 34

def initialize(text:, href: nil, **)
  super(**)

  @text = text
  @href = href
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for a cookie banner message action

Returns:

  • (ActiveSupport::SafeBuffer)


45
46
47
48
49
50
51
52
# File 'lib/ccs/components/govuk/cookie_banner/action.rb', line 45

def render
  if href && options[:attributes][:type] != :button
    link_to(text, href, **options[:attributes])
  else
    options[:attributes][:type] ||= :button
    Button.new(text: text, href: href, context: context, **options).render
  end
end