-
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.
Merge pull request #2319 from projectblacklight/more-components
More components
- Loading branch information
Showing
57 changed files
with
544 additions
and
223 deletions.
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
app/components/blacklight/document/bookmark_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,16 @@ | ||
<%- | ||
# the data-doc-id attribute is used by our JS that converts to a checkbox/label. | ||
-%> | ||
<%= form_tag(@bookmark_path, | ||
method: bookmarked? ? :delete : :put, | ||
class: "bookmark-toggle", | ||
data: { | ||
'doc-id' => @document.id, | ||
present: t('blacklight.search.bookmarks.present'), | ||
absent: t('blacklight.search.bookmarks.absent'), | ||
inprogress: t('blacklight.search.bookmarks.inprogress') | ||
}) do %> | ||
<%= submit_tag(t(bookmarked? ? 'remove.button' : 'add.button', scope: 'blacklight.bookmarks'), | ||
id: "bookmark_toggle_#{@document.id.to_s.parameterize}", | ||
class: "bookmark-#{bookmarked? ? 'remove' : 'add'} btn btn-outline-secondary") %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Document | ||
class BookmarkComponent < ::ViewComponent::Base | ||
def initialize(document:, checked: nil, bookmark_path: nil) | ||
@document = document | ||
@checked = checked | ||
@bookmark_path = bookmark_path | ||
end | ||
|
||
def bookmarked? | ||
return @checked unless @checked.nil? | ||
|
||
@view_context.bookmarked? @document | ||
end | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/components/blacklight/document/citation_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,9 @@ | ||
<div> | ||
<h1 class="modal-title"><%= title %></h1> | ||
|
||
<%= @formats.each do |i18n_key, citation_method| %> | ||
<h2><%= t(i18n_key) %></h2> | ||
<%= @document.send(citation_method).html_safe %> | ||
<% unless @formats.keys.last === i18n_key %><br/><br/><% end %> | ||
<% end %> | ||
</div> |
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Document | ||
class CitationComponent < ::ViewComponent::Base | ||
DEFAULT_FORMATS = { | ||
'blacklight.citation.mla': :export_as_mla_citation_txt, | ||
'blacklight.citation.apa': :export_as_apa_citation_txt, | ||
'blacklight.citation.chicago': :export_as_chicago_citation_txt | ||
}.freeze | ||
|
||
with_collection_parameter :document | ||
|
||
def initialize(document:, formats: DEFAULT_FORMATS) | ||
@document = document | ||
@formats = formats.select { |_k, v| @document.respond_to?(v) } | ||
end | ||
|
||
def title | ||
@view_context.document_heading(@document) | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/components/blacklight/document/more_like_this_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,12 @@ | ||
<div class="card"> | ||
<div class="card-header">More Like This</div> | ||
<div class="card-body"> | ||
<ul> | ||
<%= @document.more_like_this.each do |document| %> | ||
<li class="more_like_this_document"> | ||
<span class="mlt_title"><%= link_to_document document %></span> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
</div> |
21 changes: 21 additions & 0 deletions
21
app/components/blacklight/document/more_like_this_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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Document | ||
class MoreLikeThisComponent < ::ViewComponent::Base | ||
with_collection_parameter :document | ||
|
||
def initialize(document:) | ||
@document = document | ||
end | ||
|
||
def render? | ||
@document.more_like_this.present? | ||
end | ||
|
||
def link_to_document(*args) | ||
@view_context.link_to_document(*args) | ||
end | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
app/components/blacklight/response/facet_group_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,25 @@ | ||
<% # main container for facets/limits menu -%> | ||
<%= content_tag :div, id: @id, class: 'facets sidenav facets-toggleable-md' do %> | ||
<div class="facets-header"> | ||
<%= content_tag :h2, @title, class: 'facets-heading' if @title %> | ||
<%= content_tag :button, | ||
class:'navbar-toggler navbar-toggler-right', | ||
type: 'button', | ||
data: { | ||
toggle: 'collapse', | ||
target: "##{@panel_id}", | ||
}, | ||
aria: { | ||
controls: @panel_id, | ||
expanded: 'false', | ||
label: t('blacklight.search.facets.group.toggle'), | ||
} do %> | ||
<span class="navbar-toggler-icon"></span> | ||
<% end %> | ||
</div> | ||
|
||
<%= content_tag :div, id: @panel_id, class: 'facets-collapse collapse' do %> | ||
<%= @view_context.render_facet_partials @fields, response: @response %> | ||
<% end %> | ||
<% end %> |
19 changes: 19 additions & 0 deletions
19
app/components/blacklight/response/facet_group_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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Response | ||
class FacetGroupComponent < ::ViewComponent::Base | ||
def initialize(response:, fields: [], title: nil, id: nil) | ||
@response = response | ||
@fields = fields | ||
@title = title | ||
@id = id ? "facets-#{id}" : 'facets' | ||
@panel_id = id ? "facet-panel-#{id}-collapse" : 'facet-panel-collapse' | ||
end | ||
|
||
def render? | ||
@view_context.has_facet_values?(@fields, @response) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= render(Blacklight::System::DropdownComponent.new( | ||
param: @param, | ||
choices: @choices, | ||
id: @id, | ||
search_state: @search_state, | ||
selected: @selected)) %> |
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Response | ||
class SortComponent < ViewComponent::Base | ||
def initialize(param: 'sort', choices: {}, search_state:, id: 'sort-dropdown', classes: [], selected: nil) | ||
@param = param | ||
@choices = choices | ||
@search_state = search_state | ||
@id = id | ||
@classes = classes | ||
@selected = selected | ||
end | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
app/components/blacklight/response/spellcheck_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,7 @@ | ||
<div id="spell"> | ||
<h3 class="suggest"> | ||
<em> | ||
<%= t('blacklight.did_you_mean', options: safe_join(@options.map { |word| link_to_query(word) }, " #{t('blacklight.or')} ")).html_safe %> | ||
</em> | ||
</h3> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
app/components/blacklight/response/spellcheck_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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Response | ||
class SpellcheckComponent < ViewComponent::Base | ||
def initialize(response:, options: nil) | ||
@response = response | ||
@options = options || @response&.spelling&.words | ||
end | ||
|
||
def link_to_query(query) | ||
@view_context.link_to_query(query) | ||
end | ||
|
||
def render? | ||
@options.any? && @view_context.should_show_spellcheck_suggestions?(@response) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<%= form_tag @url, method: @method, class: @classes.join(' '), role: 'search', 'aria-label' => t('blacklight.search.form.submit') do %> | ||
<%= render_hash_as_hidden_fields(@params) %> | ||
<% if @search_fields.length > 1 %> | ||
<label for="search_field" class="sr-only"><%= t('blacklight.search.form.search_field.label') %></label> | ||
<% end %> | ||
<div class="input-group"> | ||
<% if @search_fields.length > 1 %> | ||
<%= select_tag(:search_field, | ||
options_for_select(@search_fields, h(@search_field)), | ||
title: t('blacklight.search.form.search_field.title'), | ||
id: "#{@prefix}search_field", | ||
class: "custom-select search-field") %> | ||
<% elsif @search_fields.length == 1 %> | ||
<%= hidden_field_tag :search_field, search_fields.first.last %> | ||
<% end %> | ||
|
||
<label for="<%= @prefix %>q" class="sr-only"><%= t('blacklight.search.form.search.label') %></label> | ||
<%= text_field_tag :q, @q, placeholder: t('blacklight.search.form.search.placeholder'), class: "search-q q form-control rounded-#{@search_fields.length > 1 ? '0' : 'left'}", id: "#{@prefix}q", autocomplete: @autocomplete_path.present? ? "off" : "", autofocus: @autofocus, data: { autocomplete_enabled: @autocomplete_path.present?, autocomplete_path: @autocomplete_path } %> | ||
<%= content %> | ||
|
||
<span class="input-group-append"> | ||
<button type="submit" class="btn btn-primary search-btn" id="<%= @prefix %>search"> | ||
<span class="submit-search-text"><%= t('blacklight.search.form.submit') %></span> | ||
<%= blacklight_icon :search, aria_hidden: true %> | ||
</button> | ||
</span> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
class SearchBarComponent < ::ViewComponent::Base | ||
# rubocop:disable Metrics/ParameterLists | ||
def initialize(url:, params:, classes: [], presenter: nil, prefix: '', method: 'GET', q: nil, search_field: nil, search_fields: [], autocomplete_path: nil, autofocus: nil) | ||
@url = url | ||
@q = q || params[:q] | ||
@search_field = search_field || params[:search_field] | ||
@params = params.except(:q, :search_field, :utf8, :page) | ||
@prefix = prefix | ||
@classes = classes | ||
@presenter = presenter | ||
@method = method | ||
@autocomplete_path = autocomplete_path | ||
@autofocus = autofocus | ||
@search_fields = search_fields | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
def autocomplete_path | ||
return nil unless presenter.autocomplete_enabled? | ||
|
||
@autocomplete_path | ||
end | ||
|
||
def autofocus | ||
if @autofocus.nil? | ||
presenter.autofocus? | ||
else | ||
@autofocus | ||
end | ||
end | ||
|
||
private | ||
|
||
def presenter | ||
@presenter ||= blacklight_config.index.search_bar_presenter_class.new(controller, blacklight_config) | ||
end | ||
|
||
def blacklight_config | ||
@view_context.blacklight_config | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
app/components/blacklight/search_context_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,10 @@ | ||
<div class='pagination-search-widgets'> | ||
|
||
<div class="page-links"> | ||
<%= link_to_previous_document @search_context[:prev] %> | | ||
|
||
<%= item_page_entry_info %> | | ||
|
||
<%= link_to_next_document @search_context[:next] %> | ||
</div> | ||
</div> |
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
class SearchContextComponent < ::ViewComponent::Base | ||
with_collection_parameter :search_context | ||
|
||
def initialize(search_context:, search_session:) | ||
@search_context = search_context | ||
@search_session = search_session | ||
end | ||
|
||
def render? | ||
@search_context.present? && (@search_context[:prev] || @search_context[:next]) | ||
end | ||
|
||
def item_page_entry_info | ||
Deprecation.silence(Blacklight::CatalogHelperBehavior) do | ||
@view_context.item_page_entry_info | ||
end | ||
end | ||
|
||
def link_to_previous_document(*args) | ||
@view_context.link_to_previous_document(*args) | ||
end | ||
|
||
def link_to_next_document(*args) | ||
@view_context.link_to_next_document(*args) | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/components/blacklight/system/dropdown_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,12 @@ | ||
<%= content_tag :div, id: @id, class: @classes.join(' ') do %> | ||
<button type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> | ||
<%= t(:button_label_html, default: :label_html, scope: "blacklight.search.#{@param}", @interpolation => label_for_value(@selected)) %> <span class="caret"></span> | ||
</button> | ||
|
||
<div class="dropdown-menu" role="menu"> | ||
<%- @choices.each do |option| %> | ||
<% text, value = option_text_and_value(option) %> | ||
<%= link_to(text, url_for(@search_state.params_for_search(@param => value)), class: 'dropdown-item', role: 'menuitem') %> | ||
<%- end -%> | ||
</div> | ||
<% end %> |
Oops, something went wrong.