Hover Card
For sighted users to preview content available behind a link.
import Avatar from '@dinui/react/avatar'import Button from '@dinui/react/button'import HoverCard from '@dinui/react/hover-card'import { IconCalendar } from '@tabler/icons-react'
export default function HoverCardDemo() { return ( <HoverCard open> <HoverCard.Trigger asChild> <Button variant="ghost">@nextjs</Button> </HoverCard.Trigger> <HoverCard.Content className="w-80"> <div className="flex justify-between gap-4"> <Avatar> <Avatar.Image src="https://github.com/vercel.png" /> <Avatar.Fallback>VC</Avatar.Fallback> </Avatar> <div className="space-y-1"> <h4 className="text-sm font-semibold">@nextjs</h4> <p className="text-sm">The React Framework – created and maintained by @vercel.</p> <div className="flex items-center pt-2 text-fg-weaker"> <IconCalendar className="mr-2 h-4 w-4" />{' '} <span className="text-xs">Joined December 2021</span> </div> </div> </div> </HoverCard.Content> </HoverCard> )}Installation
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
All done
You now can start using this component in your project.
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
Run the following command in your project
Terminal window npx @dinui/cli@latest add hover-cardTerminal window yarn dlx @dinui/cli@latest add hover-cardTerminal window pnpm dlx @dinui/cli@latest add hover-cardTerminal window bunx @dinui/cli@latest add hover-card -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
Install dependencies
Terminal window npm install @radix-ui/react-hover-card tailwind-variantsTerminal window yarn add @radix-ui/react-hover-card tailwind-variantsTerminal window pnpm add @radix-ui/react-hover-card tailwind-variantsTerminal window bun add @radix-ui/react-hover-card tailwind-variants -
Copy and paste the following code into your project
'use client'import * as HoverCardPrimitive from '@radix-ui/react-hover-card'import { forwardRef } from 'react'import { tv } from 'tailwind-variants'const hoverCard = tv({slots: {content: ['z-50 rounded-md border bg-bg--contrast p-4 shadow-md','data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0','data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2','data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',],},})const HoverCardContent = forwardRef<React.ElementRef<typeof HoverCardPrimitive.Content>,React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>>((props, ref) => {const { content } = hoverCard()return (<HoverCardPrimitive.Contentalign={'center'}sideOffset={4}{...props}ref={ref}className={content({ className: props.className })}/>)})HoverCardContent.displayName = HoverCardPrimitive.Content.displayNameconst HoverCard = Object.assign(HoverCardPrimitive.Root, {Trigger: HoverCardPrimitive.Trigger,Content: HoverCardContent,})export default HoverCardexport { hoverCard, HoverCardPrimitive } -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.