Hover Card
为链接提供的预览卡片:悬停或键盘聚焦并稍作延迟后显示,指针停留在链接或卡片上时保持打开;非模态,在触摸屏上轻点即可打开。
Angular: 可用 Vue: 可用 React: 可用 React Native: 可用
用法
<div class="demo-row" style="align-items: flex-start; min-height: 11rem">
<a
href="#ada-park"
[soneHoverCardTrigger]="profile"
[openDelay]="300"
style="font-weight: var(--font-weight-medium); text-decoration: underline; text-underline-offset: var(--space-1)"
>@adapark</a>
<ng-template #profile>
<div soneHoverCard>
<div style="display: flex; gap: var(--space-3)">
<sone-avatar><span soneAvatarFallback>AP</span></sone-avatar>
<div style="display: flex; flex-direction: column; gap: var(--space-1)">
<strong>Ada Park</strong>
<span>Product design. Writes up every sync within the hour.</span>
<span style="color: var(--text-secondary); font-size: var(--font-size-xs)">Joined March 2021</span>
</div>
</div>
</div>
</ng-template>
</div>导入
import {
SoneHoverCardDirective,
SoneHoverCardTriggerDirective,
} from "@surface-one/angular/hover-card";API 参考
SoneHoverCardDirective指令
`[soneHoverCard]` (or `[soneHoverCardContent]`) — the card a `soneHoverCardTrigger` previews: the popover surface at `--hover-card-w`, with no role (it describes its trigger). Put it in the trigger's `<ng-template>` or pass it by reference (`#card="soneHoverCard"`): it stays hidden in place until the trigger opens it.
SoneHoverCardTriggerDirective指令
`[soneHoverCardTrigger]` — a link (or any focusable element) that previews a card on hover and keyboard focus (spartan/ui `brnHoverCardTrigger`, Radix HoverCard): it opens after `openDelay`, stays open while the pointer is on the trigger or the card, and closes `closeDelay` after it leaves, on Escape or on a click outside. Non-modal: focus stays on the trigger (the card is `aria-describedby` it while open) and Tab moves on as usual. On a touch screen the first tap opens the card and the next one follows the link.
| 名称 | 类型 | 默认值 |
|---|---|---|
sideThe side of the trigger the panel opens on; it flips when that side lacks room. | FloatingSide | "bottom" |
offsetGap between the trigger and the panel, in px. | number | 4 |
open双向Shown or not — `[(open)]`. | boolean | false |
keepOpenOnOutsideClickKeep the panel open on a click outside it (Escape still closes it). | boolean | false |
soneHoverCardTrigger | SoneOverlayContent | null | null |
alignAlignment along the trigger's edge (centred, as in shadcn/ui). | FloatingAlign | "center" |
openDelayms from hovering or focusing the trigger to opening. | number | 700 |
closeDelayms from leaving the trigger and the card to closing. | number | 300 |
openOnFocusOpen on keyboard focus too (on by default). | boolean | true |