Module: Protege::Components::TablesHelper
- Included in:
- ComponentsHelper
- Defined in:
- app/helpers/protege/components/tables_helper.rb
Overview
The simple data-table component: a header list + rows in, table markup out, with a built-in empty state so call sites never need their own empty-vs-populated branch. Theme colors come from CSS custom properties so the table tracks light/dark mode.
Defined Under Namespace
Classes: Table
Instance Method Summary collapse
-
#table(headers:, rows:, empty: 'No results.') ⇒ ActiveSupport::SafeBuffer
Render a simple data table from a header list and a list of rows.
Instance Method Details
#table(headers:, rows:, empty: 'No results.') ⇒ ActiveSupport::SafeBuffer
Render a simple data table from a header list and a list of rows.
Each row is an array of cell values, positionally aligned to headers; cell values may be plain
strings or already-rendered markup (e.g. a badge or destructive_link), which is emitted as-is.
Theme colors come from CSS custom properties so the table tracks light/dark mode.
When rows is empty the table renders a centered, muted empty message in place of the body, so
call sites never need their own empty-vs-populated branch.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/protege/components/tables_helper.rb', line 29 def table(headers:, rows:, empty: 'No results.') return tag.p(empty, class: 'text-center text-sm py-6', style: 'color: var(--text-faint)') if rows.empty? tag.table(class: 'w-full text-sm') do tag.thead do tag.tr do safe_join(headers.map do |header| tag.th(header, class: 'text-left font-medium pb-2 pr-4', style: 'color: var(--text-faint)') end) end end + tag.tbody do safe_join(rows.map { |cells| table_row(cells) }) end end end |