forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add table component (style, preview and code)
- Loading branch information
1 parent
69525ff
commit 17e7be8
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class TableComponent < ViewComponent::Base | ||
|
||
renders_one :header, TableRowComponent | ||
renders_many :rows, TableRowComponent | ||
|
||
def initialize(id: '', stripped: false) | ||
super | ||
@id = id | ||
@stripped = stripped | ||
end | ||
|
||
def stripped_class | ||
@stripped ? 'table-content-stripped' : '' | ||
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,6 @@ | ||
%table.table-content{id: @id, class: stripped_class} | ||
%thead | ||
= header | ||
%tbody | ||
- rows.each do |row| | ||
= row |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class TableRowComponent < ViewComponent::Base | ||
|
||
renders_many :ths | ||
renders_many :tds | ||
end |
6 changes: 6 additions & 0 deletions
6
app/components/table_row_component/table_row_component.html.haml
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,6 @@ | ||
%tr | ||
- ths.each do |th| | ||
%th= th | ||
|
||
- tds.each do |td| | ||
%td= td |
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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class TableComponentPreview < ViewComponent::Preview | ||
|
||
include ActionView::Helpers::UrlHelper | ||
|
||
def default | ||
render TableComponent.new do |t| | ||
table_content(t) | ||
end | ||
end | ||
|
||
def stripped | ||
render TableComponent.new(stripped: true) do |t| | ||
table_content(t) | ||
end | ||
end | ||
|
||
private | ||
|
||
def table_content(t) | ||
headers = 5.times.map { |i| "header #{i}" } | ||
rows = 6.times.map { |row| 5.times.map { |i| "line #{row} :#{i} " } } | ||
|
||
t.header do |h| | ||
headers.each do |header| | ||
h.th { header } | ||
end | ||
h.th { 'Action' } | ||
end | ||
|
||
rows.each do |row| | ||
t.row do |r| | ||
row.each do |col| | ||
r.td { col } | ||
end | ||
|
||
r.td do | ||
link_to('Edit', '', class: 'mr-3') + link_to('Delete', '') | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |