import { createSignal, onMount, For, Show } from 'solid-js'; import { Card } from '@/components/ui/Card'; import { Button } from '@/components/ui/Button'; import { IconCalendar, IconTrendingUp, IconBook, IconFolder, IconExternalLink, IconGitBranch, IconGitMerge, IconGitPullRequest, IconGitCommit } from '@tabler/icons-solidjs'; interface ActivityData { date: string; count: number; level: number; // 0-5 intensity level } interface ActivityEvent { type: 'push' | 'pull_request' | 'merge' | 'issue' | 'bookmark' | 'project' | 'learning' | 'note' | 'commit'; title: string; date: string; link?: string; repo?: string; action?: string; } interface GitHubActivityProps { title?: string; showStats?: boolean; showContributionGraph?: boolean; showRecentActivity?: boolean; compact?: boolean; period?: 'year' | 'month' | 'week'; customEvents?: ActivityEvent[]; hideHeader?: boolean; fullWidth?: boolean; } export const GitHubActivity = (props: GitHubActivityProps) => { const [activities, setActivities] = createSignal([]); const [recentEvents, setRecentEvents] = createSignal([]); const [selectedPeriod, setSelectedPeriod] = createSignal<'year' | 'month' | 'week'>(props.period || 'year'); const [stats, setStats] = createSignal({ totalContributions: 0, currentStreak: 0, longestStreak: 0 }); const setEmptyData = () => { setActivities([]); setRecentEvents(props.customEvents || []); setStats({ totalContributions: 0, currentStreak: 0, longestStreak: 0 }); }; onMount(() => { setEmptyData(); }); const getMonthLabels = () => { const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; const today = new Date(); const labels = []; for (let i = 11; i >= 0; i--) { const date = new Date(today); date.setMonth(date.getMonth() - i); labels.push(months[date.getMonth()]); } return labels; }; const getActivityColor = (level: number) => { // Use project-themed colors instead of Christmas tree colors // Based on the primary theme color with varying intensities const colors = [ 'hsl(var(--muted) / 0.3)', // Level 0 - no activity (very light muted) 'hsl(var(--primary) / 0.2)', // Level 1 - very light primary 'hsl(var(--primary) / 0.4)', // Level 2 - light primary 'hsl(var(--primary) / 0.6)', // Level 3 - medium primary 'hsl(var(--primary) / 0.8)', // Level 4 - strong primary 'hsl(var(--primary))' // Level 5 - full primary ]; return colors[level] || colors[0]; }; const formatContributionCount = (count: number) => { if (count >= 1000) { return `${(count / 1000).toFixed(1)}k`; } return count.toString(); }; const getEventIcon = (type: ActivityEvent['type']) => { switch (type) { case 'push': case 'commit': return ; case 'pull_request': return ; case 'merge': return ; case 'issue': return ; case 'bookmark': return ; case 'project': return ; case 'learning': return ; case 'note': return ; default: return ; } }; return (
{/* Header (can be hidden by parent) */} {!props.hideHeader && (

{props.title || 'Activity Overview'}

Track your contributions and activity over time

{(['year', 'month', 'week'] as const).map((period) => ( ))}
)} {/* Stats Overview */}

{formatContributionCount(stats().totalContributions)}

Total contributions

{stats().currentStreak}

Current streak

{stats().longestStreak}

Longest streak

{/* Contribution Graph */}

{formatContributionCount(stats().totalContributions)} contributions in the last year

0} fallback={

No GitHub contribution data yet.

} > {/* Month labels - Show all months with responsive spacing */}
{getMonthLabels().map((month) => ( {month} ))}
{/* Contribution grid - Responsive and prevents overflow */}
{/* Day labels */}
{['Mon', 'Wed', 'Fri'].map((day) => (
{day}
))}
{/* Weekly columns - Responsive with proper overflow handling */}
{Array.from({ length: 53 }, (_, weekIndex) => (
{Array.from({ length: 7 }, (_, dayIndex) => { const activityIndex = weekIndex * 7 + dayIndex; const activity = activities()[activityIndex]; if (!activity) { return (
); } return (
); })}
))}
{/* Legend */}
Less
{[0, 1, 2, 3, 4].map((level) => (
))}
More
{/* Recent Activity */}

Recent Activity

Active
0} fallback={

No GitHub events yet.

} >
{(event) => (
{getEventIcon(event.type)}

{event.title}

{event.date} {event.repo && ( <> {event.repo} )} {event.action && ( <> {event.action} )}
{event.link && ( )}
)}
); };