refactor(v4.0.0-alpha): beginning of a new era

This commit is contained in:
Amruth Pillai
2023-11-05 12:31:42 +01:00
parent 0ba6a444e2
commit 22933bd412
505 changed files with 81829 additions and 0 deletions

View File

@ -0,0 +1,47 @@
import { cn } from "@reactive-resume/utils";
import { useEffect } from "react";
import { useBoolean } from "usehooks-ts";
// Keyboard Icons
// Shift ⇧
// Control ⌃
// Option ⌥
// Command ⌘
type KeyboardShortcutProps = Omit<React.HTMLAttributes<HTMLSpanElement>, "defaultValue"> & {
defaultValue?: boolean;
};
export const KeyboardShortcut = ({
className,
defaultValue = false,
...props
}: KeyboardShortcutProps) => {
const { value, setValue } = useBoolean(defaultValue);
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => e.key === "Control" && setValue(true);
const onKeyUp = (e: KeyboardEvent) => e.key === "Control" && setValue(false);
document.addEventListener("keydown", onKeyDown);
document.addEventListener("keyup", onKeyUp);
return () => {
document.removeEventListener("keydown", onKeyDown);
document.removeEventListener("keyup", onKeyUp);
};
}, [setValue]);
return (
<span
className={cn(
"ml-auto scale-0 text-xs tracking-widest opacity-0 transition-[opacity]",
value && "scale-100 opacity-60",
className,
)}
{...props}
/>
);
};
KeyboardShortcut.displayName = "KeyboardShortcut";