The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useState, type ComponentProps, type CSSProperties } from "react"; |
| 2 | |
| 3 | const PLACEMENT_KEYS = ["position", "top", "right", "bottom", "left", "transform"] as const; |
| 4 | |
| 5 | type Placement = Pick<CSSProperties, (typeof PLACEMENT_KEYS)[number]>; |
| 6 | |
| 7 | function ClosingPositioner({ open, style, ...props }: ComponentProps<"div"> & { open: boolean }) { |
| 8 | const [openPlacement, setOpenPlacement] = useState<Placement>({}); |
| 9 | if (open && style && PLACEMENT_KEYS.some((key) => style[key] !== openPlacement[key])) { |
| 10 | const { position, top, right, bottom, left, transform } = style; |
| 11 | setOpenPlacement({ position, top, right, bottom, left, transform }); |
| 12 | } |
| 13 | return <div {...props} style={open ? style : { ...style, ...openPlacement }} />; |
| 14 | } |
| 15 | |
| 16 | export function renderClosingPositioner(props: ComponentProps<"div">, state: { open: boolean }) { |
| 17 | return <ClosingPositioner {...props} open={state.open} />; |
| 18 | } |