Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Web

Dialog

The Dialog component is a window overlaid on either the primary window or another dialog window, It can be opened anywhere by calling context.dialog.open() with an object containing the necessary parameters.

Info

Renamed from Modal in Gravity 12.

Usage

import { useContext } from 'react';
import { ViewContext, Button } from 'components/lib';

function MyComponent({ ...props }) {

  const viewContext = useContext(ViewContext);

function openDialog() {
    viewContext.dialog.open({
      title: 'Invite user',
      form: {
        inputs: {
          email: { type: 'email', label: 'Email', required: true },
          permission: { type: 'hidden', value: 'user' }
        },
        buttonText: 'Send invite',
        url: '/api/invite',
        method: 'POST'
      }
    });
  }

  return <Button text="Invite user" action={openDialog} />;
}

Parameters

Pass title, an optional description, and either children or a form object. Inside form, use the Form props, including inputs, buttonText, url and method. The optional second argument to dialog.open(content, callback) receives the submitted data and response after a successful submission.

Notes

  • The Dialog component uses DialogPrimitive components from @radix-ui/react-dialog.
  • The onClose prop is a callback function that gets executed when the dialog is closed.
  • The open prop can be used to control the open state of the dialog.
  • The title and description props provide the title and description for the dialog.
  • For more details, refer to the Shadcn Dialog documentation.