Pointer Holder
Remembers which elements the pointer has passed over, until it leaves the container.
Usage
Pass a function as the child. It receives keys: the elements the pointer has crossed, in order. Move across the buttons, then leave the row.
tsx
<PointerHolder attribute="aria-label">
{({ keys }) => (
<div className="flex gap-1">
<Button aria-label="theme" open={keys.includes("theme")} onClick={onTheme}>
<Button.IconLabel icon={<Button.Icon><MdDarkMode /></Button.Icon>} label={<Button.Label>theme</Button.Label>} />
</Button>
<Button aria-label="like" open={keys.includes("like")} onClick={onLike}>
<Button.IconLabel icon={<Button.Icon><MdFavorite /></Button.Icon>} label={<Button.Label>like</Button.Label>} />
</Button>
<Button aria-label="share" open={keys.includes("share")} onClick={onShare}>
<Button.IconLabel icon={<Button.Icon><MdShare /></Button.Icon>} label={<Button.Label>share</Button.Label>} />
</Button>
</div>
)}
</PointerHolder>Where keys come from
A key is the value of attribute on the nearest element that has it. Use one your elements already carry, like href…
tsx
<PointerHolder attribute="href">
{({ keys }) => (
<nav>
<Button as={Link} to={row.to} open={keys.includes(row.to)}>
…
</Button>
</nav>
)}
</PointerHolder>…or mark them with data-margo-pointer-holder, the default.
tsx
<PointerHolder>
{({ keys }) => (
<ul>
<li data-margo-pointer-holder="play">
<ButtonPlayer open={keys.includes("play")} />
</li>
</ul>
)}
</PointerHolder>Using the keys
What the keys mean is up to you: open what was crossed, highlight the last one, dim the rest.
tsx
open={keys.includes(row.to)}
active={keys.at(-1) === row.to}
className={cn(keys.length && !keys.includes(row.to) && "opacity-40")}Reference
| prop | type | default | |
|---|---|---|---|
children | (api: PointerHolderApi) => ReactElement | — | receives the keys and returns the container |
attribute? | string | "data-margo-pointer-holder" | the attribute each key is read from |
disabled? | boolean | false | stops adding keys; leaving still clears them |