When to use
- A rounded container with rounded things inside it, where the inner corners should follow the outer one: a media card with its cover image, a player with a button group, a tile with an inset well.
- Frames nested several deep: a frame with no
radiuscontinues its parent's curve, so each level rounds a little less. - Geometry that has to match the rendered corners (guides, a canvas, an SVG):
useFrame()gives the numbers in px.
When not to use
Installation
pnpm dlx shadcn add https://eased.dev/r/concentric-frame.jsonnpx shadcn add https://eased.dev/r/concentric-frame.jsonyarn dlx shadcn add https://eased.dev/r/concentric-frame.jsonbunx --bun shadcn add https://eased.dev/r/concentric-frame.jsonThe command adds Concentric Frame, everything it builds on and Eased’s tokens to your project.
Add the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/concentric-frame/concentric-frame.tsxTSX "use client";import { createContext, useContext, useMemo, type ComponentProps, type CSSProperties, type ElementType, type ReactNode,} from "react";/** A px number, or any CSS length (`"var(--eased-radius-panel)"`, `"1rem"`). */export type FrameLength = number | string;export type FrameMetrics = { /** CSS lengths, safe to drop into `style` or `calc()`. */ radius: string; /** The larger of the two paddings: the one the inner radius is cut by. */ pad: string; padX: string; padY: string; border: string; /** The smallest inner radius, so a deep nest rounds at this instead of squaring off (R5). */ min: string; inner: string; /** The same values in px, or null when any input is a CSS string. */ px: { radius: number; pad: number; border: number; min: number; inner: number } | null; concentric: boolean;};// ComponentProps, not ComponentPropsWithoutRef: React 19 passes `ref` as a prop, and ...rest forwards it.type Poly<T extends ElementType, P> = P & { as?: T } & Omit<ComponentProps<T>, keyof P | "as">;type FrameOwnProps = { /** Outer corner radius. Defaults to the parent frame's inner radius, else `--eased-radius-panel`. */ radius?: FrameLength; /** Padding on every side, or `{ x, y }`. Default 12. The inner radius is cut by the larger one. */ pad?: FrameLength | { x: FrameLength; y: FrameLength }; /** Border width, subtracted from the inner radius. Default 1; colour it with a class. */ border?: FrameLength; /** Floor for the inner radius. Default 2: below that a corner reads as a mistake, so it stays slightly round. */ min?: FrameLength; /** False hands children the outer radius unchanged: the naive look, for comparisons. Inherited. */ concentric?: boolean; style?: CSSProperties; children?: ReactNode;};export type FrameProps<T extends ElementType = "div"> = Poly<T, FrameOwnProps>;export type FrameInnerProps<T extends ElementType = "div"> = Poly<T, { style?: CSSProperties; children?: ReactNode }>;const FrameContext = createContext<FrameMetrics | null>(null);const toCss = (v: FrameLength) => (typeof v === "number" ? `${v}px` : v);const cssVars = (m: FrameMetrics) => ({ "--radius-outer": m.radius, "--pad": m.pad, "--pad-x": m.padX, "--pad-y": m.padY, "--border-w": m.border, "--radius-inner": m.inner, }) as CSSProperties;/** * A layout primitive that keeps nested curves parallel. It exposes `--radius-outer`, * `--pad`, `--border-w` and `--radius-inner` on its root, so any descendant can round * itself with `var(--radius-inner)` (or `<FrameInner>`, or `radius-nested`) without props. * Padding, radius and border (width and style) are owned here: Tailwind `p-*`, `rounded-*` * and `border-*` width classes on the root are overridden. Style only the border colour. */export function Frame<T extends ElementType = "div">({ as, radius, pad = 12, border = 1, min = 2, concentric, style, ...rest}: FrameProps<T>) { const parent = useContext(FrameContext); const metrics = useMemo<FrameMetrics>(() => { const isConcentric = concentric ?? parent?.concentric ?? true; // A nested frame with no radius continues the parent's curve. const r: FrameLength = radius ?? (parent ? (parent.px?.inner ?? parent.inner) : "var(--eased-radius-panel)"); const { x, y } = typeof pad === "object" ? pad : { x: pad, y: pad }; if ([r, x, y, border, min].every((v) => typeof v === "number")) { const [R, X, Y, B, M] = [r, x, y, border, min] as number[]; const P = Math.max(X, Y); // Never rounder than the outer corner, never squarer than the floor. const inner = isConcentric ? Math.min(R, Math.max(M, R - P - B)) : R; return { radius: toCss(R), pad: toCss(P), padX: toCss(X), padY: toCss(Y), border: toCss(B), min: toCss(M), inner: toCss(inner), px: { radius: R, pad: P, border: B, min: M, inner }, concentric: isConcentric, }; } const [R, X, Y, B, M] = [toCss(r), toCss(x), toCss(y), toCss(border), toCss(min)]; const P = X === Y ? X : `max(${X}, ${Y})`; return { radius: R, pad: P, padX: X, padY: Y, border: B, min: M, inner: isConcentric ? `min(${R}, max(${M}, calc(${R} - ${P} - ${B})))` : R, px: null, concentric: isConcentric, }; }, [radius, pad, border, min, concentric, parent]); const Comp: ElementType = as ?? "div"; const vars = { ...cssVars(metrics), borderRadius: "var(--radius-outer)", padding: "var(--pad-y) var(--pad-x)", borderWidth: "var(--border-w)", // Set with the width so the border never depends on Tailwind's preflight. borderStyle: "solid", ...style, } as CSSProperties; return ( <FrameContext value={metrics}> <Comp {...rest} style={vars} /> </FrameContext> );}/** A direct child that takes the frame's concentric inner radius. Images inside should use `rounded-[inherit]`. */export function FrameInner<T extends ElementType = "div">({ as, style, ...rest }: FrameInnerProps<T>) { const Comp: ElementType = as ?? "div"; return <Comp {...rest} style={{ borderRadius: "var(--radius-inner)", ...style }} />;}/** The nearest frame's metrics, or null outside one. Use `px` for geometry (guides, canvases). */export function useFrame() { return useContext(FrameContext);}/** * The nearest frame's CSS variables as a style object, empty outside one. Spread it onto * anything that cannot inherit them: a portal, or an SVG or canvas wrapper rendered elsewhere. */export function useFrameVar(): CSSProperties { const metrics = useContext(FrameContext); return metrics ? cssVars(metrics) : {};}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Frame, FrameInner } from "@/components/eased/concentric-frame/concentric-frame";export function NowPlaying() { return ( <Frame radius={24} pad={10} className="flex w-72 flex-col gap-3 border-line-subtle bg-surface"> <FrameInner className="aspect-[2/1] overflow-hidden"> <img src="/covers/slow-light.jpg" alt="" className="size-full rounded-[inherit] object-cover" /> </FrameInner> <p className="px-1 text-ui font-medium text-text">Slow Light</p> </Frame> );}Examples
Nested frames
A frame inside a frame takes the parent's inner radius as its outer one, so the button group below rounds at 24 − 10 − 1 = 13px and its buttons at 13 − 4 = 9px.
<Frame radius={24} pad={10} className="border-line-subtle bg-surface"> <Frame pad={4} border={0} className="flex gap-1 bg-surface-sunken"> <FrameInner as="button" className="h-9 flex-1 bg-surface">Previous</FrameInner> <FrameInner as="button" className="h-9 flex-1 bg-brand text-text-on-brand">Play</FrameInner> </Frame></Frame>Reading the variables
Any descendant can round itself with var(--radius-inner), without FrameInner.
<Frame pad={{ x: 16, y: 12 }} className="border-line-subtle bg-surface"> <div className="rounded-[var(--radius-inner)] bg-surface-sunken p-3">Inset well</div></Frame>Portals and canvases
Content rendered elsewhere cannot inherit the variables; spread useFrameVar() onto it. useFrame() returns the metrics, with px values when every input is a number.
function Guides() { const frame = useFrame(); if (!frame?.px) return null; return <svg>{/* draw a circle of radius frame.px.inner */}</svg>;}API reference
Frame
| Prop | Type | Default | Description |
|---|---|---|---|
radius | number | string | parent's inner radius, else var(--eased-radius-panel) | Outer corner radius, in px or any CSS length. |
pad | number | string | { x, y } | 12 | Padding on every side, or per axis. The inner radius is cut by the larger of the two. |
border | number | string | 1 | Border width, subtracted from the inner radius. Colour it with a class. |
min | number | string | 2 | Floor for the inner radius, so a deep nest stays slightly round instead of squaring off. |
concentric | boolean | true | false hands children the outer radius unchanged, for comparisons. Inherited by nested frames. |
as | ElementType | "div" | The element to render. |
style | CSSProperties | Merged after the frame's own styles. |
The inner radius is min(radius, max(min, radius − pad − border)): never rounder than the outer corner. Padding, radius and border width are set inline, so Tailwind p-*, rounded-* and border-* width classes on the frame are overridden; style only the border colour. Other props of the rendered element pass through, including ref.
The frame sets --radius-outer, --pad, --pad-x, --pad-y, --border-w and --radius-inner on its root. The radius-nested utility in the Eased tokens reads the same variables.
FrameInner
A direct child that takes border-radius: var(--radius-inner). Takes as, style and the rendered element's props. Images inside it should use rounded-[inherit].
useFrame and useFrameVar
| Hook | Returns |
|---|---|
useFrame() | The nearest frame's FrameMetrics (radius, pad, padX, padY, border, min, inner as CSS lengths, px with the same values as numbers or null when any input is a CSS string, and concentric), or null outside a frame. |
useFrameVar() | The nearest frame's CSS variables as a style object, or {} outside a frame. |
Notes for AI
Use Frame wherever rounded content sits inside a rounded, padded container, and let it own the padding, radius and border width: pass pad, radius and border as props rather than classes. Nest frames instead of computing inner radii by hand, and use FrameInner or var(--radius-inner) for the inner corners.
Do not put p-*, rounded-* or border width classes on a Frame; they are overridden. When any input is a CSS string, useFrame().px is null, so pass numbers if you need the geometry in JavaScript.
Related components
- Clickable Card: a container with header, content and footer parts.
- Squircle Smooth Corners: superellipse corners for large surfaces.
- Progressive Blur Effect