Module: MaquinaComponents::TableHelper
- Defined in:
- app/helpers/maquina_components/table_helper.rb
Overview
Table Component Helper
Provides a simple helper for rendering basic tables from collections. For complex tables, use the partials directly for full control.
Instance Method Summary collapse
-
#simple_table(collection, columns:, caption: nil, variant: nil, table_variant: nil, empty_message: "No data available", row_id: nil, **html_options) ⇒ String
Render a simple table from a collection.
-
#table_alignment_class(align) ⇒ String?
Convert alignment symbol to CSS class.
-
#table_body_data_attrs ⇒ Hash
Generate data attributes for table body.
-
#table_caption_data_attrs ⇒ Hash
Generate data attributes for table caption.
-
#table_cell_data_attrs(empty: false) ⇒ Hash
Generate data attributes for table cell.
-
#table_container_data_attrs(variant: nil) ⇒ Hash
Generate data attributes for table container.
-
#table_data_attrs(variant: nil) ⇒ Hash
Generate data attributes for table elements Useful when composing tables with other Rails helpers.
-
#table_footer_data_attrs ⇒ Hash
Generate data attributes for table footer.
-
#table_head_data_attrs ⇒ Hash
Generate data attributes for table head cell.
-
#table_header_data_attrs(sticky: false) ⇒ Hash
Generate data attributes for table header.
-
#table_row_data_attrs(selected: false) ⇒ Hash
Generate data attributes for table row.
Instance Method Details
#simple_table(collection, columns:, caption: nil, variant: nil, table_variant: nil, empty_message: "No data available", row_id: nil, **html_options) ⇒ String
Render a simple table from a collection
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/maquina_components/table_helper.rb', line 39 def simple_table(collection, columns:, caption: nil, variant: nil, table_variant: nil, empty_message: "No data available", row_id: nil, **) render partial: "components/simple_table", locals: { collection: collection, columns: columns, caption: caption, variant: variant, table_variant: table_variant, empty_message: , row_id: row_id, html_options: } end |
#table_alignment_class(align) ⇒ String?
Convert alignment symbol to CSS class
136 137 138 139 140 141 |
# File 'app/helpers/maquina_components/table_helper.rb', line 136 def table_alignment_class(align) case align&.to_sym when :right then "text-right" when :center then "text-center" end end |
#table_body_data_attrs ⇒ Hash
Generate data attributes for table body
116 117 118 |
# File 'app/helpers/maquina_components/table_helper.rb', line 116 def table_body_data_attrs {data: {table_part: "body"}} end |
#table_caption_data_attrs ⇒ Hash
Generate data attributes for table caption
128 129 130 |
# File 'app/helpers/maquina_components/table_helper.rb', line 128 def table_caption_data_attrs {data: {table_part: "caption"}} end |
#table_cell_data_attrs(empty: false) ⇒ Hash
Generate data attributes for table cell
108 109 110 111 112 |
# File 'app/helpers/maquina_components/table_helper.rb', line 108 def table_cell_data_attrs(empty: false) attrs = {data: {table_part: "cell"}} attrs[:data][:empty] = "true" if empty attrs end |
#table_container_data_attrs(variant: nil) ⇒ Hash
Generate data attributes for table container
72 73 74 75 76 |
# File 'app/helpers/maquina_components/table_helper.rb', line 72 def table_container_data_attrs(variant: nil) attrs = {data: {table_part: "container"}} attrs[:data][:variant] = variant.to_s if variant attrs end |
#table_data_attrs(variant: nil) ⇒ Hash
Generate data attributes for table elements Useful when composing tables with other Rails helpers
62 63 64 65 66 |
# File 'app/helpers/maquina_components/table_helper.rb', line 62 def table_data_attrs(variant: nil) attrs = {data: {component: "table"}} attrs[:data][:variant] = variant.to_s if variant attrs end |
#table_footer_data_attrs ⇒ Hash
Generate data attributes for table footer
122 123 124 |
# File 'app/helpers/maquina_components/table_helper.rb', line 122 def {data: {table_part: "footer"}} end |
#table_head_data_attrs ⇒ Hash
Generate data attributes for table head cell
100 101 102 |
# File 'app/helpers/maquina_components/table_helper.rb', line 100 def table_head_data_attrs {data: {table_part: "head"}} end |
#table_header_data_attrs(sticky: false) ⇒ Hash
Generate data attributes for table header
92 93 94 95 96 |
# File 'app/helpers/maquina_components/table_helper.rb', line 92 def table_header_data_attrs(sticky: false) attrs = {data: {table_part: "header"}} attrs[:data][:sticky] = "true" if sticky attrs end |
#table_row_data_attrs(selected: false) ⇒ Hash
Generate data attributes for table row
82 83 84 85 86 |
# File 'app/helpers/maquina_components/table_helper.rb', line 82 def table_row_data_attrs(selected: false) attrs = {data: {table_part: "row"}} attrs[:data][:state] = "selected" if selected attrs end |