Replace the combined "Round N — Name" string with a three-zone flex layout:
left (prev button + R{n} pill badge), center (prominent combatant name with
truncation), right (action buttons + next button). Adds 13 unit tests
covering all user stories including layout robustness and empty state.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
102 lines
3.0 KiB
TypeScript
102 lines
3.0 KiB
TypeScript
import type { Encounter } from "@initiative/domain";
|
|
import { Settings, StepBack, StepForward, Trash2 } from "lucide-react";
|
|
import { D20Icon } from "./d20-icon";
|
|
import { Button } from "./ui/button";
|
|
import { ConfirmButton } from "./ui/confirm-button";
|
|
|
|
interface TurnNavigationProps {
|
|
encounter: Encounter;
|
|
onAdvanceTurn: () => void;
|
|
onRetreatTurn: () => void;
|
|
onClearEncounter: () => void;
|
|
onRollAllInitiative: () => void;
|
|
onOpenSourceManager: () => void;
|
|
}
|
|
|
|
export function TurnNavigation({
|
|
encounter,
|
|
onAdvanceTurn,
|
|
onRetreatTurn,
|
|
onClearEncounter,
|
|
onRollAllInitiative,
|
|
onOpenSourceManager,
|
|
}: TurnNavigationProps) {
|
|
const hasCombatants = encounter.combatants.length > 0;
|
|
const isAtStart = encounter.roundNumber === 1 && encounter.activeIndex === 0;
|
|
const activeCombatant = encounter.combatants[encounter.activeIndex];
|
|
|
|
return (
|
|
<div className="flex items-center gap-3 rounded-md border border-border bg-card px-4 py-3">
|
|
<div className="flex flex-shrink-0 items-center gap-3">
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="h-8 w-8 text-foreground border-foreground hover:text-hover-action hover:border-hover-action hover:bg-transparent"
|
|
onClick={onRetreatTurn}
|
|
disabled={!hasCombatants || isAtStart}
|
|
title="Previous turn"
|
|
aria-label="Previous turn"
|
|
>
|
|
<StepBack className="h-5 w-5" />
|
|
</Button>
|
|
<span className="rounded-full bg-muted text-foreground text-sm px-2 py-0.5 font-semibold">
|
|
R{encounter.roundNumber}
|
|
</span>
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 text-center text-sm">
|
|
{activeCombatant ? (
|
|
<span className="truncate block font-medium">
|
|
{activeCombatant.name}
|
|
</span>
|
|
) : (
|
|
<span className="text-muted-foreground">No combatants</span>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex flex-shrink-0 items-center gap-3">
|
|
<div className="flex items-center gap-0">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8 text-muted-foreground hover:text-hover-action"
|
|
onClick={onRollAllInitiative}
|
|
title="Roll all initiative"
|
|
aria-label="Roll all initiative"
|
|
>
|
|
<D20Icon className="h-6 w-6" />
|
|
</Button>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8 text-muted-foreground hover:text-hover-neutral"
|
|
onClick={onOpenSourceManager}
|
|
title="Manage cached sources"
|
|
aria-label="Manage cached sources"
|
|
>
|
|
<Settings className="h-5 w-5" />
|
|
</Button>
|
|
<ConfirmButton
|
|
icon={<Trash2 className="h-5 w-5" />}
|
|
label="Clear encounter"
|
|
onConfirm={onClearEncounter}
|
|
disabled={!hasCombatants}
|
|
className="h-8 w-8 text-muted-foreground"
|
|
/>
|
|
</div>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="h-8 w-8 text-foreground border-foreground hover:text-hover-action hover:border-hover-action hover:bg-transparent"
|
|
onClick={onAdvanceTurn}
|
|
disabled={!hasCombatants}
|
|
title="Next turn"
|
|
aria-label="Next turn"
|
|
>
|
|
<StepForward className="h-5 w-5" />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|