| 1 | "use client"; |
| 2 | |
| 3 | import { |
| 4 | Tooltip, |
| 5 | TooltipContent, |
| 6 | TooltipProvider, |
| 7 | TooltipTrigger, |
| 8 | } from "@/components/ui/tooltip"; |
| 9 | import { Skeleton } |
| 10 | import type { components |
| 11 | |
| 12 | type Contributions |
| 13 | |
| 14 | function level(count: |
| 15 | if (count === |
| 16 | if (max <= |
| 17 | const ratio = |
| 18 | if (ratio <= |
| 19 | if (ratio <= |
| 20 | if (ratio <= |
| 21 | return 4; |
| 22 | } |
| 23 | |
| 24 | const FILL = [ |
| 25 | "bg-muted", |
| 26 | "bg-emerald-200 dark:bg-emerald-950", |
| 27 | "bg-emerald-300 dark:bg-emerald-800", |
| 28 | "bg-emerald-500 dark:bg-emerald-600", |
| 29 | "bg-emerald-700 dark:bg-emerald-400", |
| 30 | ]; |
| 31 | |
| 32 | function formatDay(date: |
| 33 | const [y, |
| 34 | return new Date |
| 35 | month: "short", |
| 36 | day: "numeric", |
| 37 | year: "numeric", |
| 38 | timeZone: "UTC", |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | export function ContributionGraph({ |
| 43 | const max = |
| 44 | |
| 45 | // Monday-first columns like GitHub: pad the first week so Jan 1 lands on its weekday row (getUTCDay 0=Sunday..6=Saturday). |
| 46 | const first = |
| 47 | const pad = |
| 48 | ? (new Date |
| 49 | : 0; |
| 50 | |
| 51 | const cells: |
| 52 | ...Array<null> |
| 53 | ...data.days, |
| 54 | ]; |
| 55 | const weeks: |
| 56 | for (let i |
| 57 | |
| 58 | return ( |
| 59 | <TooltipProvider> |
| 60 | <div className="flex flex-col gap-2 |
| 61 | <div> |
| 62 | <h2 className="text-sm font-semibold |
| 63 | <span className="font-normal text-muted-foreground tabular-nums |
| 64 | {data.totalContributions} in |
| 65 | </span> |
| 66 | </div> |
| 67 | <div className="overflow-x-auto rounded-lg border p-3 |
| 68 | <div className="flex w-max gap-1 |
| 69 | {weeks.map(( |
| 70 | <div key={wi |
| 71 | {week.map(( |
| 72 | day === null ? |
| 73 | <span key={di |
| 74 | ) : ( |
| 75 | <Tooltip key={ |
| 76 | <TooltipTrigger asChild> |
| 77 | <span |
| 78 | className={`size-2.5 rounded-[3px] ${FILL |
| 79 | /> |
| 80 | </TooltipTrigger> |
| 81 | <TooltipContent> |
| 82 | {day.count === |
| 83 | ? `No contributions on ${formatDay( |
| 84 | : `${day.count |
| 85 | </TooltipContent> |
| 86 | </Tooltip> |
| 87 | ), |
| 88 | )} |
| 89 | </div> |
| 90 | ))} |
| 91 | </div> |
| 92 | |
| 93 | <div className="mt-2 flex items-center justify-end gap-1 text-xs text-muted-foreground |
| 94 | Less |
| 95 | {FILL.map(( |
| 96 | <span key={i |
| 97 | ))} |
| 98 | More |
| 99 | </div> |
| 100 | </div> |
| 101 | |
| 102 | <p className="text-xs text-muted-foreground |
| 103 | Commits to {data.username}& |
| 104 | email. |
| 105 | </p> |
| 106 | </div> |
| 107 | </TooltipProvider> |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | export function ContributionGraphSkeleton() |
| 112 | return ( |
| 113 | <div className="flex flex-col gap-2 |
| 114 | <Skeleton className=" |
| 115 | <Skeleton className=" |
| 116 | </div> |
| 117 | ); |
| 118 | } |