Module: Components::TableHelper

Defined in:
app/helpers/components/table_helper.rb

Instance Method Summary collapse

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, **options, &block)
   :table, options.merge(
    class: tw("w-full text-sm border-b", options[:class])
  ) do
    if caption.present?
       :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(**options, &block)
   :tbody, class: options.merge(
    class: tw("[&_tr:last-child]:border-0", options[: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, **options, &block)
   :td, options.merge(
    class: tw("p-4 align-middle [&:has([role=checkbox])]:pr-0 font-medium", options[: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(**options, &block)
   :thead, options.merge(
    class: tw("[&_tr]:border-b", options[:class])
  ) do
     :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, **options, &block)
   :th, options.merge(
    class: tw("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", options[: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(**options, &block)
   :tr, options.merge(
    class: tw("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", options[:class])
  ), &block
end