Class: CCS::Components::GovUK::Table::Header::HeadCell

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/table/header/head_cell.rb

Overview

GOV.UK Table Header head cell

The individual table header head cell

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the table header head cell

{ class: 'govuk-table__header' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text:, **options) ⇒ HeadCell

Returns a new instance of HeadCell.

Parameters:

  • text (String)

    the text of the cell

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the cell

  • :format (String)

    specify format of a cell

  • :attributes (Hash) — default: {}

    any additional attributes that will be added as part of the cell



29
30
31
32
33
34
35
36
# File 'lib/ccs/components/govuk/table/header/head_cell.rb', line 29

def initialize(text:, **options)
  super(**options)

  @options[:attributes][:class] += " govuk-table__header--#{@options[:format]}" if @options[:format]
  @options[:attributes][:scope] = 'col'

  @text = text
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Table Header head cell

Returns:

  • (ActiveSupport::SafeBuffer)


42
43
44
# File 'lib/ccs/components/govuk/table/header/head_cell.rb', line 42

def render
  tag.th(text, **options[:attributes])
end