Class: BetterUi::General::Table::TdComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme: :default, align: :left, compact: false, **html_options) ⇒ TdComponent

Returns a new instance of TdComponent.



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

def initialize(theme: :default, align: :left, compact: false, **html_options)
  @theme = theme.to_sym
  @align = align.to_sym
  @compact = !!compact
  @html_options = html_options
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



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

def align
  @align
end

#compactObject (readonly)

Returns the value of attribute compact.



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

def compact
  @compact
end

#themeObject (readonly)

Returns the value of attribute theme.



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

def theme
  @theme
end

Instance Method Details

#td_attributesObject



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

def td_attributes
  attrs = @html_options.except(:class)
  attrs[:class] = td_classes
  attrs
end

#td_classesObject



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

def td_classes
  [
    "px-4 py-3 text-sm text-gray-900",
    alignment_class,
    @compact ? "py-1" : nil,
    @html_options[:class]
  ].compact.join(" ")
end