Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.
TypeScript fintechinvoiceinvoice-generatorinvoice-pdfinvoice-templateinvoicesnextjsopen-sourcequotesreactreact-pdf-rendererself-hostedshadcn-uitailwindcsstypescript
feat: implement new header component with GitHub stars display and refactor existing header structure (#224)
Vlad Sazonauc7dbe7b2dcc9
diff --git a/src/actions/fetch-github-stars.ts b/src/actions/fetch-github-stars.tsindex 13fd5ba..19a95f8 100644--- a/src/actions/fetch-github-stars.ts+++ b/src/actions/fetch-github-stars.ts@@ -20,7 +20,7 @@ export const fetchGithubStars = cache(async (): Promise<number> => {headers: {Authorization: `Bearer ${env.GITHUB_TOKEN}`,},- next: { revalidate: 60 }, // 1 minute in seconds+ next: { revalidate: 60 }, // revalidate every 1 minute (60 seconds)},);diff --git a/src/app/(components)/header/header.client.tsx b/src/app/(components)/header/header.client.tsxnew file mode 100644index 0000000..5fad4ef--- /dev/null+++ b/src/app/(components)/header/header.client.tsx@@ -0,0 +1,148 @@+"use client";++import { BlackAnimatedGoToAppBtn } from "@/app/(components)/header/animated-go-to-app-btn";+import { GithubIcon } from "@/components/etc/github-logo";+import { Button } from "@/components/ui/button";+import { GITHUB_URL } from "@/config";+import { cn } from "@/lib/utils";+import Link from "next/link";+import { useState } from "react";+import { LanguageSwitcher } from "./language-switcher";+import { Logo } from "./logo";+import { MobileMenuPanel } from "./mobile-menu";+import { MorphingMenuIcon } from "./morphing-menu-icon";+import { StarIcon } from "lucide-react";+import type { HeaderProps } from "@/app/(components)/header";+import { githubStarCountFormatter } from "@/utils/number-formatter";++const desktopNavLinkClass =+ "rounded-md text-slate-800 px-3 py-1.5 text-sm font-medium hover:bg-slate-100 hover:text-black active:scale-[0.97] transition-all duration-300";++/**+ * Header client component that renders the main navigation bar+ * @param locale - Current locale for language/region+ * @param translations - Translation object for current locale+ * @param hideLanguageSwitcher - Optional flag to hide language switcher (defaults to false)+ * @param githubStarsCount - Number of GitHub stars to display+ */+export function HeaderClient({+ locale,+ translations,+ hideLanguageSwitcher = false,+ githubStarsCount,+}: HeaderProps & { githubStarsCount: number }) {+ const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);++ const gitHubStarCountFormatted = githubStarCountFormatter+ .format(githubStarsCount)+ .toLowerCase();++ return (+ <header className="sticky top-0 z-50 w-full border-b bg-white shadow-sm">+ <div className="flex items-center justify-center">+ <div className="container h-16 px-4 md:px-6">+ <div className="flex h-full items-center justify-between gap-4">+ {/* App logo */}+ <Logo text={translations.navLinks.tagline} />++ {/* Right side actions */}+ <div className="flex items-center gap-1">+ {/* Desktop nav */}+ <nav className="hidden items-center justify-end gap-1 lg:flex">+ <Link+ href={GITHUB_URL}+ target="_blank"+ rel="noopener noreferrer"+ className={cn(+ desktopNavLinkClass,+ "group flex items-center gap-1.5 bg-stone-200/50 text-slate-800 hover:bg-stone-200/80",+ )}+ aria-label={translations.navLinks.github}+ title="Star EasyInvoicePDF on GitHub - free & open-source invoice generator"+ >+ <GithubIcon className="size-4 fill-slate-800 transition-all duration-300 group-hover:fill-current" />+ {translations.navLinks.github}++ {githubStarsCount > 0 ? (+ <>+ <div className="mx-0.5 h-4 w-[1px] bg-slate-300" />+ <StarIcon className="size-4 fill-yellow-400 text-yellow-600 transition-all duration-300 group-hover:fill-yellow-300 group-hover:text-yellow-600/80" />+ <span className="text-sm font-semibold tabular-nums text-slate-800">+ {gitHubStarCountFormatted}+ </span>+ </>+ ) : (+ <StarIcon className="size-4 fill-yellow-400 text-yellow-600 transition-all duration-300 group-hover:fill-yellow-300 group-hover:text-yellow-600/80" />+ )}+ </Link>+ {/* a href this is only reliable way to scroll to a section on route navigation*/}+ <a+ href={`/${locale}/about`}+ className={cn(desktopNavLinkClass)}+ >+ {translations.navLinks.home}+ </a>++ {/* eslint-disable-next-line @next/next/no-html-link-for-pages */}+ <a href="/changelog" className={cn(desktopNavLinkClass)}>+ {translations.changelogLinkText}+ </a>+ {/* eslint-disable-next-line @next/next/no-html-link-for-pages */}+ <a href="/tos" className={cn(desktopNavLinkClass)}>+ {translations.termsOfServiceLinkText}+ </a>+ </nav>++ {/* Language switcher -- desktop only */}+ <div className="hidden min-w-[36px] lg:block">+ {!hideLanguageSwitcher && (+ <LanguageSwitcher+ locale={locale}+ buttonText={translations.switchLanguageText}+ />+ )}+ </div>++ {/* CTA button */}+ <BlackAnimatedGoToAppBtn>+ {translations.goToAppText}+ </BlackAnimatedGoToAppBtn>++ {/* Mobile menu toggle: hamburger or X; panel opens below header */}+ <div className="relative lg:hidden">+ <Button+ type="button"+ size="icon"+ variant="ghost"+ className="rounded-full shadow-none"+ aria-label={isMobileMenuOpen ? "Close menu" : "Open menu"}+ aria-expanded={isMobileMenuOpen}+ {...(!isMobileMenuOpen+ ? { "aria-haspopup": "dialog" as const }+ : {})}+ onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}+ >+ <MorphingMenuIcon+ isOpen={isMobileMenuOpen}+ className="size-5"+ aria-hidden+ />+ </Button>+ </div>+ </div>+ </div>+ </div>+ </div>++ {isMobileMenuOpen ? (+ <MobileMenuPanel+ onOpenChange={setIsMobileMenuOpen}+ locale={locale}+ translations={translations}+ hideLanguageSwitcher={hideLanguageSwitcher}+ githubStarsCount={githubStarsCount}+ />+ ) : null}+ </header>+ );+}diff --git a/src/app/(components)/header/index.tsx b/src/app/(components)/header/index.tsxindex a497abf..09217c2 100644--- a/src/app/(components)/header/index.tsx+++ b/src/app/(components)/header/index.tsx@@ -1,17 +1,6 @@-"use client";--import { BlackAnimatedGoToAppBtn } from "@/app/(components)/header/animated-go-to-app-btn";-import { GithubIcon } from "@/components/etc/github-logo";-import { Button } from "@/components/ui/button";-import { GITHUB_URL } from "@/config";-import { cn } from "@/lib/utils";-import { type Locale } from "next-intl";-import Link from "next/link";-import { useState } from "react";-import { LanguageSwitcher } from "./language-switcher";-import { Logo } from "./logo";-import { MobileMenuPanel } from "./mobile-menu";-import { MorphingMenuIcon } from "./morphing-menu-icon";+import { fetchGithubStars } from "@/actions/fetch-github-stars";+import { HeaderClient } from "@/app/(components)/header/header.client";+import type { Locale } from "next-intl";export interface HeaderProps {locale: Locale;@@ -21,7 +10,6 @@ export interface HeaderProps {features: string;faq: string;github: string;- githubUrl: string;githubCTA: string;tagline: string;};@@ -34,108 +22,16 @@ export interface HeaderProps {hideLanguageSwitcher?: boolean;}-const desktopNavLinkClass =- "rounded-md text-slate-800 px-3 py-1.5 text-sm font-medium hover:bg-slate-100 hover:text-black active:scale-[0.97] transition-all duration-300";--export function Header({- locale,- translations,- hideLanguageSwitcher = false,-}: HeaderProps) {- const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);-- return (- <header className="sticky top-0 z-50 w-full border-b bg-white shadow-sm">- <div className="flex items-center justify-center">- <div className="container h-16 px-4 md:px-6">- <div className="flex h-full items-center justify-between gap-4">- {/* App logo */}- <Logo text={translations.navLinks.tagline} />-- {/* Right side actions */}- <div className="flex items-center gap-1">- {/* Desktop nav */}- <nav className="hidden items-center justify-end gap-1 lg:flex">- <Link- href={GITHUB_URL}- target="_blank"- rel="noopener noreferrer"- className={cn(- desktopNavLinkClass,- "flex items-center gap-1.5 text-slate-800",- )}- aria-label={translations.navLinks.github}- >- <GithubIcon className="size-4" />- {translations.navLinks.github}- </Link>- {/* a href this is only reliable way to scroll to a section on route navigation*/}- <a- href={`/${locale}/about`}- className={cn(desktopNavLinkClass)}- >- {translations.navLinks.home}- </a>-- {/* eslint-disable-next-line @next/next/no-html-link-for-pages */}- <a href="/changelog" className={cn(desktopNavLinkClass)}>- {translations.changelogLinkText}- </a>- {/* eslint-disable-next-line @next/next/no-html-link-for-pages */}- <a href="/tos" className={cn(desktopNavLinkClass)}>- {translations.termsOfServiceLinkText}- </a>- </nav>-- {/* Language switcher -- desktop only */}- <div className="hidden min-w-[36px] lg:block">- {!hideLanguageSwitcher && (- <LanguageSwitcher- locale={locale}- buttonText={translations.switchLanguageText}- />- )}- </div>-- {/* CTA button */}- <BlackAnimatedGoToAppBtn>- {translations.goToAppText}- </BlackAnimatedGoToAppBtn>-- {/* Mobile menu toggle: hamburger or X; panel opens below header */}- <div className="relative lg:hidden">- <Button- type="button"- size="icon"- variant="ghost"- className="rounded-full shadow-none"- aria-label={isMobileMenuOpen ? "Close menu" : "Open menu"}- aria-expanded={isMobileMenuOpen}- {...(!isMobileMenuOpen- ? { "aria-haspopup": "dialog" as const }- : {})}- onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}- >- <MorphingMenuIcon- isOpen={isMobileMenuOpen}- className="size-5"- aria-hidden- />- </Button>- </div>- </div>- </div>- </div>- </div>-- {isMobileMenuOpen ? (- <MobileMenuPanel- onOpenChange={setIsMobileMenuOpen}- locale={locale}- translations={translations}- hideLanguageSwitcher={hideLanguageSwitcher}- />- ) : null}- </header>- );+/**+ * Header server component that fetches GitHub stars and renders the header+ * @param props - Header props excluding githubStarsCount+ * @param props.locale - Current locale for language/region+ * @param props.translations - Translation object for current locale+ * @param props.hideLanguageSwitcher - Optional flag to hide language switcher+ * @returns Rendered header with GitHub stars count+ */+export async function Header(props: HeaderProps) {+ const githubStarsCount = await fetchGithubStars();++ return <HeaderClient {...props} githubStarsCount={githubStarsCount} />;}diff --git a/src/app/(components)/header/mobile-menu.tsx b/src/app/(components)/header/mobile-menu.tsxindex 15ea87d..0acd913 100644--- a/src/app/(components)/header/mobile-menu.tsx+++ b/src/app/(components)/header/mobile-menu.tsx@@ -3,18 +3,21 @@import { GithubIcon } from "@/components/etc/github-logo";import { Button } from "@/components/ui/button";import { cn } from "@/lib/utils";-import { ArrowRightIcon } from "lucide-react";+import { ArrowRightIcon, StarIcon } from "lucide-react";import type { Locale } from "next-intl";import Link from "next/link";import { usePathname } from "next/navigation";import { useEffect, useId, useRef } from "react";-import type { HeaderProps } from ".";import { LanguageSwitcher } from "./language-switcher";+import { GITHUB_URL } from "@/config";+import type { HeaderProps } from "@/app/(components)/header";+import { githubStarCountFormatter } from "@/utils/number-formatter";interface MobileMenuSharedProps {locale: Locale;translations: HeaderProps["translations"];hideLanguageSwitcher?: boolean;+ githubStarsCount: number;}interface MobileMenuPanelProps extends MobileMenuSharedProps {@@ -41,11 +44,16 @@ export function MobileMenuPanel({locale,translations,hideLanguageSwitcher,+ githubStarsCount,}: MobileMenuPanelProps) {const pathname = usePathname();const titleId = useId();const descriptionId = useId();+ const gitHubStarCountFormatted = githubStarCountFormatter+ .format(githubStarsCount)+ .toLowerCase();+const isChangelogActive = pathname === "/changelog";const isTosActive = pathname === "/tos";const isHomeActive = pathname === `/${locale}/about`;@@ -118,19 +126,31 @@ export function MobileMenuPanel({>{translations.termsOfServiceLinkText}</a>+<a- href={translations.navLinks.githubUrl}+ href={GITHUB_URL}target="_blank"rel="noopener noreferrer"className={cn(mobileNavLinkClass,- "flex items-center gap-3 text-slate-700",+ "group flex items-center gap-1.5 text-slate-800",)}aria-label={translations.navLinks.githubCTA}- onClick={close}>- <GithubIcon className="size-5" />+ <GithubIcon className="size-5 transition-all duration-300 group-hover:fill-current" />{translations.navLinks.githubCTA}++ {githubStarsCount > 0 ? (+ <>+ <div className="mx-0.5 h-4 w-[1px] bg-slate-300" />+ <StarIcon className="size-5 fill-yellow-400 text-yellow-600 transition-all duration-300 group-hover:fill-yellow-300 group-hover:text-yellow-500" />+ <span className="text-sm font-semibold tabular-nums text-slate-800">+ {gitHubStarCountFormatted}+ </span>+ </>+ ) : (+ <StarIcon className="size-5 fill-yellow-400 text-yellow-600 transition-all duration-300 group-hover:fill-yellow-300 group-hover:text-yellow-500" />+ )}</a><div className="w-full pt-4">diff --git a/src/app/(seo-landings)/components/seo-landing-shell.tsx b/src/app/(seo-landings)/components/seo-landing-shell.tsxindex 8abe316..e67bddf 100644--- a/src/app/(seo-landings)/components/seo-landing-shell.tsx+++ b/src/app/(seo-landings)/components/seo-landing-shell.tsx@@ -1,5 +1,4 @@import { Footer } from "@/app/(components)/footer";-import { Header, type HeaderProps } from "@/app/(components)/header";import { BlackGoToAppButton } from "@/app/(components)/header/go-to-app-button-cta";import { GITHUB_URL } from "@/config";import Link from "next/link";@@ -14,23 +13,7 @@ import { ChevronDownIcon } from "lucide-react";import { StickySeoCta } from "@/app/(seo-landings)/components/sticky-seo-cta";import { Button } from "@/components/ui/button";import { GithubIcon } from "@/components/etc/github-logo";--const HEADER_TRANSLATIONS = {- navLinks: {- home: "Product",- features: "Features",- faq: "FAQ",- github: "GitHub",- githubUrl: GITHUB_URL,- githubCTA: "Star on GitHub",- tagline: "Free & Open-Source Invoice Generator",- },- switchLanguageText: "Switch language",- goToAppText: "Open app",- startInvoicingButtonText: "Start Invoicing",- changelogLinkText: "Changelog",- termsOfServiceLinkText: "Terms of Service",-} as const satisfies HeaderProps["translations"];+import { Header } from "@/app/(components)/header";interface SeoLandingShellProps {definition: SeoLandingDefinition;@@ -51,7 +34,24 @@ export function SeoLandingShell({ definition }: SeoLandingShellProps) {<SeoLandingJsonLd definition={definition} /><div className="flex min-h-screen flex-col bg-slate-50">- <Header locale="en" translations={HEADER_TRANSLATIONS} />+ <Header+ locale="en"+ translations={{+ navLinks: {+ home: "Product",+ features: "Features",+ faq: "FAQ",+ github: "GitHub",+ githubCTA: "Star on GitHub",+ tagline: "Free & Open-Source Invoice Generator",+ },+ switchLanguageText: "Switch language",+ goToAppText: "Open app",+ startInvoicingButtonText: "Start Invoicing",+ changelogLinkText: "Changelog",+ termsOfServiceLinkText: "Terms of Service",+ }}+ /><main className="flex flex-1 flex-col md:pb-12"><div className="border-b border-slate-200 bg-white"><div className="container mx-auto max-w-4xl px-4 pb-6 pt-12 md:px-6 md:py-16 md:pb-8">diff --git a/src/app/[locale]/about/page.tsx b/src/app/[locale]/about/page.tsxindex 14b7b7a..8d7f443 100644--- a/src/app/[locale]/about/page.tsx+++ b/src/app/[locale]/about/page.tsx@@ -22,7 +22,7 @@ import { setRequestLocale } from "next-intl/server";import Link from "next/link";import { ABOUT_FAQ_ITEM_KEYS } from "@/app/[locale]/about/about-faq-item-keys";import { GithubStarCtaMarketingPageBody } from "@/app/[locale]/about/components/github-star-cta-body";-import { Header, type HeaderProps } from "@/app/(components)/header";+import { type HeaderProps, Header } from "@/app/(components)/header";// statically generate the pages for all localesexport function generateStaticParams() {@@ -42,7 +42,6 @@ export default function AboutPage({ params }: { params: { locale: Locale } }) {features: t("footer.links.features"),faq: "FAQ",github: t("footer.links.github"),- githubUrl: GITHUB_URL,githubCTA: t("buttons.viewOnGithub"),tagline: t("tagline"),} as const satisfies HeaderProps["translations"]["navLinks"];@@ -70,6 +69,7 @@ export default function AboutPage({ params }: { params: { locale: Locale } }) {termsOfServiceLinkText,}}/>+<main><HeroSection /><FeaturesSection />@@ -174,6 +174,16 @@ export default function AboutPage({ params }: { params: { locale: Locale } }) {);}+/**+ * HeroSection component+ *+ * Renders the hero section of the About page with:+ * - CTA buttons to start invoicing and view on GitHub+ * - Video demo of the app+ * - Localized title and description with colored text spans+ * - Responsive layout (single column on mobile, two columns on XL screens)+ *+ */function HeroSection() {const t = useTranslations("About");diff --git a/src/app/changelog/layout.tsx b/src/app/changelog/layout.tsxindex c368cac..eee4491 100644--- a/src/app/changelog/layout.tsx+++ b/src/app/changelog/layout.tsx@@ -95,7 +95,6 @@ export default function ChangelogLayout({ children }: ChangelogLayoutProps) {features: "Features",faq: "FAQ",github: "GitHub",- githubUrl: GITHUB_URL,githubCTA: "Star on GitHub",tagline: "Free & Open-Source Invoice Generator",},diff --git a/src/app/founder/layout.tsx b/src/app/founder/layout.tsxindex e2d0a97..287dffe 100644--- a/src/app/founder/layout.tsx+++ b/src/app/founder/layout.tsx@@ -96,7 +96,6 @@ export default function FounderLayout({ children }: FounderLayoutProps) {features: "Features",faq: "FAQ",github: "GitHub",- githubUrl: GITHUB_URL,githubCTA: "Star on GitHub",tagline: "Free & Open-Source Invoice Generator",},diff --git a/src/app/tos/layout.tsx b/src/app/tos/layout.tsxindex f5331e3..a0b48d2 100644--- a/src/app/tos/layout.tsx+++ b/src/app/tos/layout.tsx@@ -89,7 +89,6 @@ export default function TosLayout({ children }: TosLayoutProps) {features: "Features",faq: "FAQ",github: "GitHub",- githubUrl: GITHUB_URL,githubCTA: "Star on GitHub",tagline: "Free & Open-Source Invoice Generator",},diff --git a/src/components/github-star-cta.tsx b/src/components/github-star-cta.tsxindex 7bcd9b3..3a2d33a 100644--- a/src/components/github-star-cta.tsx+++ b/src/components/github-star-cta.tsx@@ -4,8 +4,8 @@ import { GITHUB_URL } from "@/config";import { umamiTrackEvent } from "@/lib/umami-analytics-track-event";import { Star } from "lucide-react";import { GithubIcon } from "./etc/github-logo";-import { CountUpNumber } from "./ui/count-up-number";import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";+import { githubStarCountFormatter } from "@/utils/number-formatter";export function GitHubStarCTA({githubStarsCount,@@ -16,6 +16,10 @@ export function GitHubStarCTA({umamiTrackEvent("github_star_cta_clicked");};+ const gitHubStarCountFormatted = githubStarCountFormatter+ .format(githubStarsCount)+ .toLowerCase();+return (<Tooltip><TooltipTrigger asChild>@@ -38,7 +42,9 @@ export function GitHubStarCTA({</span>{githubStarsCount > 0 ? (<>- <CountUpNumber number={githubStarsCount} />+ <span className="min-w-[27px] text-center text-sm font-medium tabular-nums text-slate-50">+ {gitHubStarCountFormatted}+ </span></>) : (<span>Star on GitHub</span>diff --git a/src/components/ui/count-up-number.tsx b/src/components/ui/count-up-number.tsxdeleted file mode 100644index 5dd8872..0000000--- a/src/components/ui/count-up-number.tsx+++ /dev/null@@ -1,20 +0,0 @@-"use client";--type Props = {- number: number;-};--const formatter = new Intl.NumberFormat("en-US", {- notation: "compact",- compactDisplay: "short",-});--export function CountUpNumber({ number }: Props) {- const formattedNumber = formatter.format(number).toLowerCase();-- return (- <span className="min-w-[27px] text-center text-sm font-medium tabular-nums text-slate-50">- {formattedNumber}- </span>- );-}diff --git a/src/utils/number-formatter.ts b/src/utils/number-formatter.tsnew file mode 100644index 0000000..d520b45--- /dev/null+++ b/src/utils/number-formatter.ts@@ -0,0 +1,12 @@+/**+ * Formatter for GitHub star counts using compact notation.+ * Converts numbers to abbreviated format (e.g., 1500 -> "1.5K").+ *+ * @example+ * githubStarCountFormatter.format(1500); // "1.5K"+ * githubStarCountFormatter.format(1000000); // "1M"+ */+export const githubStarCountFormatter = new Intl.NumberFormat("en-US", {+ notation: "compact",+ compactDisplay: "short",+});