diff options
Diffstat (limited to 'src/components/ToggleShifter.tsx')
| -rw-r--r-- | src/components/ToggleShifter.tsx | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/components/ToggleShifter.tsx b/src/components/ToggleShifter.tsx index 4737a6f..725a8cc 100644 --- a/src/components/ToggleShifter.tsx +++ b/src/components/ToggleShifter.tsx @@ -1,14 +1,26 @@ import Shifter from './Shifter.tsx'; -import { useState } from "react"; +import { useEffect, useState } from "react"; export default function ToggleShifter() { - const [isShowingShifter, setShowingShifter] = useState(false); - - return ( - <> - {isShowingShifter && ( - <Shifter /> - )} - </> - ) + const [isShowingShifter, setShowingShifter] = useState(false); + + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === "s") { + setShowingShifter(prev => !prev); + } + }; + + window.addEventListener("keydown", handleKeyDown); + + return () => { + window.removeEventListener("keydown", handleKeyDown); + }; + }, []); + + return ( + <> + {isShowingShifter && <Shifter />} + </> + ); } |
