-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
175 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#keyboard-shortcuts-help-container { | ||
table { | ||
th { | ||
font-weight: normal; | ||
text-align: start; | ||
padding: 0.25em 0; | ||
line-height: 1; | ||
} | ||
td { | ||
padding: 0.25em 1em; | ||
} | ||
} | ||
|
||
kbd { | ||
border-radius: 4px; | ||
display: inline-block; | ||
padding: 0.3em; | ||
line-height: 1; | ||
border: 1px solid var(--outline-color); | ||
background-color: var(--bg-faded-color); | ||
} | ||
} |
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,136 @@ | ||
import './keyboard-shortcuts-help.css'; | ||
|
||
import { useHotkeys } from 'react-hotkeys-hook'; | ||
import { useSnapshot } from 'valtio'; | ||
|
||
import states from '../utils/states'; | ||
|
||
import Icon from './icon'; | ||
import Modal from './modal'; | ||
|
||
export default function KeyboardShortcutsHelp() { | ||
const snapStates = useSnapshot(states); | ||
|
||
function onClose() { | ||
states.showKeyboardShortcutsHelp = false; | ||
} | ||
|
||
useHotkeys( | ||
'?, shift+?', | ||
(e) => { | ||
console.log('help'); | ||
states.showKeyboardShortcutsHelp = true; | ||
}, | ||
{ | ||
ignoreEventWhen: (e) => { | ||
const hasModal = !!document.querySelector('#modal-container > *'); | ||
return hasModal; | ||
}, | ||
}, | ||
); | ||
|
||
const escRef = useHotkeys('esc', onClose, []); | ||
|
||
return ( | ||
!!snapStates.showKeyboardShortcutsHelp && ( | ||
<Modal | ||
class="light" | ||
onClick={(e) => { | ||
if (e.target === e.currentTarget) { | ||
onClose(); | ||
} | ||
}} | ||
> | ||
<div | ||
id="keyboard-shortcuts-help-container" | ||
class="sheet" | ||
tabindex="-1" | ||
ref={escRef} | ||
> | ||
<button type="button" class="sheet-close" onClick={onClose}> | ||
<Icon icon="x" /> | ||
</button> | ||
<header> | ||
<h2>Keyboard shortcuts</h2> | ||
</header> | ||
<main> | ||
<table> | ||
{[ | ||
{ | ||
action: 'Keyboard shortcuts help', | ||
keys: <kbd>?</kbd>, | ||
}, | ||
{ | ||
action: 'Next post', | ||
keys: <kbd>j</kbd>, | ||
}, | ||
{ | ||
action: 'Previous post', | ||
keys: <kbd>k</kbd>, | ||
}, | ||
{ | ||
action: 'Skip carousel to next post', | ||
keys: ( | ||
<> | ||
<kbd>Shift</kbd> + <kbd>j</kbd> | ||
</> | ||
), | ||
}, | ||
{ | ||
action: 'Skip carousel to previous post', | ||
keys: ( | ||
<> | ||
<kbd>Shift</kbd> + <kbd>k</kbd> | ||
</> | ||
), | ||
}, | ||
{ | ||
action: 'Search', | ||
keys: <kbd>/</kbd>, | ||
}, | ||
{ | ||
action: 'Compose new post', | ||
keys: <kbd>c</kbd>, | ||
}, | ||
{ | ||
action: 'Send post', | ||
keys: ( | ||
<> | ||
<kbd>Ctrl</kbd> + <kbd>Enter</kbd> or <kbd>⌘</kbd> +{' '} | ||
<kbd>Enter</kbd> | ||
</> | ||
), | ||
}, | ||
{ | ||
action: 'Open post details', | ||
keys: ( | ||
<> | ||
<kbd>Enter</kbd> or <kbd>o</kbd> | ||
</> | ||
), | ||
}, | ||
{ | ||
action: 'Toggle expanded/collapsed thread', | ||
keys: <kbd>x</kbd>, | ||
}, | ||
{ | ||
action: 'Close post or dialogs', | ||
keys: ( | ||
<> | ||
<kbd>Esc</kbd> or <kbd>Backspace</kbd> | ||
</> | ||
), | ||
}, | ||
].map(({ action, keys }) => ( | ||
<tr key={action}> | ||
<th>{action}</th> | ||
<td>{keys}</td> | ||
</tr> | ||
))} | ||
</table> | ||
</main> | ||
</div> | ||
</Modal> | ||
) | ||
); | ||
} |
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