Skip to content

Themes

The theme system configures haptic intensity, sound, and visual feedback as a unified preset. Themes ensure consistent multi-sensory feedback across your app.

Built-in Themes

ThemeHapticSoundVisualStyle
default0.7On (0.3)OnFlash
gaming1.0On (0.8)OnShake
minimal0.4OffOnPulse
luxury0.6On (0.25)OnGlow
retro0.9On (0.5)OnFlash
nature0.5On (0.2)OnPulse
silent0.7OffOff--
accessible1.0On (0.6)OnFlash

Using ThemeManager

typescript
import { ThemeManager, themes } from '@hapticjs/core';

const tm = new ThemeManager();

// Apply a built-in theme
tm.setTheme('gaming');

// Read current theme
const theme = tm.getTheme();
console.log(theme.hapticIntensity); // 1.0
console.log(theme.soundEnabled);    // true
console.log(theme.soundVolume);     // 0.8
console.log(theme.visualStyle);     // 'shake'
console.log(theme.colors.primary);  // '#a855f7'

// Current theme name
tm.current;         // 'gaming'

// List all available themes
tm.listThemes();    // ['default', 'gaming', 'minimal', ...]

Custom Themes

Register a custom ThemePreset:

typescript
import { ThemeManager } from '@hapticjs/core';
import type { ThemePreset } from '@hapticjs/core';

const tm = new ThemeManager();

const myTheme: ThemePreset = {
  name: 'neon',
  hapticIntensity: 0.8,
  soundEnabled: true,
  soundVolume: 0.4,
  visualEnabled: true,
  visualStyle: 'ripple',
  colors: {
    primary: '#ff6bff',
    success: '#39ff14',
    error: '#ff073a',
    warning: '#ffbe0b',
  },
};

tm.registerTheme(myTheme);
tm.setTheme('neon');

ThemePreset Interface

typescript
interface ThemePreset {
  name: string;
  hapticIntensity: number;        // 0.0 - 1.0
  soundEnabled: boolean;
  soundVolume: number;            // 0.0 - 1.0
  visualEnabled: boolean;
  visualStyle: 'flash' | 'ripple' | 'shake' | 'glow' | 'pulse';
  colors: {
    primary: string;
    success: string;
    error: string;
    warning: string;
  };
}

Themes with SensoryEngine

Themes are most powerful when combined with the SensoryEngine:

typescript
import { SensoryEngine } from '@hapticjs/core';

const engine = SensoryEngine.create({ theme: 'gaming' });

// All effects use gaming theme settings automatically
await engine.tap();       // Strong haptic + loud click + shake
await engine.success();   // Strong haptic + chime + neon green glow

// Switch themes dynamically
engine.setTheme('luxury');
await engine.tap();       // Moderate haptic + soft click + gold glow

Visual Styles

Each theme specifies a visualStyle that determines the CSS effect:

StyleEffect
flashQuick screen color flash
rippleMaterial Design ripple at center
shakeCSS shake animation
glowBox shadow glow effect
pulseScale pulse animation

Released under the MIT License.