Prepare SDG tag list component to render list with or without links

Now the tag list can render tags with or without links, so we need
to adapt the styles slightly.

We want to use the same text color for tags without links.

The hover style is only needed when using tags with links.
This commit is contained in:
Senén Rodero Rodríguez
2021-01-27 18:34:43 +01:00
committed by taitus
parent cc2ce38d13
commit bb1315def1
4 changed files with 69 additions and 6 deletions

View File

@@ -11,18 +11,23 @@
.sdg-target-tag-list { .sdg-target-tag-list {
@extend %tags; @extend %tags;
a:not(.more-targets) { a:not(.more-targets),
span {
color: $white; color: $white;
} }
@each $code, $color in $sdg-colors { @each $code, $color in $sdg-colors {
[data-code^="#{$code}"] { a[data-code^="#{$code}"] {
background-color: $color; background-color: $color;
&:hover { &:hover {
background-color: darken($color, 10%); background-color: darken($color, 10%);
} }
} }
span[data-code^="#{$code}"] {
background-color: $color;
}
} }
} }
} }

View File

@@ -1,4 +1,4 @@
<div class="sdg-tag-list"> <div class="sdg-tag-list">
<%= render SDG::Goals::TagListComponent.new(record, limit: limit) %> <%= goals_list %>
<%= render SDG::Targets::TagListComponent.new(record, limit: limit) %> <%= targets_list %>
</div> </div>

View File

@@ -1,8 +1,27 @@
class SDG::TagListComponent < ApplicationComponent class SDG::TagListComponent < ApplicationComponent
attr_reader :record, :limit attr_reader :record, :limit, :linkable
def initialize(record, limit: nil) def initialize(record, limit: nil, linkable: true)
@record = record @record = record
@limit = limit @limit = limit
@linkable = linkable
end end
private
def goals_list
if linkable
render SDG::Goals::TagListComponent.new(record, limit: limit)
else
render SDG::Goals::PlainTagListComponent.new(record, limit: limit)
end
end
def targets_list
if linkable
render SDG::Targets::TagListComponent.new(record, limit: limit)
else
render SDG::Targets::PlainTagListComponent.new(record, limit: limit)
end
end
end end

View File

@@ -0,0 +1,39 @@
require "rails_helper"
describe SDG::TagListComponent, type: :component do
let(:debate) do
create(:debate,
sdg_goals: [SDG::Goal[3]],
sdg_targets: [SDG::Target[3.2], create(:sdg_local_target, code: "3.2.1")]
)
end
let(:component) { SDG::TagListComponent.new(debate) }
before do
Setting["feature.sdg"] = true
Setting["sdg.process.debates"] = true
end
it "renders tags list with links" do
render_inline component
expect(page).to have_link "3. Good Health and Well-Being"
expect(page).to have_link "target 3.2"
expect(page).to have_link "target 3.2.1"
end
context "when linkable is false" do
let(:component) { SDG::TagListComponent.new(debate, linkable: false) }
it "renders plain tags list" do
render_inline component
expect(page.find(".sdg-goal-icon")[:alt]).to eq "3. Good Health and Well-Being"
expect(page).to have_content "target 3.2"
expect(page).to have_content "target 3.2.1"
expect(page).not_to have_link "3. Good Health and Well-Being"
expect(page).not_to have_link "target 3.2"
expect(page).not_to have_link "target 3.2.1"
end
end
end