-
Notifications
You must be signed in to change notification settings - Fork 498
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
1 parent
538f0a8
commit fbf2950
Showing
21 changed files
with
912 additions
and
1,170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import useKeyboardShortcut from "use-keyboard-shortcut"; | ||
import { classNames, isAppleDevice } from "../../Utils/utils"; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
shortcut: string[]; | ||
onTrigger: () => void; | ||
shortcutSeperator?: string; | ||
helpText?: string; | ||
tooltipClassName?: string; | ||
} | ||
|
||
export default function KeyboardShortcut(props: Props) { | ||
useKeyboardShortcut(props.shortcut, props.onTrigger, { | ||
overrideSystem: true, | ||
}); | ||
|
||
return ( | ||
<div className="tooltip"> | ||
{props.children} | ||
<span | ||
className={classNames( | ||
"tooltip-text flex items-center gap-0.5 text-xs", | ||
props.tooltipClassName || "tooltip-bottom" | ||
)} | ||
> | ||
<span className="px-1 font-bold">{props.helpText}</span> | ||
<kbd className="hidden items-center px-1.5 font-sans font-medium text-zinc-300 shadow md:inline-flex"> | ||
{getShortcutKeyDescription(props.shortcut).join(" + ")} | ||
</kbd> | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
const SHORTCUT_KEY_MAP = { | ||
Meta: "⌘", | ||
Shift: "⇧Shift", | ||
Alt: "⌥Alt", | ||
Control: isAppleDevice ? "⌃Ctrl" : "Ctrl", | ||
ArrowUp: "↑", | ||
ArrowDown: "↓", | ||
ArrowLeft: "←", | ||
ArrowRight: "→", | ||
} as Record<string, string>; | ||
|
||
export const getShortcutKeyDescription = (shortcut: string[]) => { | ||
return shortcut.map((key) => SHORTCUT_KEY_MAP[key] || key); | ||
}; |
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,34 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
fullscreen: boolean; | ||
onExit: () => void; | ||
} | ||
|
||
export default function Fullscreen({ children, fullscreen, onExit }: Props) { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
if (fullscreen) { | ||
ref.current?.requestFullscreen(); | ||
} else { | ||
document.exitFullscreen(); | ||
} | ||
}, [fullscreen]); | ||
|
||
useEffect(() => { | ||
const listener = () => { | ||
if (!document.fullscreenElement) { | ||
onExit(); | ||
} | ||
}; | ||
|
||
document.addEventListener("fullscreenchange", listener); | ||
return () => { | ||
document.removeEventListener("fullscreenchange", listener); | ||
}; | ||
}, [onExit]); | ||
|
||
return <div ref={ref}>{children}</div>; | ||
} |
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.