Skip to content

Commit 410fe70

Browse files
authored
Merge pull request #3610 from projectblacklight/selected_value
Extract selected facet value component
2 parents fbccc6d + e4a1c51 commit 410fe70

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
lines changed

app/assets/builds/blacklight.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ main {
338338
.facet-values .remove {
339339
color: var(--bl-facet-remove-color);
340340
font-weight: bold;
341-
padding-left: 0.5rem;
342341
text-decoration: none;
343342
}
344343
.facet-values .remove:hover {

app/assets/stylesheets/blacklight/_facets.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
.remove {
100100
color: var(--bl-facet-remove-color);
101101
font-weight: bold;
102-
padding-left: $spacer * 0.5;
103102
text-decoration: none;
104103

105104
&:hover {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Blacklight
4+
module Facets
5+
# Display count of a facet value
6+
class CountComponent < Blacklight::Component
7+
def initialize(hits:, classes:)
8+
@hits = hits
9+
@classes = classes
10+
end
11+
12+
attr_reader :hits, :classes
13+
14+
def render?
15+
hits.present?
16+
end
17+
18+
def call
19+
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(hits)), class: classes)
20+
end
21+
end
22+
end
23+
end

app/components/blacklight/facets/item_component.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,8 @@ def render_facet_value
5151
#
5252
# @private
5353
def render_selected_facet_value
54-
tag.span(class: "facet-label") do
55-
tag.span(label, class: "selected") +
56-
# remove link
57-
link_to(href, class: "remove", rel: "nofollow") do
58-
render(Blacklight::Icons::RemoveComponent.new(aria_hidden: true)) +
59-
tag.span(helpers.t(:'blacklight.search.facets.selected.remove'), class: 'visually-hidden')
60-
end
61-
end + render_facet_count(classes: ["selected"])
54+
concat render(Blacklight::Facets::SelectedValueComponent.new(label: label, href: href))
55+
concat render_facet_count(classes: ["selected"])
6256
end
6357

6458
##
@@ -70,10 +64,9 @@ def render_selected_facet_value
7064
# @return [String]
7165
# @private
7266
def render_facet_count(options = {})
73-
return '' if hits.blank?
74-
7567
classes = (options[:classes] || []) << "facet-count"
76-
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(hits)), class: classes)
68+
69+
render Blacklight::Facets::CountComponent.new(hits: hits, classes: classes)
7770
end
7871
end
7972
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module Blacklight
4+
module Facets
5+
# Standard display of a selected facet value (e.g. without a link and with a remove button)
6+
class SelectedValueComponent < Blacklight::Component
7+
def initialize(label:, href:)
8+
@label = label
9+
@href = href
10+
super
11+
end
12+
13+
attr_reader :label, :href
14+
15+
def call
16+
tag.span(class: "facet-label") do
17+
tag.span(label, class: "selected") + remove_link
18+
end
19+
end
20+
21+
def remove_link
22+
link_to(href, class: "remove ps-2", rel: "nofollow") do
23+
render(Blacklight::Icons::RemoveComponent.new(aria_hidden: true)) +
24+
tag.span(t(:'blacklight.search.facets.selected.remove'), class: 'visually-hidden')
25+
end
26+
end
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)