Dialog

Popover Dialog

A modal built on the HTML popover attribute: opening, Esc, click-outside, the backdrop and the top layer all come from the browser, with no JS at all.

  • dialog
  • modal
  • popover
  • no-js

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/dialog-001?lang=en

Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "dialog-001" (Popover Dialog) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/dialog-001.json

Registry item: https://vibeui.ru/r/dialog-001.json
Installs to: components/vibeui/dialog-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A modal built on the HTML popover attribute: opening, Esc, click-outside, the backdrop and the top layer all come from the browser, with no JS at all.

A JS-free confirmation dialog. The button is wired to the window through popovertarget, and the browser supplies Esc, light dismiss, the dimmed backdrop and the top layer. The entrance is animated with @starting-style. Title, body, cancel and confirm buttons. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Dialog001 } from "@/components/vibeui/dialog-001"

<Dialog001
  id="delete-project"
  trigger="Delete project"
  title="Delete this project?"
  description="This cannot be undone."
  confirmLabel="Delete"
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-dialog-001-* palette — do not swap it for your theme tokens (bg-background, border-border and the like)
- the popover mechanism: popover="auto" and popovertarget are the entire behaviour; it needs no React state
- styling the window through the [data-vibeui-dialog-001-window] attribute: in the top layer the window is no longer a descendant of the root, so descendant selectors stop matching
- passing the palette to the window through its own style attribute: for the same reason variables do not inherit into it
- ::backdrop and its dimming — without a backdrop a modal does not read as modal
- aria-labelledby tying the window to its heading, and role="dialog"
- @starting-style together with transition-behavior for display and overlay: without them the entrance jumps
- the <style> block inside the component — it holds the palette, the buttons and the animation

## 6. You may change
- id — every dialog on a page needs its own: it is what links button and window
- the trigger, title, description, confirmLabel and cancelLabel copy
- children — your own content instead of the description: a form, a list, anything
- the accent through the accent prop — it colours the buttons and the focus ring
- the confirm handler: attach onClick to the confirm button in your copy

## 7. Rules
- Two instances sharing an id on one page conflict: the button opens whichever window it finds first. Give each its own id.
- popover="auto" closes on an outside click. For a window that must not be dismissed by accident use popover="manual".
- This is not <dialog>: popover has no modality in the sense of making the rest of the page inert. For a payment form use <dialog> with showModal and client code.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/dialog-001.json
https://vibeui.ru/r/dialog-001.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-dialog-001-*. Открытие держит HTML popover: кнопка объявляет цель атрибутом popovertarget, окно — popover="auto". Отсюда бесплатно приходят закрытие по Esc и по клику мимо, подложка ::backdrop и верхний слой, в котором окно не зависит от overflow и z-index родителей. Анимация появления собрана на @starting-style и transition-behavior для display и overlay. Окно стилизуется по атрибуту [data-vibeui-dialog-001-window], а не по вложенности: в верхнем слое оно перестаёт быть потомком корня компонента.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import type { ComponentPropsWithoutRef, CSSProperties, ReactNode } from "react"

export type Dialog001Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "title" | "children" | "id"
> & {
  /** Уникальный идентификатор: связывает кнопку и окно. */
  id?: string
  trigger?: string
  title?: string
  description?: string
  confirmLabel?: string
  cancelLabel?: string
  /** Собственное содержимое вместо описания. */
  children?: ReactNode
  accent?: string
}

