Dialog
A modal dialog; on narrow screens the same dialog becomes a bottom sheet.
import { Dialog, DialogClose } from '@iffday/ui';Example
On wide screens the dialog is centred and at most 560px wide. Below 768px the same dialog rises from the bottom of the screen as a sheet. While it is open the page behind stops scrolling and focus stays inside; Escape closes it and returns focus to the trigger. The close button in the corner comes with it.
import { useT } from '@iffday/i18n';
import { Button, Dialog, DialogClose, Field, Form, Input } from '@iffday/ui';
import { useApp } from '@iffday/web/src/state';
import { useState } from 'react';
export default function Example() {
const t = useT();
const { notify } = useApp();
const [open, setOpen] = useState(false);
return (
<Dialog
open={open}
onOpenChange={setOpen}
title={t('film.entry.logAViewing')}
description={t('film.entry.selfReportedViewingNoTicketIsRequiredLeaveThe')}
trigger={
<Button type="button" className="button primary">
{t('film.entry.markAsWatched')}
</Button>
}
>
<Form
onSubmit={(event) => {
event.preventDefault();
setOpen(false);
notify(t('film.entry.markedAsWatched'));
}}
>
<Field label={t('film.entry.viewingDateOptional')}>
<Input type="date" />
</Field>
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 8 }}>
<DialogClose className="button neutral">{t('common.cancel')}</DialogClose>
<Button className="button primary">{t('common.save')}</Button>
</div>
</Form>
</Dialog>
);
}Usage
titleis required: it is the dialog’s accessible name. Put explanations indescription.- Make Cancel a
DialogClose, so you do not manageopenfor it. - Pass
openandonOpenChangeto control it; when one button opens it,triggeris enough.
Props
A modal dialog; on narrow screens the same popup becomes a bottom sheet.
| Prop | Type | Default |
|---|---|---|
open | boolean | |
onOpenChange | (open: boolean) => void | |
title* | ReactNode | |
description | ReactNode | |
trigger | ReactElement<Record<string, unknown>> | |
children* | ReactNode | |
className | string | '' |
DialogClose
packages/ui/src/overlays.tsx:114Exports BaseDialog.Close as it is, with Base UI’s props (see the Base UI documentation).
Not used directly in apps/web yet.