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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ii-react-chessboard

v2.0.3

Published

<h1 align="center">ii-react-chessboard</h1>

Downloads

11

Readme

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";

| Name | Type | Default | Description | | --- | --- | --- | ---| | allowMarkers | boolean | false | allow round markers with right click | | check | boolean|false| true if current position contains check | | clickable | boolean | false | allow click-click moves | | draggable | boolean | false | allow moves & premoves to use drag'n drop | | lastMoveSquares | string[] | [] | squares part of the last move ["c3", "c4"] | | turnColor | "white" | "black" | "white" | turn to play | | maxWidth | number | Infinity | Max width in pixels | | minWidth | number | 160 | Min width in pixels | | movableColor | "white" | "black" | "both" | "both" | color that can move | | onMove | (move: Move) => void | | called after move | | onResize | (width: number) => void| | called after resize | | onSetPremove | (move: Move, playPremove: () => void, cancelPremove: () => void): void | | called after the premove has been set | | onUnsetPremove | () => void | | called after the premove has been unset | | orientation | "white" | "black" | "white" | board orientation | | position | Position | string | {} | FEN string or Position object | | premovable | boolean | false | allow premoves for color that can not move | | resizable | boolean | false | allow resize | | showCoordinates| boolean | true | include coords attributes | | transitionDuration | number | 300 | The time in seconds it takes for a piece to slide to the target square | | validMoves | ValidMoves | {} | valid moves. {"a2" ["a3" "a4"] "b1" ["a3" "c3"]} | | viewOnly | boolean | false | don't bind events: the user will never be able to move pieces around | | width | number | 480 | board 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[]>;