govuk-components 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc521c772f5513d62d1b8fd78e77a504c4c1eb913770ffc1dd5d2d3020946980
4
- data.tar.gz: ee85598308825985ca7e84120562fbecb04c7b6f359aba0bc37386e2a33f8a9f
3
+ metadata.gz: 97d2ca8aa2e5c29f692f791ec5e91d98a8aea3ed49cb6d03071aca7ac19dfee5
4
+ data.tar.gz: 6afbe25f03a8ee9d053a1c563d821e8e82b6f5471fdf9b30549aa3bed582a22a
5
5
  SHA512:
6
- metadata.gz: 0c20bba8e5c5b9457d2065edd6f496f8ad93f1baebc7206e5a89260629db9713b59385f61857312aff3947716bc2d1e14064843dd6543655a619e1a050a88f4c
7
- data.tar.gz: 8f1c590b69e35bb0ba47840a7fc7f3b12eb6ec6ee30ef92e58cfb67852a1954633808911100160491a0fd1a1d8a1353603cdbcc2eae55fa0686782717a9aa250
6
+ metadata.gz: 2ea35b519c098911bdff24e526ed013baff28bd74a13a48661ff0531000e0f78274dad0c39bc99ebab2b8b2fb5643b19c021fa073ab805498edba1597c2697dd
7
+ data.tar.gz: 62ed085b07abb5321f15b9a72ce4df1f07129a7147757b657bfb7c70961fae263e1554cca61fcaca01daadfd0530f8bced219623e5b223ff7f638a0421d9e5da
data/README.md CHANGED
@@ -44,7 +44,7 @@ All of the components can be rendered in two ways:
44
44
  * directly using Rails' `#render` method:
45
45
 
46
46
  ```erb
47
- <%= render GovukComponent::GovukComponent::WarningTextComponent.new do %>
47
+ <%= render GovukComponent::WarningTextComponent.new do %>
48
48
  A serious warning
49
49
  <% end %>
50
50
  ```
