Modus UI

Iron Filings

Web (React)

A field of fine ink filings that turn to face the pointer, like iron around a lodestone.

A field of fine filings in alternating ink and accent. It renders a CSS grid of simple <span> elements and uses a single window event listener to calculate the geometric angle (using Math.acos()) from each line to your mouse, applying the rotation via CSS custom properties.

Modus / Iron Filings

Installation

CLI

npx @modus-ui/cli add iron-filings

Manual

  1. Copy the code from the component tab.
  2. Create a file at components/ui/iron-filings.tsx.
  3. Paste the code.

Usage

tsx
import { IronFilings } from "@/components/ui/iron-filings";

export default function Example() {
  return (
    <div className="flex h-screen w-full items-center justify-center bg-background">
      <IronFilings
        rows={9}
        columns={9}
        lineColor="hsl(var(--primary))"
        lineWidth="2px"
        lineHeight="40px"
      />
    </div>
  );
}

Props

PropTypeDefaultDescription
rowsnumber13Number of rows of lines.
columnsnumber13Number of columns of lines.
containerSizestring"70vmin"CSS size of the square container.
lineColorstring"hsl(var(--foreground))"Colour of the lines.
lineWidthstring"0.4vmin"CSS width of each line.
lineHeightstring"3.6vmin"CSS length of each line.
baseAnglenumber45Resting rotation of the lines in degrees.

Comments

  • No comments yet.