Skip to content

Commit 78cafbd

Browse files
author
Cristian Yáñez
committed
feat(2312): make CSS dynamic via django template logic
1 parent 36563ba commit 78cafbd

3 files changed

Lines changed: 33 additions & 60 deletions

File tree

static/css/v3/testimonial-card-nojs.css

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

static/css/v3/testimonial-card.css

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,9 @@
157157
display: none;
158158
}
159159

160-
.testimonial-card:has(.testimonial-card__state[data-state-index="0"]:checked) .testimonial-card__nav-set[data-nav-index="0"],
161-
.testimonial-card:has(.testimonial-card__state[data-state-index="1"]:checked) .testimonial-card__nav-set[data-nav-index="1"],
162-
.testimonial-card:has(.testimonial-card__state[data-state-index="2"]:checked) .testimonial-card__nav-set[data-nav-index="2"],
163-
.testimonial-card:has(.testimonial-card__state[data-state-index="3"]:checked) .testimonial-card__nav-set[data-nav-index="3"],
164-
.testimonial-card:has(.testimonial-card__state[data-state-index="4"]:checked) .testimonial-card__nav-set[data-nav-index="4"],
165-
.testimonial-card:has(.testimonial-card__state[data-state-index="5"]:checked) .testimonial-card__nav-set[data-nav-index="5"],
166-
.testimonial-card:has(.testimonial-card__state[data-state-index="6"]:checked) .testimonial-card__nav-set[data-nav-index="6"],
167-
.testimonial-card:has(.testimonial-card__state[data-state-index="7"]:checked) .testimonial-card__nav-set[data-nav-index="7"],
168-
.testimonial-card:has(.testimonial-card__state[data-state-index="8"]:checked) .testimonial-card__nav-set[data-nav-index="8"],
169-
.testimonial-card:has(.testimonial-card__state[data-state-index="9"]:checked) .testimonial-card__nav-set[data-nav-index="9"] {
170-
display: inline-flex;
171-
}
160+
/* Per-index `display: inline-flex` overrides for the checked radio's nav-set
161+
are generated in _testimonial_card.html (the testimonials count is
162+
data-driven, so the rule set is rendered inline by the template). */
172163

173164
.carousel-buttons label.btn-carousel {
174165
display: inline-flex;

templates/v3/includes/_testimonial_card.html

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{% load static %}
21
{% comment %}
32
Testimonial Card — displays a carousel of testimonial quotes with author profiles.
43

@@ -13,9 +12,36 @@
1312
{% endcomment %}
1413

1514
{% with carousel_id='_testimonials_cards_carousel' %}
16-
<noscript>
17-
<link rel="stylesheet" href="{% static 'css/v3/testimonial-card-nojs.css' %}">
18-
</noscript>
15+
{% comment %}
16+
Per-index visibility rules generated from the testimonials list (the count is
17+
data-driven, so they can't live as static rules in the CSS). The first <style>
18+
block runs in both JS and no-JS modes; only the nav-set for the checked radio
19+
is shown. The <noscript> block additionally switches the track to a CSS
20+
transform-based carousel: items are flex: 0 0 100% with gap: 0, so
21+
translateX(-N00%) shifts by exactly one item per radio. visibility: hidden on
22+
non-current items mirrors the JS-mode `inert` behavior so off-screen author
23+
links can't receive tab focus. Touch-swipe is lost in no-JS mode (the parent
24+
`.testimonial-card__post` clips with overflow: hidden) but arrow buttons work
25+
without scrolling the page.
26+
{% endcomment %}
27+
{% if testimonials %}
28+
<style>
29+
{% for testimonial in testimonials %}
30+
.testimonial-card:has(.testimonial-card__state[data-state-index="{{ forloop.counter0 }}"]:checked) .testimonial-card__nav-set[data-nav-index="{{ forloop.counter0 }}"] { display: inline-flex; }
31+
{% endfor %}
32+
</style>
33+
<noscript>
34+
<style>
35+
.testimonial-card__list { overflow: visible !important; gap: 0 !important; transition: transform 0.3s ease; }
36+
.testimonial-card__list-item { visibility: hidden; }
37+
38+
{% for testimonial in testimonials %}
39+
.testimonial-card:has(.testimonial-card__state[data-state-index="{{ forloop.counter0 }}"]:checked) .testimonial-card__list { transform: translateX(-{{ forloop.counter0 }}00%); }
40+
.testimonial-card:has(.testimonial-card__state[data-state-index="{{ forloop.counter0 }}"]:checked) .testimonial-card__list-item[data-item-index="{{ forloop.counter0 }}"] { visibility: visible; }
41+
{% endfor %}
42+
</style>
43+
</noscript>
44+
{% endif %}
1945
<div class="card testimonial-card py-large" id="{{carousel_id}}" data-carousel data-carousel-radios role="region" aria-labelledby="{{ carousel_id }}-heading">
2046
{% if testimonials %}
2147
{% for testimonial in testimonials %}

0 commit comments

Comments
 (0)