2.0.3 • Published 4 years ago

ii-react-chessboard v2.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Customizable React chessboard component

ii-react-chessboard is a React component with a flexible "just a board" API. It's compatible with touch as well as standard HTML5 drag and drop. Live Demo

Usage

Installation

npm install ii-react-chessboard # or yarn add ii-react-chessboard

Example

import { Board } from "ii-react-chessboard";

function App() {
  return (
    <Board position="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" />
  );
}

The code above will render chessboard with starting position:

For more examples please visit our Storybook page

API

Board

import { Board } from "ii-react-chessboard";
NameTypeDefaultDescription
allowMarkersbooleanfalseallow round markers with right click
checkbooleanfalsetrue if current position contains check
clickablebooleanfalseallow click-click moves
draggablebooleanfalseallow moves & premoves to use drag'n drop
lastMoveSquaresstring[][]squares part of the last move "c3", "c4"
turnColor"white" | "black""white"turn to play
maxWidthnumberInfinityMax width in pixels
minWidthnumber160Min width in pixels
movableColor"white" | "black" | "both""both"color that can move
onMove(move: Move) => voidcalled after move
onResize(width: number) => voidcalled after resize
onSetPremove(move: Move, playPremove: () => void, cancelPremove: () => void): voidcalled after the premove has been set
onUnsetPremove() => voidcalled after the premove has been unset
orientation"white" | "black""white"board orientation
positionPosition | string{}FEN string or Position object
premovablebooleanfalseallow premoves for color that can not move
resizablebooleanfalseallow resize
showCoordinatesbooleantrueinclude coords attributes
transitionDurationnumber300The time in seconds it takes for a piece to slide to the target square
validMovesValidMoves{}valid moves. {"a2" "a3" "a4" "b1" "a3" "c3"}
viewOnlybooleanfalsedon't bind events: the user will never be able to move pieces around
widthnumber480board width in pixels

Position Object

import { Position } from "ii-react-chessboard";

You can use a JavaScript object to represent a board position.

The object property names must be algebraic squares (ie: e4, b2, c6, etc) and the values must be valid piece codes (ie: wP, bK, wQ, etc).

FEN String

You can use Forsyth-Edwards Notation (FEN) to represent a board position.

Note that FEN notation captures more information than ii-react-chessboard requires, like who's move it is and whether or not castling is allowed. This information will be ignored; only the position information is used.

Move

import { Move } from "ii-react-chessboard";

Source code:

export interface Move {
  /**
   * The location the piece is moving from.
   * Must be in san format, e.g "h8"
   */
  from: string;

  /**
   * The location the piece is moving to.
   * Must be in san format, e.g "a1"
   */
  to: string;
}

ValidMoves

import { ValidMoves } from "ii-react-chessboard";

Source code:

export type ValidMoves = Record<string, string[]>;
2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

1.3.1

4 years ago

1.1.1

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

2.4.0

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.6.0

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago