The reearth.modal namespace defines the structure and capabilities of modal dialog components within reearth.
Methods
Section titled “Methods”This method displays a modal window with customizable HTML content in reearth. Developers can define the modal’s size, background, and behavior when clicking outside the modal.
Syntax
Section titled “Syntax”reearth.modal.show: ( html: string, options?: Options) => void;Parameters
Section titled “Parameters”Type: string
A string of HTML content to be displayed in the modal.
options
Section titled “options”Optional
An object to customize the modal’s appearance and behavior:
Type:
type Options = { width?: number | string; height?: number | string; background?: string; clickBgToClose?: boolean;};width?: number | string;: Specifies the width of the modal. If not specified, a default width may be used.height?: number | string;: Specifies the height of the modal. The absence of this parameter may result in a default height.background?: string;: The background color or CSS value for the modal (e.g., “#fff”, “rgba(0, 0, 0, 0.5)”).clickBgToClose?: boolean;: Determines whether clicking on the modal background will close the modal. Set to true to enable this feature, otherwise, it defaults to false.
Return Value:
Section titled “Return Value:”None (void). The method performs its operation without returning a value.
Example
Section titled “Example”// Example 1: Display a modal with custom HTML contentreearth.modal.show("<p>Welcome to Re:Earth!</p>", { width: 400, height: 300, background: "rgba(0, 0, 0, 0.5)", clickBgToClose: true,});
// Example 2: Display a modal with a larger, fixed-size and solid backgroundreearth.modal.show( "<h1>Important Information</h1><p>Details about the project...</p>", { width: 600, height: 400, background: "#f8f8f8", clickBgToClose: false, });postMessage
Section titled “postMessage”This enables communication between a modal window and other parts of reearth , or between components within the modal itself. It can be utilized for a variety of purposes, such as notifying reearth about user interactions within the modal or requesting data or actions from other components.
Syntax
Section titled “Syntax”reearth.modal.postMessage: (message: any) => void;Parameters
Section titled “Parameters”message
Section titled “message”Type: any
The message to be sent to the modal.
Return Value:
Section titled “Return Value:”None (void). The method performs its operation without returning a value.
Example
Section titled “Example”// Example 1: Send a simple text messagereearth.modal.postMessage("Hello, Re:Earth!");
// Example 2: Send a simple string message to the Re:Earth applicationreearth.modal.postMessage("User clicked the button!");
// Example 3: Send an object messagereearth.modal.postMessage({ message: "greeting" });
// Example 4: Sending an object containing user datareearth.modal.postMessage({ eventType: "userAction", details: { action: "submit", userId: 12345, },});update
Section titled “update”This method modifies the appearance and behavior of the currently open modal in reearth. It allows developers to dynamically adjust properties like the modal’s size, background color, and click-to-close behavior.
Syntax
Section titled “Syntax”reearth.modal.update: (options: Options) => void;Parameters
Section titled “Parameters”options
Section titled “options”An object that contains properties to update the modal’s appearance and behavior.
Type:
type Options = { width?: number | string; height?: number | string; background?: string; clickBgToClose?: boolean;};width?: number | string;: Sets the modal’s new width.height?: number | string;: Sets the modal’s new height.background?: string;: Sets a new background for the modal.clickBgToClose?: boolean;: Determines whether clicking outside the modal will close it.trueallows the modal to close when the user clicks the background.falseprevents the modal from closing on background clicks.
Return Value:
Section titled “Return Value:”None (void). The method performs its operation without returning a value.
Example
Section titled “Example”// Example 1: Resize the modal to 300px width and 400px height with a light blue backgroundreearth.modal.update({ width: 300, height: 400, background: "#ADD8E6", clickBgToClose: true,});
// Example 2: Update the modal with a a custom background color, larger size, and disable click-to-closereearth.modal.update({ width: 600, height: 450, background: "rgba(0, 128, 128, 0.8)", clickBgToClose: false, // Prevent closing the modal by clicking the background});
// Example 3: Allow the modal to close when clicking the backgroundreearth.modal.update({ clickBgToClose: true,});
// Example 4: Change only the modal's width to 300px, keeping other properties unchangedreearth.modal.update({ width: 300,});This method is used to close an open modal. Users can dismiss the modal based on task completion, logical conditions or other user actions. It does not require any parameters.
Syntax
Section titled “Syntax”reearth.modal.close: () => voidParameters
Section titled “Parameters”None
Return Value:
Section titled “Return Value:”None (void). The method performs its operation without returning a value.
Example
Section titled “Example”// Close the currently open modalreearth.modal.close();Events
Section titled “Events”The close event is triggered when the modal in reearth is closed. This event allows you to perform actions in response to the modal’s closure, such as cleaning up resources, saving data, or updating the UI. You can configure the listener to execute once or multiple times, based on the provided options.
Syntax
Section titled “Syntax”reearth.modal.on("close", () => void): void;Example
Section titled “Example”reearth.modal.on("close", () => { console.log("The Modal was closed.");});