Class: Pulse::Table
- Inherits:
-
Component
- Object
- Component
- Pulse::Table
- Defined in:
- app/components/pulse/table.rb,
app/components/pulse/table/cell.rb,
app/components/pulse/table/column.rb
Overview
Renders a table Inspiration taken from https://github.com/baoagency/polaris_view_components/
Defined Under Namespace
Constant Summary collapse
- DEFAULT_TABLE_CLASSES =
'pulse-min-w-full pulse-divide-y ' \ 'pulse-divide-gray-300'
- DEFAULT_HEAD_CLASSES =
'pulse-bg-gray-100'- DEFAULT_TH_CLASSES =
'pulse-text-start pulse-text-gray pulse-uppercase ' \ 'pulse-tracking-wider pulse-px-4 print:pulse-px-2 ' \ 'pulse-py-4 print:pulse-py-3 text-xs pulse-font-medium'
- DEFAULT_BODY_CLASSES =
'pulse-bg-white pulse-divide-y pulse-text-sm ' \ 'pulse-leading-extra-snug pulse-divide-gray-300 ' \ 'print:pulse-divide-gray-400 pulse-tracking-tight ' \ ''
- DEFAULT_ROW_CLASSES =
'pulse-border-secondary-300'- DEFAULT_TD_CLASSES =
'pulse-px-4 print:pulse-px-2 pulse-py-4'
Instance Attribute Summary collapse
-
#additional_params ⇒ Object
readonly
Returns the value of attribute additional_params.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#current_sort_column ⇒ Object
readonly
Returns the value of attribute current_sort_column.
-
#current_sort_direction ⇒ Object
readonly
Returns the value of attribute current_sort_direction.
-
#full_width ⇒ Object
readonly
Returns the value of attribute full_width.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#hoverable ⇒ Object
readonly
Returns the value of attribute hoverable.
-
#pagination ⇒ Object
readonly
Returns the value of attribute pagination.
-
#row_classes ⇒ Object
readonly
Returns the value of attribute row_classes.
-
#scroll ⇒ Object
readonly
Returns the value of attribute scroll.
-
#striped ⇒ Object
readonly
Returns the value of attribute striped.
Instance Method Summary collapse
- #body_classes ⇒ Object
- #footer? ⇒ Boolean
- #head_cell_classes ⇒ Object
- #head_classes ⇒ Object
-
#initialize(collection, additional_params: {}, pagination: true, striped: false, current_sort_column: nil, current_sort_direction: nil, hoverable: false, row_classes: nil, header: true, scroll: true, **options) ⇒ Table
constructor
A new instance of Table.
- #pagination? ⇒ Boolean
- #render_cell(**arguments) ⇒ Object
- #row_arguments(row) ⇒ Object
- #table_options ⇒ Object
Constructor Details
#initialize(collection, additional_params: {}, pagination: true, striped: false, current_sort_column: nil, current_sort_direction: nil, hoverable: false, row_classes: nil, header: true, scroll: true, **options) ⇒ Table
Returns a new instance of Table.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/components/pulse/table.rb', line 32 def initialize(collection, additional_params: {}, pagination: true, striped: false, current_sort_column: nil, current_sort_direction: nil, hoverable: false, row_classes: nil, header: true, scroll: true, **) @collection = collection @additional_params = additional_params @pagination = pagination @striped = striped @current_sort_column = current_sort_column @current_sort_direction = current_sort_direction @hoverable = hoverable @row_classes = row_classes @header = header @scroll = scroll @options = end |
Instance Attribute Details
#additional_params ⇒ Object (readonly)
Returns the value of attribute additional_params.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def additional_params @additional_params end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def collection @collection end |
#current_sort_column ⇒ Object (readonly)
Returns the value of attribute current_sort_column.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def current_sort_column @current_sort_column end |
#current_sort_direction ⇒ Object (readonly)
Returns the value of attribute current_sort_direction.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def current_sort_direction @current_sort_direction end |
#full_width ⇒ Object (readonly)
Returns the value of attribute full_width.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def full_width @full_width end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def header @header end |
#hoverable ⇒ Object (readonly)
Returns the value of attribute hoverable.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def hoverable @hoverable end |
#pagination ⇒ Object (readonly)
Returns the value of attribute pagination.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def pagination @pagination end |
#row_classes ⇒ Object (readonly)
Returns the value of attribute row_classes.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def row_classes @row_classes end |
#scroll ⇒ Object (readonly)
Returns the value of attribute scroll.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def scroll @scroll end |
#striped ⇒ Object (readonly)
Returns the value of attribute striped.
28 29 30 |
# File 'app/components/pulse/table.rb', line 28 def striped @striped end |
Instance Method Details
#body_classes ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/components/pulse/table.rb', line 81 def body_classes merge_classes( DEFAULT_BODY_CLASSES, '[&>tr:nth-child(even)]:pulse-bg-gray-50': striped, 'pulse-border-b [&>tr]:pulse-border-t [&>tr:first-child]:pulse-border-t-0': !striped # rubocop:disable Layout/LineLength ) end |
#footer? ⇒ Boolean
53 54 55 |
# File 'app/components/pulse/table.rb', line 53 def columns.any?(&:footer) end |
#head_cell_classes ⇒ Object
75 76 77 78 79 |
# File 'app/components/pulse/table.rb', line 75 def head_cell_classes merge_classes( DEFAULT_TH_CLASSES ) end |
#head_classes ⇒ Object
68 69 70 71 72 73 |
# File 'app/components/pulse/table.rb', line 68 def head_classes merge_classes( DEFAULT_HEAD_CLASSES, @options[:head_classes] ) end |
#pagination? ⇒ Boolean
49 50 51 |
# File 'app/components/pulse/table.rb', line 49 def pagination? pagination end |
#render_cell(**arguments) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'app/components/pulse/table.rb', line 101 def render_cell(**arguments, &) render( Pulse::Table::Cell.new( additional_params:, **arguments ), & ) end |
#row_arguments(row) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/components/pulse/table.rb', line 89 def row_arguments(row) { tag: 'tr' }.tap do |args| args[:classes] = merge_classes( DEFAULT_ROW_CLASSES, { 'hover:pulse-bg-dark-charcoal-50': hoverable }, row_classes ) args[:id] = dom_id(row) if row.respond_to?(:to_key) args[:data] ||= {} end end |
#table_options ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/components/pulse/table.rb', line 57 def { tag: 'table' }.deep_merge(@options).tap do |args| args[:classes] = merge_classes( DEFAULT_TABLE_CLASSES, 'pulse-container pulse-mx-auto', args[:classes] ) args[:data] ||= {} end end |