Class: Tailwinds::Table::RowComponent

Inherits:
Tramway::BaseComponent show all
Defined in:
app/components/tailwinds/table/row_component.rb

Overview

Component for rendering a row in a table

Constant Summary

Constants included from Tramway::Helpers::ViewsHelper

Tramway::Helpers::ViewsHelper::FORM_SIZES

Instance Method Summary collapse

Methods included from Tramway::Helpers::ViewsHelper

#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title

Methods included from Tramway::Helpers::ComponentHelper

#component

Methods included from Tramway::Helpers::DecorateHelper

#tramway_decorate

Instance Method Details

#around_renderObject



48
49
50
51
52
53
54
55
56
# File 'app/components/tailwinds/table/row_component.rb', line 48

def around_render
  ensure_view_context_accessor
  previous_flag = view_context.tramway_inside_cell
  view_context.tramway_inside_cell = href.present?

  yield
ensure
  view_context.tramway_inside_cell = previous_flag
end

#cell_classesObject



42
43
44
45
46
# File 'app/components/tailwinds/table/row_component.rb', line 42

def cell_classes
  theme_classes(
    classic: 'div-table-cell px-6 py-4 font-medium text-gray-100 text-xs sm:text-base'
  )
end

#default_attributesObject



11
12
13
# File 'app/components/tailwinds/table/row_component.rb', line 11

def default_attributes
  { role: :row }
end

#desktop_row_classes(cells_count) ⇒ Object



27
28
29
30
31
32
33
34
# File 'app/components/tailwinds/table/row_component.rb', line 27

def desktop_row_classes(cells_count)
  theme_classes(
    classic: [
      'div-table-row', 'grid', 'gap-4', 'border-b', 'last:border-b-0', 'bg-gray-900',
      'border-gray-700', "md:grid-cols-#{cells_count}", 'grid-cols-1'
    ]
  ).join(' ')
end


36
37
38
39
40
# File 'app/components/tailwinds/table/row_component.rb', line 36

def link_row_classes
  theme_classes(
    classic: 'cursor-pointer hover:bg-gray-800'
  )
end

#row_tag(**options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/tailwinds/table/row_component.rb', line 15

def row_tag(**options, &)
  if href.present?
    link_to(href, options.merge(class: "#{options[:class] || ''} #{link_row_classes}", **default_attributes)) do
      yield if block_given?
    end
  else
    tag.div(**options, **default_attributes) do
      yield if block_given?
    end
  end
end