Skip to content

Commit

Permalink
Extract a shared component that wraps search pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 29, 2020
1 parent d2ec950 commit e3e1d4c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= content_tag :nav, class: 'pagination', role: 'region', **@html_attr do %>
<%= pagination %>
<% end %>
17 changes: 17 additions & 0 deletions app/components/blacklight/response/pagination_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Blacklight
module Response
class PaginationComponent < ::ViewComponent::Base
def initialize(response:, html: {}, **pagination_args)
@response = response
@html_attr = { aria: { label: t('views.pagination.aria.container_label') } }.merge(html)
@pagination_args = { outer_window: 2, theme: 'blacklight' }.merge(pagination_args)
end

def pagination
@view_context.paginate @response, **@pagination_args
end
end
end
end
1 change: 1 addition & 0 deletions app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def default_sort_field
# The available options for results per page, in the style of #options_for_select
def per_page_options_for_select
return [] if blacklight_config.per_page.blank?

blacklight_config.per_page.map do |count|
[t(:'blacklight.search.per_page.label', count: count).html_safe, count]
end
Expand Down
12 changes: 6 additions & 6 deletions app/views/catalog/_paginate_compact.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%# Call with a Blacklight::Solr::Response or any other kaminari-compatible collection
to render Blacklight's compact pagination info component:
<%= render :partial => "paginate_compact", :object => @response
-%>
<%= paginate paginate_compact, :page_entries_info => page_entries_info(paginate_compact), :theme => :blacklight_compact %>
<%= render Blacklight::Response::PaginationComponent.new(
response: paginate_compact,
theme: :blacklight_compact,
page_entries_info: page_entries_info(paginate_compact),
html: { aria: {} })
%>
4 changes: 1 addition & 3 deletions app/views/catalog/_results_pagination.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<% if show_pagination? and @response.total_pages > 1 %>
<div class="row record-padding">
<div class="col-md-12">
<nav class="pagination" role="region" aria-label="<%= t('views.pagination.aria.container_label') %>">
<%= paginate @response, :outer_window => 2, :theme => 'blacklight' %>
</nav>
<%= render Blacklight::Response::PaginationComponent.new(response: @response) %>
</div>
</div>
<% end %>

0 comments on commit e3e1d4c

Please sign in to comment.