// Идея компонента: модальное окно без единой строки JS. Открытие и закрытие
// держит HTML popover: кнопка объявляет цель через popovertarget, браузер сам
// даёт закрытие по Esc и клику мимо, подложку через ::backdrop и верхний слой,
// в котором окно не зависит от overflow и z-index родителей.
const STYLES = `
:where([data-vibeui-block="dialog-001"]){
--vibeui-dialog-001-fg:oklch(0.22 0.016 265);
--vibeui-dialog-001-muted:oklch(0.5 0.014 265);
--vibeui-dialog-001-bg:oklch(1 0 0);
--vibeui-dialog-001-border:oklch(0.9 0.006 265);
--vibeui-dialog-001-accent:oklch(0.55 0.2 262);
--vibeui-dialog-001-accent-fg:oklch(1 0 0);
--vibeui-dialog-001-radius:1rem;
--vibeui-dialog-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="dialog-001"]{
display:inline-flex;font-family:var(--vibeui-dialog-001-font);
}
[data-vibeui-block="dialog-001"] [data-part="trigger"],
[data-vibeui-block="dialog-001"] [data-part="confirm"],
[data-vibeui-block="dialog-001"] [data-part="cancel"]{
appearance:none;cursor:pointer;font:inherit;font-size:0.875rem;font-weight:500;
display:inline-flex;align-items:center;justify-content:center;
height:2.25rem;padding:0 0.9375rem;border-radius:0.5rem;border:1px solid transparent;
transition:background-color .16s ease,border-color .16s ease,color .16s ease;
}
[data-vibeui-block="dialog-001"] [data-part="trigger"],
[data-vibeui-block="dialog-001"] [data-part="confirm"]{
background:var(--vibeui-dialog-001-accent);color:var(--vibeui-dialog-001-accent-fg);
}
[data-vibeui-block="dialog-001"] [data-part="trigger"]:hover,
[data-vibeui-block="dialog-001"] [data-part="confirm"]:hover{
background:color-mix(in oklab,var(--vibeui-dialog-001-accent) 88%,black);
}
[data-vibeui-block="dialog-001"] [data-part="cancel"]{
background:transparent;color:var(--vibeui-dialog-001-fg);
border-color:var(--vibeui-dialog-001-border);
}
[data-vibeui-block="dialog-001"] [data-part="cancel"]:hover{
background:color-mix(in oklab,var(--vibeui-dialog-001-border) 40%,transparent);
}
[data-vibeui-block="dialog-001"] [data-part="trigger"]:focus-visible,
[data-vibeui-block="dialog-001"] [data-part="confirm"]:focus-visible,
[data-vibeui-block="dialog-001"] [data-part="cancel"]:focus-visible{
outline:2px solid var(--vibeui-dialog-001-accent);outline-offset:2px;
}
[data-vibeui-dialog-001-window]{
/* inset:0 вместе с margin:auto центрирует окно в верхнем слое. */
position:fixed;inset:0;margin:auto;height:fit-content;
width:min(26rem,calc(100vw - 2rem));box-sizing:border-box;
padding:1.375rem;border:1px solid var(--vibeui-dialog-001-border,oklch(0.9 0.006 265));
border-radius:var(--vibeui-dialog-001-radius,1rem);
background:var(--vibeui-dialog-001-bg,oklch(1 0 0));
color:var(--vibeui-dialog-001-fg,oklch(0.22 0.016 265));
font-family:var(--vibeui-dialog-001-font,ui-sans-serif,system-ui,sans-serif);
box-shadow:0 24px 60px -24px oklch(0.2 0.03 265 / 45%);
opacity:0;transform:translateY(0.5rem) scale(0.98);
transition:opacity .18s ease,transform .18s ease,display .18s allow-discrete,overlay .18s allow-discrete;
}
[data-vibeui-dialog-001-window]:popover-open{opacity:1;transform:none}
@starting-style{[data-vibeui-dialog-001-window]:popover-open{opacity:0;transform:translateY(0.5rem) scale(0.98)}}
[data-vibeui-dialog-001-window]::backdrop{
background:oklch(0.18 0.02 265 / 45%);backdrop-filter:blur(2px);
}
[data-vibeui-dialog-001-window] [data-part="title"]{margin:0 0 0.375rem;font-size:1.0625rem;font-weight:600;line-height:1.35}
[data-vibeui-dialog-001-window] [data-part="body"]{margin:0;font-size:0.875rem;line-height:1.55;color:var(--vibeui-dialog-001-muted,oklch(0.5 0.014 265))}
[data-vibeui-dialog-001-window] [data-part="actions"]{display:flex;justify-content:flex-end;gap:0.5rem;margin-top:1.125rem}
@media (prefers-reduced-motion:reduce){
[data-vibeui-block="dialog-001"] *{animation:none!important;transition:none!important}
[data-vibeui-dialog-001-window]{transition:none!important;opacity:1;transform:none}
}
`

/**
 * Модальное окно на HTML popover: открытие, Esc и клик мимо — без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Dialog001({
  id = "vibeui-dialog-001",
  trigger = "Удалить проект",
  title = "Удалить проект?",
  description = "Вместе с проектом удалятся страницы, домены и история публикаций. Отменить это будет нельзя.",
  confirmLabel = "Удалить",
  cancelLabel = "Отмена",
  children,
  accent,
  className,
  style,
  ...props
}: Dialog001Props) {
  const palette = {
    ...(accent ? { "--vibeui-dialog-001-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-dialog-001" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="dialog-001"
        className={className}
        style={palette}
      >
        <button data-part="trigger" type="button" popoverTarget={id}>
          {trigger}
        </button>
        <div
          id={id}
          popover="auto"
          data-vibeui-dialog-001-window=""
          role="dialog"
          aria-labelledby={`${id}-title`}
          style={palette}
        >
          <h2 data-part="title" id={`${id}-title`}>
            {title}
          </h2>
          {children ?? <p data-part="body">{description}</p>}
          <div data-part="actions">
            <button data-part="cancel" type="button" popoverTarget={id}>
              {cancelLabel}
            </button>
            <button data-part="confirm" type="button" popoverTarget={id}>
              {confirmLabel}
            </button>
          </div>
        </div>
      </div>
    </>
  )
}