--- title: "hover-card" description: "Preview card shown when a trigger is hovered or focused." category: "Overlays" --- # hover-card Preview card shown when a trigger is hovered or focused. ## Installation ```bash php artisan ui:add hover-card ``` ## Dependencies - composer: `gehrisandro/tailwind-merge-laravel` ## Usage ```blade @abdulkadersafi

Builds LaralCN-UI.

``` ## Example The demo rendered on the docs page. ```blade @abdulkadersafi

@abdulkadersafi

Builds LaralCN-UI. Laravel, Blade, Tailwind.

``` ## Source Copy this file to the path shown above it. `resources/views/components/ui/hover-card.blade.php` ```blade @props([ 'side' => 'top', ]) @php // Hover and focus-within do the work, so this ships no script, the same // approach the tooltip takes. // // The gap between trigger and card is padding on the positioning wrapper, // never margin on the card. Margin would leave a dead strip that drops the // hover the moment the pointer sets off toward the card. $position = match ($side) { 'bottom' => 'top-full left-1/2 -translate-x-1/2 pt-2', 'left' => 'right-full top-1/2 -translate-y-1/2 pr-2', 'right' => 'left-full top-1/2 -translate-y-1/2 pl-2', default => 'bottom-full left-1/2 -translate-x-1/2 pb-2', }; // `block` is load-bearing: the card is a span (it has to be, the wrapper is // phrasing content) and width does nothing to an inline box. The wrapper // escapes this only because position:absolute blockifies it. $classes = \TailwindMerge\Laravel\Facades\TailwindMerge::merge( 'block w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md', $attributes->get('class'), ); @endphp except('class') }}> {{ $trigger }} ``` ## Theme tokens `--popover`, `--popover-foreground`, `--border` CSS only, no JavaScript: opens on hover and on keyboard focus. Put the trigger in the `trigger` slot and the card body in the default slot. Sides: top, bottom, left, right.