Class: HakumiComponents::Table::Configs::Expandable

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/table/configs.rb

Constant Summary collapse

Input =
T.type_alias { T.nilable(InputHash) }
RowRenderer =
T.type_alias { T.nilable(Proc) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(show_expand_column:, expanded_row_keys:, expanded_row_render:) ⇒ Expandable

Returns a new instance of Expandable.



204
205
206
207
208
# File 'app/components/hakumi_components/table/configs.rb', line 204

def initialize(show_expand_column:, expanded_row_keys:, expanded_row_render:)
  @show_expand_column = T.let(show_expand_column, T::Boolean)
  @expanded_row_keys = T.let(expanded_row_keys, T::Array[String])
  @expanded_row_render = T.let(expanded_row_render, RowRenderer)
end

Instance Attribute Details

#expanded_row_keysObject (readonly)

Returns the value of attribute expanded_row_keys.



214
215
216
# File 'app/components/hakumi_components/table/configs.rb', line 214

def expanded_row_keys
  @expanded_row_keys
end

#expanded_row_renderObject (readonly)

Returns the value of attribute expanded_row_render.



217
218
219
# File 'app/components/hakumi_components/table/configs.rb', line 217

def expanded_row_render
  @expanded_row_render
end

#show_expand_columnObject (readonly)

Returns the value of attribute show_expand_column.



211
212
213
# File 'app/components/hakumi_components/table/configs.rb', line 211

def show_expand_column
  @show_expand_column
end

Class Method Details

.coerce(value) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'app/components/hakumi_components/table/configs.rb', line 225

def self.coerce(value)
  return nil unless value.is_a?(Hash)

  normalized = value.deep_symbolize_keys
  expanded_row_keys = Array(
    normalized[:expanded_row_keys] ||
    normalized[:expandedRowKeys] ||
    normalized[:default_expanded_row_keys] ||
    normalized[:defaultExpandedRowKeys]
  ).map(&:to_s)

  expanded_row_render = normalized[:expanded_row_render]
  expanded_row_render = nil unless expanded_row_render.is_a?(Proc)

  new(
    show_expand_column: normalized[:show_expand_column] != false,
    expanded_row_keys: expanded_row_keys,
    expanded_row_render: expanded_row_render
  )
end

Instance Method Details

#expanded_row?(row_key) ⇒ Boolean

Returns:

  • (Boolean)


220
221
222
# File 'app/components/hakumi_components/table/configs.rb', line 220

def expanded_row?(row_key)
  @expanded_row_keys.include?(row_key.to_s)
end