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
23
24
# 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)

  Deprecation.silence(Blacklight::CatalogHelperBehavior) do
    helpers.render_view_type_group_icon(@view.icon || @key)
  end
end

#labelObject



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

def label
  Deprecation.silence(Blacklight::ConfigurationHelperBehavior) do
    helpers.view_label(@key)
  end
end

#selected?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/components/blacklight/response/view_type_button_component.rb', line 36

def selected?
  @selected
end

#urlObject



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

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