Class: Anchor::FilterComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/anchor/filter_component.rb

Constant Summary collapse

TYPE_DEFAULT =
:select
TYPE_OPTIONS =
[TYPE_DEFAULT, :checkbox, :radio].freeze
FROM_REQUEST =
:_request

Constants included from ViewHelper

ViewHelper::ANCHOR_HELPERS

Instance Method Summary collapse

Methods inherited from Component

generate_id

Methods included from ViewHelper

#anchor_form_with, #anchor_svg, #deep_blank?, #merge_options, #popover_trigger_attributes

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(label:, options:, param_key:, selected: FROM_REQUEST, type: TYPE_DEFAULT, default_selected: false, **kwargs) ⇒ FilterComponent

Returns a new instance of FilterComponent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/anchor/filter_component.rb', line 7

def initialize(
  label:,
  options:,
  param_key:,
  selected: FROM_REQUEST,
  type: TYPE_DEFAULT,
  default_selected: false,
  **kwargs
)
  @label = label
  @blank_option = options.detect { |_text, value| value.nil? }
  @every_option = options
  @options = options - [blank_option]
  @param_key = param_key
  @selected = selected
  @type = fetch_or_fallback(TYPE_OPTIONS, type, TYPE_DEFAULT)
  @default_selected = default_selected

  super(**kwargs)
end