-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract a shared component that wraps search pagination
- Loading branch information
Showing
5 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
app/components/blacklight/response/pagination_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
app/components/blacklight/response/pagination_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} }) | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |