DNA loaders
Five helix and strand loaders: a DNA helix, a ladder, a twist, a coil and a weave. Each is sized and token-driven.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/loaders-dnaDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/loaders-dna.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* DNA loader family: 5 decorative indicators on a helix, braid and wave theme. Colour comes ONLY from tokens (currentColor / bg-current). Size = the box scale (aligned with the base spinner). DELIBERATE: the loader keeps moving under reduced-motion too. The delays and phases are index-derived and deterministic, nothing random. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const box: Record<StyledSize, string> = {
sm: "size-4",
md: "size-5",
lg: "size-6",
xl: "size-8",
}
type Props = React.ComponentProps<"div"> & { size?: StyledSize; label?: string }
/* Helix: iki dikey nokta serisi sinus fazinda kaymis, DNA sarmali. */
export function HelixLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const dots = [0, 1, 2, 3, 4]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center justify-between text-primary", box[size], className)}
{...props}
>
{dots.map((i) => (
<span key={i} className="relative flex h-full w-1/6 items-center">
<motion.span
className="absolute left-0 size-1 rounded-full bg-current"
animate={{ y: ["-140%", "140%", "-140%"] }}
transition={{ duration: 1.4, ease: "easeInOut", repeat: Infinity, delay: i * 0.14 }}
/>
<motion.span
className="absolute left-0 size-1 rounded-full bg-current/50"
animate={{ y: ["140%", "-140%", "140%"] }}
transition={{ duration: 1.4, ease: "easeInOut", repeat: Infinity, delay: i * 0.14 }}
/>
</span>
))}
</div>
)
}
/* Ladder: yatay basamaklar sirayla yanar. */
export function LadderLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const rungs = [0, 1, 2, 3, 4]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex flex-col items-stretch justify-between text-info", box[size], className)}
{...props}
>
{rungs.map((i) => (
<motion.span
key={i}
className="block h-[12%] w-full rounded-full bg-current"
animate={{ opacity: [0.25, 1, 0.25], scaleX: [0.7, 1, 0.7] }}
transition={{ duration: 1.1, ease: "easeInOut", repeat: Infinity, delay: i * 0.12 }}
/>
))}
</div>
)
}
/* Twist: donen kesikli halka (conic token). */
export function TwistLoader({ className, size = "md", label = "Loading", ...props }: Props) {
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-block text-brand", box[size], className)}
{...props}
>
<motion.span
className="block size-full rounded-full border-2 border-dashed border-current"
animate={{ rotate: 360 }}
transition={{ duration: 2.2, ease: "linear", repeat: Infinity }}
/>
</div>
)
}
/* Coil: bir sira nokta gezen sinus dalgasinda zipla-in. */
export function CoilLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const dots = [0, 1, 2, 3, 4, 5]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("inline-flex items-center justify-between text-success", box[size], className)}
{...props}
>
{dots.map((i) => (
<motion.span
key={i}
className="size-1 rounded-full bg-current"
animate={{ y: ["-120%", "120%", "-120%"] }}
transition={{ duration: 1.2, ease: "easeInOut", repeat: Infinity, delay: i * 0.1 }}
/>
))}
</div>
)
}
/* Weave: two rows of dots cross over each other (a weave). */
export function WeaveLoader({ className, size = "md", label = "Loading", ...props }: Props) {
const reduce = useReducedMotion()
const dots = [0, 1, 2, 3]
return (
<div
data-slot="styled-loader"
role="status"
aria-label={label}
className={cn("relative inline-flex items-center justify-between text-warning", box[size], className)}
{...props}
>
{dots.map((i) => (
<span key={i} className="relative flex h-full w-1/5 items-center justify-center">
<motion.span
className="absolute size-1 rounded-full bg-current"
animate={{ y: reduce ? ["-90%", "90%", "-90%"] : ["-90%", "90%", "-90%"] }}
transition={{ duration: 1, ease: "easeInOut", repeat: Infinity, delay: i * 0.16 }}
/>
<motion.span
className="absolute size-1 rounded-full bg-current/50"
animate={{ y: ["90%", "-90%", "90%"] }}
transition={{ duration: 1, ease: "easeInOut", repeat: Infinity, delay: i * 0.16 }}
/>
</span>
))}
</div>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Helix
Two strands of dots offset in a sine, like a helix.
import { HelixLoader } from "@/components/ui/loaders-dna"
<HelixLoader />Ladder
Horizontal rungs light up in sequence.
import { LadderLoader } from "@/components/ui/loaders-dna"
<LadderLoader />Twist
A dashed token ring rotates.
import { TwistLoader } from "@/components/ui/loaders-dna"
<TwistLoader />Coil
A row of dots bobs in a traveling wave.
import { CoilLoader } from "@/components/ui/loaders-dna"
<CoilLoader />Weave
Two rows of dots cross and weave.
import { WeaveLoader } from "@/components/ui/loaders-dna"
<WeaveLoader />ai2 DNA loaders: 5 styled variations on the token system
The ai2 DNA loaders are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around helix and strand loading indicators. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion drives the sine strands, sequenced rungs and rotation. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the strands keep moving on purpose, like the base Spinner, because a frozen loader reads as a hang.
What is in the ai2 DNA loaders?
5 exports in one file: Helix, Ladder, Twist, Coil and Weave. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion drives the sine strands, sequenced rungs and rotation.
- Reduced-motion aware: Under prefers-reduced-motion, the strands keep moving on purpose, like the base Spinner, because a frozen loader reads as a hang.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The DNA loaders sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.