feat: polish double-elimination bracket navigation
Highlight connected routes, add readable round labels and accessible path descriptions, widen routing gaps, and centralize brand colors for winner progression.
This commit is contained in:
1 parent
03e88a03bc
commit
b115072005
8 files changed
+761
-165
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import type {
|
||||
SeriesConnectorView,
|
||||
SeriesId,
|
||||
SeriesSlot,
|
||||
} from "@lolympus/contracts";
|
||||
import type { BracketConnectorKind } from "./double-elimination-bracket-layout";
|
||||
|
||||
export interface BracketFocusConnector {
|
||||
fromSeriesId: SeriesId;
|
||||
select: SeriesConnectorView["from"]["select"];
|
||||
toSeriesId: SeriesId;
|
||||
toSlot: SeriesSlot;
|
||||
}
|
||||
|
||||
export interface BracketFocusState {
|
||||
seriesIds: ReadonlySet<SeriesId>;
|
||||
connectorKeys: ReadonlySet<string>;
|
||||
}
|
||||
|
||||
export interface HorizontalScrollMetrics {
|
||||
scrollLeft: number;
|
||||
scrollWidth: number;
|
||||
clientWidth: number;
|
||||
}
|
||||
|
||||
export interface HorizontalOverflowCues {
|
||||
showStart: boolean;
|
||||
showEnd: boolean;
|
||||
}
|
||||
|
||||
export function bracketConnectorKey(connector: BracketFocusConnector): string {
|
||||
return `${connector.fromSeriesId}:${connector.select}:${connector.toSeriesId}:${connector.toSlot}`;
|
||||
}
|
||||
|
||||
export function getBracketConnectorColorClass(
|
||||
kind: BracketConnectorKind,
|
||||
focused = false,
|
||||
): string {
|
||||
if (kind === "winner") return "text-bracket-winner";
|
||||
return focused ? "text-base-content" : "text-base-content/55";
|
||||
}
|
||||
|
||||
export function getBracketFocusState(
|
||||
connectors: readonly BracketFocusConnector[],
|
||||
activeSeriesId: SeriesId | null,
|
||||
): BracketFocusState {
|
||||
if (!activeSeriesId) {
|
||||
return {
|
||||
seriesIds: new Set(),
|
||||
connectorKeys: new Set(),
|
||||
};
|
||||
}
|
||||
|
||||
const seriesIds = new Set<SeriesId>([activeSeriesId]);
|
||||
const connectorKeys = new Set<string>();
|
||||
for (const connector of connectors) {
|
||||
if (
|
||||
connector.fromSeriesId !== activeSeriesId &&
|
||||
connector.toSeriesId !== activeSeriesId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
seriesIds.add(connector.fromSeriesId);
|
||||
seriesIds.add(connector.toSeriesId);
|
||||
connectorKeys.add(bracketConnectorKey(connector));
|
||||
}
|
||||
|
||||
return { seriesIds, connectorKeys };
|
||||
}
|
||||
|
||||
export function getHorizontalOverflowCues({
|
||||
scrollLeft,
|
||||
scrollWidth,
|
||||
clientWidth,
|
||||
}: HorizontalScrollMetrics): HorizontalOverflowCues {
|
||||
const threshold = 1;
|
||||
const maxScrollLeft = Math.max(0, scrollWidth - clientWidth);
|
||||
if (maxScrollLeft <= threshold) {
|
||||
return { showStart: false, showEnd: false };
|
||||
}
|
||||
return {
|
||||
showStart: scrollLeft > threshold,
|
||||
showEnd: scrollLeft < maxScrollLeft - threshold,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user