-
Notifications
You must be signed in to change notification settings - Fork 172
Migrate out of react-hotkeys to @mantine/hooks #2968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b70fa5f
Migrate playground hulk hotkey bindings to alt+shift+h
chownces b63fd75
Migrate SubstVisualizer hotkey bindings
chownces 3d80647
Migrate Data Viz hotkey bindings
chownces 10286c1
Migrate CSE machine hotkey bindings
chownces 27b1ce5
Remove react-hotkeys from package.json
chownces 086b614
Fix PR comments
chownces c0727e7
Fix snapshots
chownces f9ada4f
Use Blueprint Card component instead of div
RichDom2185 c1e0a97
Move documentation from props to component
RichDom2185 44c602b
Fix format and snapshots
RichDom2185 56fb6a2
Merge branch 'master' into hotkeys-migration
chownces 68926ee
Merge branch 'master' into hotkeys-migration
RichDom2185 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
import { getHotkeyHandler, HotkeyItem } from '@mantine/hooks'; | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
type HotKeysProps = { | ||
bindings: HotkeyItem[]; | ||
}; | ||
|
||
/** | ||
* This HOC was created to facilitate the migration out of react-hotkeys in favor of @mantine/hooks useHotkeys, | ||
* as SideContentCseMachine.tsx and SideContentDataVisualizer still use class-based React. | ||
* | ||
* NOTE: | ||
* - New hotkey implementations should NOT use this component. Use functional React and the useHotkeys hook | ||
* from @mantine/hooks directly. | ||
* | ||
* TODO: | ||
* - Eventually migrate out of class-based React in the aforementioned components and use useHotkeys directly. | ||
*/ | ||
const HotKeys: React.FC< | ||
PropsWithChildren< | ||
HotKeysProps & { | ||
style?: React.CSSProperties; | ||
} | ||
> | ||
> = ({ bindings, children, style }) => { | ||
const handler = getHotkeyHandler(bindings); | ||
|
||
return ( | ||
<div | ||
tabIndex={-1} // tab index necessary to fire keydown events on div element | ||
onKeyDown={handler} | ||
style={style} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default HotKeys; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While not related to this PR, it it just be or are the keyboard shortcuts not intuitive? I would expect the following:
(first, prev, next, last) to be mapped to (h, j, k, l) or (a, s, d, f) -- basically just a sequence of keys that are next to each other on the keyboard.