Positioner
Anchors a floating box to its trigger: below or above, at the start or the end, flipped when there is no room, and kept inside the window.
import { Positioner } from '@sypnia/ui/react'
Anchored to a button
Code
import { useRef, useState } from 'react';
import { Button, Positioner } from '@sypnia/ui/react';
// The box follows its button while the page scrolls, and flips above when there is no room below.
export default function Anchor() {
const ref = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false);
return (
<>
<Button ref={ref} onClick={() => setOpen(!open)}>{open ? 'Hide' : 'Show'} the box</Button>
<Positioner anchorRef={ref} open={open} placement="bottom-start">
<div style={{ padding: 'var(--s-3) var(--s-4)', background: 'var(--bg-raised)', border: '1px solid var(--line)', borderRadius: 'var(--r-2)', boxShadow: 'var(--shadow-2)' }}>Anchored to its button.</div>
</Positioner>
</>
);
} When to use it
Use it when
- A floating thing of your own next to a trigger.
Do not use it when
- Popover, Menu and Tooltip: they already place themselves.
For everyone
- Placement is visual only; give the box its role and name.
Props
| Positioner | Type | Default |
|---|---|---|
anchorRefrequired | RefObject<HTMLElement | null> | |
openrequired | boolean | |
className | string | |
offset | number | 6 |
placement | "bottom-start" | "bottom-end" | "top-start" | "top-end" | "right-start" | "left-start" | bottom-start |