Class: Blacklight::Response::ViewTypeButtonComponent

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

Overview

Render spellcheck results for a search query

Constant Summary

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(view:, key: nil, selected: false, search_state: nil, classes: 'btn btn-outline-secondary btn-icon') ⇒ ViewTypeButtonComponent

Returns a new instance of ViewTypeButtonComponent.

Parameters:

  • view (Blacklight::Configuration::View)


9
10
11
12
13
14
15
# File 'app/components/blacklight/response/view_type_button_component.rb', line 9

def initialize(view:, key: nil, selected: false, search_state: nil, classes: 'btn btn-outline-secondary btn-icon')
  @view = view
  @key = key || view.key
  @selected = selected
  @classes = classes
  @search_state = search_state
end

Instance Method Details

#iconObject



17
18
19
20
21
22
# File 'app/components/blacklight/response/view_type_button_component.rb', line 17

def icon
  return render(@view.icon.new) if @view.icon.is_a?(Class)
  return render(@view.icon) if @view.icon.is_a?(ViewComponent::Base)

  helpers.blacklight_icon(@view.icon || @key)
end

#labelObject



24
25
26
# File 'app/components/blacklight/response/view_type_button_component.rb', line 24

def label
  @view.display_label
end

#selected?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/components/blacklight/response/view_type_button_component.rb', line 32

def selected?
  @selected
end

#urlObject



28
29
30
# File 'app/components/blacklight/response/view_type_button_component.rb', line 28

def url
  helpers.url_for(@search_state.to_h.merge(view: @key))
end