react-chessboard-ui 2.8.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,9 +3,14 @@
3
3
  [![NPM](https://img.shields.io/npm/v/react-chessboard-ui.svg)](https://www.npmjs.com/package/react-chessboard-ui)
4
4
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
5
5
 
6
- A lightweight and customizable React chessboard component built with modern UI in mind. Easily integrate chess functionality into your React apps with FEN support, game-end detection, and position handling.
6
+ <p align="center">
7
+ <img src="./blob/default.png?raw=true" width="23%" alt="Default react-chessboard-ui board" />
8
+ <img src="./blob/customization.png?raw=true" width="23%" alt="Customized react-chessboard-ui board" />
9
+ <img src="./blob/colorfull_arrows.png?raw=true" width="23%" alt="React chessboard with colorful arrows" />
10
+ <img src="./blob/all_queens.png?raw=true" width="23%" alt="React chessboard with custom pieces" />
11
+ </p>
7
12
 
8
- <img src="./blob/ChessBoard.png?raw=true" width="400px" alt="react-chessboard-ui preview" />
13
+ An all-in-one React chessboard component with both the chess engine and UI included. Drop it into your React app and get a ready-to-use chessboard without wiring up separate chess logic, move validation, or board state tools. Control the board position with simple FEN notation and react to moves or game-end events through callbacks.
9
14
 
10
15
  ## 📘 **Full documentation**: [https://react-chessboard-ui.dev/](https://react-chessboard-ui.dev/)
11
16
 
@@ -14,10 +19,18 @@ A lightweight and customizable React chessboard component built with modern UI i
14
19
  ## 🚀 Features
15
20
 
16
21
  - 🎯 Fully controlled via FEN strings
22
+ - ♟️ Built-in chess engine and ready-made board UI
23
+ - ✅ Move validation included
17
24
  - ♻️ React functional component with hooks support
18
25
  - 🎨 Customizable styles (via CSS or override)
19
26
  - ♟️ Game-end and move-change callbacks
20
- - 🧩 Easy integration into any React project
27
+ - 🧩 No extra chess packages or setup required
28
+
29
+ ---
30
+
31
+ ## Why react-chessboard-ui?
32
+
33
+ `react-chessboard-ui` is designed for developers who need a React chessboard, chess UI, and chess engine in one package. It is not just a board renderer: it provides drag-and-drop chess pieces, FEN-based position control, legal move handling, game-end detection, and customization options out of the box.
21
34
 
22
35
  ---
23
36
 
@@ -46,19 +59,16 @@ import 'react-chessboard-ui/dist/index.css'; // Required CSS
46
59
 
47
60
  export const App = () => {
48
61
  return (
49
- <div>
50
- <ChessBoard
51
- FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
52
- onChange={handleChangePosition}
53
- onEndGame={handleEndGame}
54
- />
55
- </div>
62
+ <ChessBoard
63
+ FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
64
+ onChange={handleChangePosition}
65
+ onEndGame={handleEndGame}
66
+ />
56
67
  );
57
68
  };
58
69
  ```
59
70
 
60
71
  ## Full customizable
61
- <img src="./blob/customization.png?raw=true" width="400px" alt="react-chessboard-ui preview" />
62
72
 
63
73
  ### 📘 **Documentation for customization**: [https://react-chessboard-ui.dev/properties/config/](https://react-chessboard-ui.dev/properties/config/)
64
74
 
@@ -82,4 +92,4 @@ MIT © [react-chessboard-ui](https://github.com/)
82
92
 
83
93
  ## 🧠 Keywords (for discoverability)
84
94
 
85
- `react` `chess` `chessboard` `react-chess` `chess ui` `react chess component` `fen` `chess game` `react board game`
95
+ `react` `react-chess` `react-chessboard` `react-chessboard-ui` `js-chess` `chess` `chessboard` `chessboard component` `chess engine`
@@ -5,6 +5,9 @@ declare type ArrowLayoutType = {
5
5
  startArrowCoord: CellPos;
6
6
  arrowsCoords: ArrowCoords[];
7
7
  externalArrowsCoords?: ArrowCoords[];
8
+ externalArrows?: (ArrowCoords & {
9
+ color?: string;
10
+ })[];
8
11
  grabbingPos: CellPos;
9
12
  boardConfig: ChessBoardConfig;
10
13
  };
@@ -1,10 +1,11 @@
1
1
  import { PieceColor, GameResult, MoveData, SquarePos } from "../JSChessEngine";
2
2
  import { FC } from "react";
3
- import { ArrowCoords, ChangeMove, ChessBoardConfig } from "./models";
3
+ import { ArrowCoords, ChangeMove, ChessBoardConfig, ClickData } from "./models";
4
4
  declare type ChessBoardProps = {
5
5
  FEN: string;
6
6
  onChange: (moveData: MoveData) => void;
7
7
  onEndGame: (result: GameResult) => void;
8
+ onClick?: (data: ClickData) => void;
8
9
  change?: ChangeMove;
9
10
  reversed?: boolean;
10
11
  config?: Partial<ChessBoardConfig>;
@@ -12,6 +13,9 @@ declare type ChessBoardProps = {
12
13
  viewOnly?: boolean;
13
14
  moveHighlight?: [SquarePos, SquarePos];
14
15
  moveArrows?: ArrowCoords[];
16
+ arrows?: (ArrowCoords & {
17
+ color?: string;
18
+ })[];
15
19
  };
16
20
  export declare const ChessBoard: FC<ChessBoardProps>;
17
21
  export {};
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { Cell, CellPos, Figure, FigureColor, GameResult, MoveData } from "../JSChessEngine";
3
- import { ArrowCoords, ChangeMove, ChessBoardConfig } from "./models";
3
+ import { ArrowCoords, ChangeMove, ChessBoardConfig, ClickData } from "./models";
4
4
  declare type UseChessBoardInteractiveProps = {
5
5
  config?: Partial<ChessBoardConfig>;
6
6
  onChange: (moveData: MoveData) => void;
7
7
  onEndGame: (result: GameResult) => void;
8
+ onClickByChessBoard?: (data: ClickData) => void;
8
9
  };
9
10
  export declare const useChessBoardInteractive: (props: UseChessBoardInteractiveProps) => {
10
11
  fromPos: CellPos;
package/dist/index.js CHANGED
@@ -2311,7 +2311,8 @@ var ChessBoardControlLayout = function ChessBoardControlLayout(props) {
2311
2311
  var useChessBoardInteractive = function useChessBoardInteractive(props) {
2312
2312
  var config = props.config,
2313
2313
  onChange = props.onChange,
2314
- onEndGame = props.onEndGame;
2314
+ onEndGame = props.onEndGame,
2315
+ onClickByChessBoard = props.onClickByChessBoard;
2315
2316
  var _useState = React.useState(DEFAULT_CHESSBORD_CONFIG),
2316
2317
  boardConfig = _useState[0],
2317
2318
  setBoardConfig = _useState[1];
@@ -2439,6 +2440,14 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2439
2440
  return !prevReversed;
2440
2441
  });
2441
2442
  };
2443
+ var handleClickByChessBoard = function handleClickByChessBoard(cellData, pos) {
2444
+ if (!onClickByChessBoard) return;
2445
+ onClickByChessBoard({
2446
+ cellData: cellData,
2447
+ pos: pos,
2448
+ currentColor: currentColor
2449
+ });
2450
+ };
2442
2451
  var selectFigureFrom = function selectFigureFrom(cellPos, extActualState) {
2443
2452
  var nowState = extActualState || actualState;
2444
2453
  var cell = nowState[cellPos[1]][cellPos[0]];
@@ -2713,6 +2722,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2713
2722
  if (viewOnly === void 0) {
2714
2723
  viewOnly = false;
2715
2724
  }
2725
+ handleClickByChessBoard(actualState[cellPos[1]][cellPos[0]], cellPos);
2716
2726
  clearMarkedCells();
2717
2727
  clearArrows();
2718
2728
  if (viewOnly) return;
@@ -2963,7 +2973,9 @@ var ArrowLayout = function ArrowLayout(props) {
2963
2973
  grabbingPos = props.grabbingPos,
2964
2974
  boardConfig = props.boardConfig,
2965
2975
  _props$externalArrows = props.externalArrowsCoords,
2966
- externalArrowsCoords = _props$externalArrows === void 0 ? [] : _props$externalArrows;
2976
+ externalArrowsCoords = _props$externalArrows === void 0 ? [] : _props$externalArrows,
2977
+ _props$externalArrows2 = props.externalArrows,
2978
+ externalArrows = _props$externalArrows2 === void 0 ? [] : _props$externalArrows2;
2967
2979
  return React__default.createElement("div", {
2968
2980
  className: styles.arrowsLayer
2969
2981
  }, startArrowCoord[0] > -1 && grabbingPos[0] > -1 && React__default.createElement(Arrow, {
@@ -2982,6 +2994,12 @@ var ArrowLayout = function ArrowLayout(props) {
2982
2994
  }, coords, {
2983
2995
  color: boardConfig.arrowColor
2984
2996
  }));
2997
+ }), externalArrows.map(function (arrow, i) {
2998
+ return React__default.createElement(Arrow, Object.assign({
2999
+ key: "extArrow_" + i
3000
+ }, arrow, {
3001
+ color: arrow.color || boardConfig.arrowColor
3002
+ }));
2985
3003
  }));
2986
3004
  };
2987
3005
 
@@ -3015,6 +3033,7 @@ var ChessBoard = function ChessBoard(props) {
3015
3033
  var FEN = props.FEN,
3016
3034
  onChange = props.onChange,
3017
3035
  onEndGame = props.onEndGame,
3036
+ onClick = props.onClick,
3018
3037
  change = props.change,
3019
3038
  reversed = props.reversed,
3020
3039
  config = props.config,
@@ -3022,10 +3041,13 @@ var ChessBoard = function ChessBoard(props) {
3022
3041
  viewOnly = props.viewOnly,
3023
3042
  moveHighlight = props.moveHighlight,
3024
3043
  _props$moveArrows = props.moveArrows,
3025
- moveArrows = _props$moveArrows === void 0 ? [] : _props$moveArrows;
3044
+ moveArrows = _props$moveArrows === void 0 ? [] : _props$moveArrows,
3045
+ _props$arrows = props.arrows,
3046
+ arrows = _props$arrows === void 0 ? [] : _props$arrows;
3026
3047
  var _useChessBoardInterac = useChessBoardInteractive({
3027
3048
  onChange: onChange,
3028
3049
  onEndGame: onEndGame,
3050
+ onClickByChessBoard: onClick,
3029
3051
  config: config
3030
3052
  }),
3031
3053
  fromPos = _useChessBoardInterac.fromPos,
@@ -3071,12 +3093,19 @@ var ChessBoard = function ChessBoard(props) {
3071
3093
  var reversedChange = reversed ? JSChessEngine.reverseMove(change.move) : change.move;
3072
3094
  handleChangeFromExternal(reversedChange, change.withTransition);
3073
3095
  }, [change]);
3074
- var externalArrows = moveArrows.map(function (arrow) {
3096
+ var DEPRECATED_externalArrows = moveArrows.map(function (arrow) {
3075
3097
  return {
3076
3098
  start: correctGrabbingPosForArrow(arrow.start, boardConfig),
3077
3099
  end: correctGrabbingPosForArrow(arrow.end, boardConfig)
3078
3100
  };
3079
3101
  });
3102
+ var externalArrows = arrows.map(function (arrow) {
3103
+ return {
3104
+ start: correctGrabbingPosForArrow(arrow.start, boardConfig),
3105
+ end: correctGrabbingPosForArrow(arrow.end, boardConfig),
3106
+ color: arrow.color
3107
+ };
3108
+ });
3080
3109
  return React__default.createElement("div", {
3081
3110
  className: styles.chessBoard
3082
3111
  }, React__default.createElement(ChessBoardCellsLayout, {
@@ -3098,7 +3127,8 @@ var ChessBoard = function ChessBoard(props) {
3098
3127
  onHasCheck: getHasCheckByCellPos
3099
3128
  }), React__default.createElement(ArrowLayout, {
3100
3129
  arrowsCoords: arrowsCoords,
3101
- externalArrowsCoords: externalArrows,
3130
+ externalArrowsCoords: DEPRECATED_externalArrows,
3131
+ externalArrows: externalArrows,
3102
3132
  startArrowCoord: startArrowCoord,
3103
3133
  grabbingPos: correctGrabbingPosForArrow(grabbingCell, boardConfig),
3104
3134
  boardConfig: boardConfig