--- import Icon from './Icon.astro'; import SheetFilterBars from './SheetFilterBars.astro'; import type { SheetFacets } from '../lib/sheets'; interface Group { key: string; label: string; count: number; accent: string; } interface Props { /** One entry per row in the list below — the same facets the rows carry, * so the panel's opening numbers and the script's agree. */ rows: SheetFacets[]; /** Completes "Search …": `this shelf`, `all sheets`, `#kerberos`. */ scope: string; accent?: string; /** The list's own grouping — sections on a shelf, shelves elsewhere — * drawn as the second split bar. Omit for a flat list. */ groups?: Group[]; groupLabel?: string; /** Tags every row shares (the shelf's own name, the tag page's tag): a * chip that cannot narrow anything is noise. */ hideTags?: string[]; } const { rows, scope, accent = 'love', groups = [], groupLabel = 'Sections', hideTags = [] } = Astro.props; /** * The filter panel, in the main site's category-page grammar: a search field * with a live count, the list's tags as chips, and a stats block whose bars * are the same filters drawn as proportions. Everything in it that shows a * number is a button — pressing a bar narrows the list just as its chip does. * * The markup here is the panel at rest. scripts/sheet-filter.ts binds it, * and from then on owns every count, width and pressed state; the * `data-sf-*` attributes are the contract between the two. */ const pad = (n: number) => String(n).padStart(2, '0'); const tally = (values: string[]) => { const map = new Map(); for (const v of values) map.set(v, (map.get(v) ?? 0) + 1); return [...map.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])); }; const hidden = new Set(hideTags.map((t) => t.toLowerCase())); const tags = tally(rows.flatMap((r) => r.tags)).filter(([t]) => !hidden.has(t)); // A tag used once is a label, not a way to narrow a list: on a long list // they would bury the chips that do something. Short lists keep them all. const CHIP_FLOOR = tags.length > 30 ? 2 : 1; const CHIPS_SHOWN = 12; const chips = tags.filter(([, n]) => n >= CHIP_FLOOR); const extra = Math.max(0, chips.length - CHIPS_SHOWN); const BARS = 6; const techniques = tags.slice(0, BARS); const DIFFS = [ { key: 'beginner', accent: 'foam' }, { key: 'intermediate', accent: 'gold' }, { key: 'advanced', accent: 'love' }, ].map((d) => ({ ...d, count: rows.filter((r) => r.diff === d.key).length })) .filter((d) => d.count > 0); // The tools the list reaches for most. They sit under the difficulty split // on a flat list and under the techniques on a grouped one, whichever column // is the shorter, so the two stay roughly level. const tools = tally(rows.flatMap((r) => r.tools)).slice(0, 4); const grouped = groups.length > 1; ---
{rows.length} shown
{chips.length > 0 && (
{chips.map(([tag, n], i) => ( ))} {extra > 0 && ( )}
)} {chips.length === 0 && (
)} {/* Open in the markup, so it reads in full without JS. On a narrow screen the script folds it: there the block is a thousand pixels tall and would sit between the search field and its results. */}
Breakdown
{DIFFS.length > 0 && (

Difficulty

{DIFFS.map((d) => ( ))}
)} {groups.length > 1 && (

{groupLabel}

{groups.map((g) => ( ))}
)} {!grouped && tools.length > 0 && }
{(techniques.length > 0 || (grouped && tools.length > 0)) && (
{techniques.length > 0 && } {grouped && tools.length > 0 && }
)}