@raymondjosephsotto/github-stats-widget
v1.0.2
Published
A React component that displays GitHub profile stats — plug in your own API endpoint
Maintainers
Readme
github-stats-widget
A React widget for displaying GitHub profile metadata, repository totals, contribution activity, and top languages using your own API endpoint.
This project is designed to pair with github-stats-api, which collects and normalizes GitHub data for the widget to render.
Published package:
npm install @raymondjosephsotto/github-stats-widgetWhat It Shows
- Profile avatar, display name, and username
- Total repositories
- Total commits
- Total pull requests
- Total stars earned
- A GitHub-style contribution heatmap for the 2026 calendar year
- Top languages based on repository language usage
API Shape
The widget expects an endpoint that returns data in this general shape:
{
"profile": {
"avatarUrl": "https://avatars.githubusercontent.com/u/123456?v=4",
"displayName": "Your Name",
"username": "yourusername"
},
"repositories": {
"contributedTo": 0,
"total": 42
},
"totalCommits": 592,
"totalPullRequests": 140,
"totalStars": 2,
"topLanguages": [
{
"name": "TypeScript",
"color": "#3178c6",
"percentage": 55.3
}
],
"contributions": {
"total": 212,
"from": "2026-01-01T00:00:00.000Z",
"to": "2026-03-14T15:22:22.837Z",
"weeks": [
{
"days": [
{
"date": "2026-03-01",
"count": 5,
"level": 1
}
]
}
]
}
}The widget also includes fallback normalization for a few legacy field names, but the profile, repositories, topLanguages, and contributions structure above is the recommended contract.
Companion API
Use this widget with:
That API is responsible for:
- authenticating with GitHub
- gathering profile metadata
- aggregating repository counts
- calculating total commits, pull requests, and stars
- building the contribution heatmap payload
- aggregating top languages
The widget itself is intentionally presentation-focused. It does not call GitHub directly.
Installation
Install the package in your React app:
npm install @raymondjosephsotto/github-stats-widgetUsage
Import the widget and pass your deployed API endpoint:
import { GitHubStatsWidget } from "@raymondjosephsotto/github-stats-widget";
export default function Home() {
return (
<GitHubStatsWidget apiUrl="https://your-api.vercel.app/api/github" />
);
}You can also pass an optional username prop. The widget will prefer the username from the API response when available.
<GitHubStatsWidget
apiUrl="https://your-api.vercel.app/api/github"
username="yourusername"
/>Clone Or Fork Setup
If you clone or fork this repository, the usual workflow is:
- Install dependencies
- Run the local preview app
- Build the package
- Publish your own npm package name if you want to consume it from another repository or CI environment
Initial setup:
npm install
npm run devIf you are creating your own fork for publishing, update package.json with your own package name before publishing. A scoped name is recommended:
{
"name": "@your-npm-username/github-stats-widget"
}This is especially important if another project installs the widget through GitHub Actions, Vercel, or any remote CI environment, because local file references such as file:../github-stats-widget will not exist there.
Local Development
Install dependencies:
npm installStart the local preview app:
npm run devThen open the local Vite URL and point the preview form at your API endpoint.
You can also set a default API URL through an environment variable:
VITE_GITHUB_STATS_API_URL=https://your-api.vercel.app/api/github npm run devPublishing
To publish the package to npm:
npm login
npm run build
npm publish --access publicIf your npm account requires two-factor authentication for publishing, you may need:
npm publish --access public --otp=123456If you fork this repository, publish under your own scoped package name and then update your consuming app to install that package from npm instead of using a local file: reference.
Automated Versioning And Publishing
This repository can be configured to automate versioning and publishing with GitHub Actions.
Included workflows:
- ci.yml: runs
npm ciandnpm run buildon every push tomainand every pull request - release-please.yml: watches
main, opens or updates a release PR, and manages version bumps - publish.yml: publishes to npm when a GitHub Release is published from
main
Supporting config:
How It Works
- Push changes to
main - Release Please opens or updates a release PR with the next version
- When that PR is merged, Release Please creates a GitHub Release
- The publish workflow builds the package and publishes it to npm
Required Repository Secret
Add this GitHub Actions secret in your repository settings:
NPM_TOKEN: an npm token with permission to publish this package
Commit Message Guidance
Release Please works best when commit messages follow conventional commit style, for example:
feat: add top languages section
fix: correct heatmap weekday alignment
docs: update README publishing instructionsTypical version behavior:
fix:-> patch releasefeat:-> minor releasefeat!:or a breaking change footer -> major release
If you fork this project, remember to update:
package.jsonpackage name- release-please-config.json package name
- npm secret configuration in your forked repository
Build
Create the distributable package:
npm run buildIf you want to rebuild continuously while developing the package output:
npm run build:watchStyling
The widget ships with scoped CSS classes prefixed with gsw- and uses CSS variables for core colors. You can override those variables from a consuming app if you want to adapt the look:
.my-widget-wrapper .gsw-root {
--gsw-bg: #0b1220;
--gsw-bg2: #111827;
--gsw-border: #243041;
--gsw-text: #f8fafc;
--gsw-text-muted: #94a3b8;
}Project Structure
src/GitHubStatsWidget.tsx: main widget componentsrc/useGitHubStats.ts: fetch + response normalizationsrc/types.ts: TypeScript response typessrc/GitHubStatsWidget.css: widget stylesdemo/DemoApp.tsx: local preview app
Notes For Other Developers
- This package is a UI layer, not a GitHub data collector.
- The API should handle secrets, GitHub auth, pagination, aggregation, and caching.
- The widget expects contribution data as
weeks -> days, similar to GitHub’s contribution calendar. - The heatmap layout is responsive and computes cell sizing based on available width.
- If you change the API contract, update both
src/types.tsand the normalization logic insrc/useGitHubStats.ts. - If another repository consumes this widget, prefer installing the published npm package instead of using a local
file:dependency so CI and deployments can resolve it correctly.
Related Repositories
- Widget repo:
github-stats-widget - API:
github-stats-api
