Module: Components::TableHelper
- Defined in:
- app/helpers/components/table_helper.rb
Instance Method Summary collapse
- #render_table(caption = nil, **options, &block) ⇒ Object
- #table_body(**options, &block) ⇒ Object
- #table_column(content = nil, **options, &block) ⇒ Object
- #table_head(**options, &block) ⇒ Object
- #table_header(content = nil, **options, &block) ⇒ Object
- #table_row(**options, &block) ⇒ Object
Instance Method Details
#render_table(caption = nil, **options, &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/components/table_helper.rb', line 2 def render_table(caption = nil, **, &block) content_tag :table, .merge( class: tw("w-full text-sm border-b", [:class]) ) do if caption.present? content_tag :caption, caption, class: "mt-4 text-sm text-muted-foreground " do capture(&block) end else capture(&block) end end end |
#table_body(**options, &block) ⇒ Object
38 39 40 41 42 |
# File 'app/helpers/components/table_helper.rb', line 38 def table_body(**, &block) content_tag :tbody, class: .merge( class: tw("[&_tr:last-child]:border-0", [:class]) ), &block end |
#table_column(content = nil, **options, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/components/table_helper.rb', line 50 def table_column(content = nil, **, &block) content_tag :td, .merge( class: tw("p-4 align-middle [&:has([role=checkbox])]:pr-0 font-medium", [:class]) ) do if block capture(&block) else content end end end |
#table_head(**options, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/components/table_helper.rb', line 16 def table_head(**, &block) content_tag :thead, .merge( class: tw("[&_tr]:border-b", [:class]) ) do content_tag :tr, class: "border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted" do capture(&block) end end end |
#table_header(content = nil, **options, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/components/table_helper.rb', line 26 def table_header(content = nil, **, &block) content_tag :th, .merge( class: tw("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", [:class]) ) do if block capture(&block) else content end end end |
#table_row(**options, &block) ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/components/table_helper.rb', line 44 def table_row(**, &block) content_tag :tr, .merge( class: tw("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", [:class]) ), &block end |