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
Dialogcomponent usesDialogPrimitivecomponents from@radix-ui/react-dialog. - The
onCloseprop is a callback function that gets executed when the dialog is closed. - The
openprop can be used to control the open state of the dialog. - The
titleanddescriptionprops provide the title and description for the dialog. - For more details, refer to the Shadcn Dialog documentation.