Sha256: f6a99a1277e14ab90693285b525a8816f22b37dd95d0d82b3fea1b73570dfb61

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require_relative '../../base'
require_relative '../button'

module CCS::Components
  module GovUK
    class CookieBanner < Base
      # = 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
      #
      # @!attribute [r] text
      #   @return [String] Text for the action
      # @!attribute [r] href
      #   @return [String] The href for the action

      class Action < Base
        private

        attr_reader :text, :href

        public

        # @param text [String] the button or link text
        # @param href [String] the href for a link
        # @param options [Hash] options that will be used in customising the HTML
        #
        # @option options [String] : classes additional CSS classes for the cookie action button or link
        # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
        #                                    If the +:type+ key is present with a value of +:button+,
        #                                   the action will be rendered as a button

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

          @text = text
          @href = href
        end

        # Generates the HTML for a cookie banner message action
        #
        # @return [ActiveSupport::SafeBuffer]

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

        # The default attributes for the cookie banner action

        DEFAULT_ATTRIBUTES = { class: 'govuk-link' }.freeze
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.1.0.rc.2 lib/ccs/components/govuk/cookie_banner/action.rb