Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

PreviewCard Primitive

PreviewCard is a Starwind Runtime primitive in the presence-floating-overlay contract family.

Anatomy

Use the Astro primitive adapter to render PreviewCard anatomy with the Runtime wiring included.

---
import { PreviewCard } from "@starwind-ui/astro/preview-card";
---
<PreviewCard.Root>
<PreviewCard.Trigger>Preview profile</PreviewCard.Trigger>
<PreviewCard.Positioner>
<PreviewCard.Popup>
<PreviewCard.Arrow />
</PreviewCard.Popup>
</PreviewCard.Positioner>
</PreviewCard.Root>

Floating Behavior

FactValue
Anchor parttrigger
Positioner partpositioner
Popup partpopup
Portal partportal
Option propsside, align, sideOffset, avoidCollisions

API Reference

Root

The main element that owns the PreviewCard Runtime instance.

Default element
div
Discovery hook
data-sw-preview-card
Role
-

Props

Prop Type Default Toggle
open boolean -
Description
Controls whether PreviewCard is open.
Kind
control
Targets
root
Full type
boolean
defaultOpen boolean false
Description
Sets whether PreviewCard starts open.
Kind
control
Targets
root
Full type
boolean
closeDelay number 300
Description
Sets how long PreviewCard waits before closing.
Kind
option
Targets
-
Full type
number
closeOnEscape boolean true
Description
Closes PreviewCard when Escape is pressed.
Kind
option
Targets
-
Full type
boolean
closeOnOutsideInteract boolean true
Description
Closes PreviewCard when the user interacts outside it.
Kind
option
Targets
-
Full type
boolean
disableHoverableContent boolean false
Description
Configures the disable hoverable content option for the Root part.
Kind
option
Targets
root
Full type
boolean
openDelay number 600
Description
Sets how long PreviewCard waits before opening.
Kind
option
Targets
-
Full type
number
onOpenChange (open: boolean, details: PreviewCardOpenChangeDetails) => void -
Description
Runs when PreviewCard opens or closes.
Kind
callback
Targets
-
Full type
(open: boolean, details: PreviewCardOpenChangeDetails) => void

Events

Event Callback Value Toggle
openChange onOpenChange open: boolean
Description
Fires when PreviewCard opens or closes.
DOM event
starwind:open-change
Details type
PreviewCardOpenChangeDetails
Timing
before-state-commit
Cancelable
Yes

State

State Type Props Toggle
open boolean open / defaultOpen
Description
Tracks whether PreviewCard is open.
Initial attribute
data-default-open
Runtime getter
getOpen
Runtime setter
setOpen
State control support
React supports controlled and default state with open and defaultOpen props. Runtime/HTML reads initial state from data-default-open, emits starwind:open-change, and updates with setOpen. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Root part.
Metadata
Attribute Value Description
data-default-open - Reflects the default open prop on the Root part.
data-close-delay - Reflects the close delay prop on the Root part.
data-close-on-escape - Reflects the close on escape prop on the Root part.
data-close-on-outside-interact - Reflects the close on outside interact prop on the Root part.
data-content-hoverable - Reflects the content hoverable prop on the Root part.
data-open-delay - Reflects the open delay prop on the Root part.

Trigger

The control that opens, closes, or targets the PreviewCard content.

Default element
button
Discovery hook
data-sw-preview-card-trigger
Role
-

Props

Prop Type Default Toggle
asChild boolean -
Description
Merges behavior onto your child element instead of rendering the default Trigger element.
Kind
rendering
Targets
trigger
Full type
boolean
disabled boolean false
Description
Disables the Trigger part.
Kind
option
Targets
trigger
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-trigger - Marks the Trigger part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Trigger part.
Metadata
Attribute Value Description
data-as-child - Reflects the as child prop on the Trigger part.
data-close-delay - Reflects the close delay prop on the Trigger part.
data-disabled - Reflects the disabled prop on the Trigger part.
data-open-delay - Reflects the open delay prop on the Trigger part.

Portal

Moves PreviewCard overlay content to the document body when needed.

Default element
div
Discovery hook
data-sw-preview-card-portal
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-portal - Marks the Portal part so Starwind Runtime can find it.

Positioner

Positions the PreviewCard content relative to its trigger.

Default element
div
Discovery hook
data-sw-preview-card-positioner
Role
-

Props

Prop Type Default Toggle
side "top" | "right" | "bottom" | "left" "bottom"
Description
Sets the preferred side for PreviewCard content.
Kind
option
Targets
positioner, popup
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "center"
Description
Sets how PreviewCard content aligns to its trigger.
Kind
option
Targets
positioner, popup
Full type
"start" | "center" | "end"
sideOffset number 0
Description
Sets the distance between PreviewCard content and its trigger.
Kind
option
Targets
positioner, popup
Full type
number
avoidCollisions boolean true
Description
Allows PreviewCard content to shift or flip to stay visible.
Kind
option
Targets
positioner, popup
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-positioner - Marks the Positioner part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Positioner part.
Metadata
Attribute Value Description
data-side - Reflects the side prop on the Positioner part.
data-align - Reflects the align prop on the Positioner part.
data-side-offset - Reflects the side offset prop on the Positioner part.
data-avoid-collisions - Reflects the avoid collisions prop on the Positioner part.

The floating content container for PreviewCard.

Default element
div
Discovery hook
data-sw-preview-card-popup
Role
tooltip

Props

Prop Type Default Toggle
side "top" | "right" | "bottom" | "left" "bottom"
Description
Sets the preferred side for PreviewCard content.
Kind
option
Targets
positioner, popup
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "center"
Description
Sets how PreviewCard content aligns to its trigger.
Kind
option
Targets
positioner, popup
Full type
"start" | "center" | "end"
sideOffset number 0
Description
Sets the distance between PreviewCard content and its trigger.
Kind
option
Targets
positioner, popup
Full type
number
avoidCollisions boolean true
Description
Allows PreviewCard content to shift or flip to stay visible.
Kind
option
Targets
positioner, popup
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-popup - Marks the Popup part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Popup part.
Metadata
Attribute Value Description
data-side - Reflects the side prop on the Popup part.
data-align - Reflects the align prop on the Popup part.
data-side-offset - Reflects the side offset prop on the Popup part.
data-avoid-collisions - Reflects the avoid collisions prop on the Popup part.

Arrow

The arrow element that visually points to the trigger.

Default element
div
Discovery hook
data-sw-preview-card-arrow
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-arrow - Marks the Arrow part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Arrow part.

Backdrop

The backdrop shown behind the PreviewCard overlay.

Default element
div
Discovery hook
data-sw-preview-card-backdrop
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-backdrop - Marks the Backdrop part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Backdrop part.

Viewport

The visible viewport for PreviewCard content.

Default element
div
Discovery hook
data-sw-preview-card-viewport
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-preview-card-viewport - Marks the Viewport part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Viewport part.

Runtime API

Factory
createPreviewCard
Import
@starwind-ui/runtime/preview-card
Root hook
root data-sw-preview-card
Option props
closeDelay, closeOnEscape, closeOnOutsideInteract, defaultOpen, disableHoverableContent, onOpenChange, open, openDelay

Option Lifecycles

OptionLifecycle
closeDelayconstructor-only
closeOnEscapeconstructor-only
closeOnOutsideInteractconstructor-only
defaultOpenconstructor-only
disableHoverableContentconstructor-only
onOpenChangeconstructor-only
opensetter-backed
openDelayconstructor-only

Runtime Setters

Method Target Description
setOpen state: open Opens or closes PreviewCard from Runtime code.
Component Relationship
Hover Card Renamed primitive