Skip to content

Commit 61e2d40

Browse files
theskumarwes-otf
authored andcommitted
Refractor traffic light scss -> utility classes (HyphaApp#4603)
Also ensure the overall recommendation is accessible ![Screenshot 2025-07-11 at 6  14 47@2x](https://github.com/user-attachments/assets/d7c244a3-79f3-4d85-b687-9470384926d3)
1 parent f824408 commit 61e2d40

4 files changed

Lines changed: 40 additions & 44 deletions

File tree

hypha/apply/review/templatetags/review_tags.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django import template
2-
from django.utils.safestring import mark_safe
2+
from django.utils.html import format_html
33
from django.utils.translation import gettext_lazy as _
44

55
from ..models import MAYBE, NO, YES
@@ -8,25 +8,31 @@
88
register = template.Library()
99

1010

11-
TRAFFIC_LIGHT_COLORS = {
12-
YES: {
13-
"color": "green",
14-
"value": "Y",
15-
},
16-
MAYBE: {
17-
"color": "amber",
18-
"value": "M",
19-
},
20-
NO: {"color": "red", "value": "N"},
21-
}
22-
23-
TRAFFIC_LIGHT_TEMPLATE = '<span class="traffic-light traffic-light--{color}"></span>'
24-
25-
2611
@register.filter()
2712
def traffic_light(value):
13+
mapping = {
14+
YES: {
15+
"label": _("Overall recommendation: Yes"),
16+
"class": "triangle-up text-success",
17+
},
18+
MAYBE: {
19+
"label": _("Overall recommendation: Maybe"),
20+
"class": "circle text-warning",
21+
},
22+
NO: {
23+
"label": _("Overall recommendation: No"),
24+
"class": "triangle-down text-error",
25+
},
26+
}
27+
2828
try:
29-
return mark_safe(TRAFFIC_LIGHT_TEMPLATE.format(**TRAFFIC_LIGHT_COLORS[value]))
29+
html = """
30+
<div class="flex items-center">
31+
<span class="size-3 {class}" aria-hidden=true></span>
32+
<span class="sr-only">{label}</span>
33+
</div>
34+
"""
35+
return format_html(html, **mapping[value])
3036
except KeyError:
3137
return ""
3238

hypha/static_src/sass/components/_traffic-light.scss

Lines changed: 0 additions & 26 deletions
This file was deleted.

hypha/static_src/sass/main.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
@use "components/reviews-sidebar";
66
@use "components/reviews-summary";
77
@use "components/sidebar";
8-
@use "components/traffic-light";
98
@use "components/two-factor";
109
@use "components/wrapper";
1110

hypha/static_src/tailwind/utilities/misc.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,20 @@
9797
@utility js-hidden {
9898
@apply hidden noscript:block;
9999
}
100+
101+
@utility triangle-up {
102+
@apply size-4 inline-block aspect-square;
103+
background-color: currentColor;
104+
clip-path: polygon(50% 0, 0 100%, 100% 100%);
105+
}
106+
107+
@utility triangle-down {
108+
@apply size-4 inline-block aspect-square;
109+
background-color: currentColor;
110+
clip-path: polygon(100% 0, 0 0, 50% 100%);
111+
}
112+
113+
@utility circle {
114+
@apply size-4 inline-block aspect-square rounded-full;
115+
background-color: currentColor;
116+
}

0 commit comments

Comments
 (0)