import { type FunctionComponent, type PropsWithChildren, useRef } from "react"; import { usePress } from "@react-aria/interactions"; import { useLongPressDigit, usePressDigit } from "~/features/keypad/hooks/atoms"; const Keypad: FunctionComponent> = ({ children }) => { return (
ABC DEF GHI JKL MNO PQRS TUV WXYZ {typeof children !== "undefined" ? {children} : null}
); }; export default Keypad; const Row: FunctionComponent> = ({ children }) => (
{children}
); const DigitLetters: FunctionComponent> = ({ children }) => (
{children}
); type DigitProps = { digit: string; }; const Digit: FunctionComponent> = ({ children, digit }) => { const pressDigit = usePressDigit(); const onPressProps = { onPress() { // navigator.vibrate(1); // removed in webkit pressDigit(digit); }, }; const { pressProps } = usePress(onPressProps); return (
{digit} {children}
); }; const ZeroDigit: FunctionComponent = () => { const timeoutRef = useRef | null>(null); const pressDigit = usePressDigit(); const longPressDigit = useLongPressDigit(); const onPressProps = { onPressStart() { pressDigit("0"); timeoutRef.current = setTimeout(() => { longPressDigit("+"); }, 750); }, onPressEnd() { if (timeoutRef.current) { clearTimeout(timeoutRef.current); timeoutRef.current = null; } }, }; const { pressProps } = usePress(onPressProps); return (
0 +
); };