@@ -0,0 +1,5 @@
1
+ <%= tag.tbody(class: classes, **html_attributes) do %>
2
+ <% rows.each do |row| %>
3
+ <%= row %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,21 @@
1
+ class GovukComponent::TableComponent::BodyComponent < GovukComponent::Base
2
+ renders_many :rows, GovukComponent::TableComponent::RowComponent
3
+
4
+ def initialize(rows: nil, first_cell_is_header: false, classes: [], html_attributes: {})
5
+ super(classes: classes, html_attributes: html_attributes)
6
+
7
+ build_rows_from_row_data(rows, first_cell_is_header)
8
+ end
9
+
10
+ private
11
+
12
+ def build_rows_from_row_data(data, first_cell_is_header)
13
+ return if data.blank?
14
+
15
+ data.each { |d| row(cell_data: d, first_cell_is_header: first_cell_is_header) }
16
+ end
17
+
18
+ def default_classes
19
+ %w(govuk-table__body)
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ class GovukComponent::TableComponent::CaptionComponent < GovukComponent::Base
2
+ attr_reader :text, :size
3
+
4
+ SIZES = %w(s m l xl).freeze
5
+
6
+ def initialize(text: nil, id: nil, size: 'm', classes: [], html_attributes: {})
7
+ super(classes: classes, html_attributes: html_attributes)
8
+
9
+ @id = id
10
+ @text = text
11
+ @size = size
12
+ end
13
+
14
+ def call
15
+ tag.caption(caption_content, class: classes, **html_attributes)
16
+ end
17
+
18
+ def render?
19
+ caption_content.present?
20
+ end
21
+
22
+ private
23
+
24
+ def caption_content
25
+ @caption_content ||= (content || text)
26
+ end
27
+
28
+ def default_classes
29
+ %w(govuk-table__caption).tap do |c|
30
+ c << caption_size_class if @size
31
+ end
32
+ end
33
+
34
+ def caption_size_class
35
+ fail(ArgumentError, "bad size #{size}, must be in #{SIZES}") unless size.in?(SIZES)
36
+
37
+ %(govuk-table__caption--#{size})
38
+ end
39
+ end
@@ -0,0 +1 @@
1
+ <%= content_tag(cell_element, cell_content, class: classes, **html_attributes) %>
@@ -0,0 +1,55 @@
1
+ class GovukComponent::TableComponent::CellComponent < GovukComponent::Base
2
+ attr_reader :text, :header, :numeric, :width
3
+
4
+ alias_method :numeric?, :numeric
5
+
6
+ WIDTHS = {
7
+ "full" => "govuk-input govuk-!-width-full",
8
+ "three-quarters" => "govuk-input govuk-!-width-three-quarters",
9
+ "two-thirds" => "govuk-input govuk-!-width-two-thirds",
10
+ "one-half" => "govuk-input govuk-!-width-one-half",
11
+ "one-third" => "govuk-input govuk-!-width-one-third",
12
+ "one-quarter" => "govuk-input govuk-!-width-one-quarter",
13
+ }.freeze
14
+
15
+ def initialize(header: false, text: nil, numeric: false, width: nil, classes: [], html_attributes: {})
16
+ super(classes: classes, html_attributes: html_attributes)
17
+
18
+ @header = header
19
+ @text = text
20
+ @numeric = numeric
21
+ @width = width
22
+ end
23
+
24
+ private
25
+
26
+ def width?
27
+ width.present?
28
+ end
29
+
30
+ def cell_content
31
+ content || text
32
+ end
33
+
34
+ def cell_element
35
+ header ? :th : :td
36
+ end
37
+
38
+ def default_classes
39
+ if header
40
+ %w(govuk-table__header).tap do |c|
41
+ c << "govuk-table__header--numeric" if numeric?
42
+ c << width_class if width?
43
+ end
44
+ else
45
+ %w(govuk-table__cell).tap do |c|
46
+ c << "govuk-table__cell--numeric" if numeric?
47
+ c << width_class if width?
48
+ end
49
+ end
50
+ end
51
+
52
+ def width_class
53
+ WIDTHS.fetch(width)
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ <%= tag.thead(class: classes, **html_attributes) do %>
2
+ <% rows.each do |row| %>
3
+ <%= row %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,23 @@
1
+ class GovukComponent::TableComponent::HeadComponent < GovukComponent::Base
2
+ renders_many :rows, GovukComponent::TableComponent::RowComponent
3
+
4
+ attr_reader :row_data
5
+
6
+ def initialize(rows: nil, classes: [], html_attributes: {})
7
+ super(classes: classes, html_attributes: html_attributes)
8
+
9
+ build_rows_from_row_data(rows)
10
+ end
11
+
12
+ private
13
+
14
+ def build_rows_from_row_data(data)
15
+ return if data.blank?
16
+
17
+ data.each { |d| row(cell_data: d, header: true) }
18
+ end
19
+
20
+ def default_classes
21
+ %w(govuk-table__head)
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ <%= tag.tr(class: classes, **html_attributes) do %>
2
+ <% cells.each do |cell| %>
3
+ <%= cell %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,30 @@
1
+ class GovukComponent::TableComponent::RowComponent < GovukComponent::Base
2
+ renders_many :cells, GovukComponent::TableComponent::CellComponent
3
+
4
+ attr_reader :header, :first_cell_is_header
5
+
6
+ def initialize(cell_data: nil, first_cell_is_header: false, header: false, classes: [], html_attributes: {})
7
+ super(classes: classes, html_attributes: html_attributes)
8
+
9
+ @header = header
10
+ @first_cell_is_header = first_cell_is_header
11
+
12
+ build_cells_from_cell_data(cell_data)
13
+ end
14
+
15
+ private
16
+
17
+ def build_cells_from_cell_data(cell_data)
18
+ return if cell_data.blank?
19
+
20
+ cell_data.map.with_index { |cd, i| cell(header: cell_is_header?(i), text: cd) }
21
+ end
22
+
23
+ def cell_is_header?(count)
24
+ header || (first_cell_is_header && count.zero?)
25
+ end
26
+
27
+ def default_classes
28
+ %w(govuk-table__row)
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ <%= tag.table(id: id, class: classes, **html_attributes) do %>
2
+ <%= caption %>
3
+ <%= head %>
4
+ <% bodies.each do |body| %>
5
+ <%= body %>
6
+ <% end %>
7
+ <% end %>
@@ -0,0 +1,33 @@
1
+ class GovukComponent::TableComponent < GovukComponent::Base
2
+ renders_one :caption, GovukComponent::TableComponent::CaptionComponent
3
+ renders_one :head, GovukComponent::TableComponent::HeadComponent
4
+ renders_many :bodies, GovukComponent::TableComponent::BodyComponent
5
+
6
+ attr_accessor :id, :first_cell_is_header, :caption_text
7
+
8
+ def initialize(id: nil, rows: nil, head: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {})
9
+ super(classes: classes, html_attributes: html_attributes)
10
+
11
+ @id = id
12
+ @first_cell_is_header = first_cell_is_header
13
+ @caption_text = caption
14
+
15
+ # when no rows are passed in it's likely we're taking the slot approach
16
+ return unless rows.presence
17
+
18
+ # if no head is passed in,use the first row for headers
19
+ build(*(head ? [head, rows] : [rows[0], rows[1..]]), caption_text)
20
+ end
21
+
22
+ private
23
+
24
+ def build(head_data, body_data, caption_text)
25
+ caption(text: caption_text)
26
+ head(rows: [head_data])
27
+ body(rows: body_data, first_cell_is_header: first_cell_is_header)
28
+ end
29
+
30
+ def default_classes
31
+ %w(govuk-table)
32
+ end
33
+ end
@@ -13,6 +13,7 @@ module GovukComponentsHelper
13
13
  govuk_phase_banner: 'GovukComponent::PhaseBannerComponent',
14
14
  govuk_start_button: 'GovukComponent::StartButtonComponent',
15
15
  govuk_summary_list: 'GovukComponent::SummaryListComponent',
16
+ govuk_table: 'GovukComponent::TableComponent',
16
17
  govuk_tabs: 'GovukComponent::TabComponent',
17
18
  govuk_tag: 'GovukComponent::TagComponent',
18
19
  govuk_warning_text: 'GovukComponent::WarningTextComponent',
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '2.0.1'.freeze
3
+ VERSION = '2.1.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DfE developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.36.0
47
+ version: 2.39.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.36.0
54
+ version: 2.39.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -191,6 +191,17 @@ files:
191
191
  - app/components/govuk_component/summary_list_component/value_component.rb
192
192
  - app/components/govuk_component/tab_component.html.erb
193
193
  - app/components/govuk_component/tab_component.rb
194
+ - app/components/govuk_component/table_component.html.erb
195
+ - app/components/govuk_component/table_component.rb
196
+ - app/components/govuk_component/table_component/body_component.html.erb
197
+ - app/components/govuk_component/table_component/body_component.rb
198
+ - app/components/govuk_component/table_component/caption_component.rb
199
+ - app/components/govuk_component/table_component/cell_component.html.erb
200
+ - app/components/govuk_component/table_component/cell_component.rb
201
+ - app/components/govuk_component/table_component/head_component.html.erb
202
+ - app/components/govuk_component/table_component/head_component.rb
203
+ - app/components/govuk_component/table_component/row_component.html.erb
204
+ - app/components/govuk_component/table_component/row_component.rb
194
205
  - app/components/govuk_component/tag_component.rb
195
206
  - app/components/govuk_component/traits/custom_classes.rb
196
207
  - app/components/govuk_component/traits/custom_html_attributes.rb
@@ -209,7 +220,7 @@ homepage: https://github.com/DFE-Digital/govuk-components
209
220
  licenses:
210
221
  - MIT
211
222
  metadata: {}
212
- post_install_message:
223
+ post_install_message:
213
224
  rdoc_options: []
214
225
  require_paths:
215
226
  - lib
@@ -225,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
236
  version: '0'
226
237
  requirements: []
227
238
  rubygems_version: 3.1.6
228
- signing_key:
239
+ signing_key:
229
240
  specification_version: 4
230
241
  summary: Lightweight set of reusable GOV.UK Design System components
231
242
  test_files: []