Skip to content

[dev-v5] [Dialog Service] Add the FluentDialog and services - #3112

Merged
Denis Voituron (dvoituron) merged 58 commits into
dev-v5from
users/dvoituron/dialog
Jan 8, 2025
Merged

Denis Voituron (dvoituron) merged 58 commits into
dev-v5from
users/dvoituron/dialog

Conversation

@dvoituron

@dvoituron Denis Voituron (dvoituron) commented Dec 30, 2024 •

Copy link
Copy Markdown
Collaborator

[dev-v5] [Dialog Service] Add the FluentDialog and services

Dialog

FluentDialog is a window overlaid on either the primary window or another dialog window. Windows under a modal dialog are inert. That is, users cannot interact with content outside an active dialog window. Inert content outside an active dialog is typically visually obscured or dimmed so it is difficult to discern, and in some implementations, attempts to interact with the inert content cause the dialog to close

Usage

The simplest way is to use the DialogService to display a dialog box. By injecting this service, you have ShowDialogAsync methods at your disposal. You can pass the type of Dialog to be displayed and the options to be passed to that window.

Once the user closes the dialog window, the ShowDialogAsync method returns a DialogResult object containing the return data.

Any Blazor component can be used as a dialog type.

@inject IDialogService DialogService

var result = await DialogService.ShowDialogAsync<SimpleDialog>(options =>
{
    // Options
});

if (result.Cancelled == false)
{
    ...
}

The SimpleDialog window can inherit from the FluentDialogInstance class to have access to the DialogInstance property, which contains all parameters defined when calling ShowDialogAsync, as well as the CloseAsync and CancelAsync methods. Using CloseAsync you can pass a return object to the parent component. It is then retrieved in the DialogResult like in the example below.

@inherits FluentDialogInstance

<FluentDialogBody>
    Content dialog
</FluentDialogBody>

Data exchange between components

You can easily send data from your main component to the dialog box by using the options.Parameters.Add() method in the ShowDialogAsync method options.

Parameters is a dictionary that allows you to send any type of data to the dialog box. the key is the name of the property in the dialog box, and the value is the data to be sent.

PersonDetails John = new() { Age = "20" };

var result = await DialogService.ShowDialogAsync<CustomizedDialog>(options =>
{
    options.Parameters.Add(nameof(SimpleDialog.Name), "John");  // Simple type
    options.Parameters.Add(nameof(SimpleDialog.Person), John);  // Updatable object
});

MessageBox

A MessageBox is a dialog that is used to display information with a specific intent to the user. It uses the DialogService to display the dialog.

The DialogService is an injected service that can be used into any component. It exposes methods to show a dialog. For working with a MessageBox, the following methods are available:

  • ShowSuccessAsync: Shows a dialog with a success (green) icon, a message and an OK button.

  • ShowWarningAsync: Shows a dialog with a warning (orange) icon, a message and an OK button.

  • ShowInfoAsync: Shows a dialog with an information (gray) icon, a message and an OK button.

  • ShowErrorAsync: Shows a dialog with an error (red) icon, a message and an OK button.

  • ShowConfirmationAsync: Shows a dialog with a confirmation icon, a message and a Yes/No buttons. This method returns a DialogResult object where Cancelled = false if Yes is pressed and Cancelled = true if No is pressed.

  • ShowMessageBoxAsync: Shows a dialog with the specified options.

Live Demo

See the Dialog page,
and the MessageBox page.

Unit Tests

{BE0299BF-30F2-4201-8462-1EC89C04F7F3}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants