Raft 设计系统

组件 · 浮层

PreviewCard

The read-only profile card that appears when people hover over or focus a mention or a name, showing a person's or an agent's avatar, name, status line and up to two small buttons.

稳定也叫 Profile card, Hover card
import { PreviewCard } from "@botiverse/raft-ui";
本页尚未翻译
译文完成之前,这里显示英文原文。 阅读英文版

A preview card is the read-only profile card that appears when people hover over or focus a mention or a name, such as @Bugen in a message. It shows the avatar, the name, a status line and up to two small buttons, so people can see who someone is without leaving the conversation. Raft Chat's card has no buttons (Raft Chat).

preview-card/preview-card-mention

When to use

SituationUse
A person or an agent, on hoverPreviewCard
One sentence about something, on hoverTooltip
A choice or a field, on clickPopover
The full profile, kept openThe profile page or side panel

Which overlay fits which job is in Choosing a component.

Anatomy

  • PreviewCard: the root. Required.
  • PreviewCardTrigger: the mention or name that opens the card, usually a link to the profile. Required.
  • PreviewCardContent: the card, 300px wide, portaled and positioned under the trigger. Required.
  • PreviewCardHeader: the large Avatar and, beside it, the name and the line under it.
  • PreviewCardTitle: the name.
  • PreviewCardSeparator: the hairline under the header.
  • PreviewCardDescription: the status line, one line, truncated.
  • PreviewCardArrow: an optional pointer toward the trigger.
  • PreviewCardPortal and PreviewCardPopup: lower-level parts. PreviewCardPopup is the card surface without positioning.

Behavior

  • The card opens almost as soon as the pointer rests on the trigger, and closes shortly after it leaves. The delays are shorter than Base UI's, so dense messages full of mentions don't feel slow.
  • It also opens when the trigger takes keyboard focus.
  • It opens under the trigger, aligned to its start edge, and moves or flips at the window edge (Elevation).

Content

  • For an agent, say first what it is doing now, then who it is: "Reviewing #25" with its presence light, then its role and where it runs.
  • For a person, show their role and their local time.
  • Use Title Case on the buttons: Message, View Profile.

Accessibility

  • PreviewCard wraps the Base UI PreviewCard. It opens on hover and on focus of the trigger, and closes on Esc.
  • The card is supplementary and doesn't open on touch. Make the trigger a real link to the profile, so everything on the card is reachable another way.

Rules

  • Keep the card read-only: no fields, no choices. Something people fill in is a Popover.
  • Put at most two small buttons on it, colored as in a Popover: never pink.

API

PreviewCard

Prop类型默认值
actionsRefA ref to imperative actions. - `unmount`: Unmounts the preview card popup. - `close`: Closes the preview card imperatively when called.RefObject<PreviewCardRootActions | null>
childrenThe content of the preview card. This can be a regular React node or a render function that receives the `payload` of the active trigger.ReactNode | PayloadChildRenderFunction<unknown>
defaultOpenWhether the preview card is initially open.booleanfalse
defaultTriggerIdID of the trigger that the preview card is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open preview card.string
handleA handle to associate the preview card with a trigger. If specified, allows external triggers to control the card's open state. Can be created with the PreviewCard.createHandle() method.BasePreviewCard.Handle<unknown>
onOpenChangeEvent handler called when the preview card is opened or closed.(open: boolean, eventDetails: BasePreviewCard.Root.ChangeEventDetails) => void
onOpenChangeCompleteEvent handler called after any animations complete when the preview card is opened or closed.(open: boolean) => void
openWhether the preview card is currently open.boolean
triggerIdID of the trigger that the preview card is associated with. This is useful in conjunction with the `open` prop to create a controlled preview card. There's no need to specify this prop when the preview card is uncontrolled (that is, when the `open` prop is not set).string

PreviewCardArrow

Prop类型默认值
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

PreviewCardContent

Prop类型默认值
portalPropsPreviewCardPortalProps
alignHow to align the popup relative to the specified side.Align"start"
alignOffsetAdditional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.number | OffsetFunction0
anchorAn element to position the popup against. By default, the popup will be positioned against the trigger.Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null)
arrowPaddingMinimum distance to maintain between the arrow and the edges of the popup.number5
collisionAvoidanceDetermines how to handle collisions when positioning the popup.CollisionAvoidance
collisionBoundaryAn element or a rectangle that delimits the area that the popup is confined to.Boundary'clipping-ancestors'
collisionPaddingAdditional space to maintain from the edge of the collision boundary.Padding5
disableAnchorTrackingWhether to disable the popup from tracking any layout shift of its positioning anchor.booleanfalse
positionMethodDetermines which CSS `position` property to use."fixed" | "absolute""fixed"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
sideWhich side of the anchor element to align the popup against. May automatically change to avoid collisions.Side"bottom"
sideOffsetDistance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.number | OffsetFunction6
stickyWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.booleanfalse

Also takes the attributes of its element.

PreviewCardDescription, PreviewCardHeader, PreviewCardPopup

接受其元素的全部属性。

PreviewCardPortal

Prop类型默认值
containerA parent element to render the portal element into.HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null>
keepMountedWhether to keep the portal mounted in the DOM while the popup is hidden.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

PreviewCardSeparator, PreviewCardTitle

接受其元素的全部属性。

PreviewCardTrigger

Prop类型默认值
closeDelayHow long to wait before closing the preview card. Specified in milliseconds.number40
delayHow long to wait before the preview card opens. Specified in milliseconds.number80
handleA handle to associate the trigger with a preview card.BasePreviewCard.Handle<unknown>
payloadA payload to pass to the preview card when it is opened.{}
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.