mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-12-03 16:59:42 +00:00
* feat(docs): add keyboard shortcuts to the icons page Add the shortcuts suggested in #4916 and list them on the page: - Ctrl/Cmd + click on an icon copies its name - Arrow keys move from the search field into the results and between the icons - Ctrl/Cmd + C copies the name of the selected icon - Ctrl/Cmd + Shift + C copies the SVG of the selected icon Icons can now be focused with the keyboard, and a keyboard button next to the sort select opens a dialog with all shortcuts, including the existing Ctrl/Cmd + K and Shift + click. The dialog also opens with Shift + ? (except while typing in a field). Closes #4916 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(docs): add copy toasts, open icons with Enter and a shared Kbd component - Copying an icon shows a toast (vue-sonner, bottom-center) that says whether its name or its SVG was copied - Enter opens the selected icon's drawer - The SVG shortcut is now Shift + C, as Ctrl/Cmd + Shift + C opens the browser's inspect tool - Kbd component shared by the search inputs and the shortcuts dialog Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Adjust keyboard shortcuts * Revert customizer change * Adjust kbd style * Fix toaster styling * Fix types --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Eric <eric.fennis@gmail.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
|
|
|
/**
|
|
* Composable for handling search keyboard shortcuts.
|
|
* Listens for Cmd/Ctrl+K and "/" keys to trigger a search action.
|
|
*
|
|
* @param callback - Function to execute when shortcut is triggered
|
|
* @returns Object containing the platform-specific shortcut display text
|
|
*/
|
|
export default function useSearchShortcut(callback: () => void) {
|
|
const shortcutText = ref('');
|
|
|
|
function handleKeydown(event: KeyboardEvent) {
|
|
// Check for Cmd+K (Mac), Ctrl+K (Windows/Linux), or forward slash
|
|
if (((event.metaKey || event.ctrlKey) && event.key === 'k') || event.key === '/') {
|
|
event.preventDefault();
|
|
// Algolia listens for the same keys on window, so claim them before it sees them
|
|
event.stopImmediatePropagation();
|
|
callback();
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
// Detect platform and set appropriate keyboard shortcut for search focus
|
|
const isMac = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
|
shortcutText.value = isMac ? '⌘K' : 'Ctrl+K';
|
|
|
|
// Add keyboard shortcut listener
|
|
window.addEventListener('keydown', handleKeydown, { capture: true });
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
window.removeEventListener('keydown', handleKeydown, { capture: true });
|
|
});
|
|
|
|
return { shortcutText };
|
|
}
|