Class: Blacklight::FacetItemPivotComponent

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

Overview

Render facet items and any subtree

Constant Summary collapse

ID_COUNTER_MAX =

Somewhat arbitrary number; the only important thing is that it is bigger than the number of leaf nodes in any collapsing pivot facet on the page.

(2**20) - 1

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(facet_item:, wrapping_element: 'li', suppress_link: false, collapsing: nil) ⇒ FacetItemPivotComponent

Returns a new instance of FacetItemPivotComponent.



22
23
24
25
26
27
28
# File 'app/components/blacklight/facet_item_pivot_component.rb', line 22

def initialize(facet_item:, wrapping_element: 'li', suppress_link: false, collapsing: nil)
  @facet_item = facet_item
  @wrapping_element = wrapping_element
  @suppress_link = suppress_link
  @collapsing = collapsing.nil? ? facet_item.facet_config.collapsing : collapsing
  @icons = { show: tag.span(class: 'icon'), hide: tag.span(class: 'icon') }.merge(facet_item.facet_config.icons || {})
end

Class Method Details

.mint_idObject

Mint a (sufficiently) unique identifier, so we can associate the expand/collapse control with labels



13
14
15
16
17
18
# File 'app/components/blacklight/facet_item_pivot_component.rb', line 13

def self.mint_id
  @id_counter = ((@id_counter || 0) + 1) % ID_COUNTER_MAX

  # We convert the ID to hex for markup compactness
  @id_counter.to_s(16)
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/blacklight/facet_item_pivot_component.rb', line 30

def call
  facet = Blacklight::FacetItemComponent.new(facet_item: @facet_item, wrapping_element: nil, suppress_link: @suppress_link)

  id = "h-#{self.class.mint_id}" if @collapsing && has_items?

   @wrapping_element, role: 'treeitem', class: 'treeitem' do
    concat(('span', class: "d-flex flex-row align-items-center") do
      concat facet_toggle_button(id) if has_items? && @collapsing
      concat ('span', render(facet), class: "facet-values d-flex flex-row flex-grow-1 #{'facet-leaf-node' if has_items? && @collapsing}", id: id && "#{id}_label")
    end)
    if has_items?
      concat(('ul', class: "pivot-facet flex-column list-unstyled ps-4 #{'collapse' if @collapsing} #{'show' if expanded?}", id: id, role: 'group') do
        render(
          self.class.with_collection(
            @facet_item.facet_item_presenters.to_a
          )
        )
      end)
    end
  end
end