-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clients/web/docs: adapt command palette trigger to platform
- Loading branch information
1 parent
9c4c0eb
commit a614922
Showing
5 changed files
with
52 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
clients/apps/web/src/components/CommandPalette/commands/trigger.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useEffect, useState } from 'react' | ||
|
||
const KEY = 'k' | ||
|
||
const isMac = (navigator: Navigator): boolean => { | ||
if (typeof navigator == 'undefined') { | ||
return false | ||
} | ||
return navigator.platform.toLowerCase().includes('mac') | ||
} | ||
|
||
export const CommandPaletteTriggerKey: React.FC = () => { | ||
const [isMacOS, setIsMacOS] = useState(false) | ||
|
||
useEffect(() => { | ||
setIsMacOS(isMac(navigator)) | ||
}, []) | ||
|
||
return <span>{`${isMacOS ? '⌘' : '^'}${KEY.toUpperCase()}`}</span> | ||
} | ||
|
||
export const useCommandPaletteTrigger = (onTrigger: () => void): void => { | ||
useEffect(() => { | ||
const handleKeyPress = (e: KeyboardEvent) => { | ||
const controlKeyPressed = isMac(navigator) ? e.metaKey : e.ctrlKey | ||
if (e.key === KEY && controlKeyPressed) { | ||
onTrigger() | ||
} | ||
} | ||
|
||
window.addEventListener('keydown', handleKeyPress) | ||
|
||
return () => { | ||
window.removeEventListener('keydown', handleKeyPress) | ||
} | ||
}, [onTrigger]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters