component
Dialog
A question or a short task that stops everything else until it's answered. A grey plate over the page with a title, a few words and its buttons.
Try it
Every variant
Delete this invoice?
Defaultimport { Dialog } from 'rost/components/dialog/Dialog'
<Dialog
open={asking}
onClose={() => setAsking(false)}
title="Delete this invoice?"
actions={<>
<Button variant="secondary" onClick={() => setAsking(false)}>Keep it</Button>
<Button onClick={remove}>Delete</Button>
</>}
>
It's gone for good, and so is its number.
</Dialog> src/components/dialog/Dialog.tsx
import { useEffect, useId, useRef, type HTMLAttributes, type ReactNode } from 'react'
import './dialog.css'
export interface DialogProps extends Omit<HTMLAttributes<HTMLDialogElement>, 'title'> {
/** Shows it as a modal. */
readonly open?: boolean
/** What it asks or what it's for. */
readonly title: ReactNode
/** Its Buttons, the main one last. */
readonly actions?: ReactNode
/** Called when it closes, by Esc or otherwise. */
readonly onClose?: () => void
/** Draws the plate in place, without the modal, for previews. */
readonly preview?: boolean
readonly children?: ReactNode
}
const b = 'rost-dialog'
/**
* A question or a short task that stops everything else. The browser's
* `<dialog>`, opened with `showModal()`, so focus, Esc and the page behind
* are the browser's. Built from contracts/dialog.contract.yaml.
*/
export function Dialog({ open = false, title, actions, onClose, preview = false, children, className, ...rest }: DialogProps) {
const ref = useRef<HTMLDialogElement>(null)
const titleId = useId()
useEffect(() => {
const d = ref.current
if (!d || preview) return
if (open && !d.open) d.showModal()
if (!open && d.open) d.close()
}, [open, preview])
const panel = (
<div className={`${b}__panel`}>
<h2 id={titleId} className={`${b}__title`}>{title}</h2>
{children != null && <div className={`${b}__body`}>{children}</div>}
{actions != null && <div className={`${b}__actions`}>{actions}</div>}
</div>
)
const cls = [b, className].filter(Boolean).join(' ')
if (preview) return <div className={cls} role="dialog" aria-labelledby={titleId}>{panel}</div>
return <dialog ref={ref} className={cls} aria-labelledby={titleId} onClose={onClose} {...rest}>{panel}</dialog>
}
The source for everything on this page: contracts/dialog.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: dialog
name: Dialog
kind: component
status: review
summary: A question or a short task that stops everything else until it's answered. A grey plate over the page with a title, a few words and its buttons.
category: surfaces
related: [ popover, button, card ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "738:35"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=738-35
extractedAt: "2026-11-16"
extractedBy: hand
frozenAt: "2026-11-16"
props:
open: { type: boolean, default: false, notes: "Shows it as a modal, with `showModal()`: the page behind can't be reached until it closes." }
title: { type: slot, required: true, notes: "What it asks or what it's for. It names the dialog." }
children: { type: slot, notes: "A sentence or two, or a short form." }
actions: { type: slot, notes: "Its Buttons, the main one last. Esc closes it too, and calls `onClose`." }
elements:
root:
notes: "The browser's `<dialog>`, with its own look taken away. The browser shows and hides it, and centres it, so the plate is a part inside it."
styles:
padding: { token: spacing/gap/none, value: 0px }
border: { value: none, assert: false }
background: { value: transparent, assert: false }
overflow: { value: visible, assert: false }
max-width: { value: none, assert: false }
margin: { value: auto, assert: false, notes: "The browser centres a modal dialog with its margins; Rost's reset would take them away." }
color: { value: inherit, assert: false }
backdrop:
pseudo: "::backdrop"
notes: "The layer the browser puts between the dialog and the page. The page's own colour at 72%, so the page stays in view but steps back."
styles:
background: { token: dialog/backdrop, value: "#060805" }
opacity: { token: opacity/hard, value: "0.72" }
panel:
notes: "The plate: the dialog's fill, a 1px edge and the floating shadow. It holds the title, the words and the buttons in a column, 16px apart."
styles:
display: { value: flex, assert: false }
flex-direction: { value: column, assert: false }
gap: { token: spacing/gap/medium, value: 16px }
width: { value: 400px, notes: "Wide enough for two lines of words and two buttons. On a phone it's as wide as the screen allows." }
max-width: { value: calc(100vw - 32px), assert: false }
padding: { token: spacing/gap/large, value: 24px }
border-radius: { token: spacing/radius/xlarge, value: 24px }
background: { token: dialog/background, value: "#171717" }
outline-style: { value: solid, assert: false }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside the plate." }
outline-color: { token: dialog/edge, value: "#3a3a3a" }
box-shadow: { token: shadow/floating, value: "0px 16px 24px 0px rgba(0, 0, 0, 0.16)", notes: "The kit's only drop shadow, for things that float above the page." }
title:
notes: "An `<h2>` in title type, medium weight."
styles:
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/title/font-weight/medium, value: "500" }
font-size: { token: typography/title/font-size, value: 24px }
line-height: { token: typography/title/line-height, value: 32px }
letter-spacing: { token: typography/title/letter-spacing, value: 0px }
color: { token: dialog/title, value: "#ededed" }
body:
notes: Paragraph type, a step quieter than the title.
styles:
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/paragraph/font-weight/regular, value: "400" }
font-size: { token: typography/paragraph/font-size, value: 14px }
line-height: { token: typography/paragraph/line-height, value: 20px }
letter-spacing: { token: typography/paragraph/letter-spacing, value: 0px }
color: { token: dialog/body, value: "#d3d9d5" }
actions:
notes: "The Buttons, in a row on the right, 8px apart. The main one goes last, where the eye ends up."
styles:
display: { value: flex, assert: false }
justify-content: { value: flex-end }
gap: { token: spacing/gap/small, value: 8px }
guidance:
status: proposed
use:
- title: Before something you can't undo
text: "Deleting an invoice, closing a year. Say what will happen in the title, and put it on the main button too."
- title: A short task
text: "Two or three fields that belong to the screen behind, like renaming a client."
avoid:
- title: News
text: "Telling someone something happened. That's **Toast**: it doesn't stop them."
- title: More detail
text: "Extra detail next to something. That's **Popover**, or **Disclosure** in the page."
- title: Long forms
text: "Anything that scrolls. Give it a page."
behaviour: |-
It opens as a modal: focus moves into it, the page behind can't be reached, and Esc closes it. That's the browser's `<dialog>` doing the work, not mine. The plate is Card's grey with an edge and the floating shadow. Behind it, the page dims to 72% of its own colour: the contract styles the browser's `::backdrop` as a part of its own.
accessibility:
element: "`<dialog>` opened with `showModal()`, labelled by its title (`aria-labelledby`)."
name: "The title."
keyboard: "Focus starts on the first thing you can press in it and stays inside until it closes. Esc closes it. Put the safe choice first, so a stray Enter doesn't delete anything."
focus: "When it closes, focus goes back to what opened it. The browser does that too."
colour: "The title is 14:1 and the words 11:1 on the plate, in dark."
content: "The title asks the question (\"Delete this invoice?\"). The buttons answer it with verbs (\"Keep it\", \"Delete\"), never \"Yes\" and \"No\"."
Install
npx github:Runceanu/rost add dialog It lands in src/rost/dialog/, with what it needs and its contract. Install has the rest.
When to use
Before something you can't undo
Deleting an invoice, closing a year. Say what will happen in the title, and put it on the main button too.
A short task
Two or three fields that belong to the screen behind, like renaming a client.
When not to use
News
Telling someone something happened. That's Toast: it doesn't stop them.
More detail
Extra detail next to something. That's Popover, or Disclosure in the page.
Long forms
Anything that scrolls. Give it a page.
Behaviour
It opens as a modal: focus moves into it, the page behind can't be reached, and Esc closes it. That's the browser's <dialog> doing the work, not mine. The plate is Card's grey with an edge and the floating shadow. Behind it, the page dims to 72% of its own colour: the contract styles the browser's ::backdrop as a part of its own.
Accessibility
- Element
<dialog>opened withshowModal(), labelled by its title (aria-labelledby). - Name
The title.
- Keyboard
Focus starts on the first thing you can press in it and stays inside until it closes. Esc closes it. Put the safe choice first, so a stray Enter doesn't delete anything.
- Focus
When it closes, focus goes back to what opened it. The browser does that too.
- Colour
The title is 14:1 and the words 11:1 on the plate, in dark.
Content
The title asks the question ("Delete this invoice?"). The buttons answer it with verbs ("Keep it", "Delete"), never "Yes" and "No".
Props
| Prop | Type | Values | Default |
|---|---|---|---|
open | boolean | | false |
title | slot | | |
children | slot | | |
actions | slot | | |
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
padding0pxspacing/gap/none
bordernone · backgroundtransparent · overflowvisible · max-widthnone · marginauto · colorinherit
backdrop
-
background#060805dialog/backdrop -
opacity0.72opacity/hard
panel
-
gap16pxspacing/gap/medium -
width400pxno token yet -
padding24pxspacing/gap/large -
border-radius24pxspacing/radius/xlarge -
background#171717dialog/background -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside the plate. -
outline-color#3a3a3adialog/edge -
box-shadow0px 16px 24px 0px rgba(0, 0, 0, 0.16)shadow/floating
displayflex · flex-directioncolumn · max-widthcalc(100vw - 32px) · outline-stylesolid
title
-
font-family'General Sans Variable'font-family/base -
font-weight500typography/title/font-weight/medium -
font-size24pxtypography/title/font-size -
line-height32pxtypography/title/line-height -
letter-spacing0pxtypography/title/letter-spacing -
color#edededdialog/title
body
-
font-family'General Sans Variable'font-family/base -
font-weight400typography/paragraph/font-weight/regular -
font-size14pxtypography/paragraph/font-size -
line-height20pxtypography/paragraph/line-height -
letter-spacing0pxtypography/paragraph/letter-spacing -
color#d3d9d5dialog/body
actions
-
gap8pxspacing/gap/small
displayflex · justify-contentflex-end