Cross-platform haptic and audio feedback library for web applications.
- 🎵 WebAudio-based click sounds with configurable intensity and gain
- 📳 Haptic feedback for mobile devices (iOS and Android)
- 🔧 Cross-platform compatibility (iOS, Android, web browsers)
- 🎛️ Multiple feedback presets (light, heavy, success, error, etc.)
- 💾 User preference management with pluggable storage
- 🚀 Framework-agnostic (works with React, Vue, vanilla JS)
- 📱 iOS special handling for optimal haptic feedback
npm install @present-day/buzzimport { triggerInteractionFeedback, INTERACTION_FEEDBACK_PRESET } from '@present-day/buzz'
// Trigger light feedback (default)
triggerInteractionFeedback()
// Trigger specific preset
triggerInteractionFeedback({ preset: INTERACTION_FEEDBACK_PRESET.SUCCESS })
// Override individual settings
triggerInteractionFeedback({
hapticEnabled: true,
soundEnabled: false,
preset: INTERACTION_FEEDBACK_PRESET.ERROR
})Triggers haptic and/or audio feedback based on the provided options.
type TriggerInteractionFeedbackOptions = {
preset?: InteractionFeedbackPreset
hapticPreset?: HapticFeedbackPreset
soundPreset?: SoundFeedbackPreset
hapticEnabled?: boolean
soundEnabled?: boolean
storageAdapter?: StorageAdapter
}Cancels any ongoing haptic feedback (if supported by the platform).
Returns whether haptic feedback is available on the current device.
Available presets for both haptic and sound feedback:
LIGHT- Subtle feedbackMEDIUM- Moderate feedbackHEAVY- Strong feedbackSUCCESS- Positive action feedbackERROR- Error/failure feedbackWARNING- Warning/caution feedbackSELECTION- Item selection feedbackBUZZ- Attention-grabbing feedbackNUDGE- Gentle notificationSOFT- Very light feedbackRIGID- Sharp, precise feedback
import {
getHapticFeedbackEnabled,
setHapticFeedbackEnabled,
getSoundFeedbackEnabled,
setSoundFeedbackEnabled
} from '@present-day/buzz'
// Get current preferences
const hapticEnabled = getHapticFeedbackEnabled()
const soundEnabled = getSoundFeedbackEnabled()
// Update preferences
setHapticFeedbackEnabled(false)
setSoundFeedbackEnabled(true)By default, preferences are stored in localStorage. You can provide a custom storage adapter:
import { LocalStorageAdapter, type StorageAdapter } from '@present-day/buzz'
class CustomStorageAdapter implements StorageAdapter {
getItem(key: string): string | null {
// Your custom storage logic
return null
}
setItem(key: string, value: string): void {
// Your custom storage logic
}
}
const customStorage = new CustomStorageAdapter()
// Use with feedback
triggerInteractionFeedback({
storageAdapter: customStorage
})
// Use with preferences
getHapticFeedbackEnabled(true, customStorage)
setHapticFeedbackEnabled(true, customStorage)- iOS Safari: Uses hidden checkbox technique for haptic feedback
- Android Chrome: Uses Vibration API
- Desktop browsers: Audio feedback only (no haptic support)
- WebAudio: Supported in all modern browsers
MIT