UI & States5 min read
Tactile State Machine Toggle Switch
Direct Definition & Architecture
An interactive toggle switch authored in ExodeUI pairs a two-state Boolean machine with elastic squash-and-stretch geometry. As the thumb traverses the track, inertia elongates its horizontal axis before snapping crisply into the active terminal.
Live Physics Canvas
120 FPS GPU RenderState: Active (Checked)
Stiffness (Tension)400
Damping (Friction)26
Technical Specifications
Bundle Footprint
< 1.8 kB gzipped
Frame Rate
120 FPS Fixed Target
States Handled
Off, Dragging, Snapping, On, Disabled
Accessibility
ARIA switch role, keyboard Space/Enter
State Machine Graph
UncheckedThumb anchored left at x: 0, track background stone-800.
Active Drag / LeapThumb elongates scaleX: 1.25 along movement vector.
CheckedThumb anchored right at x: 28, track background violet-600.
Locked / DisabledOpacity 0.4, cursor-not-allowed, gestures blocked.
Production Code Output
interactive-toggle.jsx
import React, { useState } from 'react';
import { motion } from 'framer-motion';
export function InteractiveToggle({ checked = false, onChange }) {
const [isOn, setIsOn] = useState(checked);
const toggle = () => {
const next = !isOn;
setIsOn(next);
onChange?.(next);
};
return (
<button
role="switch"
aria-checked={isOn}
onClick={toggle}
className={`relative w-16 h-9 rounded-full p-1 transition-colors duration-300 ${
isOn ? 'bg-violet-600' : 'bg-stone-800'
}`}
>
<motion.div
layout
transition={{
type: "spring",
stiffness: 450,
damping: 28,
}}
animate={{
x: isOn ? 28 : 0,
scaleX: [1, 1.25, 1],
}}
className="w-7 h-7 rounded-full bg-white shadow-md"
/>
</button>
);
}Architectural Breakdown
Traditional UI switches use linear translations that feel static and robotic.
With ExodeUI, the toggle thumb dynamically expands horizontally while in motion to simulate physical inertia, then snaps back to a circle once resting.
State machines guarantee that rapid toggling cannot trigger orphaned transition states or desynchronized visual values.
Frequently Asked Questions
Explore Related Motion Guides & Tooling
Build your next living interface today.
Design fluid physics and visual logic in ExodeUI and export directly to React, Swift, and Flutter.