Sha256: 01030178f7c4e40952221107a1b8e2e8dff8538058ba91cfac3459b4cf928316

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require_relative '../../base'

module CCS::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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.1.0.rc.2 lib/ccs/components/govuk/tabs/panel.rb