@msh-01/react-github-activity
Version:
A beautifully designed, highly customizable React component for displaying GitHub contribution graphs with TypeScript support
81 lines (77 loc) • 2.59 kB
text/typescript
import React from 'react';
import { ClassValue } from 'clsx';
interface ContributionDay {
date: string;
contributionCount: number;
contributionLevel: "NONE" | "FIRST_QUARTILE" | "SECOND_QUARTILE" | "THIRD_QUARTILE" | "FOURTH_QUARTILE";
}
interface ContributionWeek {
contributionDays: ContributionDay[];
}
interface ContributionsData {
totalContributions: number;
weeks: ContributionWeek[];
firstContribution: string | null;
lastContribution: string | null;
}
interface ContributionStats {
totalContributions: number;
avgContributionsPerDay: string;
totalActiveDays: number;
longestStreak: number;
currentStreak: number;
}
interface GitHubContributionsProps {
/** GitHub username to fetch contributions for */
username: string;
/** GitHub API token (required for rate limiting) */
token: string;
/** Whether to display contribution statistics below the graph */
showStats?: boolean;
/** Specific year to display (overrides months) */
year?: number;
/** Number of months to show from today (overrides year) */
months?: number;
/** Whether to show month labels and legend */
showLabels?: boolean;
/** Number of days per column in the grid layout */
daysPerColumn?: number;
/** Additional CSS classes to apply to the root container */
className?: string;
}
/**
* GitHub Contributions Component
*
* A React component that displays a user's GitHub contribution graph
* with optional statistics and customizable styling.
*/
declare const GitHubContributions: React.FC<GitHubContributionsProps>;
/**
* Utility function to conditionally combine class names
* Based on shadcn/ui's cn utility
*/
declare function cn(...inputs: ClassValue[]): string;
/**
* Format a date to a readable string
*/
declare function formatDate(date: string | Date): string;
/**
* Calculate the date N months ago from today
*/
declare function getDateMonthsAgo(months: number): Date;
/**
* Get the start and end of a year
*/
declare function getYearBounds(year: number): {
start: Date;
end: Date;
};
/**
* Check if a value is a valid GitHub username
*/
declare function isValidGitHubUsername(username: string): boolean;
/**
* Check if a value looks like a GitHub token
*/
declare function isValidGitHubToken(token: string): boolean;
export { type ContributionDay, type ContributionStats, type ContributionWeek, type ContributionsData, GitHubContributions, type GitHubContributionsProps, cn, formatDate, getDateMonthsAgo, getYearBounds, isValidGitHubToken, isValidGitHubUsername };