Kinetic Toggle
Accessible switch control featuring elastic thumb stretch during state changes, crisp hairline borders, and customizable active luminance.
#switch#toggle#form#accessible
Customize
#A855F7
Initial State
Installation
$pnpm dlx yourbrand@latest add @yourbrand/KineticToggle-TS-TWUsage (synced with live props)
<KineticToggle
checkedLabel="Live Sync"
accentColor="#A855F7"
size="md"
defaultChecked
/>Source Code
KineticToggle.tsx"use client";
import React from "react";
export interface KineticToggleProps {
checkedLabel?: string;
accentColor?: string;
size?: "sm" | "md" | "lg";
defaultChecked?: boolean;
}
export function KineticToggle({
checkedLabel = "Live Sync",
accentColor = "#A855F7",
size = "md",
defaultChecked = true,
}: KineticToggleProps) {
const [on, setOn] = React.useState(defaultChecked);
return (
<button
type="button"
role="switch"
aria-checked={on}
onClick={() => setOn((v) => !v)}
className="inline-flex items-center gap-3 rounded-xl border border-white/10 bg-[#1B1722] px-4 py-2.5 text-sm font-medium text-white"
data-size={size}
>
<span
className="relative inline-flex h-6 w-11 items-center rounded-full p-0.5 transition-colors"
style={{ backgroundColor: on ? accentColor : "#37313F" }}
>
<span
className="h-5 w-5 rounded-full bg-white shadow transition-transform duration-200"
style={{ transform: on ? "translateX(20px)" : "translateX(0px)" }}
/>
</span>
<span>{checkedLabel}</span>
</button>
);
}
Props API
| Prop | Type | Default | Description |
|---|---|---|---|
| checkedLabel | string | "Live Sync" | Caption beside the switch. |
| accentColor | string (hex) | "#A855F7" | Track fill when enabled. |
| size | "sm" | "md" | "lg" | "md" | Switch track dimensions. |
| defaultChecked | boolean | true | Start switched on. |