Module: HakumiComponents::Table::Concerns::SurfaceRendering
- Extended by:
- ActiveSupport::Concern, T::Helpers, T::Sig
- Included in:
- HakumiComponents::Table::Component
- Defined in:
- app/components/hakumi_components/table/concerns/surface_rendering.rb
Constant Summary collapse
- TableDisplayRow =
T.type_alias { { row: HakumiComponents::Table::RowRecord, depth: Integer } }
- RowSource =
T.type_alias { HakumiComponents::Table::RowRecord::Source }
- ScrollValue =
T.type_alias { T.nilable(String) }
- TableContent =
T.type_alias { T.nilable(T.any(Types::Renderable, Proc)) }
- PaginationValue =
T.type_alias { HakumiComponents::Table::Configs::Pagination::Value }
Instance Method Summary collapse
- #ajax_pagination_component ⇒ Object
- #clear_text ⇒ Object
- #column_filter_multiple?(column) ⇒ Boolean
- #container_classes ⇒ Object
- #current_sort_state ⇒ Object
- #default_sort_order(column) ⇒ Object
- #display_rows ⇒ Object
- #empty_state ⇒ Object
- #header_filter_options(column) ⇒ Object
- #invert_text ⇒ Object
- #pagination_component ⇒ Object
- #reset_text ⇒ Object
- #scroll_styles ⇒ Object
- #search_placeholder_text ⇒ Object
- #select_all_text ⇒ Object
- #selection_actions? ⇒ Boolean
- #selection_all_enabled? ⇒ Boolean
- #selection_header_state ⇒ Object
- #summary_content ⇒ Object
- #surface_bordered? ⇒ Boolean
- #surface_column_drag? ⇒ Boolean
- #surface_data_url ⇒ Object
- #surface_editable ⇒ Object
- #surface_empty_text ⇒ Object
- #surface_filter_mode ⇒ Object
- #surface_filter_on_close? ⇒ Boolean
- #surface_filter_search ⇒ Object
- #surface_html_options ⇒ Object
- #surface_pagination ⇒ Object
- #surface_row_drag ⇒ Object
- #surface_row_selection ⇒ Object
- #surface_scroll_x ⇒ Object
- #surface_scroll_y ⇒ Object
- #surface_size ⇒ Object
- #surface_sort_directions ⇒ Object
- #surface_sticky? ⇒ Boolean
- #surface_summary ⇒ Object
- #table_attributes ⇒ Object
- #table_classes ⇒ Object
- #table_container_attributes ⇒ Object
- #table_style ⇒ Object
- #wrapper_attributes ⇒ Object
Instance Method Details
#ajax_pagination_component ⇒ Object
161 162 163 164 165 166 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 161 def ajax_pagination_component pagination = surface_pagination return nil unless surface_data_url && pagination.is_a?(HakumiComponents::Table::Configs::Pagination) pagination.build_ajax_component end |
#clear_text ⇒ Object
255 256 257 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 255 def clear_text T.unsafe(self).t_default(:clear, default: "Clear") end |
#column_filter_multiple?(column) ⇒ Boolean
218 219 220 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 218 def column_filter_multiple?(column) column.filter_multiple end |
#container_classes ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 121 def container_classes T.unsafe(self).class_names( "table-container", { scroll_x: surface_scroll_x.present?, scroll_y: surface_scroll_y.present? } ) end |
#current_sort_state ⇒ Object
223 224 225 226 227 228 229 230 231 232 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 223 def current_sort_state sorted_column = T.unsafe(self).__send__(:leaf_columns).find { |column| default_sort_order(column).present? } return nil unless sorted_column field = sorted_column.key.to_s order = default_sort_order(sorted_column) return nil unless order { field: field, order: order.to_s } end |
#default_sort_order(column) ⇒ Object
29 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 29 def default_sort_order(column); end |
#display_rows ⇒ Object
26 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 26 def display_rows; end |
#empty_state ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 137 def empty_state empty_text = surface_empty_text if empty_text return T.unsafe(self).render(empty_text) if empty_text.is_a?(ViewComponent::Base) return T.unsafe(self).render(empty_text) if empty_text.is_a?(ViewComponent::Slot) return empty_text.call if empty_text.is_a?(Proc) empty_text else T.unsafe(self).render(HakumiComponents::Empty::Component.new) end end |
#header_filter_options(column) ⇒ Object
213 214 215 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 213 def (column) Kernel.Array(column.filters) end |
#invert_text ⇒ Object
250 251 252 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 250 def invert_text T.unsafe(self).t_default(:invert, default: "Invert") end |
#pagination_component ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 151 def pagination_component pagination = surface_pagination return nil unless pagination return nil if surface_data_url return pagination if pagination.is_a?(ViewComponent::Base) pagination.build_component end |
#reset_text ⇒ Object
265 266 267 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 265 def reset_text T.unsafe(self).t_default(:reset, default: "Reset") end |
#scroll_styles ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 182 def scroll_styles styles = T.let([], T::Array[String]) scroll_x = surface_scroll_x scroll_y = surface_scroll_y styles << "overflow-x: auto" if scroll_x if scroll_y styles << "max-height: #{T.unsafe(self).__send__(:dimension_to_css, scroll_y)}" styles << "overflow-y: auto" end styles.join("; ") end |
#search_placeholder_text ⇒ Object
260 261 262 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 260 def search_placeholder_text T.unsafe(self).t_default(:search_placeholder, default: "Search") end |
#select_all_text ⇒ Object
245 246 247 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 245 def select_all_text T.unsafe(self).t_default(:select_all, default: "Select all") end |
#selection_actions? ⇒ Boolean
203 204 205 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 203 def selection_actions? surface_row_selection&.selections_enabled == true end |
#selection_all_enabled? ⇒ Boolean
208 209 210 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 208 def selection_all_enabled? surface_row_selection&.type == :checkbox end |
#selection_header_state ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 235 def selection_header_state total = display_rows.size selected = surface_row_selection&.selected_row_keys&.size || 0 { checked: total.positive? && selected == total, indeterminate: selected.positive? && selected < total } end |
#summary_content ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 169 def summary_content summary = surface_summary return nil unless summary if summary.is_a?(Proc) rows = display_rows.map { |row_data| row_data[:row] } summary.call(rows) else summary end end |
#surface_bordered? ⇒ Boolean
35 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 35 def surface_bordered?; end |
#surface_column_drag? ⇒ Boolean
71 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 71 def surface_column_drag?; end |
#surface_data_url ⇒ Object
77 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 77 def surface_data_url; end |
#surface_editable ⇒ Object
65 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 65 def surface_editable; end |
#surface_empty_text ⇒ Object
80 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 80 def surface_empty_text; end |
#surface_filter_mode ⇒ Object
59 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 59 def surface_filter_mode; end |
#surface_filter_on_close? ⇒ Boolean
56 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 56 def surface_filter_on_close?; end |
#surface_filter_search ⇒ Object
62 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 62 def surface_filter_search; end |
#surface_html_options ⇒ Object
47 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 47 def ; end |
#surface_pagination ⇒ Object
74 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 74 def surface_pagination; end |
#surface_row_drag ⇒ Object
68 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 68 def surface_row_drag; end |
#surface_row_selection ⇒ Object
50 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 50 def surface_row_selection; end |
#surface_scroll_x ⇒ Object
41 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 41 def surface_scroll_x; end |
#surface_scroll_y ⇒ Object
44 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 44 def surface_scroll_y; end |
#surface_size ⇒ Object
32 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 32 def surface_size; end |
#surface_sort_directions ⇒ Object
53 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 53 def surface_sort_directions; end |
#surface_sticky? ⇒ Boolean
38 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 38 def surface_sticky?; end |
#surface_summary ⇒ Object
83 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 83 def surface_summary; end |
#table_attributes ⇒ Object
114 115 116 117 118 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 114 def table_attributes attrs = T.let({ class: "hakumi-table-table" }, Types::HtmlAttributes) attrs[:style] = table_style if table_style.present? attrs end |
#table_classes ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 86 def table_classes T.unsafe(self).class_names( "table", { size: surface_size, bordered: surface_bordered?, empty: display_rows.empty?, sticky: surface_sticky?, scroll_x: surface_scroll_x.present?, scroll_y: surface_scroll_y.present?, fixed: T.unsafe(self).fixed_columns? }, T.unsafe(self).html_classes() ) end |
#table_container_attributes ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 103 def table_container_attributes attrs = T.let({ class: container_classes, data: { "hakumi--table-target": "scrollContainer" } }, Types::HtmlAttributes) styles = scroll_styles attrs[:style] = styles if styles.present? attrs end |
#table_style ⇒ Object
195 196 197 198 199 200 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 195 def table_style scroll_x = surface_scroll_x return nil unless scroll_x "min-width: #{T.unsafe(self).__send__(:dimension_to_css, scroll_x)}" end |
#wrapper_attributes ⇒ Object
132 133 134 |
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 132 def wrapper_attributes T.unsafe(self).merge_attributes({ class: table_classes, data: wrapper_data_attributes }, ) end |