Class: BetterUi::General::Table::TrComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme: :default, highlighted: false, striped_index: nil, **html_options) ⇒ TrComponent

Returns a new instance of TrComponent.



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

def initialize(theme: :default, highlighted: false, striped_index: nil, **html_options)
  @theme = theme.to_sym
  @highlighted = !!highlighted
  @striped_index = striped_index
  @html_options = html_options
end

Instance Attribute Details

#highlightedObject (readonly)

Returns the value of attribute highlighted.



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

def highlighted
  @highlighted
end

#striped_indexObject (readonly)

Returns the value of attribute striped_index.



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

def striped_index
  @striped_index
end

#themeObject (readonly)

Returns the value of attribute theme.



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

def theme
  @theme
end

Instance Method Details

#tr_attributesObject



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

def tr_attributes
  attrs = @html_options.except(:class)
  attrs[:class] = tr_classes
  attrs
end

#tr_classesObject



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

def tr_classes
  [
    "border-b border-gray-100",
    @highlighted ? "bg-blue-50" : nil,
    @html_options[:class]
  ].compact.join(" ")
end