keypad page
This commit is contained in:
18
app/features/keypad/components/blurred-keypad.tsx
Normal file
18
app/features/keypad/components/blurred-keypad.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import { IoCall } from "react-icons/io5";
|
||||
|
||||
import Keypad from "~/features/keypad/components/keypad";
|
||||
|
||||
export default function BlurredKeypad() {
|
||||
return (
|
||||
<div className="filter blur-sm select-none absolute top-0 w-full h-full z-0">
|
||||
<section className="relative w-96 h-full flex flex-col justify-around mx-auto py-5 text-center">
|
||||
<div className="h-16 text-3xl text-gray-700" />
|
||||
<Keypad>
|
||||
<button className="cursor-pointer select-none col-start-2 h-12 w-12 flex justify-center items-center mx-auto bg-green-800 rounded-full">
|
||||
<IoCall className="w-6 h-6 text-white" />
|
||||
</button>
|
||||
</Keypad>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1,50 +1,45 @@
|
||||
import type { FunctionComponent, PropsWithChildren } from "react";
|
||||
import type { PressHookProps } from "@react-aria/interactions";
|
||||
import { type FunctionComponent, type PropsWithChildren, useRef } from "react";
|
||||
import { usePress } from "@react-aria/interactions";
|
||||
import { useLongPressDigit, usePressDigit } from "~/features/keypad/hooks/atoms";
|
||||
|
||||
type Props = {
|
||||
onDigitPressProps: (digit: string) => PressHookProps;
|
||||
onZeroPressProps: PressHookProps;
|
||||
};
|
||||
|
||||
const Keypad: FunctionComponent<PropsWithChildren<Props>> = ({ children, onDigitPressProps, onZeroPressProps }) => {
|
||||
const Keypad: FunctionComponent<PropsWithChildren<{}>> = ({ children }) => {
|
||||
return (
|
||||
<section>
|
||||
<Row>
|
||||
<Digit onPressProps={onDigitPressProps} digit="1" />
|
||||
<Digit onPressProps={onDigitPressProps} digit="2">
|
||||
<Digit digit="1" />
|
||||
<Digit digit="2">
|
||||
<DigitLetters>ABC</DigitLetters>
|
||||
</Digit>
|
||||
<Digit onPressProps={onDigitPressProps} digit="3">
|
||||
<Digit digit="3">
|
||||
<DigitLetters>DEF</DigitLetters>
|
||||
</Digit>
|
||||
</Row>
|
||||
<Row>
|
||||
<Digit onPressProps={onDigitPressProps} digit="4">
|
||||
<Digit digit="4">
|
||||
<DigitLetters>GHI</DigitLetters>
|
||||
</Digit>
|
||||
<Digit onPressProps={onDigitPressProps} digit="5">
|
||||
<Digit digit="5">
|
||||
<DigitLetters>JKL</DigitLetters>
|
||||
</Digit>
|
||||
<Digit onPressProps={onDigitPressProps} digit="6">
|
||||
<Digit digit="6">
|
||||
<DigitLetters>MNO</DigitLetters>
|
||||
</Digit>
|
||||
</Row>
|
||||
<Row>
|
||||
<Digit onPressProps={onDigitPressProps} digit="7">
|
||||
<Digit digit="7">
|
||||
<DigitLetters>PQRS</DigitLetters>
|
||||
</Digit>
|
||||
<Digit onPressProps={onDigitPressProps} digit="8">
|
||||
<Digit digit="8">
|
||||
<DigitLetters>TUV</DigitLetters>
|
||||
</Digit>
|
||||
<Digit onPressProps={onDigitPressProps} digit="9">
|
||||
<Digit digit="9">
|
||||
<DigitLetters>WXYZ</DigitLetters>
|
||||
</Digit>
|
||||
</Row>
|
||||
<Row>
|
||||
<Digit onPressProps={onDigitPressProps} digit="*" />
|
||||
<ZeroDigit onPressProps={onZeroPressProps} />
|
||||
<Digit onPressProps={onDigitPressProps} digit="#" />
|
||||
<Digit digit="*" />
|
||||
<ZeroDigit />
|
||||
<Digit digit="#" />
|
||||
</Row>
|
||||
{typeof children !== "undefined" ? <Row>{children}</Row> : null}
|
||||
</section>
|
||||
@ -57,15 +52,23 @@ const Row: FunctionComponent<PropsWithChildren<{}>> = ({ children }) => (
|
||||
<div className="grid grid-cols-3 p-4 my-0 mx-auto text-black">{children}</div>
|
||||
);
|
||||
|
||||
const DigitLetters: FunctionComponent<PropsWithChildren<{}>> = ({ children }) => <div className="text-xs text-gray-600">{children}</div>;
|
||||
const DigitLetters: FunctionComponent<PropsWithChildren<{}>> = ({ children }) => (
|
||||
<div className="text-xs text-gray-600">{children}</div>
|
||||
);
|
||||
|
||||
type DigitProps = {
|
||||
digit: string;
|
||||
onPressProps: Props["onDigitPressProps"];
|
||||
};
|
||||
|
||||
const Digit: FunctionComponent<PropsWithChildren<DigitProps>> = ({ children, digit, onPressProps }) => {
|
||||
const { pressProps } = usePress(onPressProps(digit));
|
||||
const Digit: FunctionComponent<PropsWithChildren<DigitProps>> = ({ children, digit }) => {
|
||||
const pressDigit = usePressDigit();
|
||||
const onPressProps = {
|
||||
onPress() {
|
||||
// navigator.vibrate(1); // removed in webkit
|
||||
pressDigit(digit);
|
||||
},
|
||||
};
|
||||
const { pressProps } = usePress(onPressProps);
|
||||
|
||||
return (
|
||||
<div {...pressProps} className="text-3xl cursor-pointer select-none">
|
||||
@ -75,11 +78,24 @@ const Digit: FunctionComponent<PropsWithChildren<DigitProps>> = ({ children, dig
|
||||
);
|
||||
};
|
||||
|
||||
type ZeroDigitProps = {
|
||||
onPressProps: Props["onZeroPressProps"];
|
||||
};
|
||||
|
||||
const ZeroDigit: FunctionComponent<PropsWithChildren<ZeroDigitProps>> = ({ onPressProps }) => {
|
||||
const ZeroDigit: FunctionComponent = () => {
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | 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 (
|
||||
|
Reference in New Issue
Block a user