Skip to content
العربية
Overlays

Dialog

A modal window with a title, a close button and an optional footer. fullScreenOnPhone fills the screen below 768 px. returnFocusTo names the element that gets the focus when the dialog closes, for example a section heading after a link in the dialog moved the person there. Without it, the focus goes back to the element that had the focus when the dialog opened. It works only without trigger. The element must take the focus (a heading needs tabIndex={-1}).

import { Dialog, DialogClose } from "@percentsa/ui";

Examples

Code
export function DialogExample() {
  const t = useT();
  return (
    <Dialog
      trigger={<Button>{t("Rename project", "إعادة تسمية المشروع")}</Button>}
      title={t("Rename project", "إعادة تسمية المشروع")}
      description={t("The new name shows everywhere.", "يظهر الاسم الجديد في كل مكان.")}
      footer={
        <>
          <DialogClose asChild>
            <Button variant="secondary">{t("Cancel", "إلغاء")}</Button>
          </DialogClose>
          <DialogClose asChild>
            <Button>{t("Save", "حفظ")}</Button>
          </DialogClose>
        </>
      }
    >
      <Field label={t("Name", "الاسم")}>
        <Input defaultValue="Masar" />
      </Field>
    </Dialog>
  );
}
Code
export function DialogFullScreenExample() {
  const t = useT();
  return (
    <Dialog
      fullScreenOnPhone
      trigger={<Button>{t("Edit profile", "تعديل الملف")}</Button>}
      title={t("Edit profile", "تعديل الملف")}
      footer={
        <DialogClose asChild>
          <Button>{t("Save", "حفظ")}</Button>
        </DialogClose>
      }
    >
      <Field label={t("Name", "الاسم")}>
        <Input defaultValue="Sara Al Noor" />
      </Field>
      <Field label={t("Job title", "المسمى الوظيفي")}>
        <Input defaultValue="Designer" />
      </Field>
    </Dialog>
  );
}