v1.0.1

github-contribution-chart

A tiny, headless npm package that fetches your GitHub contribution data via the GraphQL API and renders it as a heatmap using a zero-dependency React component.

npm install @achrekarom/github-contribution-chart

Features

GraphQL Fetcher

Hits the GitHub GraphQL API to pull your full contribution calendar — no scraping, no rate-limit hacks.

React Component

Zero-dependency component. Drop it in any React ≥ 17 project. Full SSR & Next.js Server Components support.

Full TypeScript

Bundled type declarations for every export. Enjoy full IntelliSense with zero extra configuration.

Fully Customizable

Override colors per-level, choose dark/light palette, control gap, cell radius, and month window.

Get up and running in seconds

Install via your favourite package manager. React is a peer dependency and only required if you use the chart component.

bash
# Install the library
npm install @achrekarom/github-contribution-chart

# React peer dependency (if not already installed)
npm install react
bash
yarn add @achrekarom/github-contribution-chart
bash
pnpm add @achrekarom/github-contribution-chart

Start in three steps

Fetch contribution data

Call fetchGitHubContributions with a GitHub username and a PAT token. Works in Node.js, server components, and the browser.

TypeScript
import { fetchGitHubContributions } from 'github-contribution-chart';

// Token is read from options.token, or process.env.GITHUB_TOKEN
const calendar = await fetchGitHubContributions('achrekarom', {
  token: process.env.GITHUB_TOKEN,
});

Render the chart

Pass the calendar to <GitHubContributionChart>. Choose a colour scheme, set how many months to show, and you're done.

TSX
import { GitHubContributionChart } from 'github-contribution-chart';

export default function MyPage() {
  return (
    <GitHubContributionChart
      calendar={calendar}
      colorScheme="dark"
      months={6}
    />
  );
}

Next.js Server Component — full example

Fetch and render in one async server component — no client state, no loading spinners.

app/page.tsx
import {
  fetchGitHubContributions,
  GitHubContributionChart,
} from 'github-contribution-chart';

export default async function Page() {
  const calendar = await fetchGitHubContributions('achrekarom');

  return (
    <div style={{ width: '100%', height: 120 }}>
      <GitHubContributionChart calendar={calendar} colorScheme="dark" />
    </div>
  );
}

Everything you can configure

fetchGitHubContributions(username, options?) async function

Hits the GitHub GraphQL API and returns the full contribution calendar for the given user, or null on error.

ParameterTypeDescription
usernamestringGitHub username
options.tokenstringGitHub PAT with read:user scope. Falls back to process.env.GITHUB_TOKEN.
options.fetchFntypeof fetchCustom fetch impl for Node <18 or test mocking.
Returns Promise<ContributionCalendar | null>
<GitHubContributionChart> React component

Zero-dependency heatmap grid. Renders the contribution data from fetchGitHubContributions.

PropTypeDefaultDescription
calendarContributionCalendar | nullData from the fetcher
colorScheme'dark' | 'light''dark'Built-in GitHub-style palettes
monthsnumber6Recent months to display
colorsPartial<Record<0|1|2|3|4, string>>Override per-level colours
gapnumber4Cell gap in px
cellRadiusnumber3Border-radius in px
classNamestringWrapper CSS class
styleCSSPropertiesWrapper inline styles
TypeScript types exported
ContributionCalendar { totalContributions: number; weeks: ContributionWeek[] }
ContributionWeek { contributionDays: ContributionDay[] }
ContributionDay { contributionCount: number; date: string }
ContributionLevel 0 | 1 | 2 | 3 | 4
ColorScheme 'dark' | 'light'

GitHub Token

Create a fine-grained personal access token at github.com/settings/tokens with read-only access to your public data (read:user scope). Then set it as an environment variable:

bash
export GITHUB_TOKEN=ghp_yourtoken

See it in action

An interactive preview rendered entirely in the browser — no server required.

Less
More
Generated code