Add accordion + active-filter chip bar for mobile repertoire

- repertoire-index.php: wrap each filter column in rep-accordion with toggle
  button, chevron, badge (active filter count); add rep-chip-bar with
  removable active-filter chips above the columns
- repertoire.css: mobile (≤640px) accordion mode — columns collapse to
  single-open accordion sections with 48px touch targets; chip bar becomes
  sticky; desktop/tablet layout unchanged via display:none on toggle elements
- repertoire.php: JS for single-accordion-open behavior on mobile, HTMX
  re-init after swap, resize-breakpoint cleanup
- docs/repertoire-mobile-propositions.md: analysis + 4 architecture proposals
This commit is contained in:
Pontoporeia
2026-06-22 15:45:58 +02:00
parent cca3d08f05
commit ecb90ba5dd
5 changed files with 529 additions and 45 deletions

View File

@@ -106,9 +106,50 @@ foreach ($filterColumns as $col) {
fn($i) => $i['matched']
));
}
// ── Active filter chips ─────────────────────────────────────────────────────
// Build a flat list of {dim, label, value, url} for every active filter entry.
$activeChips = [];
$dimLabels = [
'years' => 'Année',
'ap' => 'AP',
'or' => 'Orientation',
'fi' => 'Finalité',
'kw' => 'Mot-clé',
];
foreach (['years', 'ap', 'or', 'fi', 'kw'] as $dim) {
foreach ($activeSets[$dim] as $val) {
$activeChips[] = [
'dim' => $dim,
'label' => $dimLabels[$dim],
'value' => $val,
'url' => repToggleUrl($activeSets, $dim, $val),
];
}
}
?>
<div id="repertoire-index" class="repertoire-index">
<?php if ($anyActive): ?>
<!-- Active filter chips bar -->
<div class="rep-chip-bar" role="status" aria-label="Filtres actifs">
<span class="rep-chip-bar__label">Filtres&nbsp;:</span>
<?php foreach ($activeChips as $chip): ?>
<button type="button" class="rep-chip"
hx-get="<?= htmlspecialchars($chip['url']) ?>"
hx-target="#repertoire-index"
hx-swap="outerHTML"
hx-push-url="true"
hx-indicator="#rep-indicator"
aria-label="Retirer le filtre <?= htmlspecialchars($chip['label']) ?> : <?= htmlspecialchars($chip['value']) ?>">
<span class="rep-chip__dim"><?= htmlspecialchars($chip['label']) ?></span>
<span class="rep-chip__value"><?= htmlspecialchars($chip['value']) ?></span>
<span class="rep-chip__remove" aria-hidden="true">×</span>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
// Render filter columns in the correct left-to-right order.
// Students column (non-filter) is inserted between keywords and AP/or/fi/years.
@@ -117,8 +158,15 @@ $renderOrder = ['years', 'ap', 'or', 'fi', 'students', 'kw'];
foreach ($renderOrder as $colKey):
if ($colKey === 'students'): ?>
<!-- ÉTUDIANTES -->
<section class="repertoire-col" data-col="students">
<h2>Étudiant·es</h2>
<section class="repertoire-col rep-accordion" data-col="students">
<h2>
<span class="rep-accordion__heading-text">Étudiant·es</span>
<button type="button" class="rep-accordion__toggle" aria-expanded="false">
Étudiant·es
<span class="rep-accordion__chevron" aria-hidden="true"></span>
</button>
</h2>
<div class="rep-accordion__panel">
<ul>
<?php if (empty($studentWorks)): ?>
<li class="rep-empty">—</li>
@@ -143,16 +191,32 @@ foreach ($renderOrder as $colKey):
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</section>
<?php else:
$col = array_values(array_filter($filterColumns, fn($c) => $c['dim'] === $colKey))[0]; ?>
<section class="repertoire-col" data-col="<?= $col['dim'] ?>">
<h2><?= $col['heading'] ?></h2>
$col = array_values(array_filter($filterColumns, fn($c) => $c['dim'] === $colKey))[0];
// Count active filters in this column for the badge
$activeCount = count($activeSets[$col['dim']]);
?>
<section class="repertoire-col rep-accordion" data-col="<?= $col['dim'] ?>">
<h2>
<span class="rep-accordion__heading-text"><?= $col['heading'] ?></span>
<button type="button" class="rep-accordion__toggle" aria-expanded="false">
<?= $col['heading'] ?>
<?php if ($activeCount > 0): ?>
<span class="rep-accordion__badge"><?= $activeCount ?></span>
<?php endif; ?>
<span class="rep-accordion__chevron" aria-hidden="true"></span>
</button>
</h2>
<div class="rep-accordion__panel">
<ul>
<?php foreach ($repData[$col['dataKey']] as $item):
repFilterEntry($item, $col['dim'], $activeSets, $anyActive, $colHasMatches[$col['dim']], $hx);
endforeach; ?>
</ul>
</div>
</section>
<?php endif;
endforeach; ?>

View File

@@ -44,3 +44,81 @@
}, true);
}());
</script>
<script>
// Mobile accordion: single-open behavior + HTMX re-init
(function () {
var INDEX_SEL = '#repertoire-index';
var ACCORDION_SEL = '.rep-accordion';
var TOGGLE_SEL = '.rep-accordion__toggle';
var PANEL_SEL = '.rep-accordion__panel';
function isMobile() {
return window.matchMedia('(max-width: 1025px)').matches;
}
function initAccordions(root) {
if (!isMobile()) return;
var toggles = root.querySelectorAll(TOGGLE_SEL);
toggles.forEach(function (btn) {
// Skip students column — always visible, not an accordion
if (btn.closest('[data-col="students"]')) return;
if (btn._accordionBound) return;
btn._accordionBound = true;
btn.addEventListener('click', function () {
var section = btn.closest(ACCORDION_SEL);
var panel = section.querySelector(PANEL_SEL);
var isOpen = btn.getAttribute('aria-expanded') === 'true';
// Close all others (except students)
root.querySelectorAll(ACCORDION_SEL).forEach(function (s) {
if (s.dataset.col === 'students') return;
var p = s.querySelector(PANEL_SEL);
var t = s.querySelector(TOGGLE_SEL);
if (s !== section) {
t.setAttribute('aria-expanded', 'false');
p.classList.remove('is-open');
}
});
// Toggle this one
var nowOpen = !isOpen;
btn.setAttribute('aria-expanded', nowOpen ? 'true' : 'false');
if (nowOpen) {
panel.classList.add('is-open');
} else {
panel.classList.remove('is-open');
}
});
});
}
// Initial bind
initAccordions(document);
// Re-bind after HTMX swaps
document.body.addEventListener('htmx:afterSwap', function (e) {
if (e.detail.target && e.detail.target.matches && e.detail.target.matches(INDEX_SEL)) {
initAccordions(e.detail.target);
}
});
// Re-bind on resize crossing the breakpoint
var wasMobile = isMobile();
window.addEventListener('resize', function () {
var nowMobile = isMobile();
if (nowMobile !== wasMobile) {
wasMobile = nowMobile;
// When switching to desktop, close all panels
if (!nowMobile) {
document.querySelectorAll(INDEX_SEL + ' ' + TOGGLE_SEL).forEach(function (btn) {
btn.setAttribute('aria-expanded', 'false');
});
document.querySelectorAll(INDEX_SEL + ' ' + PANEL_SEL).forEach(function (p) {
p.classList.remove('is-open');
});
}
}
});
}());
</script>