Class: BetterUi::General::Table::TbodyComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/table/tbody_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme: :default, striped: false, hoverable: false, **html_options) ⇒ TbodyComponent

Returns a new instance of TbodyComponent.



7
8
9
10
11
12
# File 'app/components/better_ui/general/table/tbody_component.rb', line 7

def initialize(theme: :default, striped: false, hoverable: false, **html_options)
  @theme = theme.to_sym
  @striped = !!striped
  @hoverable = !!hoverable
  @html_options = html_options
end

Instance Attribute Details

#hoverableObject (readonly)

Returns the value of attribute hoverable.



5
6
7
# File 'app/components/better_ui/general/table/tbody_component.rb', line 5

def hoverable
  @hoverable
end

#stripedObject (readonly)

Returns the value of attribute striped.



5
6
7
# File 'app/components/better_ui/general/table/tbody_component.rb', line 5

def striped
  @striped
end

#themeObject (readonly)

Returns the value of attribute theme.



5
6
7
# File 'app/components/better_ui/general/table/tbody_component.rb', line 5

def theme
  @theme
end

Instance Method Details

#tbody_attributesObject



22
23
24
25
26
# File 'app/components/better_ui/general/table/tbody_component.rb', line 22

def tbody_attributes
  attrs = @html_options.except(:class)
  attrs[:class] = tbody_classes
  attrs
end

#tbody_classesObject



14
15
16
17
18
19
20
# File 'app/components/better_ui/general/table/tbody_component.rb', line 14

def tbody_classes
  [
    @striped ? "[&_tr:nth-child(odd)]:bg-gray-50" : nil,
    @hoverable ? "[&_tr]:hover:bg-gray-50" : nil,
    @html_options[:class]
  ].compact.join(" ")
end