Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/components/tailwinds/table/cell_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.div-table-cell.px-6.py-4.font-medium.text-gray-900.whitespace-nowrap.dark:text-white.text-xs.sm:text-base
= cell_tag do
= content
17 changes: 17 additions & 0 deletions app/components/tailwinds/table/cell_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ module Tailwinds
module Table
# Component for rendering a cell in a table
class CellComponent < Tramway::Component::Base
option :options, optional: true, default: -> { {} }

def cell_tag
classes = [*default_classes, options[:class]].join(' ')

tag.div(**options, class: classes) do
yield if block_given?
end
end

private

def default_classes
[
'div-table-cell', 'px-6', 'py-4', 'font-medium', 'text-gray-900', 'whitespace-nowrap', 'dark:text-white', 'text-xs.sm:text-base'
]
end
end
end
end
2 changes: 1 addition & 1 deletion app/components/tailwinds/table/header_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.div-table-row.grid.text-white.text-small.gap-4.bg-purple-700.dark:bg-gray-700.dark:text-gray-400{ class: "grid-cols-#{columns_count}", aria: { label: "Table Header" }, role: "row" }
= header_tag do
- if headers.any?
- headers.each do |header|
.div-table-cell.py-4.px-6
Expand Down
22 changes: 22 additions & 0 deletions app/components/tailwinds/table/header_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@ module Table
class HeaderComponent < Tramway::Component::Base
option :headers, optional: true, default: -> { [] }
option :columns, optional: true, default: -> { 3 }
option :options, optional: true, default: -> { {} }

def columns_count
headers.present? ? headers.size : columns
end

def header_tag
default_attributes = { aria: { label: "Table Header" }, role: :row }

classes = [*default_classes, options[:class]].join(' ')

tag.div(**options.merge(default_attributes), class: classes) do
yield if block_given?
end
end

private

def default_classes
[
'div-table-row', 'grid', 'text-white',
'text-small', 'gap-4', 'bg-purple-700',
'dark:bg-gray-700', 'dark:text-gray-400',
"grid-cols-#{columns_count}"
]
end
end
end
end