Biji UI

Hover Card

A card that appears when hovering over a trigger, with configurable open and close delays.

Built with @biji_ui.

Installation

biji-ui = { version = "0.5.0", features = ["hover_card"] }

Usage

use leptos::prelude::*;
use biji_ui::components::hover_card;

#[component]
pub fn MyHoverCard() -> impl IntoView {
    view! {
        <hover_card::Root>
            <hover_card::Trigger class="inline-block underline decoration-dotted cursor-pointer">
                "@biji_ui"
            </hover_card::Trigger>
            <hover_card::Content
                class="z-50 w-64 rounded-lg border shadow-md transition bg-background \
                       border-border origin-[var(--biji-transform-origin)]"
                show_class="opacity-100 scale-100 duration-150 ease-out"
                hide_class="opacity-0 scale-95 duration-100 ease-in"
            >
                <div class="p-4">
                    <p class="text-sm font-semibold">"Biji UI"</p>
                    <p class="text-xs text-muted-foreground mt-1">
                        "Headless UI components for Leptos."
                    </p>
                </div>
            </hover_card::Content>
        </hover_card::Root>
    }
}

RootWith

Use RootWith to access HoverCardState inline via the let: binding. The state is Copy and safe to pass as a prop.

Card is closed

@biji_ui
use leptos::prelude::*;
use biji_ui::components::hover_card;

#[component]
pub fn MyHoverCard() -> impl IntoView {
    view! {
        <hover_card::RootWith let:h>
            <p class="mb-1 text-sm text-muted-foreground">
                {move || if h.open.get() { "Card is open" } else { "Card is closed" }}
            </p>
            <hover_card::Trigger class="inline-block underline decoration-dotted cursor-pointer">
                "@biji_ui"
            </hover_card::Trigger>
            <hover_card::Content
                class="z-50 w-64 rounded-lg border shadow-md transition bg-background \
                       border-border origin-[var(--biji-transform-origin)]"
                show_class="opacity-100 scale-100 duration-150 ease-out"
                hide_class="opacity-0 scale-95 duration-100 ease-in"
            >
                <div class="p-4">
                    <p class="text-sm font-semibold">"Biji UI"</p>
                    <p class="text-xs text-muted-foreground mt-1">
                        "Headless UI components for Leptos."
                    </p>
                </div>
            </hover_card::Content>
        </hover_card::RootWith>
    }
}

API Reference

Root / RootWith

NameTypeDefaultDescription
classString""CSS class applied to the wrapper `<span>`.
positioningPositioningBottomWhere to render the card relative to the trigger.
avoid_collisionsAvoidCollisionsFlipHow the card reacts when it would overflow the viewport.
open_delayDuration700msHow long after the pointer enters the trigger before the card appears.
close_delayDuration300msHow long after the pointer leaves before the card hides.
hide_delayDuration200msHow long to wait before unmounting Content after closing (match your CSS transition).
arrow_sizei328Size in pixels of the optional Arrow element.
openboolfalseInitial open state.
on_open_changeOption<Callback<bool>>NoneCalled with `true` when the card opens and `false` when it closes.

Trigger

NameTypeDefaultDescription
classString""CSS class applied to the `<span>` wrapper.

Content

NameTypeDefaultDescription
classString""CSS class applied in both open and closed states.
show_classString""CSS class applied when the card is open.
hide_classString""CSS class applied while the card is closing.

Arrow

NameTypeDefaultDescription
classString""CSS class applied to the arrow `<div>`.

Data Attributes

AttributeDescription
data-state"open" when the card is visible; "closed" otherwise. Present on Trigger.