New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-pgn-viewer

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-pgn-viewer

React component for creating an interactive pgn viewer from string

latest
Source
npmnpm
Version
0.2.4
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

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

ModifierExplanation
[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.

PropTypeDefaultExplanation
innerHTMLbooleantrueif true, will parse the pgn elements. If false, will make only one pgn from a text string
nodeToModifystringN/AHTML element that should be modified by nodeModification. Only applicable if innerHTML is true.
nodeModificationfunctionN/Ainstructions for modify different HTML elements besides <pgn>. Only applicable if innerHTML is true.
backgroundColorstring#e1e5edbackground of the entire viewer
blackSquareColorstringSteelBluecolor of the dark squares
whiteSquareColorstringAliceBluecolor of the light squares
orientationstring'w'board orientation
widthstring (%) or number (px)600Width of the board and move list. The board will be 2/3rds of the width.
showCoordinatesbooleantrueshould 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

FAQs

Package last updated on 22 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts