import { useState } from "react"; import { IconArrowDown, IconArrowDownLeft, IconArrowDownRight, IconArrowLeft, IconArrowRight, IconArrowUp, IconArrowUpLeft, IconArrowUpRight, IconCircle, } from "@tabler/icons-react"; import { FloatingIndicator, UnstyledButton } from "@mantine/core"; import classes from "./FloatingControl.module.css"; import type { Position } from "@/hooks/useFloatingPositions"; function FloatingControl(props: { defaultValue: Position; onChange: (position: Position) => void; }) { const [rootRef, setRootRef] = useState(null); const [controlsRefs, setControlsRefs] = useState< Record >({}); const [active, setActive] = useState(props.defaultValue); const handleChange = (position: Position) => { setActive(position); props.onChange(position); }; const setControlRef = (name: Position) => (node: HTMLButtonElement) => { controlsRefs[name] = node; setControlsRefs(controlsRefs); }; return (
handleChange("up-left")} ref={setControlRef("up-left")} mod={{ active: active === "up-left" }} > handleChange("up")} ref={setControlRef("up")} mod={{ active: active === "up" }} > handleChange("up-right")} ref={setControlRef("up-right")} mod={{ active: active === "up-right" }} >
handleChange("left")} ref={setControlRef("left")} mod={{ active: active === "left" }} > handleChange("center")} ref={setControlRef("center")} mod={{ active: active === "center" }} > handleChange("right")} ref={setControlRef("right")} mod={{ active: active === "right" }} >
handleChange("down-left")} ref={setControlRef("down-left")} mod={{ active: active === "down-left" }} > handleChange("down")} ref={setControlRef("down")} mod={{ active: active === "down" }} > handleChange("down-right")} ref={setControlRef("down-right")} mod={{ active: active === "down-right" }} >
); } export default FloatingControl;