drape background.md
Drape Background
A pleated curtain in a breeze that you can push and pull, built with React, WebGL and a cloth simulation.
Source: https://kokonutui.com/docs/backgrounds/drape-background
Installation
npx shadcn@latest add @kokonutui/drape-background
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className? |
string |
Extra classes for the root element. | |
children? |
ReactNode |
Content shown over the curtain. Pass null for a bare background. |
|
wind? |
number |
1 |
Strength of the breeze. 0 lets the curtain hang still. |
pleat? |
number |
34 |
Depth of the pleats along the top, in px. |
interactive? |
boolean |
true |
Push the fabric with the cursor and grab it to drag it around. |
Source
"use client";
/**
* @author: @dorianbaffier
* @description: Drape Background
* @version: 1.0.0
* @date: 2026-10-14
* @license: MIT
* @website: https://kokonutui.com
* @github: https://github.com/kokonut-labs/kokonutui
*/
import { type ReactNode, useEffect, useRef } from "react";
import { cn } from "@/lib/utils";
export interface DrapeBackgroundProps {
className?: string;
/** Content shown over the curtain. Pass `null` for a bare background. */
children?: ReactNode;
/** Strength of the breeze. 0 lets the curtain hang still. */
wind?: number;
/** Depth of the pleats along the top, in px. */
pleat?: number;
/** Push the fabric with the cursor and grab it to drag it around. */
interactive?: boolean;
}
// ... (the rest of the code) ...
export default function DrapeBackground({
className,
children,
wind = 1,
pleat = 34,
interactive = true,
}: DrapeBackgroundProps) {
const rootRef = useRef<HTMLDivElement>(null);
const canvasRef = useRef<HTMLCanvasElement>(null);
const litRef = useRef<HTMLSpanElement>(null);
const shadeRef = useRef<HTMLSpanElement>(null);
useEffect(() => {
// Effect code here
}, [wind, pleat, interactive]);
return (
<div
className={cn(
"relative flex min-h-[560px] w-full touch-pan-y items-center justify-center overflow-hidden bg-zinc-100 text-zinc-900 data-[grabbing]:cursor-grabbing dark:bg-zinc-950 dark:text-zinc-100",
className
)}
ref={rootRef}
>
{/* Theme colors for the shader: the lit face and the deepest fold. */}
<span className="hidden text-white dark:text-zinc-800" ref={litRef} />
<span className="hidden text-zinc-300 dark:text-black" ref={shadeRef} />
<div aria-hidden="true" className="pointer-events-none absolute inset-0">
<canvas
className="h-full w-full opacity-0 transition-opacity duration-700 ease-out"
ref={canvasRef}
/>
</div>
{children === undefined ? <DefaultContent /> : children}
</div>
);
}
function DefaultContent() {
return (
<div className="pointer-events-none relative flex max-w-xl flex-col items-center gap-4 px-6 text-center">
<h2 className="font-semibold text-4xl tracking-tight sm:text-5xl">
Behind the curtain
</h2>
<p className="max-w-sm text-base text-zinc-500 dark:text-zinc-400">
A pleated curtain in a light breeze. Sweep the cursor through it, or
grab a fold and pull.
</p>
</div>
);
}