项目作者: jniemann66

项目描述 :
Chess Diagram React Component
高级语言: JavaScript
项目地址: git://github.com/jniemann66/react-chessdiagram.git
创建时间: 2016-10-13T00:30:42Z
项目社区:https://github.com/jniemann66/react-chessdiagram

开源协议:MIT License

下载


Build Status

react-chessdiagram

Chess Diagram React Component

LIVE DEMO: http://chessdiagram.juddn.com updated 24-apr-2017

Knight’s Tour Demo: http://knightstour.juddn.com

NPM: https://www.npmjs.com/package/react-chessdiagram

screenshot

A react component that can display chess positions from FEN strings, PGN Strings, or a form of algebraic notation (P@a5 R@h8 etc)

It is almost entirely stateless.
(some state is maintained to keep track of mouse / touch events, and an internal list of moves when displaying a game)

A callback facility is provided to report dragged pieces back to the host application.

API documentation: ./api.md

sample usage

  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Chessdiagram from 'react-chessdiagram';
  4. const lightSquareColor = '#2492FF'; // light blue
  5. const darkSquareColor = '#005EBB'; // dark blue
  6. const currentPosition = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'; // starting position
  7. const flip = false;
  8. const squareSize = 30;
  9. ReactDOM.render(
  10. <Chessdiagram flip={flip} fen={currentPosition} squareSize={squareSize}
  11. lightSquareColor={lightSquareColor} darkSquareColor={darkSquareColor} onMovePiece={onMovePiece}></Chessdiagram>,
  12. document.getElementById('root')
  13. );
  14. function onMovePiece(piece, fromSquare, toSquare) {
  15. let message = 'You moved ' + piece + fromSquare + ' to ' + toSquare + ' !';
  16. console.log(message);
  17. }

build commands:

dev: npm run dev - (output to ./build/dev.chessdiagram.js and served on http://localhost:8080 by dev server)

dist: npm run build - (output to ./build/dist.chessdiagram.js)

lint: npm run lint - runs ESLint

generate API documentation: npm run generate-docs

testing: npm test (testing is implemented with Jest, Enzyme, and sinon)

to-do:

  • add a prop for optionally hiding labels etc.
  • show side to move, castling rights and other info
  • show arrows etc
  • handle remaining 5 FEN fields etc

recently completed:

  • Added PGN viewer to show games (Thanks Stephen !). (Refer to API Documentation for details.)
  • Ability to define custom piece types and their corresponding FEN characters
  • Test suite
  • deal with Scrolling properly !
  • publish to npm (Yippee - it’s up there !!)
  • auto API-doc (api.md)
  • webpack setup for distributing as component with demo.

Contributors:

Judd Niemann

Stephen Van Gordon

Graham Kaemmer