Refactor scss for in favor against component
In order to reduce the code used to add styles to the buttons, we removed the classes that had been added and handled it with the new aria-pressed attribute
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<div class="in-favor-against">
|
||||
<div class="in-favor">
|
||||
<%= button_to polymorphic_path(votable, action: :vote, value: "yes"),
|
||||
class: "like #{voted_classes[:in_favor]}",
|
||||
title: t("votes.agree"),
|
||||
"aria-label": agree_aria_label,
|
||||
"aria-pressed": pressed?("yes"),
|
||||
@@ -14,7 +13,6 @@
|
||||
|
||||
<div class="against">
|
||||
<%= button_to polymorphic_path(votable, action: :vote, value: "no"),
|
||||
class: "unlike #{voted_classes[:against]}",
|
||||
title: t("votes.disagree"),
|
||||
"aria-label": disagree_aria_label,
|
||||
"aria-pressed": pressed?("no"),
|
||||
|
||||
@@ -8,21 +8,6 @@ class Shared::InFavorAgainstComponent < ApplicationComponent
|
||||
|
||||
private
|
||||
|
||||
def voted_classes
|
||||
@voted_classes ||= css_classes_for_vote
|
||||
end
|
||||
|
||||
def css_classes_for_vote
|
||||
case current_user&.voted_as_when_voted_for(votable)
|
||||
when true
|
||||
{ in_favor: "voted", against: "no-voted" }
|
||||
when false
|
||||
{ in_favor: "no-voted", against: "voted" }
|
||||
else
|
||||
{ in_favor: "", against: "" }
|
||||
end
|
||||
end
|
||||
|
||||
def agree_aria_label
|
||||
t("votes.agree_label", title: votable.title)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user