Class: HakumiComponents::Table::RowRenderState
- Inherits:
-
Object
- Object
- HakumiComponents::Table::RowRenderState
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/table/row_render_state.rb
Constant Summary collapse
- Row =
T.type_alias { HakumiComponents::Table::RowRecord }
- RowSource =
T.type_alias { HakumiComponents::Table::RowRecord::Source }
- RowKeyConfig =
T.type_alias { HakumiComponents::Table::RowRecord::RowKeyConfig }
- RowClassName =
T.type_alias { T.nilable(T.any(String, Proc)) }
- SelectionCellState =
T.type_alias { { type: Symbol, row_key: RowSource, checked: T::Boolean } }
- ExpandCellState =
T.type_alias { { row_key: RowSource, expanded: T::Boolean } }
Instance Method Summary collapse
- #expand_cell(row, row_index) ⇒ Object
- #expanded?(row_key) ⇒ Boolean
-
#initialize(row_key:, row_selection:, expandable:, row_class_name:) ⇒ RowRenderState
constructor
A new instance of RowRenderState.
- #row_classes(row, row_index, row_key) ⇒ Object
- #row_key_for(row, index) ⇒ Object
- #selected?(row_key) ⇒ Boolean
- #selection_cell(row, row_index) ⇒ Object
Constructor Details
#initialize(row_key:, row_selection:, expandable:, row_class_name:) ⇒ RowRenderState
Returns a new instance of RowRenderState.
24 25 26 27 28 29 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 24 def initialize(row_key:, row_selection:, expandable:, row_class_name:) @row_key = T.let(row_key, RowKeyConfig) @row_selection = T.let(row_selection, T.nilable(HakumiComponents::Table::Configs::RowSelection)) @expandable = T.let(, T.nilable(HakumiComponents::Table::Configs::Expandable)) @row_class_name = T.let(row_class_name, RowClassName) end |
Instance Method Details
#expand_cell(row, row_index) ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 76 def (row, row_index) row_key = row_key_for(row, row_index) { row_key: row_key, expanded: (row_key) } end |
#expanded?(row_key) ⇒ Boolean
42 43 44 45 46 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 42 def (row_key) return false unless row_key.is_a?(String) || row_key.is_a?(Symbol) @expandable&.(row_key) == true end |
#row_classes(row, row_index, row_key) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 49 def row_classes(row, row_index, row_key) classes = T.let([ "hakumi-table-row" ], T::Array[String]) classes << "hakumi-table-row-selected" if selected?(row_key) classes << "hakumi-table-row-odd" if row_index.odd? class_name = @row_class_name if class_name.is_a?(Proc) extra = class_name.call(row.source, row_index) classes << extra if extra.is_a?(String) elsif class_name.is_a?(String) classes << class_name end classes.join(" ") end |
#row_key_for(row, index) ⇒ Object
32 33 34 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 32 def row_key_for(row, index) row.key_for(@row_key, index) end |
#selected?(row_key) ⇒ Boolean
37 38 39 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 37 def selected?(row_key) @row_selection&.selected_row_keys&.include?(row_key.to_s) == true end |
#selection_cell(row, row_index) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/components/hakumi_components/table/row_render_state.rb', line 66 def selection_cell(row, row_index) row_key = row_key_for(row, row_index) { type: @row_selection&.type || :checkbox, row_key: row_key, checked: selected?(row_key) } end |