45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
/* eslint-disable react-hooks/exhaustive-deps */
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { isMobile } from "react-device-detect";
|
|
|
|
interface Props {
|
|
floor: string;
|
|
onSelected: () => void;
|
|
}
|
|
|
|
function FloorItem({ floor, onSelected }: Props) {
|
|
const [selected, setSelected] = useState(false);
|
|
const ref = useRef<HTMLParagraphElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (!isMobile) return;
|
|
|
|
const test = document.querySelector("#test")!.getBoundingClientRect();
|
|
|
|
setInterval(() => {
|
|
if (
|
|
ref.current!.getBoundingClientRect().x >= test!.left &&
|
|
ref.current!.getBoundingClientRect().x <= test!.right
|
|
) {
|
|
onSelected();
|
|
setSelected(true);
|
|
} else {
|
|
setSelected(false);
|
|
}
|
|
}, 0);
|
|
}, []);
|
|
|
|
return (
|
|
<p
|
|
ref={ref}
|
|
className={`snap-center min-w-[68px] w-[68px] h-4 flex items-center justify-center text-xs font-semibold transition-[color,transform] whitespace-nowrap ${
|
|
selected ? "text-[#00BED7] scale-125" : ""
|
|
}`}
|
|
>
|
|
{floor}
|
|
</p>
|
|
);
|
|
}
|
|
|
|
export default FloorItem;
|