# Popover

A small board that pops out of its trigger.

Docs: https://cozy-ui.solo.engineer/docs/components/popover/

Install: `npx shadcn@latest add @cozy/popover`

### Usage

```tsx
import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover"
```

### Example

```tsx
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";

export default function PopoverDemo() {
  return (
    <Popover>
      <PopoverTrigger asChild><Button variant="outline">Plot size</Button></PopoverTrigger>
      <PopoverContent>
        <div className="grid gap-3">
          <div className="grid gap-1">
            <h4 className="m-0 text-base font-normal">Plot size</h4>
            <p className="m-0 text-sm text-text-muted">Bigger plots take longer to till.</p>
          </div>
          <div className="grid grid-cols-[5rem_1fr] items-center gap-3">
            <Label htmlFor="pw">Width</Label><Input id="pw" defaultValue="3 tiles" />
            <Label htmlFor="ph">Depth</Label><Input id="ph" defaultValue="2 tiles" />
          </div>
        </div>
      </PopoverContent>
    </Popover>
  );
}
```

### Source (components/ui/popover.tsx)

```tsx
import * as React from "react";
import { Popover as PopoverPrimitive } from "radix-ui";
import { cn } from "@/lib/utils";

function Popover(props: React.ComponentProps<typeof PopoverPrimitive.Root>) {
  return <PopoverPrimitive.Root data-slot="popover" {...props} />;
}
function PopoverTrigger(props: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
  return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
}
function PopoverAnchor(props: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
  return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
}
function PopoverContent({ className, align = "center", sideOffset = 8, children, ...props }: React.ComponentProps<typeof PopoverPrimitive.Content>) {
  return (
    <PopoverPrimitive.Portal>
      <PopoverPrimitive.Content data-slot="popover-content" align={align} sideOffset={sideOffset} className={cn("cz-popover", className)} {...props}>
        {children}
        <PopoverPrimitive.Arrow className="cz-popover__arrow" width={16} height={8} />
      </PopoverPrimitive.Content>
    </PopoverPrimitive.Portal>
  );
}

export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
```

npm: `import { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } from "@0xtrou/cozy-ui"` (after `npm install @0xtrou/cozy-ui` and `import "@0xtrou/cozy-ui/styles.css"`).
