Timace

Popover

Share this project

Install
npm install react-aria-components
components/ui/popover.tsx
"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_-_16px)] rounded-(--tui-popover-radius) border-solid border-(length:--tui-popover-border-width) border-(--tui-popover-border) bg-(--tui-popover-bg) font-(family-name:--tui-font) text-(length:--tui-popover-font-size) text-(--tui-popover-fg) shadow-(--tui-popover-shadow)",
  body: "flex flex-col gap-(--tui-popover-gap) p-(--tui-popover-padding) leading-normal outline-none",
  title: "m-0 text-(length:--tui-popover-title-size) leading-tight font-(--tui-popover-title-weight)",
};

export interface PopoverProps extends Omit<AriaPopoverProps, "className" | "children"> {
  title?: string;
  children: ReactNode;
  className?: string;
}

/** A panel that opens beside its trigger. Goes inside a PopoverTrigger, after the button that opens it. */
export function Popover({ title, children, className, offset = 8, ...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>
  );
}
styles/timace-ui.css
: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: 280px;
  --tui-popover-padding: calc(var(--tui-space) * 4);
  --tui-popover-gap: calc(var(--tui-space) * 3);
  --tui-popover-radius: calc(var(--tui-radius) * 1.25);
  --tui-popover-border-width: var(--tui-border-width);
  --tui-popover-shadow: 0 12px 32px rgb(0 0 0 / 0.14);
  --tui-popover-font-size: var(--tui-text);
  --tui-popover-title-size: 15px;
  --tui-popover-title-weight: 600;
  --tui-popover-bg: var(--tui-bg);
  --tui-popover-fg: var(--tui-fg);
  --tui-popover-border: var(--tui-border);
}

.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.