Arc Ring
Arc ring background graphic: a faint full ring with a bright stroke along part of it that fades toward its end, placed by its center and turning on its own when animated. Hidden from assistive tech; reduced motion holds it still.
import { useId, type ComponentProps, type CSSProperties } from "react"
import { cn } from "cn"
// One turn for every ring, backwards when ccw; reduced motion holds it still.
// Arc ships the same rule under the same href, so React keeps one copy.
const ARC_CSS = `@keyframes arc-turn{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion: no-preference){
[data-slot="arc-layer"][data-animate] :is([data-slot="arc"],[data-slot="arc-ring"]),:is([data-slot="arc"],[data-slot="arc-ring"])[data-animate]{animation:arc-turn var(--arc-duration) linear infinite var(--arc-direction)}}`
const finite = (n: number | undefined, fallback: number) =>
n !== undefined && Number.isFinite(n) ? n : fallback
type ArcRingProps = Omit<ComponentProps<"div">, "color"> & {
/** Diameter in px, or any CSS length such as "80cqw". 900 by default. */
size?: number | string
/** The center's distance from the parent's left edge; any CSS length. */
left?: string
/** The center's distance from the parent's top edge; any CSS length. */
top?: string
/** Where the lit stroke starts, in degrees clockwise from 12 o'clock; 0. */
from?: number
/** How far the lit stroke runs, in degrees from 0 to 360; 108. */
sweep?: number
/** The lit stroke's color. */
color?: string
/** The faint full ring's color. */
track?: string
/** The lit stroke's thickness in px; 2.5. */
width?: number
/** The faint full ring's thickness in px; 1.5. */
trackWidth?: number
/** Which way the ring turns when animated: clockwise or counterclockwise. */
turn?: "cw" | "ccw"
/** Turns this ring on its own. Reduced motion holds it still. */
animate?: boolean
/** Seconds per full turn; 26 by default. */
duration?: number
}
/**
* A faint full ring with a bright stroke along part of it that fades toward
* its end, for the background behind a section. Place it like `Arc`: in an
* `ArcLayer` or another positioned parent, with `left` and `top` setting its
* center.
*
* It is hidden from assistive tech and ignores the pointer. When animated it
* makes one full turn per `duration`; reduced motion holds it still.
*/
function ArcRing({
size = 900,
left = "50%",
top = "50%",
from,
sweep,
color = "oklch(0.842 0.061 196)",
track = "oklch(0.842 0.061 196 / 0.14)",
width,
trackWidth = 1.5,
turn = "cw",
animate = false,
duration,
className,
style,
...props
}: ArcRingProps) {
const gradientId = `arc-ring-${useId().replace(/[^\w-]/g, "")}`
const start = finite(from, 0)
const lit = Math.min(360, Math.max(0, finite(sweep, 108)))
const stroke = Math.max(0, finite(width, 2.5))
const seconds =
duration !== undefined && Number.isFinite(duration) && duration > 0
? duration
: 26
const diameter = typeof size === "number" ? `${size}px` : size
// The stroke fades along its own chord, clamped at a half turn.
const end = (Math.min(lit, 180) * Math.PI) / 180
return (
<div
data-slot="arc-ring"
data-turn={turn}
data-animate={animate || undefined}
aria-hidden="true"
className={cn("pointer-events-none absolute rounded-full", className)}
style={
{
left,
top,
width: size,
height: size,
margin: `calc(${diameter} / -2) 0 0 calc(${diameter} / -2)`,
rotate: start ? `${start}deg` : undefined,
"--arc-duration": `${seconds}s`,
"--arc-direction": turn === "ccw" ? "reverse" : "normal",
...style,
} as CSSProperties
}
{...props}
>
<style href="arc" precedence="medium">
{ARC_CSS}
</style>
<svg className="block size-full overflow-visible">
<defs>
<linearGradient
id={gradientId}
x1="0.5"
y1="0"
x2={0.5 + 0.5 * Math.sin(end)}
y2={0.5 - 0.5 * Math.cos(end)}
>
<stop offset="0" stopColor={color} />
<stop offset="0.55" stopColor={color} />
<stop offset="1" stopColor={color} stopOpacity="0" />
</linearGradient>
</defs>
<circle
cx="50%"
cy="50%"
r="50%"
fill="none"
stroke={track}
strokeWidth={trackWidth}
/>
{lit > 0 && (
<circle
cx="50%"
cy="50%"
r="50%"
fill="none"
stroke={`url(#${gradientId})`}
strokeWidth={stroke}
strokeLinecap="round"
pathLength={360}
strokeDasharray={`${lit} ${360 - lit}`}
strokeDashoffset={90}
/>
)}
</svg>
</div>
)
}
export { ArcRing }
import type { ComponentProps } from "react"
import { ArcLayer } from "@/components/glow/arc"
import { ArcRing } from "@/components/glow/arc-ring"
import { Grid } from "@/components/grid/grid"
import { DemoLabel } from "@/components/text/demo-label"
const COPY = {
default: "Default: sweep 108, width 2.5, faint track",
sweep: "sweep",
width: "width",
from: "from 200",
color: "color amber, track amber at 20%",
noTrack: "track transparent",
animate: "animate: one turn every 26 s",
} as const
// The ring the examples start from, sized to show whole in a tile.
const BASE = { size: 220 } as const
const ITEMS: { label: string; props: ComponentProps<typeof ArcRing> }[] = [
{ label: COPY.default, props: {} },
{ label: `${COPY.sweep} 40`, props: { sweep: 40 } },
{ label: `${COPY.sweep} 240`, props: { sweep: 240 } },
{ label: `${COPY.width} 1`, props: { width: 1 } },
{ label: `${COPY.width} 6`, props: { width: 6 } },
{ label: COPY.from, props: { from: 200 } },
{
label: COPY.color,
props: {
color: "oklch(0.85 0.14 80)",
track: "oklch(0.85 0.14 80 / 0.2)",
},
},
{ label: COPY.noTrack, props: { track: "transparent" } },
{ label: COPY.animate, props: { animate: true } },
]
/** Arc Ring as it ships, then with other sweeps, widths, a starting angle,
* another color, no track, and turning. */
export default function ArcRingDemo() {
return (
<Grid cols={1} gap="sm" className="p-6 sm:grid-cols-2 lg:grid-cols-3">
{ITEMS.map(({ label, props }) => (
<div key={label} className="grid gap-2">
<div className="dark relative isolate aspect-video overflow-hidden rounded-(--tile-radius) bg-background text-foreground">
<ArcLayer>
<ArcRing {...BASE} {...props} />
</ArcLayer>
</div>
<DemoLabel>{label}</DemoLabel>
</div>
))}
</Grid>
)
}
import type { ComponentProps, CSSProperties } from "react"
import { cn } from "cn"
// One turn for every ring, backwards when ccw; reduced motion holds it still.
// Arc Ring ships the same rule under the same href, so React keeps one copy.
const ARC_CSS = `@keyframes arc-turn{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion: no-preference){
[data-slot="arc-layer"][data-animate] :is([data-slot="arc"],[data-slot="arc-ring"]),:is([data-slot="arc"],[data-slot="arc-ring"])[data-animate]{animation:arc-turn var(--arc-duration) linear infinite var(--arc-direction)}}`
const finite = (n: number | undefined, fallback: number) =>
n !== undefined && Number.isFinite(n) ? n : fallback
/**
* A layer for `Arc` and `ArcRing` rings behind a section's content. It fills
* its positioned parent, clips any ring that runs past its edge, and ignores
* the pointer.
*/
function ArcLayer({
animate = false,
className,
...props
}: ComponentProps<"div"> & {
/**
* Turns every ring inside, each at its own speed and direction. Reduced
* motion holds them still.
*/
animate?: boolean
}) {
return (
<div
data-slot="arc-layer"
data-animate={animate || undefined}
className={cn(
"pointer-events-none absolute inset-0 overflow-hidden",
className
)}
{...props}
/>
)
}
type ArcProps = Omit<ComponentProps<"div">, "color"> & {
/** Diameter in px, or any CSS length such as "80cqw". 900 by default. */
size?: number | string
/** The center's distance from the parent's left edge; any CSS length. */
left?: string
/** The center's distance from the parent's top edge; any CSS length. */
top?: string
/** Where the lit part starts, in degrees clockwise from 12 o'clock; 150. */
from?: number
/** How far the lit part runs, in degrees from 0 to 360; 150. */
sweep?: number
/** The color at the brightest point of the lit part. */
color?: string
/** The dimmer color the lit part fades through. */
fade?: string
/** Which way the ring turns when animated: clockwise or counterclockwise. */
turn?: "cw" | "ccw"
/** Turns this ring on its own. Reduced motion holds it still. */
animate?: boolean
/** Seconds per full turn: 90 clockwise, 120 counterclockwise by default. */
duration?: number
}
/**
* A ring of light for the background behind a section: thin and soft, it
* brightens and fades along its lit part and lightens what is under it. Put
* it in an `ArcLayer` or another positioned parent: `left` and `top` set its
* center, and a ring often sits partly past the frame's edge. For a bright
* stroke over a faint full ring, use `ArcRing`.
*
* It is hidden from assistive tech and ignores the pointer. When animated it
* makes one full turn per `duration`; reduced motion holds it still.
*/
function Arc({
size = 900,
left = "50%",
top = "50%",
from,
sweep,
color = "oklch(0.80 0.06 350 / 0.65)",
fade = "oklch(0.60 0.05 340 / 0.25)",
turn = "cw",
animate = false,
duration,
className,
style,
...props
}: ArcProps) {
const start = finite(from, 150)
const lit = Math.min(360, Math.max(0, finite(sweep, 150)))
const seconds =
duration !== undefined && Number.isFinite(duration) && duration > 0
? duration
: turn === "ccw"
? 120
: 90
const diameter = typeof size === "number" ? `${size}px` : size
return (
<div
data-slot="arc"
data-turn={turn}
data-animate={animate || undefined}
aria-hidden="true"
className={cn(
"pointer-events-none absolute rounded-full mix-blend-screen",
className
)}
style={
{
left,
top,
width: size,
height: size,
margin: `calc(${diameter} / -2) 0 0 calc(${diameter} / -2)`,
"--arc-duration": `${seconds}s`,
"--arc-direction": turn === "ccw" ? "reverse" : "normal",
background: `conic-gradient(from ${start}deg, transparent 0deg, ${color} ${lit * 0.37}deg, ${fade} ${lit * 0.63}deg, transparent ${lit}deg)`,
mask: "radial-gradient(closest-side in srgb, transparent calc(100% - 2px), oklch(0 0 0) calc(100% - 0.5px), transparent calc(100% + 1px))",
...style,
} as CSSProperties
}
{...props}
>
<style href="arc" precedence="medium">
{ARC_CSS}
</style>
</div>
)
}
export { Arc, ArcLayer }
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 { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const GRID_DEFAULTS = { cols: 3, gap: "lg" } as const
const containerGridVariants = cva("grid w-full grid-cols-1", {
variants: {
/**
* The most columns. Below 40rem of screen width the grid is one
* column (two for `6`); it steps up at 40rem and 48rem: `2` is two
* columns from 40rem, `3` two then three, `4` two then four, `5` three
* then five, and `6` three, then four, then six from 64rem. The default
* is 3.
*/
cols: {
1: "",
2: "sm:grid-cols-2",
3: "sm:grid-cols-2 md:grid-cols-3",
4: "sm:grid-cols-2 md:grid-cols-4",
5: "sm:grid-cols-3 md:grid-cols-5",
6: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6",
},
/**
* Space between items: `xs` 8px, `sm` 16px, `md` 24px, `lg` 40px, `xl` 64px, `px` 1px, `none` 0. `lg`
* is the default. The sizes are the `--gap-*` values in globals.css.
*/
gap: {
xs: "gap-(--gap-xs)",
sm: "gap-(--gap-sm)",
md: "gap-(--gap-md)",
lg: "gap-(--gap-lg)",
xl: "gap-(--gap-xl)",
px: "gap-px",
none: "gap-0",
},
},
defaultVariants: GRID_DEFAULTS,
})
type GridState = { slot: "grid" } & VariantProps<typeof containerGridVariants>
type GridProps = useRender.ComponentProps<"div", GridState> &
VariantProps<typeof containerGridVariants>
/**
* Columns follow the screen, stepping at 40rem and 48rem (and 64rem for six).
* Gap sizes read the shared `--gap-*` values in globals.css. The grid fills
* its parent's width: without that, a grid given `mx-auto` or set inside a
* centering parent shrinks to fit its content, and a part built on it that
* is a container collapses to nothing.
*
* className, render and every other prop go to the grid. To narrow a Grid, pass
* a `max-w-*` class or size its parent.
*/
function Grid({
className,
cols = GRID_DEFAULTS.cols,
gap = GRID_DEFAULTS.gap,
render,
...props
}: GridProps) {
const grid = useRender({
defaultTagName: "div",
render,
state: { slot: "grid", cols, gap },
props: mergeProps<"div">(
{ className: cn(containerGridVariants({ cols, gap }), className) },
props
),
})
return grid
}
export { Grid, type GridProps }
Installation
npx shadcn@latest add @01orbital/arc-ringUsage
import type { ComponentProps } from "react"
import { ArcLayer } from "@/components/glow/arc"
import { ArcRing } from "@/components/glow/arc-ring"
import { Grid } from "@/components/grid/grid"
import { DemoLabel } from "@/components/text/demo-label"
const COPY = {
default: "Default: sweep 108, width 2.5, faint track",
sweep: "sweep",
width: "width",
from: "from 200",
color: "color amber, track amber at 20%",
noTrack: "track transparent",
animate: "animate: one turn every 26 s",
} as const
// The ring the examples start from, sized to show whole in a tile.
const BASE = { size: 220 } as const
const ITEMS: { label: string; props: ComponentProps<typeof ArcRing> }[] = [
{ label: COPY.default, props: {} },
{ label: `${COPY.sweep} 40`, props: { sweep: 40 } },
{ label: `${COPY.sweep} 240`, props: { sweep: 240 } },
{ label: `${COPY.width} 1`, props: { width: 1 } },
{ label: `${COPY.width} 6`, props: { width: 6 } },
{ label: COPY.from, props: { from: 200 } },
{
label: COPY.color,
props: {
color: "oklch(0.85 0.14 80)",
track: "oklch(0.85 0.14 80 / 0.2)",
},
},
{ label: COPY.noTrack, props: { track: "transparent" } },
{ label: COPY.animate, props: { animate: true } },
]
/** Arc Ring as it ships, then with other sweeps, widths, a starting angle,
* another color, no track, and turning. */
export default function ArcRingDemo() {
return (
<Grid cols={1} gap="sm" className="p-6 sm:grid-cols-2 lg:grid-cols-3">
{ITEMS.map(({ label, props }) => (
<div key={label} className="grid gap-2">
<div className="dark relative isolate aspect-video overflow-hidden rounded-(--tile-radius) bg-background text-foreground">
<ArcLayer>
<ArcRing {...BASE} {...props} />
</ArcLayer>
</div>
<DemoLabel>{label}</DemoLabel>
</div>
))}
</Grid>
)
}This example installs with everything it uses:
npx shadcn@latest add @01orbital/arc-ring-demoAPI reference
A faint full ring with a bright stroke along part of it that fades toward its end, for the background behind a section. Place it like Arc: in an ArcLayer or another positioned parent, with left and top setting its center.
It is hidden from assistive tech and ignores the pointer. When animated it makes one full turn per duration; reduced motion holds it still.
Prop
Type
It also 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 Arc Ring.
Last updated on