npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mdwebb/react-chess

v2.0.4

Published

Feature-rich React chess board component with chessground and chess.js

Downloads

1,099

Readme

@mdwebb/react-chess

A feature-rich, highly configurable React chess board component powered by chessground and chess.js.

Features

  • Custom Themes — 4 built-in presets or create your own with custom colors
  • PGN Support — Load games with annotations, NAG symbols, comments, and metadata
  • Compound Components — Compose Board, MoveHistory, Navigation independently
  • Promotion UI — Visual piece selection dialog for pawn promotions
  • Keyboard Navigation — Arrow keys and Home/End to step through moves
  • Game CallbacksonCheck, onGameOver, onIllegalMove, onPromotion, onFlip
  • Board Flip — Toggle orientation via button, prop, or ref
  • Full TypeScript — Every prop, callback, and ref fully typed

Installation

npm install @mdwebb/react-chess
# or
pnpm add @mdwebb/react-chess
# or
yarn add @mdwebb/react-chess

React 17, 18, or 19 is supported as a peer dependency.

Quick Start

import { Chessboard } from "@mdwebb/react-chess";
import "@mdwebb/react-chess/styles";

function App() {
  return (
    <Chessboard
      width={400}
      height={400}
      theme="brown"
      showMoveHistory
      showNavigation
      showBoardControls
      onMove={(from, to, move) => {
        console.log(move.san);
      }}
      onGameOver={(result) => {
        console.log(result.reason);
      }}
    />
  );
}

CSS Setup

Import the bundled stylesheet — it includes chessground base styles, piece assets, and component CSS:

import "@mdwebb/react-chess/styles";

Note: the Chessboard and Board components must not be wrapped in animation/motion containers (e.g. framer-motion's motion.div, custom FadeIn wrappers). Chessground manipulates the DOM directly and these wrappers break its layout. Apply animations elsewhere.

Usage

Basic Board

<Chessboard width={400} height={400} theme="brown" />

PGN Viewer

<Chessboard
  pgn={pgnString}
  theme="blue"
  showMoveHistory
  showNavigation
  showBoardControls
  enableKeyboardNavigation
  moveHistoryWidth="350px"
/>

Custom Theme

<Chessboard
  theme={{
    lightSquare: "#f0d9b5",
    darkSquare: "#b58863",
    selectedSquare: "rgba(20, 85, 30, 0.5)",
    lastMoveHighlight: "rgba(155, 199, 0, 0.41)",
    moveDestination: "rgba(20, 85, 30, 0.5)",
  }}
/>

Compound Components

For fully custom layouts, compose the primitives yourself:

import {
  ChessProvider,
  Board,
  MoveHistory,
  Navigation,
  BoardControls,
} from "@mdwebb/react-chess";

function CustomLayout() {
  return (
    <ChessProvider pgn={pgn} theme="blue">
      <div style={{ display: "grid", gridTemplateColumns: "450px 1fr" }}>
        <Board width={450} height={450} />
        <MoveHistory />
      </div>
      <Navigation />
      <BoardControls />
    </ChessProvider>
  );
}

Game Callbacks

<Chessboard
  onMove={(from, to, move) => console.log(move.san)}
  onCheck={(color) => console.log(`${color} in check`)}
  onGameOver={(result) => console.log(result.reason)}
  onPromotion={(from, to, piece) => console.log(`Promoted to ${piece}`)}
  onIllegalMove={(from, to) => console.log("Illegal")}
  onFlip={(orientation) => console.log(orientation)}
  onPositionChange={(fen, moves) => console.log(fen)}
/>

Ref Access

import { useRef } from "react";
import { Chessboard, ChessboardRef } from "@mdwebb/react-chess";

function App() {
  const ref = useRef<ChessboardRef>(null);

  return (
    <>
      <Chessboard ref={ref} />
      <button onClick={() => ref.current?.flip()}>Flip</button>
      <button onClick={() => ref.current?.goFirst()}>First</button>
      <button onClick={() => console.log(ref.current?.game?.fen())}>
        Log FEN
      </button>
    </>
  );
}

API Reference

Chessboard props

| Prop | Type | Default | Description | |------|------|---------|-------------| | width | string \| number | '400px' | Board width | | height | string \| number | '400px' | Board height | | theme | ChessboardThemePreset \| CustomTheme | 'brown' | "brown", "blue", "green", "gray", or a custom theme object | | fen | string | 'start' | FEN string for the position | | pgn | string | — | PGN notation to load a game | | orientation | 'white' \| 'black' | 'white' | Board orientation | | showMoveHistory | boolean | false | Show move history panel | | showNavigation | boolean | false | Show navigation controls | | showBoardControls | boolean | false | Show board flip button | | showCoordinates | boolean | true | Show rank/file labels | | layout | 'horizontal' \| 'vertical' \| 'board-only' | 'horizontal' | Layout arrangement | | moveHistoryWidth | string \| number | '300px' | Width of the move history panel | | autoPromoteToQueen | boolean | false | Skip promotion dialog | | enableKeyboardNavigation | boolean | true | Arrow key navigation |

Callbacks

| Callback | Type | Description | |----------|------|-------------| | onMove | (from, to, move) => void | Fired after a legal move | | onPositionChange | (fen, moves) => void | Fired when position changes | | onCheck | (color) => void | Fired when a player is in check | | onGameOver | (result) => void | Fired on checkmate, stalemate, draw | | onIllegalMove | (from, to) => void | Fired on illegal move attempt | | onPromotion | (from, to, piece) => void | Fired when a pawn promotes | | onFlip | (orientation) => void | Fired when board is flipped |

Style overrides

| Prop | Type | Description | |------|------|-------------| | className | string | Container class | | boardClassName | string | Board wrapper class | | boardStyle | CSSProperties | Board wrapper inline styles | | moveHistoryClassName | string | Move history class | | moveHistoryStyle | CSSProperties | Move history inline styles | | navigationClassName | string | Navigation class | | navigationStyle | CSSProperties | Navigation inline styles |

Ref methods

interface ChessboardRef {
  api: Api | null;           // Chessground API
  game: Chess | null;        // chess.js instance
  flip: () => void;
  navigateToMove: (i: number) => void;
  goFirst: () => void;
  goPrevious: () => void;
  goNext: () => void;
  goLast: () => void;
}

Exports

// Components
import {
  Chessboard,
  ChessProvider,
  useChess,
  Board,
  MoveHistory,
  Navigation,
  BoardControls,
} from "@mdwebb/react-chess";

// Theme utilities
import {
  resolveTheme,
  themePresets,
  themeToCSSSVars,
  generateBoardSVG,
} from "@mdwebb/react-chess";

// Hooks
import { useKeyboardNavigation } from "@mdwebb/react-chess";

// Types
import type {
  ChessboardProps,
  ChessboardRef,
  ChessboardTheme,
  ChessboardThemePreset,
  CustomTheme,
  ChessboardLayout,
  ChessboardCallbacks,
  ChessProviderProps,
  BoardProps,
  MoveHistoryProps,
  NavigationProps,
  BoardControlsProps,
  PromotionDialogProps,
  PieceColor,
  PromotionPiece,
  GameOverResult,
  PGNMetadata,
  PGNHeaders,
  ChessContextValue,
} from "@mdwebb/react-chess";

Contributing

This package lives in the react-chess monorepo. See CONTRIBUTING.md for the dev loop, build pipeline, and release flow.

License

MIT © Matt Webb