Files
kit-ui/lib/figlet/hooks/useKeyboardShortcuts.ts
Sebastian Krüger 2000623c67 feat: implement Figlet, Pastel, and Unit tools with a unified layout
- Add Figlet text converter with font selection and history
- Add Pastel color palette generator and manipulation suite
- Add comprehensive Units converter with category-based logic
- Introduce AppShell with Sidebar and Header for navigation
- Modernize theme system with CSS variables and new animations
- Update project configuration and dependencies
2026-02-22 21:35:53 +01:00

35 lines
1.0 KiB
TypeScript

'use client';
import { useEffect } from 'react';
export interface KeyboardShortcut {
key: string;
ctrlKey?: boolean;
metaKey?: boolean;
shiftKey?: boolean;
handler: () => void;
description: string;
}
export function useKeyboardShortcuts(shortcuts: KeyboardShortcut[]) {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
for (const shortcut of shortcuts) {
const keyMatches = event.key.toLowerCase() === shortcut.key.toLowerCase();
const ctrlMatches = shortcut.ctrlKey ? event.ctrlKey || event.metaKey : !event.ctrlKey && !event.metaKey;
const metaMatches = shortcut.metaKey ? event.metaKey : true;
const shiftMatches = shortcut.shiftKey ? event.shiftKey : !event.shiftKey;
if (keyMatches && ctrlMatches && shiftMatches) {
event.preventDefault();
shortcut.handler();
break;
}
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [shortcuts]);
}