Modus UI

Tactile Switch

Web (React)

One switch in four treatments drawn from the Modus tokens: a flat sprung switch, a pressed-paper tactile slider, Three.js glass and a shader-lit capsule.

A switch that fills its stage, in four styles: a flat switch with a sprung knob in --primary (the default), a tactile slider whose track, knob and mono label come from the theme tokens, a refractive Three.js glass capsule, and a single-shader plasma trough. Every variant follows light and dark appearance automatically, works with keyboard and screen readers, and the WebGL variants react to the pointer. The WebGL variants pause off screen, and with reduced motion every variant snaps instead of animating.

Draft modeOn

Modus / Tactile Switch

Installation

CLI

npx @modus-ui/cli add tactile-switch

Manual

  1. Install three.
  2. Copy the code from the component tab.
  3. Create a file at components/ui/tactile-switch.tsx.
  4. Paste the code.

Usage

tsx
import { TactileSwitch } from "@/components/ui/tactile-switch";

export default function Example() {
  return (
    <div className="flex h-[400px] w-full">
      <TactileSwitch variant="glass" onChange={(on) => console.log(on)} />
    </div>
  );
}

Props

PropTypeDefaultDescription
variant"classic" | "modern" | "glass" | "shader""modern"Which treatment to render.
mode"auto" | "dark" | "light""auto"Appearance; "auto" follows the page theme, then the system.
defaultOnbooleantrueInitial state.
labelstring"Draft mode"Accessible name, also shown on the knob or in the caption.
speednumber1Animation speed of the shader variant (0 to 3).
sizenumber1Scale of the switch (0.35 to 2.5).
opacitynumber1Opacity of the whole stage.
huenumber0Hue rotation in degrees.
saturationnumber1Saturation multiplier.
brightnessnumber1Brightness multiplier.
onChange(on: boolean) => voidnoneCalled with the new state after each toggle.

Comments

  • No comments yet.