|
1 | 1 | import { Controller } from "@hotwired/stimulus" |
2 | 2 |
|
| 3 | +function setInactive(btn) { |
| 4 | + btn.style.borderColor = "rgba(255,255,255,0.15)" |
| 5 | + btn.style.background = "transparent" |
| 6 | + btn.style.color = "rgba(255,255,255,0.45)" |
| 7 | +} |
| 8 | + |
| 9 | +function setActive(btn) { |
| 10 | + btn.style.borderColor = "var(--retro-gold)" |
| 11 | + btn.style.background = "rgba(200,155,60,0.15)" |
| 12 | + btn.style.color = "var(--retro-gold)" |
| 13 | +} |
| 14 | + |
3 | 15 | export default class extends Controller { |
4 | 16 | filter(event) { |
5 | 17 | const team = event.currentTarget.dataset.team |
6 | 18 | const rows = document.querySelectorAll("[data-champion-row]") |
7 | 19 |
|
8 | | - // Update button styles |
9 | | - this.element.querySelectorAll("button").forEach(btn => { |
10 | | - btn.classList.remove("bg-kl-gold", "text-kl-bg") |
11 | | - btn.classList.add("bg-white/5", "text-gray-300") |
12 | | - }) |
13 | | - event.currentTarget.classList.add("bg-kl-gold", "text-kl-bg") |
14 | | - event.currentTarget.classList.remove("bg-white/5", "text-gray-300") |
| 20 | + this.element.querySelectorAll("button").forEach(setInactive) |
| 21 | + setActive(event.currentTarget) |
15 | 22 |
|
16 | | - if (!team) { |
| 23 | + if (team === "") { |
17 | 24 | rows.forEach(r => r.style.display = "") |
18 | 25 | return |
19 | 26 | } |
20 | 27 |
|
21 | | - // Filter champion rows by team picks/bans (requires server-side data attr) |
22 | 28 | rows.forEach(r => { |
23 | 29 | const teams = r.dataset.teams || "" |
24 | | - r.style.display = teams.includes(team) ? "" : "none" |
| 30 | + r.style.display = teams.split(",").includes(team) ? "" : "none" |
25 | 31 | }) |
26 | 32 | } |
27 | 33 | } |
0 commit comments