Class: RubyUIAdmin::Views::FilterBar

Inherits:
Phlex::HTML
  • Object
show all
Includes:
UI, Translation
Defined in:
app/components/ruby_ui_admin/views/filter_bar.rb

Overview

Renders a GET form with one control per filter, above the index table.

Instance Method Summary collapse

Methods included from Translation

#rua_t

Constructor Details

#initialize(filters:, values:, action_path:, scope_param: nil) ⇒ FilterBar

Returns a new instance of FilterBar.



10
11
12
13
14
15
# File 'app/components/ruby_ui_admin/views/filter_bar.rb', line 10

def initialize(filters:, values:, action_path:, scope_param: nil)
  @filters = filters
  @values = values || {}
  @action_path = action_path
  @scope_param = scope_param
end

Instance Method Details

#view_templateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/ruby_ui_admin/views/filter_bar.rb', line 17

def view_template
  return if @filters.empty?

  render RubyUI::Card.new(class: "mb-4") do
    render RubyUI::CardContent.new(class: "pt-6") do
      form(method: "get", action: @action_path, class: "flex flex-wrap items-end gap-4") do
        # Preserve the active scope when applying filters.
        input(type: "hidden", name: "scope", value: @scope_param) if @scope_param.present?

        @filters.each { |filter| render_filter(filter) }
        render_buttons
      end
    end
  end
end