Pages
Footer
Footer Section
A footer section for React with link columns and a giant wordmark that fits the full width of your layout at any screen size.
footer-section.preview
Install
Copies the source into components/blocks/footer-section.tsx and installs what it needs.
$ pnpm dlx shadcn@latest add https://makeui.xyz/r/footer-section.jsonUsage
app/page.tsx
import { FooterSection } from "@/components/blocks/footer-section"
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<>
{children}
<FooterSection brand="MakeUI" />
</>
)
}Source
Prefer to copy by hand? It's one file. Requires motion and the shadcn cn helper.
components/blocks/footer-section.tsx
"use client"
import { useLayoutEffect, useRef, useState } from "react"
import { motion, useInView, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
type LinkItem = { label: string; href: string }
type Column = { title: string; links: LinkItem[] }
type Props = {
brand?: string
tagline?: string
columns?: Column[]
/** Small print under the wordmark. */
legal?: string
className?: string
}
const defaultColumns: Column[] = [
{
title: "Product",
links: [
{ label: "Components", href: "#" },
{ label: "Pages", href: "#" },
{ label: "Illustrations", href: "#" },
],
},
{
title: "Resources",
links: [
{ label: "Docs", href: "#" },
{ label: "Changelog", href: "#" },
{ label: "Support", href: "#" },
],
},
{
title: "Built with",
links: [
{ label: "Next.js", href: "#" },
{ label: "Tailwind CSS", href: "#" },
{ label: "Motion", href: "#" },
],
},
]
const BASE = 1000
/**
* Fits its text to the full width of the parent, at any screen size.
* Measures the real ink (not the advance box, which has side bearings) at 1000px, then scales the
* font so the first and last letters touch both edges.
*/
export function FitText({
children,
className,
letterClassName,
}: {
children: string
className?: string
/** Applied to every letter, e.g. a hover color. */
letterClassName?: string
}) {
const box = useRef<HTMLDivElement>(null)
const text = useRef<HTMLSpanElement>(null)
const [ready, setReady] = useState(false)
const reduce = useReducedMotion()
const inView = useInView(box, { once: true, margin: "0px 0px -8% 0px" })
const show = reduce || inView
useLayoutEffect(() => {
const b = box.current
const t = text.current
if (!b || !t) return
const ctx = document.createElement("canvas").getContext("2d")
const fit = () => {
t.style.fontSize = `${BASE}px`
t.style.marginLeft = "0px"
const cs = getComputedStyle(t)
// offsetWidth ignores CSS transforms, so this also works inside a scaled preview
const advance = t.offsetWidth
const spacing = parseFloat(cs.letterSpacing) || 0
let left = 0
let right = 0
if (ctx) {
ctx.font = `${cs.fontWeight} ${BASE}px ${cs.fontFamily}`
const first = ctx.measureText(children[0])
const last = ctx.measureText(children[children.length - 1])
left = -first.actualBoundingBoxLeft // space before the first glyph's ink
right = last.width - last.actualBoundingBoxRight // space after the last glyph's ink
}
const ink = advance - spacing - left - right
if (ink > 0) {
const k = b.clientWidth / ink
t.style.fontSize = `${BASE * k}px`
t.style.marginLeft = `${-left * k}px`
}
setReady(true)
}
fit()
const ro = new ResizeObserver(fit)
ro.observe(b)
document.fonts?.ready.then(fit)
return () => ro.disconnect()
}, [children])
return (
<div ref={box} aria-hidden className="w-full select-none overflow-hidden">
<span
ref={text}
style={{ fontSize: "16vw", opacity: ready ? 1 : 0 }}
className={cn("block w-max whitespace-nowrap font-medium leading-[0.8] tracking-[-0.05em]", className)}
>
{/* letters rise from below the edge one after another, then react to the pointer */}
{children.split("").map((letter, i) => (
<motion.span
key={i}
className={cn("inline-block transition-colors duration-300", letterClassName)}
initial={false}
animate={{ y: show ? "0%" : "110%" }}
transition={{ type: "spring", stiffness: 120, damping: 17, mass: 0.9, delay: show && !reduce ? 0.07 * i : 0 }}
>
{letter}
</motion.span>
))}
</span>
</div>
)
}
/** Footer: brand, link columns, and a wordmark that spans the whole width. */
export function FooterSection({
brand = "MakeUI",
tagline = "Copy-paste components with the motion already done.",
columns = defaultColumns,
legal = "Free and open source.",
className,
}: Props) {
return (
<div className="@container">
<footer className={cn("bg-white px-6 pt-16 dark:bg-neutral-950", className)}>
<div className="mx-auto max-w-6xl">
<div className="grid grid-cols-2 gap-x-6 gap-y-10 @2xl:grid-cols-[1fr_repeat(3,auto)] @2xl:gap-20">
<div className="col-span-2 @2xl:col-span-1">
<div className="text-base font-medium text-neutral-900 dark:text-neutral-50">{brand}</div>
<p className="mt-3 max-w-xs text-sm text-neutral-500 dark:text-neutral-400">{tagline}</p>
</div>
{columns.map((col) => (
<nav key={col.title} aria-label={col.title}>
<div className="text-sm text-neutral-900 dark:text-neutral-50">{col.title}</div>
<ul className="mt-4 space-y-2.5 text-sm text-neutral-500 dark:text-neutral-400">
{col.links.map((l) => (
<li key={l.label}>
<a href={l.href} className="transition-colors hover:text-neutral-900 dark:hover:text-neutral-50">
{l.label}
</a>
</li>
))}
</ul>
</nav>
))}
</div>
<p className="mt-14 text-xs text-neutral-400 dark:text-neutral-500">{legal}</p>
<div className="mt-6">
<FitText
className="text-neutral-900/[0.06] dark:text-white/[0.06]"
letterClassName="hover:text-neutral-900/[0.14] dark:hover:text-white/[0.14]"
>
{brand}
</FitText>
</div>
</div>
</footer>
</div>
)
}