Skip to content
GitHub11 stars

Preview Card

A link that shows a destination preview without interrupting keyboard or screen reader navigation.

The principles of good typography remain in the digital age.

<PreviewCardRoot>
    <p class="preview-card-paragraph">
        The principles of good 

Usage guidelines

  • Protect screen reader users' current context: Exposing each preview to screen readers would force people through its contents before they could continue through the page. Keep the link as the only accessible interface, and include all the previewed information at its destination.
  • Keep popup content supplementary: Don't put unique or essential information in the popup unless it's also on the linked page. For the reason above, the card's content isn't reachable by touch, keyboard or screen reader: it's a visual progressive enhancement for sighted mouse and keyboard users only.

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<PreviewCardRoot>
    <PreviewCardTrigger />
    <PreviewCardPortal>
        <PreviewCardBackdrop />
        <PreviewCardPositioner>
            <PreviewCardPopup>
                <PreviewCardArrow />
                <PreviewCardViewport />
            </PreviewCardPopup>
        </PreviewCardPositioner>
    </PreviewCardPortal>
</PreviewCardRoot>

API Reference

PreviewCardRoot

Doesn't render its own HTML element.

ParameterTypeDefault
Open bool false
OpenChanged

Called with the new value when Open changes, for @bind-Open.

EventCallback<bool> -
OnOpenChange EventCallback<OpenChangeEventArgs> -
OnOpenChangeComplete EventCallback<bool> -
Handle PopupHandle? -
ContentTemplate RenderFragment<object?>? -
ChildContent

The part's content.

RenderFragment? -

PreviewCardTrigger

Renders a <a> element.

ParameterTypeDefault
Handle PopupHandle? -
Payload object? -
Delay int 600
CloseDelay int 300
Render RenderFragment<PopupTriggerRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-popup-open

Present when the corresponding preview card is open.

-

PreviewCardPortal

Doesn't render its own HTML element.

ParameterTypeDefault
KeepMounted bool false
ChildContent

The part's content.

RenderFragment? -

PreviewCardBackdrop

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the preview card is open.

-
data-closed

Present when the preview card is closed.

-
data-starting-style

Present when the preview card begins animating in.

-
data-ending-style

Present when the preview card is animating out.

-

PreviewCardPositioner

Doesn't render its own HTML element.

ParameterTypeDefault
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int? -
Sticky bool? -
Anchor string? -
ChildContent

The part's content.

RenderFragment? -
AttributeType
data-open

Present when the preview card is open.

-
data-closed

Present when the preview card is closed.

-
data-anchor-hidden

Present when the anchor is hidden.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
CSS variableType
--anchor-height

The anchor's height.

number
--anchor-width

The anchor's width.

number
--available-height

The available height between the trigger and the edge of the viewport.

number
--available-width

The available width between the trigger and the edge of the viewport.

number
--positioner-height

The height of the preview card's positioner. It is important to set height to this value when using CSS to animate size changes.

number
--positioner-width

The width of the preview card's positioner. It is important to set width to this value when using CSS to animate size changes.

number
--transform-origin

The coordinates that this element is anchored to. Used for animations and transitions.

string

PreviewCardPopup

Renders a <div> element.

ParameterTypeDefault
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int 5
Sticky bool false
Anchor string? -
FallbackAxis bool? -
KeepMounted bool false
InitialFocus string? -
FinalFocus string? -
PositionerAttributes IReadOnlyDictionary<string, object>? -
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the preview card is open.

-
data-closed

Present when the preview card is closed.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
data-starting-style

Present when the preview card begins animating in.

-
data-ending-style

Present when the preview card is animating out.

-

PreviewCardArrow

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the preview card is open.

-
data-closed

Present when the preview card is closed.

-
data-uncentered

Present when the preview card arrow is uncentered.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

PreviewCardViewport

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-activation-direction

Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.

`${'left' | 'right' | ''} ${'down' | 'up' | ''}`
data-current

Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.

-
data-instant

Present if animations should be instant.

'dismiss' | 'focus'
data-previous

Applied to the direct child of the viewport that contains the exiting content when transitions are present.

-
data-transitioning

Indicates that the viewport is currently transitioning between old and new content.

-
CSS variableType
--popup-height

The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

\`\`
--popup-width

The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

\`\`

PreviewCardHandle