react-chessboard
Version:
The React Chessboard Library
118 lines (117 loc) • 5.8 kB
TypeScript
import { getPositionUpdates } from './utils.js';
import { Arrow, SquareDataType, DraggingPieceDataType, PieceDropHandlerArgs, PieceHandlerArgs, PieceRenderObject, PositionDataType, SquareHandlerArgs, SquareRenderer } from './types.js';
import { defaultArrowOptions } from './defaults.js';
type Defined<T> = T extends undefined ? never : T;
type ContextType = {
id: Defined<ChessboardOptions['id']>;
pieces: Defined<ChessboardOptions['pieces']>;
boardOrientation: Defined<ChessboardOptions['boardOrientation']>;
chessboardRows: Defined<ChessboardOptions['chessboardRows']>;
chessboardColumns: Defined<ChessboardOptions['chessboardColumns']>;
boardStyle: Defined<ChessboardOptions['boardStyle']>;
squareStyle: Defined<ChessboardOptions['squareStyle']>;
squareStyles: Defined<ChessboardOptions['squareStyles']>;
darkSquareStyle: Defined<ChessboardOptions['darkSquareStyle']>;
lightSquareStyle: Defined<ChessboardOptions['lightSquareStyle']>;
dropSquareStyle: Defined<ChessboardOptions['dropSquareStyle']>;
draggingPieceStyle: Defined<ChessboardOptions['draggingPieceStyle']>;
draggingPieceGhostStyle: Defined<ChessboardOptions['draggingPieceGhostStyle']>;
darkSquareNotationStyle: Defined<ChessboardOptions['darkSquareNotationStyle']>;
lightSquareNotationStyle: Defined<ChessboardOptions['lightSquareNotationStyle']>;
alphaNotationStyle: Defined<ChessboardOptions['alphaNotationStyle']>;
numericNotationStyle: Defined<ChessboardOptions['numericNotationStyle']>;
showNotation: Defined<ChessboardOptions['showNotation']>;
animationDurationInMs: Defined<ChessboardOptions['animationDurationInMs']>;
showAnimations: Defined<ChessboardOptions['showAnimations']>;
allowDragging: Defined<ChessboardOptions['allowDragging']>;
allowDragOffBoard: Defined<ChessboardOptions['allowDragOffBoard']>;
allowDrawingArrows: Defined<ChessboardOptions['allowDrawingArrows']>;
arrows: Defined<ChessboardOptions['arrows']>;
arrowOptions: Defined<ChessboardOptions['arrowOptions']>;
canDragPiece: ChessboardOptions['canDragPiece'];
onMouseOutSquare: ChessboardOptions['onMouseOutSquare'];
onMouseOverSquare: ChessboardOptions['onMouseOverSquare'];
onPieceClick: ChessboardOptions['onPieceClick'];
onSquareClick: ChessboardOptions['onSquareClick'];
onSquareMouseDown: ChessboardOptions['onSquareMouseDown'];
onSquareMouseUp: ChessboardOptions['onSquareMouseUp'];
onSquareRightClick: ChessboardOptions['onSquareRightClick'];
squareRenderer: ChessboardOptions['squareRenderer'];
board: SquareDataType[][];
isWrapped: boolean;
draggingPiece: DraggingPieceDataType | null;
currentPosition: PositionDataType;
positionDifferences: ReturnType<typeof getPositionUpdates>;
newArrowStartSquare: string | null;
newArrowOverSquare: {
square: string;
color: string;
} | null;
setNewArrowStartSquare: (square: string | null) => void;
setNewArrowOverSquare: (square: string | null, modifiers?: {
shiftKey: boolean;
ctrlKey: boolean;
altKey?: boolean;
metaKey?: boolean;
}) => void;
internalArrows: Arrow[];
drawArrow: (newArrowEndSquare: string, modifiers?: {
shiftKey: boolean;
ctrlKey: boolean;
altKey?: boolean;
metaKey?: boolean;
}) => void;
clearArrows: () => void;
};
export declare const useChessboardContext: () => ContextType;
export type ChessboardOptions = {
id?: string;
pieces?: PieceRenderObject;
position?: string | PositionDataType;
boardOrientation?: 'white' | 'black';
chessboardRows?: number;
chessboardColumns?: number;
boardStyle?: React.CSSProperties;
squareStyle?: React.CSSProperties;
squareStyles?: Record<string, React.CSSProperties>;
darkSquareStyle?: React.CSSProperties;
lightSquareStyle?: React.CSSProperties;
dropSquareStyle?: React.CSSProperties;
draggingPieceStyle?: React.CSSProperties;
draggingPieceGhostStyle?: React.CSSProperties;
darkSquareNotationStyle?: React.CSSProperties;
lightSquareNotationStyle?: React.CSSProperties;
alphaNotationStyle?: React.CSSProperties;
numericNotationStyle?: React.CSSProperties;
showNotation?: boolean;
animationDurationInMs?: number;
showAnimations?: boolean;
allowDragging?: boolean;
allowDragOffBoard?: boolean;
allowAutoScroll?: boolean;
dragActivationDistance?: number;
allowDrawingArrows?: boolean;
arrows?: Arrow[];
arrowOptions?: typeof defaultArrowOptions;
clearArrowsOnClick?: boolean;
clearArrowsOnPositionChange?: boolean;
canDragPiece?: ({ isSparePiece, piece, square }: PieceHandlerArgs) => boolean;
onArrowsChange?: ({ arrows }: {
arrows: Arrow[];
}) => void;
onMouseOutSquare?: ({ piece, square }: SquareHandlerArgs) => void;
onMouseOverSquare?: ({ piece, square }: SquareHandlerArgs) => void;
onPieceClick?: ({ isSparePiece, piece, square }: PieceHandlerArgs) => void;
onPieceDrag?: ({ isSparePiece, piece, square }: PieceHandlerArgs) => void;
onPieceDragCancel?: () => void;
onPieceDrop?: ({ piece, sourceSquare, targetSquare, }: PieceDropHandlerArgs) => boolean;
onSquareClick?: ({ piece, square }: SquareHandlerArgs) => void;
onSquareMouseDown?: ({ piece, square }: SquareHandlerArgs, e: React.MouseEvent) => void;
onSquareMouseUp?: ({ piece, square }: SquareHandlerArgs, e: React.MouseEvent) => void;
onSquareRightClick?: ({ piece, square }: SquareHandlerArgs) => void;
squareRenderer?: SquareRenderer;
};
export declare function ChessboardProvider({ children, options, }: React.PropsWithChildren<{
options?: ChessboardOptions;
}>): import("react/jsx-runtime").JSX.Element;
export {};