Skip to main content

Starwind UI v3.0 is now available! Migration guide

Preview Card Primitive

Preview Card is a Starwind Runtime primitive in the presence-floating-overlay contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.

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 Preview Card Runtime instance.

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

Props

Prop Type Default Toggle
open boolean -
Description
Controls whether Preview Card is open.
Kind
control
Targets
root
Full type
boolean
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen
defaultOpen boolean false
Description
Sets whether Preview Card starts open.
Kind
control
Targets
root
Full type
boolean
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen
closeDelay number 300
Description
Sets how long Preview Card waits before closing.
Kind
option
Targets
-
Full type
number
closeOnEscape boolean true
Description
Closes Preview Card when Escape is pressed.
Kind
option
Targets
-
Full type
boolean
closeOnOutsideInteract boolean true
Description
Closes Preview Card 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 Preview Card waits before opening.
Kind
option
Targets
-
Full type
number
onOpenChange (open: boolean, details: PreviewCardOpenChangeDetails) => void -
Description
Runs when Preview Card opens or closes.
Kind
callback
Targets
-
Full type
(open: boolean, details: PreviewCardOpenChangeDetails) => void
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen

Events

Event Callback Value Toggle
openChange onOpenChange open: boolean
Description
Fires when Preview Card opens or closes.
DOM event
starwind:open-change
Details type
PreviewCardOpenChangeDetails
Timing
before-state-commit
Cancelable
Yes
Cancellation sequence
  1. Check internal eligibility and intent.
  2. Create one details object for the proposal.
  3. Call the Runtime callback with the details object when the controller exposes one.
  4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
  5. Read details.isCanceled, including cancellation caused by preventDefault().
  6. Apply the accepted state.
  7. Notify Runtime subscribers and other accepted-only observers.

State

State Type Props Toggle
open boolean open / defaultOpen
Description
Tracks whether Preview Card is open.
Initial attribute
data-default-open
Runtime getter
getOpen
Runtime setter
setOpen
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen

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 Preview Card 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 Preview Card 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 Preview Card 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 Preview Card content.
Kind
option
Targets
positioner, popup
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "center"
Description
Sets how Preview Card content aligns to its trigger.
Kind
option
Targets
positioner, popup
Full type
"start" | "center" | "end"
sideOffset number 0
Description
Sets the distance between Preview Card content and its trigger.
Kind
option
Targets
positioner, popup
Full type
number
avoidCollisions boolean true
Description
Allows Preview Card 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 Preview Card.

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 Preview Card content.
Kind
option
Targets
positioner, popup
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "center"
Description
Sets how Preview Card content aligns to its trigger.
Kind
option
Targets
positioner, popup
Full type
"start" | "center" | "end"
sideOffset number 0
Description
Sets the distance between Preview Card content and its trigger.
Kind
option
Targets
positioner, popup
Full type
number
avoidCollisions boolean true
Description
Allows Preview Card 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 Preview Card 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 Preview Card 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 Preview Card from Runtime code.
Component Relationship
Hover Card Renamed primitive

Changelog

View version history v1.0.0 3 releases

v1.0.0

  • Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.

v0.1.1

  • Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
  • Kept generated React state-change callbacks and DOM events cancelable until the Runtime accepts the proposed state, then synchronized rendered state.

v0.1.0

  • Introduced hover and focus timing, floating placement, presence, and dismissal for preview content.