Baktiyar Ablaikhan

Scales

Source
Aceternity UI ↗
Author
Aceternity UI
Licence
Aceternity UI licence (free component)

Loading…

A hairline scales pattern; the pointer sets its size and a click rotates it.

Code

"use client";
import { useState } from "react";
import { Scales } from "@/lab/aceternity/ui/scales";

const orientations = ["diagonal", "horizontal", "vertical"] as const;

/**
 * The Scales pattern itself is static. For the lab card the pointer sets the
 * pattern size (left → right) and a click cycles the orientation.
 */
export default function ScalesDemo() {
  const [size, setSize] = useState(10);
  const [index, setIndex] = useState(0);
  const orientation = orientations[index];

  return (
    <div
      className="@container relative h-full w-full cursor-pointer overflow-hidden bg-white select-none dark:bg-black"
      onPointerMove={(e) => {
        const rect = e.currentTarget.getBoundingClientRect();
        const t = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
        setSize(Math.round(6 + t * 22));
      }}
      onPointerLeave={() => setSize(10)}
      onClick={() => setIndex((i) => (i + 1) % orientations.length)}
    >
      <Scales orientation={orientation} size={size} />
      <div className="relative z-10 flex h-full flex-col items-center justify-center gap-2">
        <h2 className="text-[clamp(1.1rem,4cqw,2rem)] font-bold text-neutral-900 capitalize dark:text-white">
          {orientation} Scales
        </h2>
        <p className="font-mono text-[clamp(0.6rem,1.4cqw,0.8rem)] text-neutral-500">
          size {size}px · move to resize · click to rotate
        </p>
      </div>
    </div>
  );
}
Prompt

Build "Scales", a background animation. What it does: A hairline scales pattern; the pointer sets its size and a click rotates it. Write it as a single self-contained React component in TypeScript that fills its parent (w-full h-full), styled with Tailwind CSS. Technique: pointer tracking. It sits on a light background, in a 16:10 frame. Respect prefers-reduced-motion with a still state, pause work when the element is off screen, and keep it accessible. Original: https://ui.aceternity.com/components/scales (Aceternity UI, Aceternity UI licence (free component)).