Overlay Hero
Poster-style hero: art fills the screen and words sit over it in top, center and bottom slots.
import type { ComponentProps, ReactNode } from "react"
import { cn } from "cn"
import { Hero } from "@/components/hero/hero"
type OverlayHeroProps = Omit<ComponentProps<typeof Hero>, "children"> & {
/**
* Art behind everything, such as a scene or a painting. It fills the whole
* hero; the block that passes it decides dark or light.
*/
background?: ReactNode
/**
* Pinned to the top of the hero, such as a masthead or a row of corner
* tags. Lay out its left and right yourself, for example with
* `flex justify-between`.
*/
top?: ReactNode
/**
* Between the top and the bottom. With both of those it floats in the
* middle; give it `flex-1` or `my-auto` to take the free space itself.
*/
center?: ReactNode
/**
* Pinned to the bottom of the hero, such as a very large title or the
* credits. Lay out its left and right yourself.
*/
bottom?: ReactNode
/**
* Classes for the layer the slots sit in, which fills the hero as a column
* with the slots spread from top to bottom: use it for the hero's padding
* (`p-8 sm:p-12`), the gap between slots, `justify-end` to sit everything at
* the bottom, or a text shadow.
*/
contentClassName?: string
}
/**
* A poster-style hero: art fills the screen and the words sit over it in named
* slots, `top`, `center` and `bottom`, spread from the top edge to the bottom
* edge. Use it when the layout is a composition over a picture, such as a
* masthead, a concert poster or a corner-tagged title, rather than a column of
* copy. Other props go to the Hero.
*/
function OverlayHero({
background,
top,
center,
bottom,
contentClassName,
...props
}: OverlayHeroProps) {
return (
<Hero {...props}>
{background ? (
// Not HeroBackground: its negative z-index starts a stacking context,
// which would cut a scene's blend modes off from the hero's own
// background. This layer has no z-index, so they blend with it.
<div
data-slot="overlay-hero-background"
aria-hidden="true"
className="pointer-events-none absolute inset-0"
>
{background}
</div>
) : null}
<div
data-slot="overlay-hero-content"
className={cn(
"absolute inset-0 z-10 flex flex-col justify-between",
contentClassName
)}
>
{top}
{center}
{bottom}
</div>
</Hero>
)
}
export { OverlayHero }
export type { OverlayHeroProps }
import { OverlayHero } from "@/components/hero/overlay-hero"
import { BlueHourPhotographicScene } from "@/components/scene/blue-hour-photographic-scene"
// The copy: change text here, not in the markup.
const COPY = {
brand: "Scarlet.",
links: "Studio · Projects · Blog",
tagline: "Interfaces that feel considered.",
title: "Chloe Design Studio",
} as const
/** Overlay Hero over the Blue Hour Photographic Scene, with its top, center
* and bottom slots filled. */
export default function OverlayHeroDemo() {
return (
<OverlayHero
className="dark min-h-144 w-full"
contentClassName="p-6 sm:p-10"
background={
<figure className="m-0 size-full overflow-hidden">
<BlueHourPhotographicScene />
</figure>
}
top={
<div className="flex justify-between text-sm">
<span>{COPY.brand}</span>
<span>{COPY.links}</span>
</div>
}
center={
<h2 className="text-center font-serif text-5xl sm:text-7xl">
{COPY.title}
</h2>
}
bottom={<p className="text-sm">{COPY.tagline}</p>}
/>
)
}
import { cn } from "cn"
// A gradient sky with screen-blended glow passes and fine grain on top.
const SKY =
"linear-gradient(180deg, oklch(0.18 0.09 270) 0%, oklch(0.24 0.10 265) 22%, oklch(0.32 0.10 250) 42%, oklch(0.42 0.09 235) 60%, oklch(0.52 0.07 215) 73%, oklch(0.60 0.08 75) 82%, oklch(0.45 0.10 50) 87%, oklch(0.20 0.05 30) 91%, oklch(0.10 0.03 250) 96%, oklch(0.07 0.02 260) 100%)"
const GRAIN = `url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
/**
* Full-bleed art layer — drop inside a `relative` parent; sits behind content.
*/
function BlueHourPhotographicScene({
className,
grain = true,
style,
...props
}: Omit<React.ComponentProps<"div">, "children"> & {
/** Set false when stacking your own grain on top. */
grain?: boolean
}) {
return (
<div
className={cn(
"pointer-events-none absolute inset-0 overflow-hidden",
className
)}
style={{ background: SKY, ...style }}
aria-hidden="true"
data-slot="blue-hour-photographic-scene"
{...props}
>
{/* Atmospheric glow — warm horizon haze + cool zenith pool */}
<div
className="absolute inset-0 mix-blend-screen"
style={{
background:
"radial-gradient(ellipse 120% 60% at 50% 82%, oklch(0.55 0.06 60 / 0.18) 0%, oklch(0.45 0.08 50 / 0.10) 30%, transparent 60%), radial-gradient(ellipse 100% 80% at 50% 30%, oklch(0.28 0.10 265 / 0.4) 0%, transparent 70%)",
}}
/>
{/* Horizon ember — the sun's last warmth, softened */}
<div
className="absolute inset-0 mix-blend-screen"
style={{
background:
"radial-gradient(ellipse 60% 22% at 50% 88%, oklch(0.72 0.13 65 / 0.35) 0%, oklch(0.55 0.10 55 / 0.18) 30%, transparent 65%)",
}}
/>
{grain && (
<div
className="absolute inset-0 opacity-10 mix-blend-overlay"
style={{ backgroundImage: GRAIN, backgroundSize: "256px" }}
/>
)}
</div>
)
}
export { BlueHourPhotographicScene }
import type { ComponentProps } from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
/** A hero is a full-screen band, so its parts step on the screen width. */
function Hero({ className, ...props }: ComponentProps<"section">) {
return (
<section
data-slot="hero"
className={cn(
"relative isolate flex min-h-svh flex-col overflow-hidden bg-background text-foreground",
className
)}
{...props}
/>
)
}
/** Absolute, behind everything; scenes need this relative parent. */
function HeroBackground({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="hero-background"
aria-hidden="true"
className={cn("pointer-events-none absolute inset-0 -z-10", className)}
{...props}
/>
)
}
const heroContainerVariants = cva("mx-auto w-full max-w-[90.5rem] px-6", {
variants: {
/** `default`, `stack`, `split` or `columns`, as described on HeroContainer. */
variant: {
default: "",
stack: "flex flex-1 flex-col justify-center",
split:
"grid flex-1 content-center items-center gap-16 lg:grid-cols-2 lg:gap-(--gutter)",
columns:
"grid flex-1 grid-cols-12 content-center items-center gap-x-6 gap-y-6",
},
},
defaultVariants: { variant: "default" },
})
/**
* The inner layout, with up to 1400px of content and 24px side padding at
* every width, matching Section's column. `stack` fills the height and
* centers; `split` is two columns from `lg`; `columns` is a
* 12-column grid with 24px gutters, where each child takes a span (for
* example `col-span-full lg:col-span-6`) so text gets its width from the
* grid rather than a max width. Use `className` to customize the width,
* padding or layout.
*/
function HeroContainer({
className,
variant = "default",
...props
}: ComponentProps<"div"> & VariantProps<typeof heroContainerVariants>) {
return (
<div
data-slot="hero-container"
data-variant={variant}
className={cn(heroContainerVariants({ variant }), className)}
{...props}
/>
)
}
const heroContentVariants = cva(
"group/hero-content flex min-w-0 flex-col gap-6",
{
variants: {
/**
* `start` (the default) or `center`, which centers the copy and its
* actions.
*/
align: {
start: "items-start",
center: "mx-auto items-center text-center",
},
},
defaultVariants: { align: "start" },
}
)
/**
* The copy column: the announcement, title and text 24px apart, and the
* actions 32px below them.
*/
function HeroContent({
className,
align = "start",
...props
}: ComponentProps<"div"> & VariantProps<typeof heroContentVariants>) {
return (
<div
data-slot="hero-content"
data-align={align}
className={cn(heroContentVariants({ align }), className)}
{...props}
/>
)
}
const heroActionsVariants = cva(
"flex flex-wrap items-center gap-4 group-data-[align=center]/hero-content:justify-center group-data-[slot=hero-content]/hero-content:mt-2",
{
variants: {
/** `start` (the default) or `center`, for actions on their own. */
align: {
start: "",
center: "justify-center",
},
},
defaultVariants: { align: "start" },
}
)
/**
* A wrapping row with 16px gaps. Inside HeroContent it sits 32px below the
* copy (the column's 24px gap and 8px more), and
* centers inside a centered HeroContent; `align` is for actions on their
* own. Buttons and links retain their own size and typography.
*/
function HeroActions({
className,
align = "start",
...props
}: ComponentProps<"div"> & VariantProps<typeof heroActionsVariants>) {
return (
<div
data-slot="hero-actions"
className={cn(heroActionsVariants({ align }), className)}
{...props}
/>
)
}
/** The picture or demo beside the copy in a `split` container. */
function HeroMedia({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="hero-media"
className={cn("relative min-w-0", className)}
{...props}
/>
)
}
export {
Hero,
HeroBackground,
HeroContainer,
HeroContent,
HeroActions,
HeroMedia,
}
Installation
npx shadcn@latest add @01orbital/overlay-heroUsage
import { OverlayHero } from "@/components/hero/overlay-hero"
import { BlueHourPhotographicScene } from "@/components/scene/blue-hour-photographic-scene"
// The copy: change text here, not in the markup.
const COPY = {
brand: "Scarlet.",
links: "Studio · Projects · Blog",
tagline: "Interfaces that feel considered.",
title: "Chloe Design Studio",
} as const
/** Overlay Hero over the Blue Hour Photographic Scene, with its top, center
* and bottom slots filled. */
export default function OverlayHeroDemo() {
return (
<OverlayHero
className="dark min-h-144 w-full"
contentClassName="p-6 sm:p-10"
background={
<figure className="m-0 size-full overflow-hidden">
<BlueHourPhotographicScene />
</figure>
}
top={
<div className="flex justify-between text-sm">
<span>{COPY.brand}</span>
<span>{COPY.links}</span>
</div>
}
center={
<h2 className="text-center font-serif text-5xl sm:text-7xl">
{COPY.title}
</h2>
}
bottom={<p className="text-sm">{COPY.tagline}</p>}
/>
)
}This example installs with everything it uses:
npx shadcn@latest add @01orbital/overlay-hero-demoAPI reference
A poster-style hero: art fills the screen and the words sit over it in named slots, top, center and bottom, spread from the top edge to the bottom edge. Use it when the layout is a composition over a picture, such as a masthead, a concert poster or a corner-tagged title, rather than a column of copy. Other props go to the Hero.
Prop
Type
It also accepts the HTML attributes of the element it renders.
Dependencies
npm: cn. The CLI installs it for you.
Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
Used in blocks
4 blocks are built with Overlay Hero:
Last updated on