Giter VIP home page Giter VIP logo

react-pgn-viewer's Introduction

React Pgn Viewer

npm version npm Downloads license

Installation

npm install react-pgn-viewer --save

Usage

import PgnViewer from 'react-pgn-viewer'

class Example1 extends React.Component {

  htmlModification = (node) => {
    modifyNode(node)
  }

  render() {
    return (
      <PgnViewer
        blackSquareColour='steelBlue'
        nodeToModify='pre code'
        nodeModification={this.htmlModification}
        innerHTML
      >
        {'<pgn>1.e4 e5 2.f4 exf4'</pgn>}
      </PgnViewer
      )
  }
}

OR

import PgnViewer from 'react-pgn-viewer'

class Example2 extends React.Component {

  render() {
    return (
      <PgnViewer
        blackSquareColour='steelBlue'
        innerHTML={false}
      >
        1.e4 e5 2.f4 exf4
      </PgnViewer
      )
  }
}

Different viewing methods

For viewing partial pgns or a singular FEN position, add these modifiers to the pgn text

Modifier Explanation
[StartAtMove "8"] This will skip the first 7 moves and start immediately at move 8. Must be a whole number.
[EndAtMove "15"] This will cut off the game after move 15 and must be used in combination with StartAtMove. Must be a whole number.
[Fen "10w"] Fen cannot be used with StartAtMove or EndAtMove because it is one position. This shows move 10 after white moved so it will be blacks move
[Fen "15b"] This shows the position after Black moved in 15. It will be whites move.

The styles

The icons use font-awesome 4 CSS. If you aren't already using that, simply put the cdn in the head of your html

<head>
  <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
  integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
...
</head>

Properties

This library uses reactjs-chessboard for the board logic and display and it shares many props.

Prop Type Default Explanation
innerHTML boolean true if true, will parse the pgn elements. If false, will make only one pgn from a text string
nodeToModify string N/A HTML element that should be modified by nodeModification. Only applicable if innerHTML is true.
nodeModification function N/A instructions for modify different HTML elements besides <pgn>. Only applicable if innerHTML is true.
backgroundColor string #e1e5ed background of the entire viewer
blackSquareColor string SteelBlue color of the dark squares
whiteSquareColor string AliceBlue color of the light squares
orientation string 'w' board orientation
width string (%) or number (px) 600 Width of the board and move list. The board will be 2/3rds of the width.
showCoordinates boolean true should show coordinates along the A file and first Rank

Demo

https://blog.andrewgingrich.com/#/post/2018/07/22/chess-urbina-duran-2018

Contributing

To run the examples:

npm install
npm run dev

Then open localhost:8000 in a browser.

Tested with React 16.3

react-pgn-viewer's People

Contributors

ajgingrich avatar ps2-controller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.