Skip to content

Extra table components #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/concepts/matestack/ui/core/tbody/tbody.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%tbody{@tag_attributes}
- if block_given?
= yield
5 changes: 5 additions & 0 deletions app/concepts/matestack/ui/core/tbody/tbody.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Matestack::Ui::Core::Tbody
class Tbody < Matestack::Ui::Core::Component::Static

end
end
3 changes: 3 additions & 0 deletions app/concepts/matestack/ui/core/tfoot/tfoot.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%tfoot{@tag_attributes}
- if block_given?
= yield
5 changes: 5 additions & 0 deletions app/concepts/matestack/ui/core/tfoot/tfoot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Matestack::Ui::Core::Tfoot
class Tfoot < Matestack::Ui::Core::Component::Static

end
end
3 changes: 3 additions & 0 deletions app/concepts/matestack/ui/core/thead/thead.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%thead{@tag_attributes}
- if block_given?
= yield
5 changes: 5 additions & 0 deletions app/concepts/matestack/ui/core/thead/thead.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Matestack::Ui::Core::Thead
class Thead < Matestack::Ui::Core::Component::Static

end
end
110 changes: 95 additions & 15 deletions docs/components/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

Show [specs](../../spec/usage/components/table_spec.rb)

Use tables to implement `<table>`, `<tr>`, `<th>` and `<td>`-tags.
Use tables to implement `<table>`, `<tr>`, `<th>`, `<td>`, `<thead>`, `<tbody>` and `<tfoot>` tags.

## Parameters

`<table>`, `<tr>`, can take 2 optional configuration params.
`<th>` and `<td>`-tags can also take a third param, text input.
`<table>`, `<tr>`, `<thead>`, `<tbody>` and `<tfoot>` can take 2 optional configuration params.
`<th>` and `<td>` tags can also take a third param, text input.

#### # id (optional)
Expects a string with all ids the element should have.
Expand All @@ -23,20 +23,31 @@ Implementing a simple, hard coded table.

```ruby
table class: "foo" do
tr class: "bar" do
th text: "First"
th text: "Matestack"
th text: "Table"
thead do
tr class: "bar" do
th text: "First"
th text: "Matestack"
th text: "Table"
end
end
tr do
td text: "One"
td text: "Two"
td text: "Three"
tbody do
tr do
td text: "One"
td text: "Two"
td text: "Three"
end
tr do
td text: "Uno"
td text: "Dos"
td text: "Tres"
end
end
tr do
td text: "Uno"
td text: "Dos"
td text: "Tres"
tfoot do
tr do
td text: "Eins"
td text: "Zwei"
td text: "Drei"
end
end
end
```
Expand Down Expand Up @@ -128,3 +139,72 @@ returns
</tr>
</table>
```

## Example 3

`thead`, `tbody` and `tfoot` are optional containers for any number of `tr`s. If none are specified, `tbody` will be used to contain all `tr` components. `thead` is typically used for the head of the table, and `tfoot` for any table footer, where applicable, such as a sum or count.

```ruby
table do
thead do
tr do
th text: "Product"
th text: "Price"
end
end
# tbody is unnecessary, since it has no class or id and will be added automatically
# tbody do
tr do
td text: "Apples"
td text: "3.50"
end
tr do
td text: "Oranges"
td text: "2.75"
end
tr do
td text: "Bananas"
td text: "4.99"
end
# end
tfoot do
tr do
td text: "Total:"
td text: "11.24"
end
end
end
```

returns

```html
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apples</td>
<td>3.50</td>
</tr>
<tr>
<td>Oranges</td>
<td>2.75</td>
</tr>
<tr>
<td>Bananas</td>
<td>4.99</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total:</td>
<td>11.24</td>
</tr>
</tfoot>
</table>
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../../support/utils'
include Utils

describe 'Table Components table, th, tr, td', type: :feature, js: true do
describe 'Table Components table, th, tr, td, thead, tbody, tfoot', type: :feature, js: true do

it 'Example 1' do

Expand All @@ -10,20 +10,31 @@ class ExamplePage < Matestack::Ui::Page
def response
components {
table class: 'foo' do
tr class: 'bar' do
th text: 'First'
th text: 'Matestack'
th text: 'Table'
thead class: 'head' do
tr class: 'bar' do
th text: 'First'
th text: 'Matestack'
th text: 'Table'
end
end
tr do
td text: 'One'
td text: 'Two'
td text: 'Three'
tbody class: 'body' do
tr do
td text: 'One'
td text: 'Two'
td text: 'Three'
end
tr do
td text: 'Uno'
td text: 'Dos'
td text: 'Tres'
end
end
tr do
td text: 'Uno'
td text: 'Dos'
td text: 'Tres'
tfoot class: 'foot' do
tr do
td text: 'Eins'
td text: 'Zwei'
td text: 'Drei'
end
end
end
}
Expand All @@ -37,12 +48,14 @@ def response

expected_static_output = <<~HTML
<table class="foo">
<tbody>
<thead class="head">
<tr class="bar">
<th>First</th>
<th>Matestack</th>
<th>Table</th>
</tr>
</thead>
<tbody class="body">
<tr>
<td>One</td>
<td>Two</td>
Expand All @@ -54,13 +67,20 @@ def response
<td>Tres</td>
</tr>
</tbody>
<tfoot class="foot">
<tr>
<td>Eins</td>
<td>Zwei</td>
<td>Drei</td>
</tr>
</tfoot>
</table>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
end

it 'Example 2' do
it 'Example 2, when thead, tbody, tfoot are omitted, then tbody is implied' do

class ExamplePage < Matestack::Ui::Page

Expand Down Expand Up @@ -137,4 +157,55 @@ def response
expect(stripped(static_output)).to include(stripped(expected_static_output))
end

it 'Example 2, with only thead, then tbody is implied for other rows' do

class ExamplePage < Matestack::Ui::Page

def response
components {
table do
thead do
tr do
th text: 'First'
th text: 'Matestack'
th text: 'Table'
end
end
tr do
td text: 'One'
td text: 'Two'
td text: 'Three'
end
end
}
end

end

visit '/example'

static_output = page.html

expected_static_output = <<~HTML
<table>
<thead>
<tr>
<th>First</th>
<th>Matestack</th>
<th>Table</th>
</tr>
</thead>
<tbody>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</tbody>
</table>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
end

end