Skip to content

Repository files navigation

@echecs/react-movesheet

React move notation panel — displays chess game moves with click navigation, variations, comments, NAGs, evaluation, clock, and keyboard navigation. Inline styles with CSS variable theming, zero dependencies beyond React and @echecs/pgn.

Installation

npm install @echecs/react-movesheet
# or
pnpm add @echecs/react-movesheet

react >=18 and @echecs/pgn >=4 are peer dependencies.

Quick start

Minimal

importparsefrom'@echecs/pgn';import{MoveSheet}from'@echecs/react-movesheet';const[game]=parse('1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 *');exportfunctionApp(){return<MoveSheetgame={game}/>;}

With navigation

import{useState}from'react';importparsefrom'@echecs/pgn';import{MoveSheet}from'@echecs/react-movesheet';const[game]=parse('1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 *');exportfunctionApp(){const[moveId,setMoveId]=useState<string|undefined>();return(<MoveSheetcurrentMoveId={moveId}game={game}onSelectMove={setMoveId}showCommentsshowNags/>);}

Props

PropTypeDefaultDescription
gamePGNrequiredParsed PGN game from @echecs/pgn
currentMoveIdstringundefinedID of the currently active move
onSelectMove(moveId: string) => voidCalled when a move is clicked
onContextMenu(moveId: string) => voidCalled on right-click of a move
showCommentsbooleantrueShow inline comment text
showEvaluationbooleanfalseShow engine evaluation after moves
showNagsbooleantrueShow NAG glyphs (!, ?, !!, ??)
showClockbooleanfalseShow clock times
keyboardbooleantrueEnable arrow key navigation

Keyboard navigation

When keyboard is enabled and the panel is focused:

KeyAction
RightNext move (main continuation)
LeftPrevious move
DownEnter variation / cycle between variations
UpExit variation (jump to move before the branch)
HomeFirst move
EndLast move in current line

CSS variable theming

All colours are controlled via CSS custom properties on a parent element:

<divstyle={{'--movesheet-background': '#1a1a2e','--movesheet-move-text': '#e0e0e0','--movesheet-active-move': '#3a5a8c','--movesheet-comment': '#8899aa','--movesheet-nag': '#cc8844','--movesheet-evaluation': '#6699cc','--movesheet-variation': '#7788aa','--movesheet-move-number': '#556677',}}><MoveSheetgame={game}/></div>
VariableDefaultDescription
--movesheet-backgroundtransparentPanel background
--movesheet-active-move#d4e8ffActive move bg
--movesheet-move-textinheritMove SAN colour
--movesheet-move-numberinheritMove number colour
--movesheet-comment#666Comment text colour
--movesheet-comment-displayinlineComment display mode
--movesheet-comment-font-styleitalicComment font style
--movesheet-font-familyinheritPanel font family
--movesheet-font-sizeinheritPanel font size
--movesheet-line-height1.6Panel line height
--movesheet-naginheritNAG glyph colour
--movesheet-evaluationgrayEval text colour
--movesheet-variation#888Variation text colour

Utilities

The package also exports tree utilities for advanced use:

import{buildTree,findNode,pathToNode}from'@echecs/react-movesheet';importtype{MoveNode}from'@echecs/react-movesheet';constroot=buildTree(game);constnode=findNode(root,'m3w');constpath=pathToNode(root,'m3w');// [root, m1w, m1b, m2w, m2b, m3w]

Exported types

TypeDescription
Eval{ type: 'cp' | 'mate'; value: number; depth?: number } — engine evaluation
MoveNodeTree node representing a single move, with id, san, side, children, and optional eval/comment/nags/clock
MoveSheetPropsAll props accepted by <MoveSheet />
importtype{Eval,MoveNode,MoveSheetProps}from'@echecs/react-movesheet';

License

MIT

About

React move notation panel — displays chess game moves with click navigation, variations, comments, NAGs, evaluation, and keyboard navigation.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages