Sha256: 5a2f0e331d8b563a162443d759f38e66fea173fc64f4943eac8665a928721356

Contents?: true

Size: 1.74 KB

Versions: 20

Compression:

Stored size: 1.74 KB

Contents

require_relative '../../base'

module CCS
  module Components
    module CCS
      class Header < Base
        # = CCS Header link
        #
        # The individual header link item
        #
        # @!attribute [r] text
        #   @return [String] Text for the header link
        # @!attribute [r] li_class
        #   @return [String] The class for the li elements
        # @!attribute [r] href
        #   @return [String] The href for the header link

        class Link < Base
          private

          attr_reader :text, :li_class, :href

          public

          # @param text [String] the text for the header link
          # @param li_class [String] class for the li elements
          # @param href [String] the href for the header link
          # @param options [Hash] options that will be used in customising the HTML
          #
          # @option options [Boolean] :active flag to mark the navigation item as active or not
          # @option options [Hash] :attributes any additional attributes that will added as part of the HTML

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

            @text = text
            @href = href
            @li_class = li_class
          end

          # Generates the HTML for the CCS Header link
          #
          # @return [ActiveSupport::SafeBuffer]

          def render
            tag.li(class: "#{li_class} #{'ccs-header__navigation-item--active' if options[:active]}".rstrip) do
              if href
                options[:attributes][:class] = 'ccs-header__link'

                link_to(text, href, **options[:attributes])
              else
                text
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ccs-frontend_helpers-2.1.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-2.0.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-1.2.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-1.1.2 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-1.1.1 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-1.1.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-1.1.0.beta0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-1.0.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.5.0.beta1 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.5.0.beta0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.3.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.2 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/ccs/header/link.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/ccs/header/link.rb