Skip to content

Repository files navigation

react-github-snake

NPM VersionLicenseBundle Size

An interactive GitHub contribution snake game for React. Transform any GitHub contribution heatmap into a playable snake game.

react-github-snake

👉 Live Studio

Features

  • Playable Heatmap: Turn standard GitHub contribution data into an interactive game.
  • Automode: Built-in pathfinding that clears the board for you.
  • Export Assets: Generate static or animated SVGs for your GitHub profile README.
  • Responsive: Dynamically fit columns to container width.
  • Zero Dependencies: Lightweight and fast.

Installation

npm install react-github-snake

Quick Start

import{GitHubSnake}from'react-github-snake';import'react-github-snake/style.css';functionApp(){return(<GitHubSnaketheme="dark"initialMode="AUTOMODE"initialSpeed={80}/>);}

Props

PropTypeDefaultDescription
dataContributionDataundefinedManual contribution data object. If not provided, renders an empty board.
theme'light' | 'dark''light'UI theme preset matching GitHub's aesthetics.
boardWidthnumber53Number of columns in the game board (max 53).
boardHeightnumber7Number of rows in the game board (7 days per week).
initialMode'MANUAL' | 'AUTOMODE''MANUAL'Starting game mode.
initialSpeednumber100Delay (ms) between moves.
initialWallsbooleanfalseEnable wall-collision (game over on edge hit).
initialSoundbooleantrueToggle spatial audio feedback.
initialGrowbooleanfalseEnable snake body growth when eating contributions.
initialShowScorebooleantrueShow score HUD during gameplay.
initialShowHeaderbooleantrueShow user identity header.
blockSizenumber15Cell size in pixels.
blockMarginnumber4Gap between cells in pixels.
responsivebooleanfalseDynamically fit columns to container width.
columnsnumberundefinedForce a specific number of columns (overrides boardWidth).
showLabelsbooleantrueShow month labels above the grid.
showLegendbooleantrueShow the legend and contribution count.
scrollablebooleanfalseEnable horizontal scrolling for overflow.
labelsGitHubSnakeLabelsundefinedCustom text labels for UI elements.
classNamestring''Additional CSS class for the container.
styleReact.CSSPropertiesundefinedInline styles for the container.

Export Options

The useGitHubSnakeExport hook supports:

  • theme: 'light' | 'dark'
  • radius: 'square' | 'sm-rounded' | 'md-rounded' | 'xl-rounded'
  • showHeader: boolean
  • showLabels: boolean
  • showLegend: boolean

Advanced Usage

For external control or multi-component synchronization, wrap your application in the SnakeProvider and use the useSnakeContext hook.

import{SnakeProvider,GitHubSnake,useSnakeContext}from'react-github-snake';functionCustomControls(){const{ startGame, stopGame, gameState }=useSnakeContext();return(<buttononClick={gameState==='PLAYING' ? stopGame : startGame}>{gameState==='PLAYING' ? 'Stop' : 'Start'}</button>);}functionApp(){return(<SnakeProviderinitialSpeed={50}><CustomControls/><GitHubSnake/></SnakeProvider>);}

Exporting

You can programmatically trigger SVG exports using the useGitHubSnakeExport hook. This is perfect for generating assets for your GitHub profile README.

import{SnakeProvider,useGitHubSnakeExport}from'react-github-snake';importtype{ContributionData}from'react-github-snake';functionExportButton({ data }: {data: ContributionData}){const{ exportSVG, exportAnimatedSVG }=useGitHubSnakeExport();return(<div><buttononClick={()=>exportSVG(data,{theme: 'dark'})}>
Download Static SVG
</button><buttononClick={()=>exportAnimatedSVG(data,{theme: 'dark'})}>
Download Animated SVG
</button></div>);}// Must be wrapped in SnakeProvider<SnakeProvider><ExportButtondata={myContributionData}/></SnakeProvider>

Development

npm run dev # Start local demo
npm run check # Lint and format code
npm run test:run # Run all tests
npm run build # Build for production

License

MIT © akashtdev.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages