Class: NitroKit::Table

Inherits:
Component
  • Object
show all
Defined in:
app/components/nitro_kit/table.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(wrapper: {}, **attrs) ⇒ Table

Returns a new instance of Table.



5
6
7
8
# File 'app/components/nitro_kit/table.rb', line 5

def initialize(wrapper: {}, **attrs)
  super(attrs)
  @wrapper = wrapper
end

Instance Attribute Details

#wrapperObject (readonly)

Returns the value of attribute wrapper.



10
11
12
# File 'app/components/nitro_kit/table.rb', line 10

def wrapper
  @wrapper
end

Instance Method Details

#html_tbodyObject



26
# File 'app/components/nitro_kit/table.rb', line 26

alias :html_tbody :tbody

#html_tdObject



29
# File 'app/components/nitro_kit/table.rb', line 29

alias :html_td :td

#html_thObject



28
# File 'app/components/nitro_kit/table.rb', line 28

alias :html_th :th

#html_theadObject



25
# File 'app/components/nitro_kit/table.rb', line 25

alias :html_thead :thead

#html_trObject



27
# File 'app/components/nitro_kit/table.rb', line 27

alias :html_tr :tr

#tbody(**attrs) ⇒ Object



37
38
39
40
41
# File 'app/components/nitro_kit/table.rb', line 37

def tbody(**attrs)
  builder do
    html_tbody(**mattr(attrs, class: "[&_tr:last-child]:border-0")) { yield }
  end
end

#td(text = nil, align: nil, **attrs, &block) ⇒ Object



57
58
59
60
61
62
63
# File 'app/components/nitro_kit/table.rb', line 57

def td(text = nil, align: nil, **attrs, &block)
  builder do
    html_td(**mattr(attrs, class: [ cell_classes, align_classes(align) ])) do
      text_or_block(text, &block)
    end
  end
end

#th(text = nil, align: :left, **attrs, &block) ⇒ Object



49
50
51
52
53
54
55
# File 'app/components/nitro_kit/table.rb', line 49

def th(text = nil, align: :left, **attrs, &block)
  builder do
    html_th(**mattr(attrs, class: [ header_cell_classes, cell_classes, align_classes(align), "font-medium" ])) do
      text_or_block(text, &block)
    end
  end
end

#thead(**attrs) ⇒ Object



31
32
33
34
35
# File 'app/components/nitro_kit/table.rb', line 31

def thead(**attrs)
  builder do
    html_thead(**attrs) { yield }
  end
end

#tr(**attrs) ⇒ Object



43
44
45
46
47
# File 'app/components/nitro_kit/table.rb', line 43

def tr(**attrs)
  builder do
    html_tr(**mattr(attrs, class: "border-b")) { yield }
  end
end

#view_templateObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/nitro_kit/table.rb', line 12

def view_template
  div(**mattr(wrapper, class: "w-full overflow-x-scroll")) do
    table(
      **mattr(
        attrs,
        class: "w-full caption-bottom text-sm divide-y"
      )
    ) do
      yield
    end
  end
end