-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 478ae87)
- Loading branch information
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
9 changes: 9 additions & 0 deletions
9
app/views/govuk_publishing_components/components/docs/table.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Table | ||
description: A table component to make information easier to compare and scan for users. | ||
accessibility_criteria: | ||
shared_accessibility_criteria: | ||
type: helper | ||
examples: | ||
default: | ||
data: | ||
href: '#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module GovukTableHelper | ||
def govuk_table(caption = nil) | ||
builder = TableBuilder.new(tag) | ||
|
||
tag.table class: "govuk-table" do | ||
concat tag.caption caption, class: "govuk-table__caption" | ||
yield(builder) | ||
end | ||
end | ||
|
||
class TableBuilder | ||
attr_reader :tag | ||
|
||
def initialize(tag) | ||
@tag = tag | ||
end | ||
|
||
def head | ||
tag.thead class: "govuk-table__head" do | ||
tag.tr class: "govuk-table__row" do | ||
yield(self) | ||
end | ||
end | ||
end | ||
|
||
def body | ||
tag.tbody class: "govuk-table__body" do | ||
yield(self) | ||
end | ||
end | ||
|
||
def row | ||
tag.tr class: "govuk-table__row" do | ||
yield(self) | ||
end | ||
end | ||
|
||
def header(str) | ||
tag.th str, class: "govuk-table__header", scope: "col" | ||
end | ||
|
||
def cell(str) | ||
tag.td str, class: "govuk-table__cell" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<%= render 'govuk_publishing_components/components/title', title: "A table" %> | ||
|
||
<%= govuk_table "Income tax rates" do |t| %> | ||
<%= t.head do %> | ||
<%= t.header "Band" %> | ||
<%= t.header "Taxable income" %> | ||
<%= t.header "Tax rate" %> | ||
<% end %> | ||
|
||
<%= t.body do %> | ||
<%= t.row do %> | ||
<%= t.header "Personal Allowance" %> | ||
<%= t.cell "Up to £11,850" %> | ||
<%= t.cell "0%" %> | ||
<% end %> | ||
|
||
<%= t.row do %> | ||
<%= t.header "Basic rate" %> | ||
<%= t.cell "£11,851 to £46,350" %> | ||
<%= t.cell "20%" %> | ||
<% end %> | ||
|
||
<%= t.row do %> | ||
<%= t.header "Higher rate" %> | ||
<%= t.cell link_to("over £150,000", "#") %> | ||
<%= t.cell "45%" %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters