Highlight connected routes, add readable round labels and accessible path descriptions, widen routing gaps, and centralize brand colors for winner progression.
153 lines
4.9 KiB
TypeScript
153 lines
4.9 KiB
TypeScript
import type {
|
|
CompetitionTeamView,
|
|
DoubleEliminationCompetitionProjection,
|
|
SeriesId,
|
|
TeamId,
|
|
} from "@lolympus/contracts";
|
|
import { useId } from "react";
|
|
import type { DoubleEliminationBracketLayout } from "./double-elimination-bracket-layout";
|
|
import { SeriesScoreCard } from "./SeriesScoreCard";
|
|
import { getSeriesScoreCardAccessibleLabel } from "./series-score-card-model";
|
|
|
|
export function DoubleEliminationMobileBracket({
|
|
projection,
|
|
layout,
|
|
teamById,
|
|
}: {
|
|
projection: DoubleEliminationCompetitionProjection;
|
|
layout: DoubleEliminationBracketLayout;
|
|
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
|
}) {
|
|
const bracketId = useId();
|
|
const seriesById = new Map(
|
|
projection.series.map((series) => [series.seriesId, series]),
|
|
);
|
|
const nodeById = new Map(layout.nodes.map((node) => [node.seriesId, node]));
|
|
const sections = [
|
|
{
|
|
key: "upper",
|
|
title: "승자조",
|
|
description: "승리하면 승자조에 남고, 패배하면 패자조로 이동합니다.",
|
|
stages: new Set(["upper"]),
|
|
},
|
|
{
|
|
key: "lower",
|
|
title: "패자조",
|
|
description: "승리하면 다음 라운드로 진출하고, 패배하면 탈락합니다.",
|
|
stages: new Set(["lower"]),
|
|
},
|
|
{
|
|
key: "final",
|
|
title: "결승",
|
|
description: "승자조 우승 팀과 패자조 우승 팀이 최종 우승을 결정합니다.",
|
|
stages: new Set(["grand-final", "reset-final"]),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<div
|
|
className="space-y-7 xl:hidden"
|
|
role="region"
|
|
aria-label="더블 엘리미네이션 대진표"
|
|
>
|
|
{sections.map((section) => {
|
|
const groups = layout.mobileGroups.filter((group) =>
|
|
section.stages.has(group.stage),
|
|
);
|
|
if (groups.length === 0) return null;
|
|
return (
|
|
<section
|
|
key={section.key}
|
|
aria-labelledby={`${bracketId}-${section.key}`}
|
|
>
|
|
<div className="mb-3 border-b border-base-content/10 pb-2">
|
|
<h3
|
|
id={`${bracketId}-${section.key}`}
|
|
className="text-sm font-bold"
|
|
>
|
|
{section.title}
|
|
</h3>
|
|
<p className="mt-0.5 text-xs text-content-muted">
|
|
{section.description}
|
|
</p>
|
|
</div>
|
|
<div className="space-y-5">
|
|
{groups.map((group) => (
|
|
<section
|
|
key={`${group.stage}:${group.roundNumber}`}
|
|
aria-labelledby={`${bracketId}-${group.stage}-${group.roundNumber}`}
|
|
>
|
|
<h4
|
|
id={`${bracketId}-${group.stage}-${group.roundNumber}`}
|
|
className="mb-2 text-xs font-bold text-content-muted"
|
|
aria-label={group.accessibleLabel}
|
|
>
|
|
{group.label}
|
|
</h4>
|
|
<div className="space-y-3">
|
|
{group.seriesIds.map((seriesId) => {
|
|
const series = seriesById.get(seriesId);
|
|
if (!series) return null;
|
|
const node = nodeById.get(seriesId);
|
|
const accessibilityLabel =
|
|
getSeriesScoreCardAccessibleLabel(
|
|
series,
|
|
node?.accessibleLabel,
|
|
teamById,
|
|
);
|
|
return (
|
|
<div key={seriesId}>
|
|
<SeriesScoreCard
|
|
series={series}
|
|
displayLabel={node?.label}
|
|
teamById={teamById}
|
|
variant="bracket"
|
|
accessibilityLabel={accessibilityLabel}
|
|
/>
|
|
<MobileRoutes
|
|
layout={layout}
|
|
seriesId={seriesId}
|
|
seriesLabel={node?.accessibleLabel ?? "경기"}
|
|
/>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</section>
|
|
))}
|
|
</div>
|
|
</section>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MobileRoutes({
|
|
layout,
|
|
seriesId,
|
|
seriesLabel,
|
|
}: {
|
|
layout: DoubleEliminationBracketLayout;
|
|
seriesId: SeriesId;
|
|
seriesLabel: string;
|
|
}) {
|
|
const routes = layout.connectors.filter(
|
|
(connector) => connector.fromSeriesId === seriesId,
|
|
);
|
|
if (routes.length === 0) return null;
|
|
return (
|
|
<ul
|
|
className="mt-1.5 space-y-0.5 border-l border-base-content/10 pl-2 text-[11px] text-content-muted"
|
|
aria-label={`${seriesLabel} 연결 경로`}
|
|
>
|
|
{routes.map((route) => (
|
|
<li key={`${route.select}:${route.toSeriesId}:${route.toSlot}`}>
|
|
<span aria-hidden="true">{route.label}</span>
|
|
<span className="sr-only">{route.accessibleLabel}</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|