Replace book icon with name-click stat block toggle and pencil rename
Name click now opens/collapses the stat block panel; a hover-visible pencil icon next to the name handles renaming. Removes the standalone book icon for a cleaner, more intuitive combatant row. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
|||||||
type PlayerIcon,
|
type PlayerIcon,
|
||||||
type RollMode,
|
type RollMode,
|
||||||
} from "@initiative/domain";
|
} from "@initiative/domain";
|
||||||
import { Book, BookOpen, Brain, X } from "lucide-react";
|
import { Brain, Pencil, X } from "lucide-react";
|
||||||
import { type Ref, useCallback, useEffect, useRef, useState } from "react";
|
import { type Ref, useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { useEncounterContext } from "../contexts/encounter-context.js";
|
import { useEncounterContext } from "../contexts/encounter-context.js";
|
||||||
import { useInitiativeRollsContext } from "../contexts/initiative-rolls-context.js";
|
import { useInitiativeRollsContext } from "../contexts/initiative-rolls-context.js";
|
||||||
@@ -47,11 +47,13 @@ function EditableName({
|
|||||||
combatantId,
|
combatantId,
|
||||||
onRename,
|
onRename,
|
||||||
color,
|
color,
|
||||||
|
onToggleStatBlock,
|
||||||
}: Readonly<{
|
}: Readonly<{
|
||||||
name: string;
|
name: string;
|
||||||
combatantId: CombatantId;
|
combatantId: CombatantId;
|
||||||
onRename: (id: CombatantId, newName: string) => void;
|
onRename: (id: CombatantId, newName: string) => void;
|
||||||
color?: string;
|
color?: string;
|
||||||
|
onToggleStatBlock?: () => void;
|
||||||
}>) {
|
}>) {
|
||||||
const [editing, setEditing] = useState(false);
|
const [editing, setEditing] = useState(false);
|
||||||
const [draft, setDraft] = useState(name);
|
const [draft, setDraft] = useState(name);
|
||||||
@@ -89,14 +91,31 @@ function EditableName({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={startEditing}
|
onClick={onToggleStatBlock}
|
||||||
className="cursor-text truncate text-left text-foreground text-sm transition-colors hover:text-hover-neutral"
|
disabled={!onToggleStatBlock}
|
||||||
|
className={cn(
|
||||||
|
"truncate text-left text-sm transition-colors",
|
||||||
|
onToggleStatBlock
|
||||||
|
? "cursor-pointer text-foreground hover:text-hover-neutral"
|
||||||
|
: "cursor-default text-foreground",
|
||||||
|
)}
|
||||||
style={color ? { color } : undefined}
|
style={color ? { color } : undefined}
|
||||||
>
|
>
|
||||||
{name}
|
{name}
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={startEditing}
|
||||||
|
title="Rename"
|
||||||
|
aria-label="Rename"
|
||||||
|
className="inline-flex shrink-0 items-center rounded p-0.5 text-muted-foreground opacity-0 pointer-coarse:opacity-100 transition-colors transition-opacity hover:bg-hover-neutral-bg hover:text-hover-neutral focus:opacity-100 group-hover:opacity-100"
|
||||||
|
>
|
||||||
|
<Pencil size={14} />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,14 +447,22 @@ export function CombatantRow({
|
|||||||
toggleCondition,
|
toggleCondition,
|
||||||
toggleConcentration,
|
toggleConcentration,
|
||||||
} = useEncounterContext();
|
} = useEncounterContext();
|
||||||
const { selectedCreatureId, showCreature } = useSidePanelContext();
|
const { selectedCreatureId, showCreature, toggleCollapse } =
|
||||||
|
useSidePanelContext();
|
||||||
const { handleRollInitiative } = useInitiativeRollsContext();
|
const { handleRollInitiative } = useInitiativeRollsContext();
|
||||||
|
|
||||||
// Derive what was previously conditional props
|
// Derive what was previously conditional props
|
||||||
const isStatBlockOpen = combatant.creatureId === selectedCreatureId;
|
const isStatBlockOpen = combatant.creatureId === selectedCreatureId;
|
||||||
const { creatureId } = combatant;
|
const { creatureId } = combatant;
|
||||||
const onShowStatBlock = creatureId
|
const hasStatBlock = !!creatureId;
|
||||||
? () => showCreature(creatureId)
|
const onToggleStatBlock = hasStatBlock
|
||||||
|
? () => {
|
||||||
|
if (isStatBlockOpen) {
|
||||||
|
toggleCollapse();
|
||||||
|
} else {
|
||||||
|
showCreature(creatureId);
|
||||||
|
}
|
||||||
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
const onRollInitiative = combatant.creatureId
|
const onRollInitiative = combatant.creatureId
|
||||||
? handleRollInitiative
|
? handleRollInitiative
|
||||||
@@ -517,17 +544,6 @@ export function CombatantRow({
|
|||||||
dimmed && "opacity-50",
|
dimmed && "opacity-50",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{!!onShowStatBlock && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onShowStatBlock}
|
|
||||||
title="View stat block"
|
|
||||||
aria-label="View stat block"
|
|
||||||
className="shrink-0 text-foreground transition-colors hover:text-hover-neutral"
|
|
||||||
>
|
|
||||||
{isStatBlockOpen ? <BookOpen size={16} /> : <Book size={16} />}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
{!!combatant.icon &&
|
{!!combatant.icon &&
|
||||||
!!combatant.color &&
|
!!combatant.color &&
|
||||||
(() => {
|
(() => {
|
||||||
@@ -549,6 +565,7 @@ export function CombatantRow({
|
|||||||
combatantId={id}
|
combatantId={id}
|
||||||
onRename={editCombatant}
|
onRename={editCombatant}
|
||||||
color={pcColor}
|
color={pcColor}
|
||||||
|
onToggleStatBlock={onToggleStatBlock}
|
||||||
/>
|
/>
|
||||||
<ConditionTags
|
<ConditionTags
|
||||||
conditions={combatant.conditions}
|
conditions={combatant.conditions}
|
||||||
|
|||||||
Reference in New Issue
Block a user