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

Instance Method Details

#ajax_pagination_componentObject



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_textObject



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

Returns:

  • (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_classesObject



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_stateObject



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_rowsObject



26
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 26

def display_rows; end

#empty_stateObject



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 header_filter_options(column)
  Kernel.Array(column.filters)
end

#invert_textObject



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_componentObject



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_textObject



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_stylesObject



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_textObject



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_textObject



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

Returns:

  • (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

Returns:

  • (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_stateObject



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_contentObject



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

Returns:

  • (Boolean)


35
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 35

def surface_bordered?; end

#surface_column_drag?Boolean

Returns:

  • (Boolean)


71
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 71

def surface_column_drag?; end

#surface_data_urlObject



77
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 77

def surface_data_url; end

#surface_editableObject



65
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 65

def surface_editable; end

#surface_empty_textObject



80
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 80

def surface_empty_text; end

#surface_filter_modeObject



59
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 59

def surface_filter_mode; end

#surface_filter_on_close?Boolean

Returns:

  • (Boolean)


56
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 56

def surface_filter_on_close?; end

#surface_filter_searchObject



62
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 62

def surface_filter_search; end

#surface_html_optionsObject



47
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 47

def surface_html_options; end

#surface_paginationObject



74
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 74

def surface_pagination; end

#surface_row_dragObject



68
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 68

def surface_row_drag; end

#surface_row_selectionObject



50
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 50

def surface_row_selection; end

#surface_scroll_xObject



41
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 41

def surface_scroll_x; end

#surface_scroll_yObject



44
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 44

def surface_scroll_y; end

#surface_sizeObject



32
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 32

def surface_size; end

#surface_sort_directionsObject



53
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 53

def surface_sort_directions; end

#surface_sticky?Boolean

Returns:

  • (Boolean)


38
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 38

def surface_sticky?; end

#surface_summaryObject



83
# File 'app/components/hakumi_components/table/concerns/surface_rendering.rb', line 83

def surface_summary; end

#table_attributesObject



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_classesObject



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(surface_html_options)
  )
end

#table_container_attributesObject



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_styleObject



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_attributesObject



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 }, surface_html_options)
end