npm install react-aria-components
"use client";
import type { ReactNode } from "react";
import { Dialog, DialogTrigger, Heading, Popover as AriaPopover, type PopoverProps as AriaPopoverProps } from "react-aria-components";
export { DialogTrigger as PopoverTrigger };
export const popoverStyles = {
popover:
"w-(--tui-popover-width) max-w-[calc(100vw_-_24px)] origin-(--trigger-anchor-point) rounded-(--tui-popover-radius) bg-(--tui-popover-bg) font-(family-name:--tui-font) text-(length:--tui-popover-font-size) text-(--tui-popover-fg) shadow-(--tui-popover-shadow) transition-[opacity,scale] duration-(--tui-popover-duration) ease-out data-entering:scale-96 data-entering:opacity-0 data-exiting:scale-96 data-exiting:opacity-0",
body: "flex flex-col gap-(--tui-popover-gap) p-(--tui-popover-padding) leading-relaxed outline-none",
title: "m-0 text-(length:--tui-popover-title-size) leading-tight font-(--tui-popover-title-weight) tracking-[-0.01em]",
};
export interface PopoverProps extends Omit<AriaPopoverProps, "className" | "children"> {
title?: string;
children: ReactNode;
className?: string;
}
/** A floating panel that grows out of its trigger. Goes inside a PopoverTrigger, after the button that opens it. */
export function Popover({ title, children, className, offset = 12, ...props }: PopoverProps) {
return (
<AriaPopover data-slot="popover" offset={offset} {...props} className={[popoverStyles.popover, className].filter(Boolean).join(" ")}>
<Dialog aria-label={title ? undefined : "Details"} className={popoverStyles.body}>
{title && (
<Heading slot="title" className={popoverStyles.title}>
{title}
</Heading>
)}
{children}
</Dialog>
</AriaPopover>
);
}:root {
color-scheme: light;
--tui-bg: #ffffff;
--tui-fg: #0a0a0a;
--tui-muted: #f5f5f5;
--tui-muted-fg: #737373;
--tui-border: #e5e5e5;
--tui-primary: #171717;
--tui-primary-fg: #fafafa;
--tui-ring: #a3a3a3;
--tui-success: #16a34a;
--tui-warning: #d97706;
--tui-danger: #dc2626;
--tui-radius: 8px;
--tui-border-width: 1px;
--tui-space: 4px;
--tui-shadow: none;
--tui-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
--tui-text: 14px;
--tui-duration: 150ms;
/* Popover */
--tui-popover-width: 300px;
--tui-popover-padding: calc(var(--tui-space) * 5);
--tui-popover-gap: calc(var(--tui-space) * 3.5);
--tui-popover-radius: calc(var(--tui-radius) * 3);
--tui-popover-shadow: 0 0 0 1px color-mix(in srgb, var(--tui-fg) 5%, transparent), 0 2px 6px rgb(0 0 0 / 0.04), 0 16px 40px rgb(0 0 0 / 0.1);
--tui-popover-font-size: var(--tui-text);
--tui-popover-title-size: calc(var(--tui-text) + 2px);
--tui-popover-title-weight: 600;
--tui-popover-duration: 120ms;
--tui-popover-bg: light-dark(var(--tui-bg), color-mix(in oklab, var(--tui-bg) 90%, var(--tui-fg)));
--tui-popover-fg: var(--tui-fg);
}
.dark,
[data-theme="dark"] {
color-scheme: dark;
--tui-bg: #0a0a0a;
--tui-fg: #fafafa;
--tui-muted: #1c1c1c;
--tui-muted-fg: #a3a3a3;
--tui-border: #2a2a2a;
--tui-primary: #fafafa;
--tui-primary-fg: #171717;
--tui-ring: #737373;
--tui-success: #22c55e;
--tui-warning: #f59e0b;
--tui-danger: #ef4444;
}Needs Tailwind CSS v4. Import the stylesheet once, after Tailwind.