Add an inhouse hero, Hall of Fame, rankings, and event-specific schedules. Carry the event type through the API and admin tools, and improve results and player history displays.
105 lines
2.9 KiB
TypeScript
105 lines
2.9 KiB
TypeScript
import { useEffect, useRef } from "react";
|
|
import {
|
|
moveMatchDetailTabFocus,
|
|
type MatchDetailTab,
|
|
type MatchDetailTabId,
|
|
type MatchDetailTabNavigationKey,
|
|
} from "./match-detail-tabs";
|
|
|
|
export function MatchDetailTabBar({
|
|
tabs,
|
|
activeTab,
|
|
onChange,
|
|
}: {
|
|
tabs: readonly MatchDetailTab[];
|
|
activeTab: MatchDetailTabId;
|
|
onChange: (tab: MatchDetailTabId) => void;
|
|
}) {
|
|
const tabRefs = useRef<
|
|
Partial<Record<MatchDetailTabId, HTMLButtonElement | null>>
|
|
>({});
|
|
const previousActiveTabRef = useRef(activeTab);
|
|
|
|
useEffect(() => {
|
|
tabRefs.current[activeTab]?.scrollIntoView({
|
|
block: "nearest",
|
|
inline: "nearest",
|
|
});
|
|
if (previousActiveTabRef.current === activeTab) return;
|
|
|
|
const activePanel = document.getElementById(
|
|
`match-detail-panel-${activeTab}`,
|
|
);
|
|
const panelTop = activePanel?.getBoundingClientRect().top;
|
|
if (
|
|
activePanel &&
|
|
panelTop !== undefined &&
|
|
(panelTop < 96 || panelTop >= window.innerHeight)
|
|
) {
|
|
activePanel.scrollIntoView({ block: "start" });
|
|
}
|
|
previousActiveTabRef.current = activeTab;
|
|
}, [activeTab]);
|
|
|
|
function handleKeyDown(
|
|
event: React.KeyboardEvent<HTMLButtonElement>,
|
|
currentTab: MatchDetailTabId,
|
|
) {
|
|
if (!isNavigationKey(event.key)) return;
|
|
const nextTab = moveMatchDetailTabFocus(tabs, currentTab, event.key);
|
|
if (!nextTab) return;
|
|
|
|
event.preventDefault();
|
|
onChange(nextTab);
|
|
window.requestAnimationFrame(() => tabRefs.current[nextTab]?.focus());
|
|
}
|
|
|
|
return (
|
|
<div className="lts-panel sticky top-(--app-header-nav-height) z-40 p-1">
|
|
<div
|
|
className="no-scrollbar flex gap-1 overflow-x-auto"
|
|
role="tablist"
|
|
aria-label="내전 상세"
|
|
>
|
|
{tabs.map((tab) => {
|
|
const selected = activeTab === tab.id;
|
|
return (
|
|
<button
|
|
key={tab.id}
|
|
ref={(element) => {
|
|
tabRefs.current[tab.id] = element;
|
|
}}
|
|
id={`match-detail-tab-${tab.id}`}
|
|
type="button"
|
|
role="tab"
|
|
aria-selected={selected}
|
|
aria-controls={`match-detail-panel-${tab.id}`}
|
|
tabIndex={selected ? 0 : -1}
|
|
onClick={() => onChange(tab.id)}
|
|
onKeyDown={(event) => handleKeyDown(event, tab.id)}
|
|
className={`h-10 flex-none whitespace-nowrap rounded-[10px] px-4 text-sm font-bold transition-colors sm:px-5 ${
|
|
selected
|
|
? "bg-secondary text-secondary-content"
|
|
: "text-content-muted hover:bg-sunken hover:text-content"
|
|
}`}
|
|
>
|
|
{tab.label}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function isNavigationKey(
|
|
key: string,
|
|
): key is MatchDetailTabNavigationKey {
|
|
return (
|
|
key === "ArrowLeft" ||
|
|
key === "ArrowRight" ||
|
|
key === "Home" ||
|
|
key === "End"
|
|
);
|
|
}
|