-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate out of react-hotkeys to @mantine/hooks (#2968)
* Migrate playground hulk hotkey bindings to alt+shift+h * Migrate SubstVisualizer hotkey bindings * Migrate Data Viz hotkey bindings * Migrate CSE machine hotkey bindings * Remove react-hotkeys from package.json * Fix PR comments * Fix snapshots * Use Blueprint Card component instead of div * Move documentation from props to component * Fix format and snapshots --------- Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
- Loading branch information
1 parent
b8be875
commit 62f5a83
Showing
14 changed files
with
602 additions
and
732 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
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,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 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
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
Oops, something went wrong.