Class: ShadcnPhlexcomponents::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/table.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #default_attributes, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(**attributes) ⇒ Table

Returns a new instance of Table.



14
15
16
17
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 14

def initialize(**attributes)
  @columns = []
  super(**attributes)
end

Instance Method Details

#body(**attributes) ⇒ Object



35
36
37
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 35

def body(**attributes, &)
  TableBody(**attributes, &)
end

#caption(**attributes) ⇒ Object



19
20
21
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 19

def caption(**attributes, &)
  TableCaption(**attributes, &)
end

#cell(**attributes) ⇒ Object



39
40
41
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 39

def cell(**attributes, &)
  TableCell(**attributes, &)
end

#column(header, head_class: nil, cell_class: nil, &content) ⇒ Object



73
74
75
76
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 73

def column(header, head_class: nil, cell_class: nil, &content)
  @columns << { header:, head_class:, cell_class:, content: }
  nil
end


43
44
45
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 43

def footer(**attributes, &)
  TableFooter(**attributes, &)
end

#head(**attributes) ⇒ Object



31
32
33
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 31

def head(**attributes, &)
  TableHead(**attributes, &)
end

#header(**attributes) ⇒ Object



23
24
25
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 23

def header(**attributes, &)
  TableHeader(**attributes, &)
end

#row(**attributes) ⇒ Object



27
28
29
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 27

def row(**attributes, &)
  TableRow(**attributes, &)
end

#rows(rows) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 47

def rows(rows, &)
  @rows = rows

  vanish(&)

  thead(class: TableHeader.new.class_variants) do
    tr(class: TableRow.new.class_variants) do
      @columns.each do |column|
        th(class: TAILWIND_MERGER.merge("#{TableHead.new.class_variants} #{column[:head_class]}")) { column[:header] }
      end
    end
  end

  tbody(class: TableBody.new.class_variants) do
    @rows.each do |row|
      tr(class: TableRow.new.class_variants) do
        @columns.each do |column|
          td(class: TAILWIND_MERGER.merge("#{TableCell.new.class_variants} #{column[:cell_class]}")) do
            column[:content].call(row)
          end
        end
      end
    end
  end
end

#view_template ⇒ Object



78
79
80
81
82
# File 'lib/shadcn_phlexcomponents/components/table.rb', line 78

def view_template(&)
  TableContainer do
    table(**@attributes, &)
  end
end