Class: Blacklight::FacetItemPivotComponent
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Blacklight::FacetItemPivotComponent
- 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
Class Method Summary collapse
-
.mint_id ⇒ Object
Mint a (sufficiently) unique identifier, so we can associate the expand/collapse control with labels.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(facet_item:, wrapping_element: 'li', suppress_link: false, collapsing: nil) ⇒ FacetItemPivotComponent
constructor
A new instance of FacetItemPivotComponent.
Methods inherited from Component
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_id ⇒ Object
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
#call ⇒ Object
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? content_tag @wrapping_element, role: 'treeitem', class: 'treeitem' do concat(content_tag('span', class: "d-flex flex-row align-items-center") do concat (id) if has_items? && @collapsing concat content_tag('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(content_tag('ul', class: "pivot-facet flex-column list-unstyled ps-4 #{'collapse' if @collapsing} #{'show' if }", id: id, role: 'group') do render( self.class.with_collection( @facet_item.facet_item_presenters.to_a ) ) end) end end end |