Sha256: da359b761655f5a69f1fc3892196004d2a2e0f1786a2ccbb9fd7d21311d81ee6

Contents?: true

Size: 1.9 KB

Versions: 20

Compression:

Stored size: 1.9 KB

Contents

require_relative '../../base'

module CCS
  module Components
    module GovUK
      class Tabs < Base
        # = GOV.UK Tabs panel
        #
        # The individual tab panels
        #
        # @!attribute [r] index
        #   @return [Integer] The index of the panel
        # @!attribute [r] id_prefix
        #   @return [String] Prefix id for the panel
        # @!attribute [r] content
        #   @return [ActiveSupport::SafeBuffer] HTML for the tab panel
        # @!attribute [r] text
        #   @return [String] Text for the tabs panel

        class Panel < Base
          private

          attr_reader :index, :id_prefix, :content, :text

          public

          # @param index [Integer] the index of the tab panel
          # @param id_prefix [Integer] prefix used for the id of a panel if no id is specified
          # @param content [ActiveSupport::SafeBuffer] HTML to use as content for the tab panel
          # @param text [String] if +:content+ is blank then this is the text used for the tab panel
          # @param options [Hash] options that will be used in customising the HTML
          #
          # @option options [Hash] :attributes any additional attributes that will added as part of the HTML

          def initialize(index:, id_prefix:, content: nil, text: nil, **options)
            super(**options)
            @options[:attributes][:class] = "govuk-tabs__panel #{'govuk-tabs__panel--hidden' if index > 1}".rstrip
            @options[:attributes][:id] ||= "#{id_prefix}-#{index}"

            @index = index
            @content = content
            @text = text
          end

          # Generates the HTML for the GOV.UK Tabs panel
          #
          # @return [ActiveSupport::SafeBuffer]

          def render
            tag.div(**options[:attributes]) do
              content || tag.p(text, class: 'govuk-body')
            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/govuk/tabs/panel.rb
ccs-frontend_helpers-2.0.0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-1.2.0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-1.1.2 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-1.1.1 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-1.1.0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-1.1.0.beta0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-1.0.0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.5.0.beta1 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.5.0.beta0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/tabs/panel.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/tabs/panel.rb