LinkPreview
OverlaysA preview card shown while the pointer rests on a link (openDelay, closeDelay): a person, a project or a document behind it. The link still works as a link. The card is a mouse convenience: keyboard and touch users only get the link.
import { LinkPreview } from '@limerdev/zest'; Use for
A sighted, mouse-friendly preview of what a link leads to, such as a profile behind an @mention.
Don't
Anything the user needs, or anything to click inside the card: keyboard and touch users never see it. Use
Popover, or put the information on the linked page.Examples
A mention
A profile behind an @mention. The link works as a link; the card is extra, for mouse users.
Week 49 was approved by @anna
<script lang="ts">
import { LinkPreview } from '@limerdev/zest';
</script>
<p class="text-sm">
Week 49 was approved by
<LinkPreview.Root>
<LinkPreview.Trigger href="#anna" class="font-medium text-link underline underline-offset-4">
@anna
</LinkPreview.Trigger>
<LinkPreview.Content class="flex gap-3">
<span
class="grid size-10 shrink-0 place-content-center rounded-full bg-primary font-semibold text-primary-content"
>
AB
</span>
<span class="flex flex-col gap-1">
<span class="font-semibold">Anna Berg</span>
<span class="text-muted">Project lead, Zest. Approves hours for 12 people.</span>
</span>
</LinkPreview.Content>
</LinkPreview.Root>
</p> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
LinkPreview.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| closeDelay | number | 300 | The delay in milliseconds before the preview closes. |
| disabled | boolean | false | When true, the preview will be disabled and will not open. |
| ignoreNonKeyboardFocus | boolean | false | Prevent the preview from opening if the focus did not come using the keyboard. |
| onOpenChange | OnChangeFn<boolean> | – | A callback that will be called when the link preview is opened or closed. |
| onOpenChangeComplete | OnChangeFn<boolean> | – | A callback that will be called when the link preview finishes opening/closing animations. |
| open bindable | boolean | false | The open state of the link preview. |
| openDelay | number | 700 | The delay in milliseconds before the preview opens. |
LinkPreview.Trigger
No props of its own beyond the common ones.
LinkPreview.Content
| Prop | Type | Default | Description |
|---|---|---|---|
| align | "start" | "center" | "end" | 'center' | The preferred alignment of the anchor to render against when open. This may change when collisions occur. |
| alignOffset | number | – | An offset in pixels from the "start" or "end" alignment options. |
| arrowPadding | number | – | This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners. |
| avoidCollisions | boolean | true | When true, overrides the side and align options to prevent collisions with the boundary edges. |
| collisionBoundary | Arrayable<Boundary> | – | A boundary element or array of elements to check for collisions against. |
| collisionPadding | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 8 | The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision. |
| customAnchor | string | HTMLElement | Measurable | null | – | Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement. |
| dir | "ltr" | "rtl" | – | The text direction of the content. |
| escapeKeydownBehavior | "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" | close | Escape behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press. |
| forceMount | boolean | – | When true, the link preview content will be forced to mount in the DOM. Useful for more control over the transition behavior. |
| hideWhenDetached | boolean | – | |
| interactOutsideBehavior | "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" | close | Interact outside behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to the parent element. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction. |
| onEscapeKeydown | ((e: KeyboardEvent) => void) | – | Callback fired when escape is pressed. |
| onFocusOutside | ((event: FocusEvent) => void) | – | Callback fired when focus leaves the dismissible layer. |
| onInteractOutside | InteractOutsideEventHandler | – | Callback fired when an outside interaction event completes, which is either a pointerup, mouseup, or touchend event, depending on the user's input device. |
| portalProps | PortalProps | – | Props for the portal the content renders in: to (the element to render in, the body by default) and disabled (render in place). |
| side | "top" | "right" | "bottom" | "left" | 'bottom' | The preferred side of the anchor to render against when open. Will be reversed when collisions occur. |
| sideOffset | number | 4 | The distance in pixels from the anchor to the floating element. |
| sticky | "partial" | "always" | – |
LinkPreview.Portal
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Disable portalling and render the component inline |
| to | PortalTarget | document.body | Where to portal the content to. |