Sha256: 0844e898425a69162fccb9e92858465871b7974f877b7f9d967dc2e92f8adf2a

Contents?: true

Size: 1.77 KB

Versions: 12

Compression:

Stored size: 1.77 KB

Contents

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

module CCS
  module Components
    module GovUK
      class TaskList < Base
        class Item < Base
          # = GOV.UK Task list item title
          #
          # @!attribute [r] text
          #   @return [String] Text for the title
          # @!attribute [r] href
          #   @return [String] Optional link for the title

          class Title < Base
            private

            attr_reader :text, :href

            public

            # @param text [String] the text for the title
            # @param id_prefix [String] the id prefix for the task list item
            # @param href [String] optional link for the title
            # @param hint_text [String] flag to indicate if there is a hint
            # @param options [Hash] options that will be used in customising the HTML
            #
            # @option options [String] :classes additional CSS classes for the task list item title HTML

            def initialize(text:, id_prefix:, href: nil, hint_text: nil, **options)
              super(**options)
              @options[:attributes][:aria] = { describedby: (hint_text ? "#{id_prefix}-hint " : '') + "#{id_prefix}-status" } if href

              @text = text
              @href = href
            end

            # Generates the HTML for the GOV.UK Task list item title
            #
            # @return [ActiveSupport::SafeBuffer]

            def render
              if href
                link_to(text, href, class: "govuk-link govuk-task-list__link #{@options[:attributes][:class]}".rstrip, aria: { describedby: @options[:attributes][:aria][:describedby] })
              else
                tag.div(text, class: @options[:attributes][:class])
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ccs-frontend_helpers-2.1.0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-2.0.0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-1.2.0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-1.1.2 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-1.1.1 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-1.1.0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-1.1.0.beta0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-1.0.0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-0.5.0.beta1 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-0.5.0.beta0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/task_list/item/title.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/task_list/item/title.rb