Class: PhlexKit::DataTableSelectionSummary

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/phlex_kit/data_table/data_table_selection_summary.rb

Overview

"N of M row(s) selected." line, kept current by the controller. format: localizes it — a template with %selected and %total placeholders, used for the server render AND stamped on the element so the controller's live updates interpolate the same string. See data_table.rb.

Constant Summary collapse

DEFAULT_FORMAT =
"%{selected} of %{total} row(s) selected."

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(total_on_page: 0, format: DEFAULT_FORMAT, **attrs) ⇒ DataTableSelectionSummary

Returns a new instance of DataTableSelectionSummary.



10
11
12
13
14
# File 'app/components/phlex_kit/data_table/data_table_selection_summary.rb', line 10

def initialize(total_on_page: 0, format: DEFAULT_FORMAT, **attrs)
  @total_on_page = total_on_page
  @format = format
  @attrs = attrs
end

Instance Method Details

#view_templateObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/phlex_kit/data_table/data_table_selection_summary.rb', line 16

def view_template
  div(**mix({
    class: "pk-data-table-selection-summary",
    role: "status", # live region — selection changes are announced to AT
    data: {
      phlex_kit__data_table_target: "selectionSummary",
      format: @format
    }
  }, @attrs)) do
    plain Kernel.format(@format, selected: 0, total: @total_on_page)
  end
end