GitHub Activity
rare-ui/github-activityFreeComponent
A contribution heatmap with a footer panel that expands over the grid to rank your top repositories.
Install it
npx shadcn@latest add https://rareui.com/r/github-activity.jsonSource
1"use client";23import * as React from "react";4import { createPortal } from "react-dom";5import {6 AnimatePresence,7 motion,8 useReducedMotion,9 type Transition,10} from "motion/react";11import { cn } from "@/lib/utils";1213export type ContributionLevel = 0 | 1 | 2 | 3 | 4;1415export type Contribution = {16 date: string;17 count: number;18 level: ContributionLevel;19};2021export type RepoContribution = {22 name: string;23 count: number;24 logo?: React.ReactNode;25 href?: string;26};2728const DEFAULT_ACCENT = "#39d353";29const DEFAULT_CELL_SIZE = 11;30const DEFAULT_LABEL = "Top contributions in:";31const DEFAULT_MONTHS = 12;32const WEEKS_PER_MONTH = 365.25 / 12 / 7;33const STACK_LIMIT = 3;34const MIN_CARD_WIDTH = 320;35const MIN_LABEL_WEEKS = 3;36// the p-4 on the card, both sides; the width math below has to add it back37const CARD_PADDING = 32;3839const gapFor = (cellSize: number) => Math.max(2, Math.round(cellSize / 4));40// never zero: weeks.slice(-0) would hand back the whole history instead of nothing41const weeksFor = (months: number) =>42 Math.max(1, Math.ceil(months * WEEKS_PER_MONTH));4344const useIsoLayoutEffect =45 typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;4647const EASE_OUT = [0.22, 1, 0.36, 1] as const;48const SPRING = { type: "spring", bounce: 0.2, duration: 0.62 } as const;49const HEADER_SPRING = { ...SPRING, bounce: 0.45 } as const;50const ROW_SPRING = { ...SPRING, bounce: 0.26, delay: 0.08 } as const;51const ROW_OFFSET = 16;52const CELL_FADE = { duration: 0.2, ease: EASE_OUT } as const;53const TOOLTIP_FADE = { duration: 0.14, ease: EASE_OUT } as const;54const TOOLTIP_EDGE = 8;55const COLUMN_STAGGER = 0.012;56const LABEL_BLUR = 6;57const LABEL_REVEAL = { duration: 0.45, ease: EASE_OUT } as const;5859const LEVELS = [0, 1, 2, 3, 4] as const;6061const MONTH_NAMES = [62 "Jan",63 "Feb",64 "Mar",65 "Apr",66 "May",67 "Jun",68 "Jul",69 "Aug",70 "Sep",71 "Oct",72 "Nov",73 "Dec",74];7576function toMonthLabels(weeks: Contribution[][]) {77 const labels: (string | null)[] = weeks.map(() => null);78 const monthAt = (index: number) => weeks[index]?.[0]?.date.slice(5, 7);7980 let start = 0;81 for (let i = 1; i <= weeks.length; i++) {82 if (i < weeks.length && monthAt(i) === monthAt(start)) continue;83 // a shorter run is narrower than the label itself, so it would sit under the next month84 if (i - start >= MIN_LABEL_WEEKS) {85 labels[start] = MONTH_NAMES[Number(monthAt(start)) - 1] ?? null;86 }87 start = i;88 }8990 return labels;91}9293// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from rare-ui
All 13 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Bounce Sidebarbounce-sidebar | rare-ui | Components | Free | 1 dep | |
| Code Blockcode-block | rare-ui | Components | Free | 3 deps | |
| Duration Pickerduration-picker | rare-ui | Components | Free | 5 deps | |
| Emoji Reactionemoji-reaction | rare-ui | Components | Free | 4 deps | |
| Family Drawerfamily drawer | rare-ui | Components | Free | 2 deps | |
| Fluid Orbfluid-orb | rare-ui | Components | Free | no deps | |
| Folder Componentfolder-component | rare-ui | Components | Free | 1 dep | |
| Gravity Lettersgravity-letters | rare-ui | Components | Free | no deps |
