Illustrations
Mail
Envelope Open
An envelope whose flap folds back while the letter slides up and out, then tucks away again on the next click.
Plays on its own. Click to take over.
Install
Copies the source into components/illustrations/envelope-open.tsx and installs what it needs.
$ pnpm dlx shadcn@latest add https://makeui.xyz/r/envelope-open.jsonUsage
app/page.tsx
import { EnvelopeOpen } from "@/components/illustrations/envelope-open"
export default function Example() {
return <EnvelopeOpen onChange={(open) => console.log(open)} />
}Source
Prefer to copy by hand? It's one file. Requires motion and the shadcn cn helper.
components/illustrations/envelope-open.tsx
"use client"
import { useEffect, useRef, useState } from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
type Props = {
/** Controlled. Leave out to let it manage itself. */
open?: boolean
defaultOpen?: boolean
onChange?: (open: boolean) => void
/** Opens and closes on its own until someone clicks it. */
autoPlay?: boolean
className?: string
}
// every piece is a triangle cut out of a box, like a real envelope
const clip = {
flap: "polygon(0 0, 100% 0, 50% 100%)",
left: "polygon(0 0, 51% 56%, 0 100%)",
right: "polygon(100% 0, 49% 56%, 100% 100%)",
bottom: "polygon(0 100%, 50% 55%, 100% 100%)",
}
const light = "[background-image:linear-gradient(to_bottom,rgb(255_255_255/0.45),transparent_70%)]"
/**
* Envelope in real 3D. The flap hinges on its top edge and flips over (you see its inside), a wax seal
* rides on it, and the letter slides up out of the pocket. Click to close it again.
*/
export function EnvelopeOpen({ open, defaultOpen = false, onChange, autoPlay, className }: Props) {
const reduce = useReducedMotion()
const [internal, setInternal] = useState(defaultOpen)
const [flapZ, setFlapZ] = useState(defaultOpen ? 1 : 5)
const hold = useRef(0)
const isOpen = open ?? internal
useEffect(() => {
if (!autoPlay || reduce || open !== undefined) return
const t = setInterval(() => {
if (Date.now() >= hold.current) setInternal((v) => !v)
}, 2800)
return () => clearInterval(t)
}, [autoPlay, reduce, open])
// the flap goes behind the letter once it has swung past vertical, and back in front on the way down
useEffect(() => {
const t = setTimeout(() => setFlapZ(isOpen ? 1 : 5), reduce ? 0 : 260)
return () => clearTimeout(t)
}, [isOpen, reduce])
const flip = reduce ? { duration: 0 } : { duration: 0.6, ease: [0.45, 0.05, 0.25, 1] as const }
const slide = reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 110, damping: 17, delay: isOpen ? 0.3 : 0 }
return (
<motion.button
role="switch"
aria-checked={isOpen}
aria-label={isOpen ? "Close letter" : "Open letter"}
whileTap={{ scale: 0.97 }}
transition={{ type: "spring", stiffness: 500, damping: 30 }}
onClick={() => {
hold.current = Date.now() + 6000
setInternal(!isOpen)
onChange?.(!isOpen)
}}
className={cn("relative block outline-none focus-visible:ring-2 focus-visible:ring-neutral-400/60 focus-visible:ring-offset-8", className)}
>
<div className="relative aspect-[14/9] w-44 [perspective:900px] sm:w-52">
{/* soft shadow on the table */}
<motion.span
aria-hidden
className="absolute -bottom-3 inset-x-3 h-5 rounded-full bg-black/20 blur-lg dark:bg-black/50"
initial={false}
animate={{ scaleX: isOpen ? 0.94 : 1, opacity: isOpen ? 0.8 : 1 }}
transition={flip}
/>
{/* back panel */}
<div className="absolute inset-0 z-0 rounded-[3px] bg-neutral-300 dark:bg-neutral-700" />
{/* flap: outer face while closed, inner face once flipped */}
<motion.div
className="absolute inset-x-0 top-0 h-[56%]"
style={{ transformStyle: "preserve-3d", transformOrigin: "50% 0%", zIndex: flapZ }}
initial={false}
animate={{ rotateX: isOpen ? -180 : 0 }}
transition={flip}
>
<div
className="absolute inset-0 bg-neutral-200 [backface-visibility:hidden] dark:bg-neutral-600"
style={{ clipPath: clip.flap }}
>
<div className={cn("absolute inset-0", light)} />
</div>
<div
className="absolute inset-0 bg-neutral-400 [backface-visibility:hidden] dark:bg-neutral-800"
style={{ clipPath: clip.flap, transform: "rotateY(180deg)" }}
>
<div className="absolute inset-0 [background-image:linear-gradient(to_bottom,rgb(0_0_0/0.18),transparent_60%)]" />
</div>
{/* wax seal, glued to the outside of the flap */}
<span
aria-hidden
className="absolute left-1/2 top-full grid aspect-square w-[22%] place-items-center rounded-full bg-rose-500 shadow-[0_2px_4px_rgb(0_0_0/0.3),inset_0_-2px_3px_rgb(0_0_0/0.25),inset_0_1px_2px_rgb(255_255_255/0.4)] [backface-visibility:hidden]"
style={{ transform: "translate(-50%, -68%) translateZ(1px)" }}
>
<span className="size-[58%] rounded-full border border-rose-300/70" />
</span>
</motion.div>
{/* the letter */}
<motion.div
className="absolute inset-x-[7%] top-[12%] z-[2] h-[82%] rounded-[3px] bg-white px-[9%] pt-[10%] shadow-[0_1px_3px_rgb(0_0_0/0.18)] dark:bg-neutral-100"
initial={false}
animate={{ y: isOpen ? "-44%" : "0%" }}
transition={slide}
>
<div className="h-2 w-[38%] rounded-full bg-rose-400" />
<div className="mt-3 space-y-[7px]">
<div className="h-[5px] w-full rounded-full bg-neutral-200" />
<div className="h-[5px] w-[92%] rounded-full bg-neutral-200" />
<div className="h-[5px] w-[96%] rounded-full bg-neutral-200" />
<div className="h-[5px] w-[58%] rounded-full bg-neutral-200" />
</div>
</motion.div>
{/* front pocket: three folded sheets, each catching the light differently */}
<div className="pointer-events-none absolute inset-0 z-[3] [filter:drop-shadow(0_-1px_2px_rgb(0_0_0/0.2))]">
<div className="absolute inset-0 bg-neutral-200 dark:bg-neutral-700" style={{ clipPath: clip.left }}>
<div className="absolute inset-0 [background-image:linear-gradient(to_right,rgb(0_0_0/0.06),transparent)]" />
</div>
<div className="absolute inset-0 bg-neutral-200 dark:bg-neutral-700" style={{ clipPath: clip.right }}>
<div className="absolute inset-0 [background-image:linear-gradient(to_left,rgb(0_0_0/0.1),transparent)]" />
</div>
<div className="absolute inset-0 bg-neutral-100 dark:bg-neutral-600" style={{ clipPath: clip.bottom }}>
<div className={cn("absolute inset-0", light)} />
</div>
</div>
</div>
</motion.button>
)
}