Skip to content

Commit

Permalink
Merge pull request #92 from PhlexUI/cirdes/migrate-table
Browse files Browse the repository at this point in the history
Migrate Table
  • Loading branch information
cirdes authored Aug 25, 2024
2 parents e85541e + 99a0291 commit 4d7f8c7
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion lib/phlex_ui/table.rb → lib/rbui/table/table.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class Table < Base
def view_template(&block)
div(class: "relative w-full overflow-auto") do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableBody < Base
def view_template(&)
tbody(**attrs, &)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableCaption < Base
def view_template(&)
caption(**attrs, &)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableCell < Base
def view_template(&)
td(**attrs, &)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableFooter < Base
def view_template(&)
tfoot(**attrs, &)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableHead < Base
def view_template(&)
th(**attrs, &)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableHeader < Base
def view_template(&)
thead(**attrs, &)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module PhlexUI
module RBUI
class TableRow < Base
def view_template(&)
tr(**attrs, &)
Expand Down
48 changes: 0 additions & 48 deletions test/phlex_ui/table_test.rb

This file was deleted.

48 changes: 48 additions & 0 deletions test/rbui/table_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require "test_helper"

class RBUI::TableTest < Minitest::Test
include Phlex::Testing::ViewHelper

def test_render_with_all_items
invoices = [
{identifier: "INV-0001", status: "Active", method: "Credit Card", amount: 100},
{identifier: "INV-0002", status: "Active", method: "Bank Transfer", amount: 230},
{identifier: "INV-0003", status: "Pending", method: "PayPal", amount: 350},
{identifier: "INV-0004", status: "Inactive", method: "Credit Card", amount: 100}
]

output = phlex_context do
RBUI.Table do
RBUI.TableCaption { "Employees at Acme inc." }
RBUI.TableHeader do
RBUI.TableRow do
RBUI.TableHead { "Name" }
RBUI.TableHead { "Email" }
RBUI.TableHead { "Status" }
RBUI.TableHead(class: "text-right") { "Role" }
end
end
RBUI.TableBody do
invoices.each do |invoice|
RBUI.TableRow do
RBUI.TableCell(class: "font-medium") { invoice[:identifier] }
RBUI.TableCell { invoice[:status] }
RBUI.TableCell { invoice[:method] }
RBUI.TableCell(class: "text-right") { invoice[:amount] }
end
end
end
RBUI.TableFooter do
RBUI.TableRow do
RBUI.TableHead(class: "font-medium", colspan: 3) { "Total" }
RBUI.TableHead(class: "font-medium text-right") { invoices.sum { |invoice| invoice[:amount] } }
end
end
end
end

assert_match(/Total/, output)
end
end

0 comments on commit 4d7f8c7

Please sign in to comment.