Class: Polaris::DataTableComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/data_table_component.rb

Constant Summary collapse

ALIGNMENT_DEFAULT =
:top
ALIGNMENT_OPTIONS =
[:top, :bottom, :middle, :baseline]

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(data, hoverable: true, vertical_alignment: ALIGNMENT_DEFAULT, totals_in_header: false, totals_in_footer: false, increased_density: false, **system_arguments) ⇒ DataTableComponent

Returns a new instance of DataTableComponent.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/polaris/data_table_component.rb', line 13

def initialize(
  data,
  hoverable: true,
  vertical_alignment: ALIGNMENT_DEFAULT,
  totals_in_header: false,
  totals_in_footer: false,
  increased_density: false,
  **system_arguments
)
  @data = data
  @hoverable = hoverable
  @vertical_alignment = fetch_or_fallback(ALIGNMENT_OPTIONS, vertical_alignment, ALIGNMENT_DEFAULT)
  @totals_in_header = totals_in_header
  @totals_in_footer = totals_in_footer
  @increased_density = increased_density
  @system_arguments = system_arguments
end

Instance Method Details

#render_cell(**arguments, &block) ⇒ Object



63
64
65
# File 'app/components/polaris/data_table_component.rb', line 63

def render_cell(**arguments, &block)
  render(DataTable::CellComponent.new(vertical_alignment: @vertical_alignment, **arguments), &block)
end

#row_arguments(row) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/polaris/data_table_component.rb', line 51

def row_arguments(row)
  {tag: "tr"}.tap do |args|
    args[:classes] = class_names(
      "Polaris-DataTable__TableRow",
      "Polaris-DataTable--hoverable": @hoverable
    )
    args[:id] = dom_id(row) if row.respond_to?(:to_key)
    args[:data] ||= {}
    args[:data][:polaris_data_table_target] = "row"
  end
end

#system_argumentsObject



31
32
33
34
35
36
37
38
39
40
# File 'app/components/polaris/data_table_component.rb', line 31

def system_arguments
  {tag: "div"}.deep_merge(@system_arguments).tap do |args|
    args[:classes] = class_names(
      args[:classes],
      "Polaris-DataTable"
    )
    args[:data] ||= {}
    args[:data][:controller] = "polaris-data-table"
  end
end

#wrapper_argumentsObject



42
43
44
45
46
47
48
49
# File 'app/components/polaris/data_table_component.rb', line 42

def wrapper_arguments
  {
    tag: "div",
    classes: class_names(
      "Polaris-DataTable__IncreasedTableDensity": @increased_density
    )
  }
end