2022-05-14 10:22:06 +00:00
|
|
|
import type { FunctionComponent, PropsWithChildren } from "react";
|
2021-08-08 11:22:34 +00:00
|
|
|
import type { PressHookProps } from "@react-aria/interactions";
|
|
|
|
import { usePress } from "@react-aria/interactions";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onDigitPressProps: (digit: string) => PressHookProps;
|
|
|
|
onZeroPressProps: PressHookProps;
|
|
|
|
};
|
|
|
|
|
2022-05-14 10:22:06 +00:00
|
|
|
const Keypad: FunctionComponent<PropsWithChildren<Props>> = ({ children, onDigitPressProps, onZeroPressProps }) => {
|
2021-08-08 11:22:34 +00:00
|
|
|
return (
|
|
|
|
<section>
|
|
|
|
<Row>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="1" />
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="2">
|
|
|
|
<DigitLetters>ABC</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="3">
|
|
|
|
<DigitLetters>DEF</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
</Row>
|
|
|
|
<Row>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="4">
|
|
|
|
<DigitLetters>GHI</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="5">
|
|
|
|
<DigitLetters>JKL</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="6">
|
|
|
|
<DigitLetters>MNO</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
</Row>
|
|
|
|
<Row>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="7">
|
|
|
|
<DigitLetters>PQRS</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="8">
|
|
|
|
<DigitLetters>TUV</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="9">
|
|
|
|
<DigitLetters>WXYZ</DigitLetters>
|
|
|
|
</Digit>
|
|
|
|
</Row>
|
|
|
|
<Row>
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="*" />
|
|
|
|
<ZeroDigit onPressProps={onZeroPressProps} />
|
|
|
|
<Digit onPressProps={onDigitPressProps} digit="#" />
|
|
|
|
</Row>
|
|
|
|
{typeof children !== "undefined" ? <Row>{children}</Row> : null}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Keypad;
|
|
|
|
|
2022-05-14 10:22:06 +00:00
|
|
|
const Row: FunctionComponent<PropsWithChildren<{}>> = ({ children }) => (
|
2021-08-08 11:22:34 +00:00
|
|
|
<div className="grid grid-cols-3 p-4 my-0 mx-auto text-black">{children}</div>
|
|
|
|
);
|
|
|
|
|
2022-05-14 10:22:06 +00:00
|
|
|
const DigitLetters: FunctionComponent<PropsWithChildren<{}>> = ({ children }) => <div className="text-xs text-gray-600">{children}</div>;
|
2021-08-08 11:22:34 +00:00
|
|
|
|
|
|
|
type DigitProps = {
|
|
|
|
digit: string;
|
|
|
|
onPressProps: Props["onDigitPressProps"];
|
|
|
|
};
|
|
|
|
|
2022-05-14 10:22:06 +00:00
|
|
|
const Digit: FunctionComponent<PropsWithChildren<DigitProps>> = ({ children, digit, onPressProps }) => {
|
2021-08-08 11:22:34 +00:00
|
|
|
const { pressProps } = usePress(onPressProps(digit));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div {...pressProps} className="text-3xl cursor-pointer select-none">
|
|
|
|
{digit}
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
type ZeroDigitProps = {
|
|
|
|
onPressProps: Props["onZeroPressProps"];
|
|
|
|
};
|
|
|
|
|
2022-05-14 10:22:06 +00:00
|
|
|
const ZeroDigit: FunctionComponent<PropsWithChildren<ZeroDigitProps>> = ({ onPressProps }) => {
|
2021-08-08 11:22:34 +00:00
|
|
|
const { pressProps } = usePress(onPressProps);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div {...pressProps} className="text-3xl cursor-pointer select-none">
|
|
|
|
0 <DigitLetters>+</DigitLetters>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|