feat: add spell and rune tooltips

This commit is contained in:
dahyeon committed 2026-06-26 23:29:47 -07:00
1 parent 4906f665fd
commit 292e37aaac
8 files changed
+404 -161

No files matched your search

+4
View File
@@ -482,6 +482,8 @@ export interface DdragonChampionEntry {
export interface DdragonSummonerSpellEntry {
key: string;
name: string;
description: string;
tooltip: string;
}
export interface DdragonRuneEntry {
@@ -489,6 +491,8 @@ export interface DdragonRuneEntry {
key: string;
icon: string;
name: string;
shortDesc: string;
longDesc: string;
}
export interface DdragonRuneStyleEntry extends DdragonRuneEntry {
@@ -3,12 +3,10 @@ import type { ApiInternalMatchDetailResponse, DdragonManifest, TeamSide } from "
import {
championDisplayName,
championIconUrl,
runeIconUrl,
runeStyleIconUrl,
} from "../lib/ddragon";
import { teamIndexLabel } from "../lib/league";
import { LANE_LABELS } from "../lib/riot-history";
import { ItemIcon } from "./ItemTooltip";
import { ItemIcon, RuneIcon, RuneStyleIcon } from "./ItemTooltip";
export type InternalGameDetailTab = "scoreboard" | "matchup" | "build";
@@ -413,21 +411,17 @@ function RuneTreeColumn({
);
}
const styleIcon = runeStyleIconUrl(manifest, runeStyle.id);
const selectionIds = new Set(selection?.perkIds ?? []);
return (
<div>
<div className="flex items-center gap-2">
<span className="h-6 w-6 overflow-hidden bg-base-content/10">
{styleIcon ? (
<img
src={styleIcon}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
<RuneStyleIcon
styleId={runeStyle.id}
manifest={manifest}
className="h-6 w-6"
slotClassName="bg-base-content/10"
/>
<div className="min-w-0">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
{label}
@@ -455,25 +449,18 @@ function RuneTreeColumn({
{slot.runes.map((rune) => {
const selected =
selectedIds.has(rune.id) || selectionIds.has(rune.id);
const icon = runeIconUrl(manifest, rune.id);
return (
<span
<RuneIcon
key={rune.id}
title={rune.name}
className={`${iconSize} overflow-hidden border bg-base-content/10 transition ${
runeId={rune.id}
manifest={manifest}
className={iconSize}
slotClassName={`border bg-base-content/10 transition ${
selected
? "border-transparent opacity-100 ring-1 ring-primary/60"
: "border-transparent opacity-20 grayscale"
}`}
>
{icon ? (
<img
src={icon}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
/>
);
})}
</div>
+226 -24
View File
@@ -1,4 +1,4 @@
import type { CSSProperties, RefObject } from "react";
import type { CSSProperties, ReactNode, RefObject } from "react";
import { useEffect, useId, useRef, useState } from "react";
import { createPortal } from "react-dom";
import type { DdragonManifest } from "../api/types";
@@ -6,7 +6,13 @@ import {
itemDetails,
itemDisplayName,
itemIconUrl,
runeDetails,
runeIconUrl,
runeStyleDetails,
runeStyleIconUrl,
safeDdragonDescriptionHtml,
summonerSpellDetails,
summonerSpellIconUrl,
} from "../lib/ddragon";
type TooltipPosition = {
@@ -24,6 +30,24 @@ type ItemIconProps = {
trinket?: boolean;
};
type TooltipIconProps = {
active: boolean;
label: string;
emptyLabel: string;
icon: string | null;
className: string;
imageClassName: string;
slotClassName: string;
children: ReactNode;
};
type ManifestIconProps = {
manifest: DdragonManifest | null | undefined;
className?: string;
imageClassName?: string;
slotClassName?: string;
};
const VIEWPORT_MARGIN = 8;
const TOOLTIP_GAP = 8;
const TOOLTIP_WIDTH = 320;
@@ -35,9 +59,6 @@ export function ItemIcon({
imageClassName = "scale-[1.18]",
trinket = false,
}: ItemIconProps) {
const anchorRef = useRef<HTMLSpanElement>(null);
const tooltipId = useId();
const [open, setOpen] = useState(false);
const icon = itemIconUrl(manifest, itemId);
const hasItem = itemId > 0;
const itemName = itemDisplayName(manifest, itemId) ?? `아이템 ${itemId}`;
@@ -45,21 +66,125 @@ export function ItemIcon({
? "border-primary/25 bg-base-content/[0.04]"
: "border-base-content/5 bg-base-content/8";
return (
<TooltipIcon
active={hasItem}
label={itemName}
emptyLabel="빈 아이템 슬롯"
icon={icon}
className={className}
imageClassName={imageClassName}
slotClassName={`border ${slotTone}`}
>
<ItemTooltipContent itemId={itemId} manifest={manifest} />
</TooltipIcon>
);
}
export function SummonerSpellIcon({
spellId,
manifest,
className = "h-5 w-5",
imageClassName = "",
slotClassName = "border border-base-content/5 bg-base-content/10",
}: ManifestIconProps & { spellId: number }) {
const spell = summonerSpellDetails(manifest, spellId);
const spellName = spell?.name ?? `스펠 ${spellId}`;
return (
<TooltipIcon
active={spellId > 0}
label={spellName}
emptyLabel="빈 스펠 슬롯"
icon={summonerSpellIconUrl(manifest, spellId)}
className={className}
imageClassName={imageClassName}
slotClassName={slotClassName}
>
<SummonerSpellTooltipContent spellId={spellId} manifest={manifest} />
</TooltipIcon>
);
}
export function RuneIcon({
runeId,
manifest,
className = "h-5 w-5",
imageClassName = "",
slotClassName = "border border-base-content/5 bg-base-content/10",
}: ManifestIconProps & { runeId: number | undefined }) {
const rune = runeDetails(manifest, runeId);
const runeName = rune?.name ?? (runeId ? `룬 ${runeId}` : "룬");
return (
<TooltipIcon
active={Boolean(runeId)}
label={runeName}
emptyLabel="빈 룬 슬롯"
icon={runeIconUrl(manifest, runeId)}
className={className}
imageClassName={imageClassName}
slotClassName={slotClassName}
>
<RuneTooltipContent runeId={runeId} manifest={manifest} />
</TooltipIcon>
);
}
export function RuneStyleIcon({
styleId,
manifest,
className = "h-5 w-5",
imageClassName = "",
slotClassName = "border border-base-content/5 bg-base-content/10",
}: ManifestIconProps & { styleId: number | undefined }) {
const style = runeStyleDetails(manifest, styleId);
const styleName = style?.name ?? (styleId ? `룬 ${styleId}` : "룬");
return (
<TooltipIcon
active={Boolean(styleId)}
label={styleName}
emptyLabel="빈 룬 슬롯"
icon={runeStyleIconUrl(manifest, styleId)}
className={className}
imageClassName={imageClassName}
slotClassName={slotClassName}
>
<RuneStyleTooltipContent styleId={styleId} manifest={manifest} />
</TooltipIcon>
);
}
function TooltipIcon({
active,
label,
emptyLabel,
icon,
className,
imageClassName,
slotClassName,
children,
}: TooltipIconProps) {
const anchorRef = useRef<HTMLSpanElement>(null);
const tooltipId = useId();
const [open, setOpen] = useState(false);
return (
<span
ref={anchorRef}
className={`relative inline-flex shrink-0 ${className}`}
role={hasItem ? "img" : undefined}
tabIndex={hasItem ? 0 : undefined}
aria-label={hasItem ? itemName : "빈 아이템 슬롯"}
aria-describedby={hasItem && open ? tooltipId : undefined}
role={active ? "img" : undefined}
tabIndex={active ? 0 : undefined}
aria-label={active ? label : emptyLabel}
aria-describedby={active && open ? tooltipId : undefined}
onBlur={() => setOpen(false)}
onFocus={() => hasItem && setOpen(true)}
onMouseEnter={() => hasItem && setOpen(true)}
onFocus={() => active && setOpen(true)}
onMouseEnter={() => active && setOpen(true)}
onMouseLeave={() => setOpen(false)}
>
<span
className={`block h-full w-full overflow-hidden border ${slotTone}`}
className={`block h-full w-full overflow-hidden ${slotClassName}`}
aria-hidden="true"
>
{icon ? (
@@ -71,28 +196,23 @@ export function ItemIcon({
/>
) : null}
</span>
{hasItem && open ? (
<ItemTooltipPortal
id={tooltipId}
anchorRef={anchorRef}
itemId={itemId}
manifest={manifest}
/>
{active && open ? (
<TooltipPortal id={tooltipId} anchorRef={anchorRef}>
{children}
</TooltipPortal>
) : null}
</span>
);
}
function ItemTooltipPortal({
function TooltipPortal({
id,
anchorRef,
itemId,
manifest,
children,
}: {
id: string;
anchorRef: RefObject<HTMLElement | null>;
itemId: number;
manifest: DdragonManifest | null | undefined;
children: ReactNode;
}) {
const [position, setPosition] = useState<TooltipPosition | null>(null);
@@ -149,12 +269,94 @@ function ItemTooltipPortal({
style={style}
className="pointer-events-none fixed z-[1000] border border-base-content/20 bg-black px-3 py-3 text-xs leading-relaxed text-white shadow-2xl"
>
<ItemTooltipContent itemId={itemId} manifest={manifest} />
{children}
</div>,
document.body,
);
}
function SummonerSpellTooltipContent({
spellId,
manifest,
}: {
spellId: number;
manifest: DdragonManifest | null | undefined;
}) {
const spell = summonerSpellDetails(manifest, spellId);
const descriptionHtml = spell?.description
? safeDdragonDescriptionHtml(spell.description)
: "";
return (
<div className="space-y-2">
<div className="font-black text-[#f0d878]">
{spell?.name ?? `스펠 ${spellId}`}
</div>
{descriptionHtml ? (
<div
className="text-white/80 [&_br]:block [&_br]:content-['']"
dangerouslySetInnerHTML={{ __html: descriptionHtml }}
/>
) : (
<div className="text-white/55">
스펠 상세 정보를 불러오는 중입니다.
</div>
)}
</div>
);
}
function RuneTooltipContent({
runeId,
manifest,
}: {
runeId: number | undefined;
manifest: DdragonManifest | null | undefined;
}) {
const rune = runeDetails(manifest, runeId);
const descriptionHtml = rune?.longDesc
? safeDdragonDescriptionHtml(rune.longDesc)
: "";
return (
<div className="space-y-2">
<div className="font-black text-[#f0d878]">
{rune?.name ?? (runeId ? `룬 ${runeId}` : "룬")}
</div>
{rune?.shortDesc ? (
<div className="font-bold text-white">{rune.shortDesc}</div>
) : null}
{descriptionHtml ? (
<div
className="text-white/80 [&_br]:block [&_br]:content-['']"
dangerouslySetInnerHTML={{ __html: descriptionHtml }}
/>
) : (
<div className="text-white/55">룬 상세 정보를 불러오는 중입니다.</div>
)}
</div>
);
}
function RuneStyleTooltipContent({
styleId,
manifest,
}: {
styleId: number | undefined;
manifest: DdragonManifest | null | undefined;
}) {
const style = runeStyleDetails(manifest, styleId);
return (
<div className="space-y-2">
<div className="font-black text-[#f0d878]">
{style?.name ?? (styleId ? `룬 ${styleId}` : "룬")}
</div>
<div className="text-white/55">룬 스타일</div>
</div>
);
}
function ItemTooltipContent({
itemId,
manifest,
+27 -4
View File
@@ -98,21 +98,44 @@ export function summonerSpellIconUrl(
return `${cdn(manifest)}/${version(manifest)}/img/spell/${spell.key}.png`;
}
export function summonerSpellDetails(
manifest: DdragonManifest | null | undefined,
spellId: number,
) {
if (!spellId) return null;
return manifest?.summonerSpells[String(spellId)] ?? null;
}
export function runeStyleDetails(
manifest: DdragonManifest | null | undefined,
styleId: number | undefined,
) {
return manifest?.runesReforged.find((entry) => entry.id === styleId) ?? null;
}
export function runeStyleIconUrl(
manifest: DdragonManifest | null | undefined,
styleId: number | undefined,
) {
const style = manifest?.runesReforged.find((entry) => entry.id === styleId);
const style = runeStyleDetails(manifest, styleId);
return style ? `${cdn(manifest)}/img/${style.icon}` : null;
}
export function runeDetails(
manifest: DdragonManifest | null | undefined,
runeId: number | undefined,
) {
if (!runeId) return null;
return manifest?.runesReforged
.flatMap((style) => style.slots.flatMap((slot) => slot.runes))
.find((entry) => entry.id === runeId) ?? null;
}
export function runeKeystoneIconUrl(
manifest: DdragonManifest | null | undefined,
runeId: number | undefined,
) {
const rune = manifest?.runesReforged
.flatMap((style) => style.slots.flatMap((slot) => slot.runes))
.find((entry) => entry.id === runeId);
const rune = runeDetails(manifest, runeId);
return rune ? `${cdn(manifest)}/img/${rune.icon}` : null;
}
+15 -37
View File
@@ -17,9 +17,6 @@ import { DEFAULT_COMMUNITY_ID } from "../config";
import {
championDisplayName,
championIconUrl,
runeKeystoneIconUrl,
runeStyleIconUrl,
summonerSpellIconUrl,
} from "../lib/ddragon";
import {
sideShortLabel,
@@ -36,7 +33,12 @@ import {
InternalGameDetailTabBar,
type InternalGameDetailTab,
} from "../components/InternalGameAnalysisTabs";
import { ItemIcon } from "../components/ItemTooltip";
import {
ItemIcon,
RuneIcon,
RuneStyleIcon,
SummonerSpellIcon,
} from "../components/ItemTooltip";
type MatchGameDetail = ApiInternalMatchDetailResponse["games"][number];
type MatchGameTeam = MatchGameDetail["teams"][number];
@@ -258,47 +260,23 @@ function SpellRuneStrip({
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const spellIcons = participant.summonerSpells
.map((spellId) => summonerSpellIconUrl(manifest, spellId))
.filter((icon): icon is string => Boolean(icon));
const runeIcons = [
runeKeystoneIconUrl(manifest, participant.perks.keystone),
runeStyleIconUrl(manifest, participant.perks.subStyle),
].filter((icon): icon is string => Boolean(icon));
return (
<div className="flex items-center gap-1.5">
<div className="grid grid-cols-1 gap-0.5">
{[0, 1].map((index) => (
<span
<SummonerSpellIcon
key={`spell-${index}`}
className="h-5 w-5 overflow-hidden bg-base-content/10"
>
{spellIcons[index] ? (
<img
src={spellIcons[index]}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
spellId={participant.summonerSpells[index] ?? 0}
manifest={manifest}
/>
))}
</div>
<div className="grid grid-cols-1 gap-0.5">
{[0, 1].map((index) => (
<span
key={`rune-${index}`}
className="h-5 w-5 overflow-hidden bg-base-content/10"
>
{runeIcons[index] ? (
<img
src={runeIcons[index]}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
))}
<RuneIcon runeId={participant.perks.keystone} manifest={manifest} />
<RuneStyleIcon
styleId={participant.perks.subStyle ?? participant.perks.primaryStyle}
manifest={manifest}
/>
</div>
</div>
);
+28 -65
View File
@@ -32,9 +32,6 @@ import {
championDisplayName,
championIconUrl,
profileIconUrl,
runeKeystoneIconUrl,
runeStyleIconUrl,
summonerSpellIconUrl,
} from "../lib/ddragon";
import {
isRiotQueueGroup,
@@ -49,7 +46,12 @@ import {
InternalGameDetailTabBar,
type InternalGameDetailTab,
} from "../components/InternalGameAnalysisTabs";
import { ItemIcon } from "../components/ItemTooltip";
import {
ItemIcon,
RuneIcon,
RuneStyleIcon,
SummonerSpellIcon,
} from "../components/ItemTooltip";
// recharts가 무거워 메인 번들에서 분리한다 (전적 페이지에서만 로드).
const TierHistoryChart = lazy(() => import("../components/TierHistoryChart"));
@@ -482,33 +484,6 @@ function barPercent(value: number, max: number) {
return Math.max(0, Math.min(100, Math.round((value / max) * 100)));
}
function AssetIcon({
url,
label,
className = "w-4 h-4",
}: {
url: string | null;
label: string;
className?: string;
}) {
return (
<div
className={`${className} bg-base-content/8 overflow-hidden border border-base-content/5`}
title={label}
aria-label={label}
>
{url ? (
<img
src={url}
alt=""
className="w-full h-full object-cover"
loading="lazy"
/>
) : null}
</div>
);
}
function LoadoutIcons({
summonerSpells,
perks,
@@ -520,25 +495,12 @@ function LoadoutIcons({
}) {
return (
<div className="grid grid-cols-2 gap-0.5 shrink-0">
<AssetIcon
url={summonerSpellIconUrl(manifest, summonerSpells[0])}
label="스펠 1"
className="w-5 h-5"
/>
<AssetIcon
url={runeKeystoneIconUrl(manifest, perks.keystone)}
label="핵심 룬"
className="w-5 h-5"
/>
<AssetIcon
url={summonerSpellIconUrl(manifest, summonerSpells[1])}
label="스펠 2"
className="w-5 h-5"
/>
<AssetIcon
url={runeStyleIconUrl(manifest, perks.subStyle ?? perks.primaryStyle)}
label="보조 룬"
className="w-5 h-5"
<SummonerSpellIcon spellId={summonerSpells[0]} manifest={manifest} />
<RuneIcon runeId={perks.keystone} manifest={manifest} />
<SummonerSpellIcon spellId={summonerSpells[1]} manifest={manifest} />
<RuneStyleIcon
styleId={perks.subStyle ?? perks.primaryStyle}
manifest={manifest}
/>
</div>
);
@@ -654,24 +616,25 @@ function ParticipantRow({
)}
</div>
<div className="grid grid-cols-2 gap-0.5 shrink-0">
<AssetIcon
url={summonerSpellIconUrl(manifest, participant.summonerSpells[0])}
label="스펠 1"
<SummonerSpellIcon
spellId={participant.summonerSpells[0]}
manifest={manifest}
className="h-4 w-4"
/>
<AssetIcon
url={runeKeystoneIconUrl(manifest, participant.perks.keystone)}
label="핵심 룬"
<RuneIcon
runeId={participant.perks.keystone}
manifest={manifest}
className="h-4 w-4"
/>
<AssetIcon
url={summonerSpellIconUrl(manifest, participant.summonerSpells[1])}
label="스펠 2"
<SummonerSpellIcon
spellId={participant.summonerSpells[1]}
manifest={manifest}
className="h-4 w-4"
/>
<AssetIcon
url={runeStyleIconUrl(
manifest,
participant.perks.subStyle ?? participant.perks.primaryStyle,
)}
label="보조 룬"
<RuneStyleIcon
styleId={participant.perks.subStyle ?? participant.perks.primaryStyle}
manifest={manifest}
className="h-4 w-4"
/>
</div>
<div className="min-w-0">