Sha256: 6695b085fde441f5215f28508cf05892964c39cc7a203087cff4310256cd82af

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require_relative '../../base'

module CCS::Components
  module CCS
    class DashboardSection < Base
      # = CCS Dashboard Section Panel
      #
      # The individual panel within a dashboard section
      #
      # @!attribute [r] title
      #   @return [String] Text for the panel title
      # @!attribute [r] href
      #   @return [String] The href for the panel
      # @!attribute [r] description
      #   @return [String] Description text for the panel

      class Panel < Base
        private

        attr_reader :title, :href, :description

        public

        # @param title [String] the text for the panel title
        # @param href [String] the href for the panel
        # @param description [String] the description text for the panel
        # @param options [Hash] options that will be used in customising the HTML
        #
        # @option options [String] :width (default: 'one-third') the width of the panel
        # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.

        def initialize(title:, href:, description:, **options)
          super(**options)

          @options[:attributes][:class] = "ccs-dashboard-section__panel govuk-grid-column-#{@options[:width] || 'one-third'}"

          @title = title
          @href = href
          @description = description
        end

        # Generates the HTML for the CCS Dashboard Section Panel
        #
        # @return [ActiveSupport::SafeBuffer]

        def render
          tag.div(**options[:attributes]) do
            concat(link_to(title, href, class: 'ccs-dashboard-section__panel-title'))
            concat(tag.p(description, class: 'ccs-dashboard-section__panel-description'))
          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/ccs/dashboard_section/panel.rb