├── .prettierignore ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── pull_request_template.md └── workflows │ └── ci.yml ├── .husky └── commit-msg ├── .storybook ├── preview.css ├── preview.ts └── main.ts ├── .vscode └── settings.json ├── tsconfig.build.json ├── docs ├── assets │ ├── chessboard.png │ ├── wood-pattern.png │ └── 3d-pieces │ │ ├── bB.webp │ │ ├── bK.webp │ │ ├── bN.webp │ │ ├── bP.webp │ │ ├── bQ.webp │ │ ├── bR.webp │ │ ├── wB.webp │ │ ├── wK.webp │ │ ├── wN.webp │ │ ├── wP.webp │ │ ├── wQ.webp │ │ └── wR.webp ├── stockfish │ ├── stockfish.wasm │ └── engine.ts ├── stories │ ├── options │ │ ├── ChessboardColumns.stories.tsx │ │ ├── DarkSquareStyle.stories.tsx │ │ ├── LightSquareStyle.stories.tsx │ │ ├── DarkSquareNotationStyle.stories.tsx │ │ ├── AlphaNotationStyle.stories.tsx │ │ ├── LightSquareNotationStyle.stories.tsx │ │ ├── NumericNotationStyle.stories.tsx │ │ ├── SquareStyle.stories.tsx │ │ ├── BoardStyle.stories.tsx │ │ ├── DropSquareStyle.stories.tsx │ │ ├── SquareRenderer.stories.tsx │ │ ├── CanDragPiece.stories.tsx │ │ ├── Pieces.stories.tsx │ │ ├── ShowNotation.stories.tsx │ │ ├── AllowDragging.stories.tsx │ │ ├── AllowDragOffBoard.stories.tsx │ │ ├── AllowDrawingArrows.stories.tsx │ │ ├── AllowAutoScroll.stories.tsx │ │ ├── ClearArrowsOnClick.stories.tsx │ │ ├── DragActivationDistance.stories.tsx │ │ ├── OnMouseOutSquare.stories.tsx │ │ ├── OnMouseOverSquare.stories.tsx │ │ ├── OnSquareClick.stories.tsx │ │ ├── BoardOrientation.stories.tsx │ │ ├── OnPieceDrag.stories.tsx │ │ ├── OnPieceClick.stories.tsx │ │ ├── ChessboardRows.stories.tsx │ │ ├── OnSquareRightClick.stories.tsx │ │ ├── SquareStyles.stories.tsx │ │ ├── OnPieceDrop.stories.tsx │ │ ├── OnSquareMouseUp.stories.tsx │ │ ├── DraggingPieceStyle.stories.tsx │ │ ├── DraggingPieceGhostStyle.stories.tsx │ │ ├── OnSquareMouseDown.stories.tsx │ │ ├── Arrows.stories.tsx │ │ ├── Position.stories.tsx │ │ ├── ShowAnimations.stories.tsx │ │ ├── ClearArrowsOnPositionChange.stories.tsx │ │ ├── AnimationDurationInMs.stories.tsx │ │ ├── OnArrowsChange.stories.tsx │ │ └── ArrowOptions.stories.tsx │ ├── basic-examples │ │ ├── Default.stories.tsx │ │ ├── PlayVsRandom.stories.tsx │ │ ├── SparePieces.stories.tsx │ │ ├── ClickToMove.stories.tsx │ │ └── ClickOrDragToMove.stories.tsx │ └── advanced-examples │ │ ├── Multiplayer.stories.tsx │ │ ├── 3DBoard.stories.tsx │ │ ├── MiniPuzzles.stories.tsx │ │ ├── AnalysisBoard.stories.tsx │ │ ├── Premoves.stories.tsx │ │ ├── PiecePromotion.stories.tsx │ │ └── FourPlayerChess.stories.tsx ├── components │ ├── HintMessage.tsx │ ├── WarningMessage.tsx │ └── DocNavigation.tsx ├── A_GetStarted.mdx ├── B_BasicExamples.mdx ├── F_Contributing.mdx └── C_AdvancedExamples.mdx ├── .npmignore ├── commitlint.config.mjs ├── src ├── index.ts ├── Droppable.tsx ├── SparePiece.tsx ├── Chessboard.tsx ├── RightClickCancelSensor.tsx ├── Draggable.tsx ├── types.ts ├── modifiers.ts ├── Board.tsx ├── defaults.ts ├── Piece.tsx └── Arrows.tsx ├── release.config.mjs ├── .gitignore ├── rollup.config.js ├── eslint.config.mjs ├── prettier.config.mjs ├── LICENSE ├── package.json └── README.md /.prettierignore: -------------------------------------------------------------------------------- 1 | **/stockfish.wasm.js -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Clariity] 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | pnpm commitlint ${1} 2 | -------------------------------------------------------------------------------- /.storybook/preview.css: -------------------------------------------------------------------------------- 1 | .docs-story > div { 2 | overflow: hidden !important; 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules\\typescript\\lib" 3 | } 4 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["docs"] 4 | } 5 | -------------------------------------------------------------------------------- /docs/assets/chessboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/chessboard.png -------------------------------------------------------------------------------- /docs/assets/wood-pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/wood-pattern.png -------------------------------------------------------------------------------- /docs/assets/3d-pieces/bB.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/bB.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/bK.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/bK.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/bN.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/bN.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/bP.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/bP.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/bQ.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/bQ.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/bR.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/bR.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/wB.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/wB.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/wK.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/wK.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/wN.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/wN.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/wP.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/wP.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/wQ.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/wQ.webp -------------------------------------------------------------------------------- /docs/assets/3d-pieces/wR.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/assets/3d-pieces/wR.webp -------------------------------------------------------------------------------- /docs/stockfish/stockfish.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clariity/react-chessboard/HEAD/docs/stockfish/stockfish.wasm -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .storybook 2 | media 3 | node_modules 4 | src 5 | stories 6 | storybook-static 7 | .gitignore 8 | package-lock.json 9 | rollup.config.js 10 | vercel.json -------------------------------------------------------------------------------- /commitlint.config.mjs: -------------------------------------------------------------------------------- 1 | export default { 2 | extends: ['@commitlint/config-conventional'], 3 | rules: { 4 | 'body-max-line-length': [0, 'always', 100], // [enabled, condition, value] 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Chessboard'; 2 | export * from './ChessboardProvider'; 3 | export * from './defaults'; 4 | export * from './pieces'; 5 | export * from './SparePiece'; 6 | export * from './types'; 7 | export * from './utils'; 8 | -------------------------------------------------------------------------------- /.storybook/preview.ts: -------------------------------------------------------------------------------- 1 | import type { Preview } from "@storybook/react"; 2 | import "./preview.css"; 3 | 4 | const preview: Preview = { 5 | parameters: { 6 | controls: { 7 | matchers: { 8 | color: /(background|color)$/i, 9 | date: /Date$/i, 10 | }, 11 | }, 12 | deepControls: { enabled: true }, 13 | }, 14 | }; 15 | 16 | export default preview; 17 | -------------------------------------------------------------------------------- /src/Droppable.tsx: -------------------------------------------------------------------------------- 1 | import { useDroppable } from '@dnd-kit/core'; 2 | 3 | type DroppableProps = { 4 | children: (props: { isOver: boolean }) => React.ReactNode; 5 | squareId: string; 6 | }; 7 | 8 | export function Droppable({ children, squareId }: DroppableProps) { 9 | const { isOver, setNodeRef } = useDroppable({ 10 | id: squareId, 11 | }); 12 | 13 | return
37 | Drag a piece to see a custom drop square style 38 |
39 |40 | Only white pieces can be dragged 41 |
42 |47 | Toggle the checkbox to show/hide board coordinates 48 |
49 |47 | Toggle the checkbox to enable/disable piece dragging 48 |
49 |47 | Try dragging a piece off the board when the checkbox is unchecked 48 |
49 |47 | Toggle the checkbox to enable/disable drawing arrows by holding right 48 | click and dragging 49 |
50 |47 | Enable the checkbox and try dragging a piece near the edge of the 48 | screen to see auto-scroll behavior 49 |
50 |52 | Toggle the checkbox to enable/disable clearing arrows when clicking on 53 | a square 54 |
55 |51 | Adjust the slider to change how far you need to drag a piece before it 52 | starts moving 53 |
54 |52 | Move your mouse over and out of squares to see the mouse out events 53 |
54 |52 | Move your mouse over squares to see the mouse over events 53 |
54 |53 | Click on squares to see the click events in action 54 |
55 |59 | Toggle the radio buttons to change the board orientation 60 |
61 |56 | Start dragging pieces to see the drag start events 57 |
58 |61 | Click on pieces to see the click events 62 |
63 |59 | Right-click on squares to see the right-click events in action 60 |
61 |66 | Right click on a square to add or remove a red background. Left click 67 | to remove all red backgrounds. 68 |
69 |65 | Drag and drop pieces to see the drop events 66 |
67 |67 | Release mouse button on squares to see the mouse up events in action 68 |
69 |69 | Drag a piece to see the custom dragging style. Adjust the sliders to 70 | change the scale and rotation of the dragged piece. 71 |
72 |70 | Drag a piece to see the ghost piece style. Adjust the sliders to 71 | change the opacity and blur of the ghost piece. 72 |
73 |67 | Press mouse button down on squares to see the mouse down events in 68 | action 69 |
70 |74 | Click the button to generate 3 random arrows on the board. 75 |
76 |{position}
102 | 103 |106 | Click on the button to generate a random FEN position 107 |
108 |{position}
103 | 104 |107 | Toggle the checkbox to enable/disable piece movement animations 108 |
109 |
22 | 112 | Toggle the checkbox to enable/disable clearing arrows when the 113 | position changes. 114 |
115 |112 | Play against random moves. Try moving pieces to see the animation 113 | effects 114 |
115 |{item.description}
102 |White's perspective
109 |Black's perspective
116 |
63 | 116 | Right-click and drag to draw arrows. The onArrowsChange callback will 117 | be triggered whenever internal arrows are added or removed. 118 |
119 |154 | Make moves on the board to analyze positions. The green arrow shows 155 | Stockfish's suggested best move. The evaluation is shown in 156 | centipawns (positive numbers favor White, negative favor Black). 157 |
158 |221 | Adjust the controls above to customize arrow appearance. Click the 222 | button to reset to default settings. 223 |
224 |209 | Move the white pawn to the 8th rank to trigger the promotion dialog. 210 | Click the reset button to return to the initial position. 211 |
212 |