Skip to content

Commit a906f33

Browse files
committed
feat: add npm package with React and vanilla JS support
- Add packages/github-contribution-graph npm package - React component (GitHubContributionGraph) with TypeScript - React hook (useContributionData) for custom implementations - Vanilla JS widget class (GitHubContributionWidget) - Browser bundle for CDN/script tag usage - 6 theme presets (default, void, slate, midnight, glacier, cyber) - 42 tests with Vitest - GitHub Actions CI/CD for testing and npm publishing - Minified bundles (~3KB gzipped) https://github.com/iamjr15/github-contribution-graph
1 parent 2efbc03 commit a906f33

34 files changed

+6878
-45
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'packages/**'
8+
- '.github/workflows/ci.yml'
9+
pull_request:
10+
branches: [main]
11+
paths:
12+
- 'packages/**'
13+
- '.github/workflows/ci.yml'
14+
15+
jobs:
16+
test:
17+
name: Test
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20'
28+
cache: 'npm'
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Type check
34+
run: npm run typecheck -w packages/github-contribution-graph
35+
36+
- name: Run tests
37+
run: npm run test -w packages/github-contribution-graph
38+
39+
- name: Build package
40+
run: npm run build

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
id-token: write
11+
12+
jobs:
13+
release:
14+
name: Release to npm
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
cache: 'npm'
28+
registry-url: 'https://registry.npmjs.org'
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Run tests
34+
run: npm run test -w packages/github-contribution-graph
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Publish to npm
40+
run: npm publish -w packages/github-contribution-graph --provenance --access public
41+
env:
42+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43+
44+
- name: Create GitHub Release
45+
uses: softprops/action-gh-release@v2
46+
with:
47+
generate_release_notes: true

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules
33
.env
44
.netlify
55
.gemini-clipboard
6-
.DS_Store
6+
.DS_Store
7+
packages/*/dist
8+
coverage

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,55 @@
22

33
A lightweight, customizable widget to embed your GitHub contribution graph on any website.
44

5+
[![npm version](https://img.shields.io/npm/v/github-contribution-graph.svg)](https://npmjs.com/package/github-contribution-graph)
56
[![Live Demo](https://img.shields.io/badge/demo-live-brightgreen)](https://github-contribution-graph.netlify.app)
67
[![Netlify Status](https://api.netlify.com/api/v1/badges/478cfe35-5d4d-4ec2-939b-b58e4de45ebe/deploy-status)](https://app.netlify.com/sites/github-contribution-graph/deploys)
78
[![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE)
89

910
![Preview](assets/media/thumbnail.png)
1011

11-
**[Live Demo](https://github-contribution-graph.netlify.app)** | **[GitHub Repo](https://github.com/iamjr15/github-contribution-graph)**
12+
**[Live Demo](https://github-contribution-graph.netlify.app)** | **[GitHub Repo](https://github.com/iamjr15/github-contribution-graph)** | **[npm Package](https://npmjs.com/package/github-contribution-graph)**
1213

13-
## Quick Start (Standard)
14+
---
15+
16+
## NPM Package
17+
18+
Install via npm for React or vanilla JavaScript projects:
19+
20+
```bash
21+
npm install github-contribution-graph
22+
```
23+
24+
### React
25+
26+
```tsx
27+
import { GitHubContributionGraph } from 'github-contribution-graph/react';
28+
import 'github-contribution-graph/styles.css';
29+
30+
function App() {
31+
return <GitHubContributionGraph username="octocat" theme="midnight" />;
32+
}
33+
```
34+
35+
### Vanilla JavaScript
36+
37+
```js
38+
import { GitHubContributionWidget } from 'github-contribution-graph/vanilla';
39+
import 'github-contribution-graph/styles.css';
40+
41+
const widget = new GitHubContributionWidget({
42+
username: 'octocat',
43+
container: '#my-graph',
44+
theme: 'void',
45+
});
46+
widget.render();
47+
```
48+
49+
See the [package README](packages/github-contribution-graph/README.md) for full API documentation.
50+
51+
---
52+
53+
## Quick Start (CDN)
1454

1555
Add the following to your HTML file to get the standard GitHub-styled graph:
1656

assets/css/index.css

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,28 @@ h1::after {
434434
to { opacity: 1; filter: blur(0); }
435435
}
436436

437-
/* Footer */
437+
/* Status Dot */
438+
.meta-info {
439+
font-size: 0.7rem;
440+
color: var(--text-dim);
441+
display: flex;
442+
gap: 2rem;
443+
margin-top: 1rem;
444+
}
445+
446+
.meta-item {
447+
display: flex;
448+
align-items: center;
449+
gap: 0.5rem;
450+
}
451+
452+
.status-dot {
453+
width: 6px;
454+
height: 6px;
455+
background-color: #00ff00;
456+
border-radius: 50%;
457+
box-shadow: 0 0 10px #00ff00;
458+
}
438459
.site-footer {
439460
margin-top: 4rem;
440461
font-size: 0.7rem;

assets/media/favicon.svg

Lines changed: 14 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)