'use client' import { useId, type ReactNode } from 'react' import { cn } from '../../lib/cn' import { Button } from '../Button' import { Text } from '../Text' import { ArrowRightIcon, ChevronLeftIcon } from '../internal/icons' export type NotFoundStateHeadingLevel = 'h1' | 'h2' | 'h3' export interface NotFoundStateLink { /** Link text — where it goes. */ label: string href: string /** One short line under the label. */ description?: string } export interface NotFoundStateProps { /** The status code, drawn large. */ code?: string /** What happened, in words. */ title?: string /** Why it might have happened and what to try. */ description?: ReactNode /** A search field — usually a SearchField wired to site search. */ search?: ReactNode /** Pages people most often meant. Three or four at most. */ links?: NotFoundStateLink[] /** Heading over the links. */ linksTitle?: string /** Where the home action goes. Pass null to leave it out. */ homeHref?: string | null /** Label on the home action. */ homeLabel?: string /** Show a back action. It calls onBack, or steps back through history. */ showBack?: boolean /** Label on the back action. */ backLabel?: string /** Replaces the default history step — for an app with its own router. */ onBack?: () => void /** Artwork above the code. It is hidden from assistive technology; pass null for none. */ illustration?: ReactNode | null /** The title's heading level. h1 when this is the whole page, lower inside an app shell. */ headingLevel?: NotFoundStateHeadingLevel /** Merged last, so it wins. */ className?: string } function DefaultIllustration() { return ( ) } /** * The body of a 404 page. * * A bare "page not found" is a dead end, and the reader got here by following * something they trusted. So the state offers every way out it can: search for * what they meant, the handful of pages people usually meant, a step back, and * home. The code is shown large because it is what people quote to support — * but the title says it in words, and the heading level is a prop, since the * same body is a whole page on a site and a region inside an app shell. */ export function NotFoundState({ code = '404', title = 'We can’t find that page', description = 'The link may be out of date, or the page may have moved. Check the address, or try one of these instead.', search, links = [], linksTitle = 'Popular pages', homeHref = '/', homeLabel = 'Go to home', showBack = true, backLabel = 'Go back', onBack, illustration, headingLevel = 'h1', className, }: NotFoundStateProps) { const linksId = useId() const Heading = headingLevel const LinksHeading = headingLevel === 'h1' ? 'h2' : headingLevel === 'h2' ? 'h3' : 'h4' const art = illustration === undefined ? : illustration const back = () => { if (onBack) onBack() else window.history.back() } return (
{art && }
Error {code} {title} {description && ( {description} )}
{search &&
{search}
} {(showBack || homeHref !== null) && (
{showBack && ( )} {homeHref !== null && ( )}
)} {links.length > 0 && ( )}
) }