Grain Overlay
Grain Overlay adds a distinctive visual surface to your composition.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/grain-overlay.jsonUse it
Scroll horizontally for long lines
"use client";
import {GrainOverlay} from '@/components/jez-ui/ui/grain-overlay';
export default function Example(){
return <><GrainOverlay className="min-h-[360px]"><div className="flex min-h-64 flex-col justify-between"><h3 className="max-w-md font-display text-5xl font-medium leading-[1.03] tracking-tight md:text-6xl">Tactile, by nature.</h3><p className="mt-8 text-sm">A quiet layer of texture.</p></div></GrainOverlay></>;
}Props & types
Scroll horizontally for long lines
{
children?: React.ReactNode;
className?: string;
}Source
View 2 source files
registry/ui/grain-overlay.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function GrainOverlay({
children,
className,
}: {
children?: React.ReactNode;
className?: string;
}) {
const ref = React.useRef<HTMLCanvasElement>(null);
React.useEffect(() => {
const c = ref.current;
if (!c) return;
const ctx = c.getContext("2d");
if (!ctx) return;
const d = ctx.createImageData(160, 160);
for (let i = 0; i < d.data.length; i += 4) {
const v = (i * 73) % 251;
d.data[i] = d.data[i + 1] = d.data[i + 2] = v;
d.data[i + 3] = 22;
}
ctx.putImageData(d, 0, 0);
}, []);
return (
<div
className={cn(
"relative min-h-60 overflow-hidden rounded-xl bg-muted",
className,
)}
>
<canvas
ref={ref}
width={160}
height={160}
aria-hidden="true"
className="pointer-events-none absolute inset-0 h-full w-full opacity-60"
/>
<div className="relative p-8">{children}</div>
</div>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Respect reduced-motion preferences. Decorative effects must not carry essential information. WebGL scenes include a static fallback and only render while visible.
Read the accessibility and performance guide →