Class: GovukComponent::TableComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/table_component.rb

Defined Under Namespace

Classes: BodyComponent, CaptionComponent, CellComponent, HeadComponent, RowComponent

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Attributes included from GovukComponent::Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Methods included from GovukComponent::Traits::CustomClasses

#classes

Methods included from Govuk::Components::Helpers::CssUtilities

#combine_classes

Constructor Details

#initialize(id: nil, rows: nil, head: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {}) ⇒ TableComponent

Returns a new instance of TableComponent.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/components/govuk_component/table_component.rb', line 8

def initialize(id: nil, rows: nil, head: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {})
  super(classes: classes, html_attributes: html_attributes)

  @id                   = id
  @first_cell_is_header = first_cell_is_header
  @caption_text         = caption

  # when no rows are passed in it's likely we're taking the slot approach
  return unless rows.presence

  # if no head is passed in,use the first row for headers
  build(*(head ? [head, rows] : [rows[0], rows[1..]]), caption_text)
end

Instance Attribute Details

#caption_textObject

Returns the value of attribute caption_text.



6
7
8
# File 'app/components/govuk_component/table_component.rb', line 6

def caption_text
  @caption_text
end

#first_cell_is_headerObject

Returns the value of attribute first_cell_is_header.



6
7
8
# File 'app/components/govuk_component/table_component.rb', line 6

def first_cell_is_header
  @first_cell_is_header
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'app/components/govuk_component/table_component.rb', line 6

def id
  @id
end