Class: ResourceListBlock
- Defined in:
- app/blocks/resource_list_block.rb
Overview
ResourceListBlock — a searchable, scrollable list panel for any resource.
Composes Header, Input, Button, and turbo-framed partial iteration into a single reusable block. Designed for sidebar/master-list patterns where a Ransack search filters a collection rendered via a per-item partial.
Usage:
ResourceListBlock(
heading: "Notes",
search_url: notes_path,
search_query: @q,
search_predicate: "title_cont",
resources: @notes,
item_partial: "notes/note_card",
item_local: "note",
new_path: new_note_path,
turbo_frame: "notes-list",
id: "item-list-panel"
)
The search section is omitted when search_query is nil. The “new” button is omitted when new_path is nil. The list is wrapped in a turbo frame when turbo_frame is provided.
For auto-submit / live-search behaviour, pass Stimulus wiring via search_form_data:
ResourceListBlock(
...,
search_form_data: {
controller: "auto-submit",
action: "input->auto-submit#submit",
turbo_frame: "notes-list"
}
)
HTML structure (all sections wrapped for predictable styling):
div.resource-list-block
div.resource-list-header
[HStack with heading + button]
div.resource-list-search
[search_form_for with Input]
turbo-frame (optional)
div.resource-list-items
[rendered partials]
Constant Summary
Constants inherited from Component
Instance Method Summary collapse
Methods inherited from Component
default, #initialize, #render_in, slot
Constructor Details
This class inherits a constructor from Component
Instance Method Details
#to_s ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'app/blocks/resource_list_block.rb', line 63 def to_s tag.div(**(class: "resource-list-block")) { safe_join([ render_header, render_search, render_list, @content ]) } end |