Implement the 032-inline-confirm-buttons feature that replaces single-click destructive actions with a reusable ConfirmButton component providing inline two-step confirmation (click to arm, click to execute), applied to the remove combatant and clear encounter buttons, with CSS scale pulse animation, 5-second auto-revert, click-outside/Escape/blur dismissal, full keyboard accessibility, and 13 unit tests via @testing-library/react

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-11 09:51:21 +01:00
parent d101906776
commit 0747d044f3
17 changed files with 1364 additions and 32 deletions

View File

@@ -0,0 +1,40 @@
# Quickstart: Inline Confirmation Buttons
## What This Feature Does
Replaces single-click destructive actions and browser `window.confirm()` dialogs with inline two-step confirmation buttons. Click once to arm, click again to execute. The button visually transforms (checkmark icon, red background, scale pulse) to signal the armed state, and auto-reverts after 5 seconds.
## Files to Create
- `apps/web/src/components/ui/confirm-button.tsx` — Reusable ConfirmButton component
## Files to Modify
- `apps/web/src/components/combatant-row.tsx` — Replace remove Button with ConfirmButton
- `apps/web/src/components/turn-navigation.tsx` — Replace trash Button with ConfirmButton
- `apps/web/src/hooks/use-encounter.ts` — Remove `window.confirm()` from clearEncounter
- `apps/web/src/index.css` — Add scale pulse keyframe animation
## How to Test
```bash
# Run all tests
pnpm test
# Run the dev server and test manually
pnpm --filter web dev
# 1. Add a combatant
# 2. Click the X button — should enter red confirm state
# 3. Click again — combatant removed
# 4. Click X, wait 5 seconds — should revert
# 5. Click trash button — same confirm behavior for clearing encounter
# 6. Test keyboard: Tab to button, Enter, Enter (confirm), Escape (cancel)
```
## Key Design Decisions
- ConfirmButton wraps the existing `Button` component (no new base component)
- Confirm state is local `useState` — no shared state or context needed
- Click-outside detection follows the `HpAdjustPopover` pattern (mousedown listener)
- Animation uses CSS `@keyframes` + `@utility` like existing animations
- Uses `bg-destructive text-primary-foreground` for the confirm state