Class: Blacklight::Facets::ListComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/facets/list_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

reset_compiler!, sidecar_files, upstream_sidecar_files

Constructor Details

#initialize(facet_field:, classes: %w[facet-values list-unstyled],, role: nil, layout: nil) ⇒ ListComponent

Returns a new instance of ListComponent.

Parameters:



7
8
9
10
11
12
13
14
15
# File 'app/components/blacklight/facets/list_component.rb', line 7

def initialize(facet_field:,
               classes: %w[facet-values list-unstyled],
               role: nil,
               layout: nil)
  @facet_field = facet_field
  @classes = classes
  @role = role
  @layout = layout == false ? Blacklight::Facets::NoLayoutComponent : Blacklight::Facets::FieldComponent
end

Instance Attribute Details

#classesObject

Returns the value of attribute classes.



17
18
19
# File 'app/components/blacklight/facets/list_component.rb', line 17

def classes
  @classes
end

#layoutObject

Returns the value of attribute layout.



17
18
19
# File 'app/components/blacklight/facets/list_component.rb', line 17

def layout
  @layout
end

#roleObject

Returns the value of attribute role.



17
18
19
# File 'app/components/blacklight/facets/list_component.rb', line 17

def role
  @role
end

Instance Method Details

#facet_configObject



41
42
43
# File 'app/components/blacklight/facets/list_component.rb', line 41

def facet_config
  @facet_field.facet_field
end

#facet_item_component_classObject



37
38
39
# File 'app/components/blacklight/facets/list_component.rb', line 37

def facet_item_component_class
  facet_config.item_component
end

#facet_item_presenter(facet_item) ⇒ Object



33
34
35
# File 'app/components/blacklight/facets/list_component.rb', line 33

def facet_item_presenter(facet_item)
  @facet_field.item_presenter(facet_item)
end

#facet_item_presentersObject



23
24
25
26
27
# File 'app/components/blacklight/facets/list_component.rb', line 23

def facet_item_presenters
  @facet_field.paginator.items.map do |item|
    facet_item_presenter(item)
  end
end

#facet_items(wrapping_element: :li, **item_args) ⇒ Object



19
20
21
# File 'app/components/blacklight/facets/list_component.rb', line 19

def facet_items(wrapping_element: :li, **item_args)
  facet_item_component_class.with_collection(facet_item_presenters, wrapping_element: wrapping_element, **item_args)
end

#render?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/components/blacklight/facets/list_component.rb', line 29

def render?
  @facet_field.paginator&.items&.any?
end