# Rim Light

> A point of light that laps a card's border at a steady pace with a fading tail, tracing rounded corners exactly; every beam on the page shares one clock, so busy cards pulse in step.

- Page: https://devl.dev/motion/rim-light
- Kind: motion · Surfaces
- Install: `npx shadcn@latest add https://devl.dev/r/rim-light.json`
- Raw source: https://devl.dev/raw/rim-light.tsx
- npm: motion
- License: MIT. The coss ui components it uses (https://coss.com/ui) are AGPL-3.0.

## Usage

```tsx
import { CheckIcon, DatabaseIcon, FileSearchIcon, LoaderIcon } from "lucide-react";
import { RimLight } from "@/components/rim-light";

const steps = [
  { label: "Build", meta: "41s", state: "done" },
  { label: "Upload assets", meta: "312 files", state: "running" },
  { label: "Promote to production", meta: "queued", state: "queued" },
] as const;

export default function RimLightDemo() {
  return (
    <div className="grid w-full max-w-md grid-cols-2 gap-3">
      <div className="relative col-span-2 flex flex-col gap-4 rounded-2xl border bg-card p-5 shadow-xs/5">
        <RimLight className="text-brand-ink" />
        <div className="flex items-center justify-between gap-3">
          <div className="flex flex-col gap-0.5">
            <span className="font-medium text-sm">Deploying northwind-web</span>
            <span className="font-mono text-muted-foreground text-xs">main · 4f2a91c</span>
          </div>
          <span className="rounded-full bg-brand/24 px-2 py-0.5 font-medium text-brand-ink text-xs">Live in ~1 min</span>
        </div>
        <ol className="flex flex-col gap-2.5">
          {steps.map((s) => (
            <li className="flex items-center gap-2.5 text-sm" key={s.label}>
              <span className="grid size-5 place-items-center rounded-full border bg-background">
                {s.state === "done" && <CheckIcon className="size-3 text-success-foreground" />}
                {s.state === "running" && <LoaderIcon className="size-3 animate-spin text-muted-foreground motion-reduce:animate-none" />}
              </span>
              <span className={s.state === "queued" ? "text-muted-foreground" : undefined}>{s.label}</span>
              <span className="ml-auto font-mono text-muted-foreground text-xs tabular-nums">{s.meta}</span>
            </li>
          ))}
        </ol>
      </div>

      <div className="relative flex flex-col gap-3 rounded-2xl border bg-card p-4 shadow-xs/5">
        <RimLight className="text-info" />
        <FileSearchIcon className="size-4 text-muted-foreground" />
        <div className="flex flex-col gap-0.5">
          <span className="font-medium text-sm">Indexing docs</span>
          <span className="text-muted-foreground text-xs tabular-nums">1,284 of 2,060 pages</span>
        </div>
      </div>

      <div className="relative flex flex-col gap-3 rounded-2xl border bg-card p-4 shadow-xs/5">
        <RimLight className="text-violet-500 dark:text-violet-400" />
        <DatabaseIcon className="size-4 text-muted-foreground" />
        <div className="flex flex-col gap-0.5">
          <span className="font-medium text-sm">Syncing contacts</span>
          <span className="text-muted-foreground text-xs tabular-nums">4,120 merged</span>
        </div>
      </div>
    </div>
  );
}
```

## Props

| Prop | Type | Default |
| --- | --- | --- |
| `duration`? | `number` | `6` |
| `length`? | `number` | `0.16` |
| `phase`? | `number` | `0` |
| `reverse`? | `boolean` | `false` |
| `width`? | `number` | `1.5` |
| `className`? | `string` |  |

## Source: components/rim-light.tsx

```tsx
"use client";

import { useReducedMotion } from "motion/react";
import { useId, useLayoutEffect, useRef, useState } from "react";
import { cn } from "@/lib/utils";

export interface RimLightProps {
  duration?: number;
  length?: number;
  phase?: number;
  reverse?: boolean;
  width?: number;
  className?: string;
}

const TAIL = [
  { share: 0.3, opacity: 1 },
  { share: 0.6, opacity: 0.45 },
  { share: 1, opacity: 0.18 },
];

export function RimLight({ duration = 6, length = 0.16, phase = 0, reverse = false, width = 1.5, className }: RimLightProps) {
  const reduce = useReducedMotion();
  const glowId = `beam-glow-${useId().replace(/:/g, "")}`;
  const ref = useRef<SVGSVGElement>(null);
  const [box, setBox] = useState<{ w: number; h: number; r: number } | null>(null);
  const [onScreen, setOnScreen] = useState(true);

  useLayoutEffect(() => {
    const parent = ref.current?.parentElement;
    if (!parent) return;
    const measure = () => {
      const r = Number.parseFloat(getComputedStyle(parent).borderTopLeftRadius) || 0;
      setBox({ w: parent.offsetWidth, h: parent.offsetHeight, r });
    };
    measure();
    const ro = new ResizeObserver(measure);
    ro.observe(parent);
    const io = new IntersectionObserver(([e]) => setOnScreen(e.isIntersecting));
    io.observe(parent);
    return () => {
      ro.disconnect();
      io.disconnect();
    };
  }, []);

  useLayoutEffect(() => {
    const svg = ref.current;
    if (!svg || !box || reduce || !onScreen) return;
    const anims = [...svg.querySelectorAll<SVGRectElement>("[data-dash]")].map((rect) => {
      const dash = Number(rect.dataset.dash);
      const from = dash - phase * 100;
      const a = rect.animate(
        { strokeDashoffset: reverse ? [from - 100, from] : [from, from - 100] },
        { duration: duration * 1000, iterations: Number.POSITIVE_INFINITY, easing: "linear" },
      );
      a.startTime = 0;
      return a;
    });
    return () => {
      for (const a of anims) a.cancel();
    };
  }, [box, duration, phase, reverse, reduce, onScreen]);

  const rect = box && {
    x: 0.5,
    y: 0.5,
    width: Math.max(box.w - 1, 0),
    height: Math.max(box.h - 1, 0),
    rx: Math.max(box.r - 0.5, 0),
  };

  return (
    <svg
      aria-hidden
      className={cn("pointer-events-none absolute -inset-px size-[calc(100%+2px)] overflow-visible", className)}
      ref={ref}
    >
      {rect && reduce && <rect {...rect} fill="none" opacity={0.35} stroke="currentColor" strokeWidth={1} />}
      {rect && !reduce && (
        <>
          <defs>
            <filter height="200%" id={glowId} width="200%" x="-50%" y="-50%">
              <feGaussianBlur stdDeviation={3} />
            </filter>
          </defs>
          <g filter={`url(#${glowId})`} opacity={0.7}>
            <Dash dash={length * 100 * TAIL[0].share} rect={rect} width={width + 2} />
          </g>
          {TAIL.map((t) => (
            <Dash dash={length * 100 * t.share} key={t.share} opacity={t.opacity} rect={rect} width={width} />
          ))}
        </>
      )}
    </svg>
  );
}

function Dash({
  rect,
  dash,
  width,
  opacity = 1,
}: {
  rect: { x: number; y: number; width: number; height: number; rx: number };
  dash: number;
  width: number;
  opacity?: number;
}) {
  return (
    <rect
      {...rect}
      data-dash={dash}
      fill="none"
      opacity={opacity}
      pathLength={100}
      stroke="currentColor"
      strokeDasharray={`${dash} ${100 - dash}`}
      strokeDashoffset={dash}
      strokeLinecap="round"
      strokeWidth={width}
    />
  );
}
```
