AeThex-OS/client/src/lib/haptics.ts
2026-01-03 23:56:43 -07:00

80 lines
1.3 KiB
TypeScript

export const haptics = {
/**
* Light impact for subtle feedback
*/
light: () => {
if ('vibrate' in navigator) {
navigator.vibrate(10);
}
},
/**
* Medium impact for standard interactions
*/
medium: () => {
if ('vibrate' in navigator) {
navigator.vibrate(20);
}
},
/**
* Heavy impact for significant actions
*/
heavy: () => {
if ('vibrate' in navigator) {
navigator.vibrate([30, 10, 30]);
}
},
/**
* Success notification pattern
*/
success: () => {
if ('vibrate' in navigator) {
navigator.vibrate([10, 30, 10]);
}
},
/**
* Warning notification pattern
*/
warning: () => {
if ('vibrate' in navigator) {
navigator.vibrate([20, 50, 20]);
}
},
/**
* Error notification pattern
*/
error: () => {
if ('vibrate' in navigator) {
navigator.vibrate([50, 50, 50]);
}
},
/**
* Selection changed pattern
*/
selection: () => {
if ('vibrate' in navigator) {
navigator.vibrate(5);
}
},
/**
* Custom vibration pattern
*/
pattern: (pattern: number | number[]) => {
if ('vibrate' in navigator) {
navigator.vibrate(pattern);
}
}
};
/**
* Check if device supports vibration
*/
export function isHapticSupported(): boolean {
return 'vibrate' in navigator;
}