Alert Dialog
Confirm Dialog
A confirmation on the native dialog: focus sits on cancel, and the button names the action instead of saying "Yes".
- alert-dialog
- confirm
- dialog
- a11y
Preview
1440pxHost theme
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/alertdialog-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 "alertdialog-001" (Confirm 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/alertdialog-001.json
Registry item: https://vibeui.ru/r/alertdialog-001.json
Installs to: components/vibeui/alertdialog-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 confirmation on the native dialog: focus sits on cancel, and the button names the action instead of saying "Yes".
A confirmation dialog: a question heading, a note about consequences and two buttons with focus on cancel. Zero dependencies, one file.
## 3. How to use it
import { Alertdialog001 } from "@/components/vibeui/alertdialog-001"
<Alertdialog001 title="Publish the catalog?" confirm="Publish" cancel="Not now" />
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-alertdialog-001-* palette — do not swap it for your theme tokens
- the native dialog: focus trapping, Escape and the backdrop come free
- focus on cancel at open — a blind Enter must not fire the action
- the action named in the button instead of "Yes" and "No"
- the aria-labelledby tying the dialog to its heading
- the row-reverse order: cancel first in markup, the action first for the eye
## 6. You may change
- title, text, confirm and the button labels
- triggerLabel — the opener's label
- the accent through the accent prop
- the dialog width
## 7. Rules
- For an irreversible action this is not enough: use alertdialog-002 with typed confirmation.
- Do not use it for messages — a confirmation asks, it does not notify.
- The action belongs to the caller: onClick only closes the dialog.
- 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/alertdialog-001.jsonhttps://vibeui.ru/r/alertdialog-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-alertdialog-001-*. Клиентский: "use client" ради открытия окна. Модалка открывается методом showModal(), поэтому ловушка фокуса, закрытие по Escape и затемнение достаются от браузера. Отмена стоит первой в разметке и получает фокус, порядок кнопок задаёт row-reverse.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useRef } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Alertdialog001Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "title"
> & {
triggerLabel?: string
title?: string
text?: string
confirm?: string
cancel?: string
accent?: string
}
// Идея компонента: базовое подтверждение на нативном <dialog>. Модалка даёт
// ловушку фокуса, закрытие по Escape и фон — три вещи, которые в своей
// реализации чинятся дольше всего. Кнопка отмены стоит первой в разметке и
// получает фокус при открытии: если человек нажмёт Enter не глядя, ничего не
// случится. Заголовок формулирует вопрос, а кнопка называет действие —
// «Вы уверены?» с кнопками «Да» и «Нет» заставляет перечитывать текст.
const STYLES = `
:where([data-vibeui-block="alertdialog-001"]){
--vibeui-alertdialog-001-bg:oklch(1 0 0);
--vibeui-alertdialog-001-fg:oklch(0.22 0.014 265);
--vibeui-alertdialog-001-muted:oklch(0.55 0.014 265);
--vibeui-alertdialog-001-border:oklch(0.9 0.006 265);
--vibeui-alertdialog-001-accent:oklch(0.55 0.2 262);
--vibeui-alertdialog-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="alertdialog-001"]{
font-family:var(--vibeui-alertdialog-001-font);color:var(--vibeui-alertdialog-001-fg);
}
[data-vibeui-block="alertdialog-001"] *{box-sizing:border-box}
[data-vibeui-block="alertdialog-001"] [data-part="open"]{
appearance:none;cursor:pointer;height:2.25rem;padding:0 0.875rem;
border:1px solid var(--vibeui-alertdialog-001-border);border-radius:0.625rem;
background:var(--vibeui-alertdialog-001-bg);color:inherit;
font:inherit;font-size:0.8125rem;font-weight:650;
}
[data-vibeui-block="alertdialog-001"] [data-part="open"]:focus-visible{outline:2px solid var(--vibeui-alertdialog-001-accent);outline-offset:2px}
/* margin:auto — без него модалка липнет к левому верхнему углу. */
[data-vibeui-block="alertdialog-001"] dialog{
margin:auto;width:min(22rem,calc(100vw - 2rem));padding:1.125rem;
border:1px solid var(--vibeui-alertdialog-001-border);border-radius:0.875rem;
background:var(--vibeui-alertdialog-001-bg);color:var(--vibeui-alertdialog-001-fg);
box-shadow:0 24px 60px -24px oklch(0.2 0.03 265 / 55%);
font-family:var(--vibeui-alertdialog-001-font);
}
[data-vibeui-block="alertdialog-001"] dialog::backdrop{background:oklch(0.2 0.02 265 / 45%)}
[data-vibeui-block="alertdialog-001"] h2{margin:0 0 0.375rem;font-size:1rem;font-weight:700;line-height:1.3}
[data-vibeui-block="alertdialog-001"] [data-part="text"]{
margin:0 0 1rem;font-size:0.8125rem;line-height:1.55;color:var(--vibeui-alertdialog-001-muted);
}
/* Отмена первой в разметке и в фокусе: Enter вслепую ничего не ломает. */
[data-vibeui-block="alertdialog-001"] [data-part="actions"]{
display:flex;flex-direction:row-reverse;gap:0.5rem;
}
[data-vibeui-block="alertdialog-001"] button[data-part="confirm"],
[data-vibeui-block="alertdialog-001"] button[data-part="cancel"]{
flex:1 1 0;appearance:none;cursor:pointer;height:2.375rem;border-radius:0.625rem;
font:inherit;font-size:0.8125rem;font-weight:650;
}
[data-vibeui-block="alertdialog-001"] [data-part="confirm"]{
border:0;background:var(--vibeui-alertdialog-001-accent);color:oklch(1 0 0);
}
[data-vibeui-block="alertdialog-001"] [data-part="cancel"]{
border:1px solid var(--vibeui-alertdialog-001-border);
background:var(--vibeui-alertdialog-001-bg);color:inherit;
}
[data-vibeui-block="alertdialog-001"] dialog button:focus-visible{outline:2px solid var(--vibeui-alertdialog-001-accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="alertdialog-001"] *{animation:none!important;transition:none!important}}
`
/**
* Подтверждение на нативном dialog: фокус на отмене, действие названо кнопкой.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Alertdialog001({
triggerLabel = "Опубликовать",
title = "Опубликовать каталог?",
text = "Страницы станут доступны всем по ссылке. Изменения можно откатить в истории версий.",
confirm = "Опубликовать",
cancel = "Не сейчас",
accent,
className,
style,
...props
}: Alertdialog001Props) {
const box = useRef<HTMLDialogElement>(null)
const palette = {
...(accent ? { "--vibeui-alertdialog-001-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-alertdialog-001" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="alertdialog-001"
className={className}
style={palette}
>
<button
type="button"
data-part="open"
onClick={() => box.current?.showModal()}
>
{triggerLabel}
</button>
<dialog ref={box} aria-labelledby="vibeui-alertdialog-001-title">
<h2 id="vibeui-alertdialog-001-title">{title}</h2>
<p data-part="text">{text}</p>
<div data-part="actions">
<button
type="button"
data-part="confirm"
onClick={() => box.current?.close()}
>
{confirm}
</button>
<button
type="button"
data-part="cancel"
autoFocus
onClick={() => box.current?.close()}
>
{cancel}
</button>
</div>
</dialog>
</div>
</>
)
}