Preview Card
A preview of a link's destination, shown on hover or keyboard focus. In the look of the app's style.
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { ScLink, ScPreviewCard, ScPreviewCardPortal, ScPreviewCardProvider, ScPreviewCardTrigger,} from '@semantic-components/ui';
@Component({ selector: 'app-preview-card-usage-demo', imports: [ ScPreviewCard, ScPreviewCardPortal, ScPreviewCardProvider, ScPreviewCardTrigger, ScLink, ], template: ` <div scPreviewCardProvider> <a scLink variant="link" href="https://nextjs.org" scPreviewCardTrigger [delay]="10" [closeDelay]="100" > Hover Here </a> <ng-template scPreviewCardPortal> <div scPreviewCard class="flex w-64 flex-col gap-0.5"> <div class="font-semibold">@nextjs</div> <div>The React Framework – created and maintained by @vercel.</div> <div class="text-muted-foreground mt-1 text-xs"> Joined December 2021 </div> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class PreviewCardUsageDemo {}Anatomy
Every part is a directive on your element; the link and the card's content are yours.
import { ScPreviewCardProvider, ScPreviewCardTrigger, ScPreviewCardPortal, ScPreviewCard,} from '@semantic-components/ui';<div scPreviewCardProvider side="…"> <a href="…" scPreviewCardTrigger>…</a> <ng-template scPreviewCardPortal> <div scPreviewCard>…</div> </ng-template></div>Accessibility
- A visual preview, for sighted mouse and keyboard users: the link is the only thing to reach. The card has no role, isn't linked to its trigger, and takes no focus — so a screen reader isn't led through it at every link.
- Keep it supplementary: what it shows must be at the link's destination too.
- Hover opens it after the trigger's delay; keyboard focus at once. Leaving, blur, Escape or a press outside close it. A touch only follows the link.
Examples
In text
The trail ends at a waterfall you can hear long before you see it.
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScPreviewCard, ScPreviewCardPortal, ScPreviewCardProvider, ScPreviewCardTrigger,} from '@semantic-components/ui';
/** A link in a sentence, previewing its destination — what the card shows is on that page too. */Sides
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScPreviewCard, ScPreviewCardPortal, ScPreviewCardProvider, ScPreviewCardTrigger,} from '@semantic-components/ui';
/** side: bottom (default), top, left, right — it flips when there is no room. */Logical sides
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScPreviewCard, ScPreviewCardPortal, ScPreviewCardProvider, ScPreviewCardTrigger,} from '@semantic-components/ui';
/** side: inline-start, inline-end — the reading start and end, which swap in right to left. */RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScButton, ScPreviewCard, ScPreviewCardPortal, ScPreviewCardProvider, ScPreviewCardTrigger,} from '@semantic-components/ui';API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScPreviewCardProvider | div[scPreviewCardProvider], span[scPreviewCardProvider] | [(open)], side ('bottom', 'top', 'left', 'right', 'inline-start', 'inline-end'), align, offset, origin. |
ScPreviewCardTrigger | a[scPreviewCardTrigger], button[scPreviewCardTrigger] | Your link (or button): delay (600) and closeDelay (300); data-popup-open while open. |
ScPreviewCardPortal, ScPreviewCard | ng-template[…], div[scPreviewCard] | The content, rendered while open; the card in the style's look, data-side as placed, animating in and out. |