Skip to main content
ExodeUI

EXODEUI DESKTOP

A little space for good ideas.

Choose your platform to get the official ExodeUI installer.

Looking for Intel Mac or other builds? Explore the web studio or check all download options.

Prefer the browser? Try for free in your browser →

React Recipe • Production Pattern

React Animated Toggle Switch: Spring-Driven Sliders & Interactive Switches

Static checkbox toggles and simple CSS slide buttons often feel stiff and unresponsive on touch devices. ExodeUI brings tactile spring dynamics, draggable handles, and state machine logic to React animated toggle switches. Whether user clicks, swipes, or drags the toggle thumb, ExodeUI simulates realistic momentum and restitution, snapping cleanly into active or inactive states with zero lag.

Live Interactive Stage
GPU WebGL / React Canvas
Toggle State: TRUE (Active)
Harmonic spring (stiffness: 220, damping: 18)

Runnable ExodeUI React Code Example

Production Ready

Import the ExodeUICanvas component directly into your React application tree. Wire states, triggers, and parameters declaratively:

jsx
import React, { useState } from 'react';
import { ExodeUICanvas } from 'exodeui';

export function DarkModeToggle({ onToggle }) {
  const [checked, setChecked] = useState(false);

  const handleToggle = () => {
    const nextState = !checked;
    setChecked(nextState);
    if (onToggle) onToggle(nextState);
  };

  return (
    <div
      role="switch"
      aria-checked={checked}
      onClick={handleToggle}
      className="toggle-wrapper"
    >
      <ExodeUICanvas
        src="/scenes/spring-toggle.json"
        stateMachine="ToggleSwitch"
        inputs={{
          "isActive": checked,
          "stiffness": 220,
          "damping": 18
        }}
      />
    </div>
  );
}

Frequently Asked Questions about animated toggle button

Can users drag the toggle handle as well as click it?

Yes. ExodeUI state machines support pointer gestures and drag constraints, so users can either tap the switch or drag the thumb across the track with real inertia.

How does ExodeUI prevent toggle bounce from triggering multiple state updates?

State transitions in ExodeUI are guarded by flow rules and entry conditions, ensuring an event only fires once when the toggle reaches its threshold.

Is an animated toggle switch accessible for screen readers?

Yes. By rendering the interactive canvas inside an element with role="switch" and aria-checked, assistive technologies announce state changes correctly.

Can ExodeUI toggles trigger custom haptic feedback on mobile?

Yes. ExodeUI’s onStateChange event fires exactly when the threshold snaps, allowing you to trigger native device haptic vibrations in React Native or iOS.

Explore Related Recipes & Architectural References