Tile
A marketing box for showcase, specimen and feature grids: art on top, a title and a muted line below. Its corner, padding, gap, shadow and ring follow the shadcn style through the box tokens.
import type { ComponentProps } from "react"
import { cn } from "cn"
/**
* A marketing box: one item in a showcase, specimen or feature grid, with art
* on top and a title and line below. It is plain markup, not a `Card` (a Card
* holds app content). Its corner, padding, gap, shadow and ring read the box
* tokens, so it takes the look of whichever shadcn style the page uses.
*
* Compose it from `TileMedia`, `TileHeader`, `TileTitle` and
* `TileDescription`. A texture such as `SimpleGrain` can go first inside it:
* it fills the box, and the parts stay above it.
*/
function Tile({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="tile"
className={cn(
"relative isolate flex h-full flex-col gap-(--box-gap) overflow-hidden rounded-(--box-radius) bg-card p-(--box-padding) text-card-foreground shadow-(--box-shadow) ring-1 ring-foreground/(--box-ring-alpha) dark:ring-foreground/(--box-ring-alpha-dark)",
className
)}
{...props}
/>
)
}
/** The art at the top of a tile: an orb, an image or an icon. */
function TileMedia({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="tile-media"
className={cn("relative flex", className)}
{...props}
/>
)
}
/** Holds the title and description, 8px apart. */
function TileHeader({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="tile-header"
className={cn("relative grid gap-2", className)}
{...props}
/>
)
}
/** The tile's name, an `<h3>` at 18px medium weight. */
function TileTitle({ className, ...props }: ComponentProps<"h3">) {
return (
<h3
data-slot="tile-title"
className={cn("text-lg/7 font-medium", className)}
{...props}
/>
)
}
/** One or two lines under the title, in the muted color. */
function TileDescription({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="tile-description"
className={cn("text-sm/6 text-pretty text-muted-foreground", className)}
{...props}
/>
)
}
export { Tile, TileMedia, TileHeader, TileTitle, TileDescription }
import { MoonSphere } from "@/components/orbs/moon-sphere"
import { DemoLabel } from "@/components/text/demo-label"
import { Grain } from "@/components/texture/grain"
import {
Tile,
TileDescription,
TileHeader,
TileMedia,
TileTitle,
} from "@/components/tile/tile"
const COPY = {
title: "Waxing gibbous",
description: "Most of the face lit, rising in the late afternoon.",
captions: {
media: "With TileMedia: art above the title",
text: "Title and description only",
grain: "With a texture inside, on a toned ground: Grain fills the box",
},
} as const
/** Tile three ways: with art, text only, and with a texture inside. */
export default function TileDemo() {
return (
<div className="grid w-full max-w-4xl gap-x-4 gap-y-10 sm:grid-cols-3">
<div className="grid content-start gap-4">
<Tile>
<TileMedia>
<MoonSphere size={96} />
</TileMedia>
<TileHeader>
<TileTitle>{COPY.title}</TileTitle>
<TileDescription>{COPY.description}</TileDescription>
</TileHeader>
</Tile>
<DemoLabel>{COPY.captions.media}</DemoLabel>
</div>
<div className="grid content-start gap-4">
<Tile>
<TileHeader>
<TileTitle>{COPY.title}</TileTitle>
<TileDescription>{COPY.description}</TileDescription>
</TileHeader>
</Tile>
<DemoLabel>{COPY.captions.text}</DemoLabel>
</div>
<div className="grid content-start gap-4">
{/* Overlay grain vanishes on white, so this tile has a toned ground. */}
<Tile className="bg-[oklch(0.78_0.04_70)] text-[oklch(0.25_0.02_70)] [--muted-foreground:oklch(0.35_0.02_70)]">
<Grain opacity={0.6} />
<TileMedia>
<MoonSphere size={96} />
</TileMedia>
<TileHeader>
<TileTitle>{COPY.title}</TileTitle>
<TileDescription>{COPY.description}</TileDescription>
</TileHeader>
</Tile>
<DemoLabel>{COPY.captions.grain}</DemoLabel>
</div>
</div>
)
}
import type { ComponentProps } from "react"
import { cn } from "cn"
/**
* A caption under a demo or gallery piece, in medium-weight mono at
* 12px/20px. Long captions wrap with balanced last lines. The caption
* inherits its ground's text color; native paragraph props pass through.
*/
function DemoLabel({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="demo-label"
className={cn("font-mono text-xs/5 font-medium text-pretty", className)}
{...props}
/>
)
}
export { DemoLabel }
import { cn } from "cn"
// Paper grain: an SVG turbulence filter as a data URI.
const PAPER_GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250' viewBox='0 0 100 100'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='1.4' numOctaves='1' seed='2' stitchTiles='stitch' result='n'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='4' intercept='1'/%3E%3CfeFuncG type='linear' slope='4' intercept='1'/%3E%3CfeFuncB type='linear' slope='4' intercept='1'/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix type='saturate' values='0' in='g'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// Sandpaper grain: an SVG turbulence filter as a data URI.
const SANDPAPER_GRAIN = `url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 100 100'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='2.2' numOctaves='2' seed='5' stitchTiles='stitch' result='n'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='2.5' intercept='0.8'/%3E%3CfeFuncG type='linear' slope='2.5' intercept='0.8'/%3E%3CfeFuncB type='linear' slope='2.5' intercept='0.8'/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix type='saturate' values='0' in='g'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// Single noise: an SVG turbulence filter as a data URI.
const SINGLE_NOISE = `url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// Square grain: an SVG turbulence filter as a data URI.
const SQUARE_GRAIN = `url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22200%22%20height=%22200%22%20viewBox=%220%200%20100%20100%22%3E%3Cfilter%20id=%22n%22%20color-interpolation-filters=%22sRGB%22%3E%3CfeTurbulence%20type=%22turbulence%22%20baseFrequency=%222.1%22%20numOctaves=%223%22%20seed=%2211%22%20stitchTiles=%22stitch%22%20result=%22n%22/%3E%3CfeComponentTransfer%20result=%22g%22%3E%3CfeFuncR%20type=%22linear%22%20slope=%225.5%22%20intercept=%221.4%22/%3E%3CfeFuncG%20type=%22linear%22%20slope=%225.5%22%20intercept=%221.4%22/%3E%3CfeFuncB%20type=%22linear%22%20slope=%225.5%22%20intercept=%221.4%22/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix%20type=%22saturate%22%20values=%220%22%20in=%22g%22/%3E%3C/filter%3E%3Crect%20width=%22100%%22%20height=%22100%%22%20filter=%22url(%23n)%22/%3E%3C/svg%3E")`
type Intensity = "fine" | "default" | "rich"
// One scale for every texture; `default` is the unscaled value.
const INTENSITY_MULT: Record<Intensity, number> = {
fine: 0.6,
default: 1,
rich: 1.45,
}
const alpha = (base: number, mult: number) => (base * mult).toFixed(4)
// Four grain treatments; each paints a single texture layer.
// Full-bleed art layer — drop inside a `relative` parent; sits behind content.
/** The texture treatment painted by `Grain`. */
type GrainVariant =
// Stylized paper-look variants — heavier filter chain than plain noise.
"paper" | "sandpaper" | "square" | "single"
type Layer = {
src: string
size: string
opacity: number
blend: "overlay" | "soft-light"
}
const BLEND_CLASS: Record<Layer["blend"], string> = {
overlay: "mix-blend-overlay",
"soft-light": "mix-blend-soft-light",
}
const VARIANT_TEXTURES: Record<GrainVariant, Layer> = {
paper: {
src: PAPER_GRAIN,
size: "250px",
opacity: 0.25,
blend: "overlay",
},
sandpaper: {
src: SANDPAPER_GRAIN,
size: "200px",
opacity: 0.25,
blend: "overlay",
},
square: {
src: SQUARE_GRAIN,
size: "200px",
opacity: 0.8,
blend: "soft-light",
},
single: { src: SINGLE_NOISE, size: "200px", opacity: 0.3, blend: "overlay" },
}
/**
* A decorative grain layer that fills a positioned parent without blocking
* clicks. Choose a texture and adjust its strength with `intensity` or
* `opacity`. `className` and other div props land on the outer layer.
*/
function Grain({
variant = "single",
intensity = "default",
opacity,
isolated = false,
className,
...props
}: React.ComponentProps<"div"> & {
/** The grain treatment: `single` (default), `paper`, `sandpaper` or `square`. */
variant?: GrainVariant
/** Multiplies the texture's opacity: `fine` 0.6×, `default` 1×, `rich` 1.45×. */
intensity?: Intensity
/** The texture opacity, from 0 to 1. Takes precedence over `intensity`. */
opacity?: number
/**
* Adds paint containment when true. This creates a stacking context, so
* the texture stops blending with scene layers outside this element.
*/
isolated?: boolean
}) {
const layer = VARIANT_TEXTURES[variant]
const m =
opacity != null ? opacity / layer.opacity : INTENSITY_MULT[intensity]
return (
<div
data-slot="grain"
data-variant={variant}
aria-hidden="true"
className={cn(
"pointer-events-none absolute inset-0",
isolated && "contain-[paint]",
className
)}
{...props}
>
<div
className={cn("absolute inset-0", BLEND_CLASS[layer.blend])}
style={{
backgroundImage: layer.src,
backgroundSize: layer.size,
opacity: layer.opacity * m,
}}
/>
</div>
)
}
export { Grain }
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/**
* Diameter: a number of px or any CSS length. `"100cqi"` fills the
* nearest size container, so the sphere follows its box without measuring.
*/
size?: number | string
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
Installation
npx shadcn@latest add @01orbital/tileUsage
import { MoonSphere } from "@/components/orbs/moon-sphere"
import { DemoLabel } from "@/components/text/demo-label"
import { Grain } from "@/components/texture/grain"
import {
Tile,
TileDescription,
TileHeader,
TileMedia,
TileTitle,
} from "@/components/tile/tile"
const COPY = {
title: "Waxing gibbous",
description: "Most of the face lit, rising in the late afternoon.",
captions: {
media: "With TileMedia: art above the title",
text: "Title and description only",
grain: "With a texture inside, on a toned ground: Grain fills the box",
},
} as const
/** Tile three ways: with art, text only, and with a texture inside. */
export default function TileDemo() {
return (
<div className="grid w-full max-w-4xl gap-x-4 gap-y-10 sm:grid-cols-3">
<div className="grid content-start gap-4">
<Tile>
<TileMedia>
<MoonSphere size={96} />
</TileMedia>
<TileHeader>
<TileTitle>{COPY.title}</TileTitle>
<TileDescription>{COPY.description}</TileDescription>
</TileHeader>
</Tile>
<DemoLabel>{COPY.captions.media}</DemoLabel>
</div>
<div className="grid content-start gap-4">
<Tile>
<TileHeader>
<TileTitle>{COPY.title}</TileTitle>
<TileDescription>{COPY.description}</TileDescription>
</TileHeader>
</Tile>
<DemoLabel>{COPY.captions.text}</DemoLabel>
</div>
<div className="grid content-start gap-4">
{/* Overlay grain vanishes on white, so this tile has a toned ground. */}
<Tile className="bg-[oklch(0.78_0.04_70)] text-[oklch(0.25_0.02_70)] [--muted-foreground:oklch(0.35_0.02_70)]">
<Grain opacity={0.6} />
<TileMedia>
<MoonSphere size={96} />
</TileMedia>
<TileHeader>
<TileTitle>{COPY.title}</TileTitle>
<TileDescription>{COPY.description}</TileDescription>
</TileHeader>
</Tile>
<DemoLabel>{COPY.captions.grain}</DemoLabel>
</div>
</div>
)
}This example installs with everything it uses:
npx shadcn@latest add @01orbital/tile-demoAnatomy
Tile is built from 5 parts. In the example they nest like this:
Tile
├─ TileMedia
└─ TileHeader
├─ TileTitle
└─ TileDescriptionTile: A marketing box: one item in a showcase, specimen or feature grid, with art on top and a title and line below. It is plain markup, not aCard(a Card holds app content). Its corner, padding, gap, shadow and ring read the box tokens, so it takes the look of whichever shadcn style the page uses.TileMedia: The art at the top of a tile: an orb, an image or an icon.TileHeader: Holds the title and description, 8px apart.TileTitle: The tile's name, an<h3>at 18px medium weight.TileDescription: One or two lines under the title, in the muted color.
API reference
Tile
A marketing box: one item in a showcase, specimen or feature grid, with art on top and a title and line below. It is plain markup, not a Card (a Card holds app content). Its corner, padding, gap, shadow and ring read the box tokens, so it takes the look of whichever shadcn style the page uses.
Compose it from TileMedia, TileHeader, TileTitle and TileDescription. A texture such as SimpleGrain can go first inside it: it fills the box, and the parts stay above it.
It accepts the HTML attributes of the element it renders.
TileMedia
The art at the top of a tile: an orb, an image or an icon.
It accepts the HTML attributes of the element it renders.
TileHeader
Holds the title and description, 8px apart.
It accepts the HTML attributes of the element it renders.
TileTitle
The tile's name, an <h3> at 18px medium weight.
It accepts the HTML attributes of the element it renders.
TileDescription
One or two lines under the title, in the muted color.
It accepts the HTML attributes of the element it renders.
Dependencies
npm: cn. The CLI installs it for you.
Used in blocks
One block is built with Tile.
Last updated on