Popover
Displays rich content in a portal, triggered by a button.
import Button from '@dinui/react/button'import Input from '@dinui/react/input'import Label from '@dinui/react/label'import Popover from '@dinui/react/popover'
export default function PopoverDemo() { return ( <Popover> <Popover.Trigger asChild> <Button variant="outline">Open popover</Button> </Popover.Trigger>
<Popover.Content className="w-80"> <div className="grid gap-4"> <div className="space-y-2"> <h4 className="font-medium leading-none">Dimensions</h4> <p className="text-sm text-fg-weaker">Set the dimensions for the layer.</p> </div>
<div className="grid gap-2"> <div className="grid grid-cols-3 items-center gap-4"> <Label htmlFor="width">Width</Label> <Input id="width" defaultValue="100%" className="col-span-2 h-8" /> </div>
<div className="grid grid-cols-3 items-center gap-4"> <Label htmlFor="maxWidth">Max. width</Label> <Input id="maxWidth" defaultValue="300px" className="col-span-2 h-8" /> </div>
<div className="grid grid-cols-3 items-center gap-4"> <Label htmlFor="height">Height</Label> <Input id="height" defaultValue="25px" className="col-span-2 h-8" /> </div>
<div className="grid grid-cols-3 items-center gap-4"> <Label htmlFor="maxHeight">Max. height</Label> <Input id="maxHeight" defaultValue="none" className="col-span-2 h-8" /> </div> </div> </div> </Popover.Content> </Popover> )}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 popoverTerminal window yarn dlx @dinui/cli@latest add popoverTerminal window pnpm dlx @dinui/cli@latest add popoverTerminal window bunx @dinui/cli@latest add popover -
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-popover @radix-ui/react-popper tailwind-variants type-festTerminal window yarn add @radix-ui/react-popover @radix-ui/react-popper tailwind-variants type-festTerminal window pnpm add @radix-ui/react-popover @radix-ui/react-popper tailwind-variants type-festTerminal window bun add @radix-ui/react-popover @radix-ui/react-popper tailwind-variants type-fest -
Copy and paste the following code into your project
'use client'import * as PopoverPrimitive from '@radix-ui/react-popover'import { forwardRef } from 'react'import { tv } from 'tailwind-variants'import type { Merge } from 'type-fest'const popover = tv({slots: {content: ['z-50 rounded-md border bg-bg--contrast p-4 shadow-md outline-none','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 PopoverContent = forwardRef<React.ElementRef<typeof PopoverPrimitive.Content>,Merge<React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>,{portalProps?: React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Portal>}>>(({ portalProps, ...props }, ref) => {const { content } = popover()return (<PopoverPrimitive.Portal {...portalProps}><PopoverPrimitive.Contentalign="center"sideOffset={4}{...props}ref={ref}className={content({ className: props.className })}/></PopoverPrimitive.Portal>)})PopoverContent.displayName = PopoverPrimitive.Content.displayNameconst Popover = Object.assign(PopoverPrimitive.Root, {Trigger: PopoverPrimitive.Trigger,Anchor: PopoverPrimitive.Anchor,Content: PopoverContent,})export default Popoverexport { popover, PopoverPrimitive } -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.