Neon toggles
Five glowing switches: neon, outline, pulse, tube and flicker. Each is sized, token-driven and keyboard accessible with role switch.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/toggles-neonDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/toggles-neon.tsx"use client"
import * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Neon toggle family: 5 glowing switches. role="switch", keyboard accessible. The
color and the glow come ONLY from tokens (box-shadow). The thumb slides with the
framer-motion `layout` and switches instantly under reduced-motion; the continuous
flicker/pulse stops under reduced-motion. Used uncontrolled (defaultChecked) or
controlled. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const trackSize: Record<StyledSize, string> = {
sm: "h-5 w-9 p-0.5",
md: "h-6 w-11 p-0.5",
lg: "h-7 w-[52px] p-1",
xl: "h-8 w-[60px] p-1",
}
const thumbSize: Record<StyledSize, string> = {
sm: "size-4",
md: "size-5",
lg: "size-5",
xl: "size-6",
}
const trackBase =
"relative inline-flex shrink-0 cursor-pointer items-center outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50"
interface ToggleProps extends Omit<React.ComponentProps<"button">, "onChange"> {
size?: StyledSize
checked?: boolean
defaultChecked?: boolean
onCheckedChange?: (checked: boolean) => void
}
function useToggle(props: ToggleProps) {
const { checked, defaultChecked, onCheckedChange } = props
const reduce = useReducedMotion()
const [internal, setInternal] = React.useState(defaultChecked ?? false)
const on = checked ?? internal
const toggle = () => {
if (checked === undefined) setInternal((v) => !v)
onCheckedChange?.(!on)
}
const spring = reduce ? { duration: 0 } : ({ type: "spring", stiffness: 500, damping: 30 } as const)
return { on, toggle, spring }
}
function stripToggleProps(props: ToggleProps) {
const { checked, defaultChecked, onCheckedChange, size, className, children, ...rest } = props
return rest
}
/* Neon: acikken izin cevresinde token neon isima. */
export function NeonToggle(props: ToggleProps) {
const { on, toggle, spring } = useToggle(props)
const size = props.size ?? "md"
return (
<button
type="button"
role="switch"
aria-checked={on}
data-slot="styled-toggle"
onClick={toggle}
className={cn(trackBase, trackSize[size], "rounded-full transition-[background-color,box-shadow]", on ? "justify-end bg-info" : "justify-start bg-input", props.className)}
style={on ? { boxShadow: "0 0 12px 2px color-mix(in oklab, var(--info) 70%, transparent)" } : undefined}
{...stripToggleProps(props)}
>
<motion.span layout transition={spring} className={cn(thumbSize[size], "rounded-full bg-background shadow-sm")} />
</button>
)
}
/* OutlineNeon: a token line outline that glows while on. */
export function OutlineNeonToggle(props: ToggleProps) {
const { on, toggle, spring } = useToggle(props)
const size = props.size ?? "md"
return (
<button
type="button"
role="switch"
aria-checked={on}
data-slot="styled-toggle"
onClick={toggle}
className={cn(
trackBase,
trackSize[size],
"rounded-full border-2 bg-transparent transition-[border-color,box-shadow]",
on ? "justify-end border-success" : "justify-start border-field-border",
props.className
)}
style={on ? { boxShadow: "0 0 8px 1px color-mix(in oklab, var(--success) 65%, transparent), inset 0 0 6px 0 color-mix(in oklab, var(--success) 40%, transparent)" } : undefined}
{...stripToggleProps(props)}
>
<motion.span layout transition={spring} className={cn(thumbSize[size], "rounded-full", on ? "bg-success" : "bg-input")} />
</button>
)
}
/* PulseNeon: acikken iz token isimayi nabiz gibi atar. */
export function PulseNeonToggle(props: ToggleProps) {
const { on, toggle, spring } = useToggle(props)
const reduce = useReducedMotion()
const size = props.size ?? "md"
const animate =
on && !reduce
? {
boxShadow: [
"0 0 6px 1px color-mix(in oklab, var(--primary) 45%, transparent)",
"0 0 16px 3px color-mix(in oklab, var(--primary) 80%, transparent)",
"0 0 6px 1px color-mix(in oklab, var(--primary) 45%, transparent)",
],
}
: { boxShadow: on ? "0 0 12px 2px color-mix(in oklab, var(--primary) 70%, transparent)" : "0 0 0px 0px transparent" }
return (
<button
type="button"
role="switch"
aria-checked={on}
data-slot="styled-toggle"
onClick={toggle}
className={cn(trackBase, trackSize[size], "rounded-full transition-colors", on ? "justify-end bg-primary" : "justify-start bg-input", props.className)}
{...stripToggleProps(props)}
>
<motion.span
aria-hidden
className="pointer-events-none absolute inset-0 rounded-full"
animate={animate}
transition={on && !reduce ? { duration: 1.4, repeat: Infinity, ease: "easeInOut" } : { duration: 0 }}
/>
<motion.span layout transition={spring} className={cn(thumbSize[size], "relative z-10 rounded-full bg-background shadow-sm")} />
</button>
)
}
/* Tube: a neon-tube look, with a thumb glowing at its ends. */
export function TubeToggle(props: ToggleProps) {
const { on, toggle, spring } = useToggle(props)
const size = props.size ?? "md"
return (
<button
type="button"
role="switch"
aria-checked={on}
data-slot="styled-toggle"
onClick={toggle}
className={cn(
trackBase,
trackSize[size],
"rounded-full border transition-[background-color,box-shadow]",
on ? "justify-end border-info bg-info/20" : "justify-start border-field-border bg-input",
props.className
)}
style={on ? { boxShadow: "0 0 10px 1px color-mix(in oklab, var(--info) 60%, transparent), inset 0 0 8px 0 color-mix(in oklab, var(--info) 55%, transparent)" } : undefined}
{...stripToggleProps(props)}
>
<motion.span
layout
transition={spring}
className={cn(thumbSize[size], "rounded-full", on ? "bg-info" : "bg-background")}
style={on ? { boxShadow: "0 0 8px 1px color-mix(in oklab, var(--info) 75%, transparent)" } : undefined}
/>
</button>
)
}
/* Flicker: acikken isimada ince neon titremesi. */
export function FlickerToggle(props: ToggleProps) {
const { on, toggle, spring } = useToggle(props)
const reduce = useReducedMotion()
const size = props.size ?? "md"
const animate = on && !reduce ? { opacity: [1, 0.6, 1, 0.8, 1] } : { opacity: on ? 1 : 0 }
return (
<button
type="button"
role="switch"
aria-checked={on}
data-slot="styled-toggle"
onClick={toggle}
className={cn(trackBase, trackSize[size], "rounded-full transition-colors", on ? "justify-end bg-success" : "justify-start bg-input", props.className)}
{...stripToggleProps(props)}
>
<motion.span
aria-hidden
className="pointer-events-none absolute inset-0 rounded-full"
style={{ boxShadow: "0 0 12px 2px color-mix(in oklab, var(--success) 70%, transparent)" }}
animate={animate}
transition={on && !reduce ? { duration: 1.1, repeat: Infinity, ease: "easeInOut", times: [0, 0.2, 0.4, 0.7, 1] } : { duration: 0 }}
/>
<motion.span layout transition={spring} className={cn(thumbSize[size], "relative z-10 rounded-full bg-background shadow-sm")} />
</button>
)
}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.
Neon
A token neon glow around the track when on.
import { NeonToggle } from "@/components/ui/toggles-neon"
<NeonToggle defaultChecked={true} />Outline
A glowing token outline.
import { OutlineNeonToggle } from "@/components/ui/toggles-neon"
<OutlineNeonToggle defaultChecked={true} />Pulse
The track pulses a token glow while on.
import { PulseNeonToggle } from "@/components/ui/toggles-neon"
<PulseNeonToggle defaultChecked={true} />Tube
A neon-tube look.
import { TubeToggle } from "@/components/ui/toggles-neon"
<TubeToggle defaultChecked={true} />Flicker
A subtle neon flicker on the glow.
import { FlickerToggle } from "@/components/ui/toggles-neon"
<FlickerToggle defaultChecked={true} />ai2 Neon toggles: 5 styled variations on the token system
The ai2 Neon toggles are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around glowing neon switches. 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 pulses and flickers the token glow and slides the thumb. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the pulse and flicker stop and a static glow remains.
What is in the ai2 Neon toggles?
5 exports in one file: Neon, Outline, Pulse, Tube and Flicker. 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 pulses and flickers the token glow and slides the thumb.
- Reduced-motion aware: Under prefers-reduced-motion, the pulse and flicker stop and a static glow remains.
- 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 Neon toggles 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.