feat(map): redesign world picker cards with overflow tooltips
Redesign the World Map picker as 4:3 cards with cover imagery, a classification strip (REF code + campaign), corner brackets, and a readout footer (size/weather/access/faction). Add OverflowTooltip, a hover tooltip that only opens when the value is actually clipped, so truncated readouts stay readable.
This commit is contained in:
parent
eff7aea914
commit
4673aa7a66
2 changed files with 212 additions and 63 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
import config from "@payload-config";
|
import config from "@payload-config";
|
||||||
import { getPayload } from "payload";
|
import { getPayload } from "payload";
|
||||||
import { Fragment } from "react";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Map as MapIcon, MapPinIcon } from "lucide-react";
|
import { Map as MapIcon, MapPinIcon } from "lucide-react";
|
||||||
import type { Campaign, Faction, Map as MapDoc, Media } from "@/payload-types";
|
import type { Campaign, Faction, Map as MapDoc, Media } from "@/payload-types";
|
||||||
|
import { OverflowTooltip } from "@/components/frontend/map/OverflowTooltip";
|
||||||
import {
|
import {
|
||||||
easeStatClass,
|
easeStatClass,
|
||||||
isWorldMapEntry,
|
isWorldMapEntry,
|
||||||
|
|
@ -38,6 +38,13 @@ function tilePreviewUrls(template: string): string[] | null {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ReadoutCell {
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
cls?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default async function MapPickerPage() {
|
export default async function MapPickerPage() {
|
||||||
const payload = await getPayload({ config: await config });
|
const payload = await getPayload({ config: await config });
|
||||||
|
|
||||||
|
|
@ -54,12 +61,15 @@ export default async function MapPickerPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-[240px] flex-1 flex-col">
|
<div className="flex min-h-[240px] flex-1 flex-col">
|
||||||
<div className="flex items-center justify-between gap-3 border-b border-white/15 bg-black/50 px-5 py-2 backdrop-blur-sm" data-tour="map-picker-header">
|
<div
|
||||||
|
className="flex items-center justify-between gap-3 border-b border-white/15 bg-black/50 px-5 py-2 backdrop-blur-sm"
|
||||||
|
data-tour="map-picker-header"
|
||||||
|
>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<MapIcon className="size-4 text-muted-foreground" />
|
<MapIcon className="size-4 text-muted-foreground" />
|
||||||
<h1 className="text-sm font-semibold uppercase tracking-[0.2em]">World Map</h1>
|
<h1 className="text-sm font-semibold uppercase tracking-[0.2em]">World Map</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-4 font-mono text-[9px] uppercase tracking-[0.2em] text-white/60">
|
<div className="flex items-center gap-4 font-mono text-[9px] uppercase tracking-widest text-white/60">
|
||||||
<span>PTF Unit Command // Tactical Grid</span>
|
<span>PTF Unit Command // Tactical Grid</span>
|
||||||
<span>
|
<span>
|
||||||
{maps.length} Active Grid{maps.length === 1 ? "" : "s"}
|
{maps.length} Active Grid{maps.length === 1 ? "" : "s"}
|
||||||
|
|
@ -76,7 +86,10 @@ export default async function MapPickerPage() {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 gap-4 p-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4" data-tour="map-picker-grid">
|
<div
|
||||||
|
className="grid grid-cols-1 gap-4 p-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
|
||||||
|
data-tour="map-picker-grid"
|
||||||
|
>
|
||||||
{maps.map((map) => {
|
{maps.map((map) => {
|
||||||
const campaign =
|
const campaign =
|
||||||
map.campaign && typeof map.campaign === "object" ? (map.campaign as Campaign) : null;
|
map.campaign && typeof map.campaign === "object" ? (map.campaign as Campaign) : null;
|
||||||
|
|
@ -89,92 +102,159 @@ export default async function MapPickerPage() {
|
||||||
map.basemapMode === "tiles" && map.tileUrlTemplate
|
map.basemapMode === "tiles" && map.tileUrlTemplate
|
||||||
? tilePreviewUrls(map.tileUrlTemplate)
|
? tilePreviewUrls(map.tileUrlTemplate)
|
||||||
: null;
|
: null;
|
||||||
const stats = [
|
const refCode = String(map.id).padStart(3, "0");
|
||||||
map.weather
|
|
||||||
? {
|
// Readout footer cells: size is always known, intel fields join when set.
|
||||||
key: `w-${map.id}`,
|
const cells: ReadoutCell[] = [
|
||||||
label: weatherStatLabel(map.weather),
|
{
|
||||||
cls: weatherStatClass(map.weather),
|
key: `s-${map.id}`,
|
||||||
}
|
value: `${map.worldSizeWidth}×${map.worldSizeHeight}`,
|
||||||
: null,
|
label: "M",
|
||||||
map.easeOfAccess
|
},
|
||||||
? {
|
];
|
||||||
key: `e-${map.id}`,
|
if (map.weather) {
|
||||||
label: `${map.easeOfAccess} access`,
|
cells.push({
|
||||||
cls: easeStatClass(map.easeOfAccess),
|
key: `w-${map.id}`,
|
||||||
}
|
value: weatherStatLabel(map.weather),
|
||||||
: null,
|
label: "WX",
|
||||||
faction ? { key: `f-${map.id}`, label: faction.name, cls: "text-violet-400" } : null,
|
cls: weatherStatClass(map.weather),
|
||||||
].filter((stat) => stat !== null);
|
});
|
||||||
|
}
|
||||||
|
if (map.easeOfAccess) {
|
||||||
|
cells.push({
|
||||||
|
key: `e-${map.id}`,
|
||||||
|
value: map.easeOfAccess,
|
||||||
|
label: "Access",
|
||||||
|
cls: easeStatClass(map.easeOfAccess),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (faction) {
|
||||||
|
cells.push({
|
||||||
|
key: `f-${map.id}`,
|
||||||
|
value: faction.name,
|
||||||
|
label: "Ctrl",
|
||||||
|
cls: "text-violet-400",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={map.id}
|
key={map.id}
|
||||||
href={`/map/${map.id}`}
|
href={`/map/${map.id}`}
|
||||||
className="group overflow-hidden rounded-lg border border-border bg-card transition-all duration-200 hover:scale-[1.01] hover:border-primary/40"
|
aria-label={`Open map ${map.name}`}
|
||||||
|
className="group relative block aspect-[4/3] overflow-hidden rounded-none border border-border/70 bg-card transition-colors duration-300 hover:border-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||||
>
|
>
|
||||||
<div className="relative aspect-video w-full overflow-hidden bg-muted">
|
{/* Cover imagery: basemap photo or zoom-1 tile mosaic, dimmed under the overlays */}
|
||||||
|
<div className="absolute inset-0 scale-100 transition-transform duration-500 ease-out group-hover:scale-110 motion-reduce:transition-none motion-reduce:group-hover:scale-100">
|
||||||
{url ? (
|
{url ? (
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
<img
|
<img
|
||||||
src={url}
|
src={url}
|
||||||
alt={map.name}
|
alt=""
|
||||||
className="size-full object-cover opacity-80 transition-opacity group-hover:opacity-100"
|
aria-hidden="true"
|
||||||
|
className="absolute inset-0 size-full object-cover opacity-60 transition-opacity duration-500 ease-out group-hover:opacity-80 motion-reduce:transition-none"
|
||||||
/>
|
/>
|
||||||
) : tileUrls ? (
|
) : tileUrls ? (
|
||||||
<div
|
<div
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className="absolute inset-0 flex items-center justify-center overflow-hidden"
|
className="absolute inset-0 flex items-center justify-center overflow-hidden"
|
||||||
>
|
>
|
||||||
<div className="grid size-[512px] max-w-none grid-cols-2 opacity-80 transition-opacity group-hover:opacity-100">
|
{/* Square mosaic sized to the card width so it always covers the
|
||||||
|
4:3 frame (vertical overflow is cropped), like object-cover. */}
|
||||||
|
<div className="grid aspect-square w-full max-w-none grid-cols-2 opacity-60 transition-opacity duration-500 ease-out group-hover:opacity-80 motion-reduce:transition-none">
|
||||||
{tileUrls.map((tileUrl) => (
|
{tileUrls.map((tileUrl) => (
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
<img key={tileUrl} src={tileUrl} alt="" className="size-[256px]" />
|
<img key={tileUrl} src={tileUrl} alt="" className="h-auto w-full" />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex size-full items-center justify-center text-muted-foreground">
|
<div className="flex size-full items-center justify-center text-muted-foreground">
|
||||||
<MapIcon className="size-8 opacity-40" />
|
<MapIcon className="size-8 opacity-30" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="border-t border-border px-3 py-2">
|
|
||||||
<div className="flex items-center justify-between gap-2">
|
{/* Legibility gradient */}
|
||||||
<p className="truncate text-sm font-semibold">{map.name}</p>
|
<div
|
||||||
<span className="shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground">
|
aria-hidden="true"
|
||||||
{map.worldSizeWidth}×{map.worldSizeHeight} m
|
className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/60 to-black/25"
|
||||||
</span>
|
/>
|
||||||
|
|
||||||
|
{/* Faint tactical grid texture (constant, never brightens) */}
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
className="pointer-events-none absolute inset-0 z-[5] opacity-[0.04]"
|
||||||
|
style={{
|
||||||
|
backgroundImage:
|
||||||
|
"linear-gradient(to right, white 1px, transparent 1px), linear-gradient(to bottom, white 1px, transparent 1px)",
|
||||||
|
backgroundSize: "28px 28px",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Classification strip */}
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
className="absolute inset-x-0 top-0 z-20 flex items-center justify-between gap-2 border-b border-white/15 bg-black/50 px-3 py-1.5 backdrop-blur-sm"
|
||||||
|
>
|
||||||
|
<OverflowTooltip
|
||||||
|
text={campaign ? `Campaign // ${campaign.name}` : "Grid // Unit Command"}
|
||||||
|
triggerClassName="truncate font-mono text-[9px] uppercase tracking-widest text-white/60"
|
||||||
|
textClassName="font-mono text-[9px] uppercase tracking-widest text-white/60"
|
||||||
|
/>
|
||||||
|
<span className="shrink-0 font-mono text-[9px] uppercase tracking-widest text-white/60">
|
||||||
|
REF {refCode}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Corner brackets */}
|
||||||
|
<div aria-hidden="true" className="pointer-events-none absolute inset-2 z-30">
|
||||||
|
<span className="absolute left-0 top-0 size-3 border-l border-t border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||||||
|
<span className="absolute right-0 top-0 size-3 border-r border-t border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||||||
|
<span className="absolute bottom-0 left-0 size-3 border-b border-l border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||||||
|
<span className="absolute bottom-0 right-0 size-3 border-b border-r border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Title block */}
|
||||||
|
<div className="absolute inset-0 z-10 flex items-center justify-center px-8 pb-10 pt-8 text-center">
|
||||||
|
<div className="flex max-w-full flex-col items-center gap-1.5">
|
||||||
|
<h2 className="text-balance text-lg font-bold text-white drop-shadow-lg">
|
||||||
|
{map.name}
|
||||||
|
</h2>
|
||||||
|
{map.description && (
|
||||||
|
<OverflowTooltip
|
||||||
|
text={map.description}
|
||||||
|
triggerClassName="line-clamp-2 max-w-prose text-pretty text-xs text-white/70 drop-shadow"
|
||||||
|
textClassName="text-xs text-white/80"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="font-mono text-[10px] uppercase tracking-wider text-muted-foreground">
|
|
||||||
{campaign ? campaign.name : "Unit grid"}
|
|
||||||
</p>
|
|
||||||
{map.description && (
|
|
||||||
<p className="mt-1 line-clamp-2 text-xs text-muted-foreground">
|
|
||||||
{map.description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{stats.length > 0 && (
|
|
||||||
<div className="mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 border-t border-border/60 pt-1.5">
|
|
||||||
{stats.map((stat, index) => (
|
|
||||||
<Fragment key={stat.key}>
|
|
||||||
{index > 0 && (
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className="font-mono text-[10px] text-white/25"
|
|
||||||
>
|
|
||||||
•
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<span
|
|
||||||
className={`font-mono text-[10px] uppercase tracking-wider ${stat.cls}`}
|
|
||||||
>
|
|
||||||
{stat.label}
|
|
||||||
</span>
|
|
||||||
</Fragment>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Readout footer */}
|
||||||
|
<footer className="absolute inset-x-0 bottom-0 z-20 flex items-stretch border-t border-white/15 bg-black/60 px-2 py-1.5 backdrop-blur-sm">
|
||||||
|
{cells.map((cell, index) => (
|
||||||
|
<div
|
||||||
|
key={cell.key}
|
||||||
|
className={`flex min-w-0 flex-1 items-center justify-center gap-1.5 px-1${
|
||||||
|
index < cells.length - 1 ? " border-r border-white/15" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<OverflowTooltip
|
||||||
|
text={cell.value}
|
||||||
|
triggerClassName={`min-w-0 truncate font-mono text-xs tabular-nums uppercase tracking-wider ${
|
||||||
|
cell.cls ?? "text-white/80"
|
||||||
|
}`}
|
||||||
|
textClassName={`font-mono text-[10px] uppercase tracking-wider ${
|
||||||
|
cell.cls ?? "text-white/80"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<span className="shrink-0 text-[9px] uppercase tracking-wider text-white/50">
|
||||||
|
{cell.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</footer>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
69
src/components/frontend/map/OverflowTooltip.tsx
Normal file
69
src/components/frontend/map/OverflowTooltip.tsx
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRef, useState } from "react";
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
|
||||||
|
interface OverflowTooltipProps {
|
||||||
|
/** Full text; shown in the tooltip only when it is actually clipped. */
|
||||||
|
readonly text: string;
|
||||||
|
/** Classes for the inline trigger span (must carry the truncate/line-clamp utilities). */
|
||||||
|
readonly triggerClassName?: string;
|
||||||
|
/** Typography classes for the tooltip text, mirroring how the value renders on the card. */
|
||||||
|
readonly textClassName?: string;
|
||||||
|
readonly side?: "top" | "bottom";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inline text that reveals a dossier-styled tooltip on hover, but only when
|
||||||
|
* the text is genuinely truncated (horizontal truncate or line clamp).
|
||||||
|
* Used by the World Map picker cards so cut-off readout values stay readable.
|
||||||
|
*/
|
||||||
|
export function OverflowTooltip({
|
||||||
|
text,
|
||||||
|
triggerClassName,
|
||||||
|
textClassName,
|
||||||
|
side = "top",
|
||||||
|
}: OverflowTooltipProps) {
|
||||||
|
const ref = useRef<HTMLSpanElement>(null);
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TooltipProvider delayDuration={150}>
|
||||||
|
<Tooltip
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(next) => {
|
||||||
|
if (!next) {
|
||||||
|
setOpen(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
const clipped =
|
||||||
|
el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1;
|
||||||
|
setOpen(clipped);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span ref={ref} className={triggerClassName}>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
side={side}
|
||||||
|
sideOffset={6}
|
||||||
|
className="max-w-xs rounded-none border-white/20 bg-black/90 px-2.5 py-1.5 text-white/80 backdrop-blur-sm"
|
||||||
|
arrowClassName="rounded-none bg-black/90 fill-black/90"
|
||||||
|
>
|
||||||
|
<span className={textClassName ?? "font-mono text-[10px] uppercase tracking-wider"}>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue