Skip to content

Commit

Permalink
Support custom table cell classes
Browse files Browse the repository at this point in the history
Our table helper and table template are modified versions taken from
GOV.UK Publishing Components. This extends them further
  • Loading branch information
yndajas committed Oct 1, 2024
1 parent 05213cd commit 1c48de6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/helpers/components/table_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def header(str, opt = {})

def cell(str, opt = {}, &block)
classes = %w[govuk-table__cell]
classes << opt[:classes] if opt[:classes]
classes << "govuk-table__cell--#{opt[:format]}" if opt[:format]
classes << "govuk-table__cell--empty" unless str || block_given?
str ||= "Not set"
Expand Down
4 changes: 3 additions & 1 deletion app/views/components/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@
<% if cellindex == 0 && first_cell_is_header %>
<%= t.header cell[:text], {
scope: "row",
classes: cell[:classes],
format: cell[:format]
} %>
<% elsif vertical_on_small_screen && head.any? %>
<%= t.cell nil, { format: cell[:format] } do %>
<%= t.cell nil, { classes: cell[:classes], format: cell[:format] } do %>
<span class="app-c-table__duplicate-heading<%= head[cellindex][:visually_hidden] ? " app-c-table__duplicate-heading--visually-hidden" : "" %>" aria-hidden="true">
<%= head[cellindex][:text] %>
</span>
<%= cell[:text] %>
<% end %>
<% else %>
<%= t.cell cell[:text], {
classes: cell[:classes],
format: cell[:format]
} %>
<% end %>
Expand Down

0 comments on commit 1c48de6

Please sign in to comment.