Skip to content

Commit

Permalink
[MessageBox] Add settable primary action text for Show... methods (#2808
Browse files Browse the repository at this point in the history
)

* Docu update

* Fix #2805 by adding primary action parameter to message box shortcut methods
  • Loading branch information
vnbaaij authored Oct 14, 2024
1 parent b9360ab commit 227e2b7
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 36 deletions.
24 changes: 16 additions & 8 deletions examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3816,32 +3816,36 @@
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowPanelAsync``1(System.Type,Microsoft.FluentUI.AspNetCore.Components.DialogParameters{``0})">
<inheritdoc cref="M:Microsoft.FluentUI.AspNetCore.Components.IDialogService.ShowPanelAsync``1(System.Type,Microsoft.FluentUI.AspNetCore.Components.DialogParameters{``0})"/>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowSuccess(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowSuccess(System.String,System.String,System.String)">
<summary>
Shows a success message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowWarning(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowWarning(System.String,System.String,System.String)">
<summary>
Shows a warning message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowError(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowError(System.String,System.String,System.String)">
<summary>
Shows an error message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowInfo(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowInfo(System.String,System.String,System.String)">
<summary>
Shows an information message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowConfirmation(System.Object,System.Func{Microsoft.FluentUI.AspNetCore.Components.DialogResult,System.Threading.Tasks.Task},System.String,System.String,System.String,System.String)">
Expand All @@ -3863,32 +3867,36 @@
</summary>
<param name="parameters">Parameters to pass to component being displayed.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowSuccessAsync(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowSuccessAsync(System.String,System.String,System.String)">
<summary>
Shows a success message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowWarningAsync(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowWarningAsync(System.String,System.String,System.String)">
<summary>
Shows a warning message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowErrorAsync(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowErrorAsync(System.String,System.String,System.String)">
<summary>
Shows an error message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowInfoAsync(System.String,System.String)">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowInfoAsync(System.String,System.String,System.String)">
<summary>
Shows an information message box. Does not have a callback function.
</summary>
<param name="message">The message to display.</param>
<param name="primaryAction">The text to display on the primary button.</param>
<param name="title">The title to display on the dialog.</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowConfirmationAsync(System.Object,System.Func{Microsoft.FluentUI.AspNetCore.Components.DialogResult,System.Threading.Tasks.Task},System.String,System.String,System.String,System.String)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

private async Task ShowConfirmationAsync()
{
var dialog = await DialogService.ShowConfirmationAsync("Do you have two eyes?", "Yup", "Nope", "Eyes on you");
var dialog = await DialogService.ShowConfirmationAsync("Do you have two eyes?");
var result = await dialog.Result;
canceled = result.Cancelled;
}
Expand Down Expand Up @@ -79,4 +79,4 @@
var result = await dialog.Result;
canceled = result.Cancelled;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@inject IDialogService DialogService


<FluentStack>
<FluentButton OnClick="@ShowSuccessAsync" Appearance="Appearance.Accent">Success</FluentButton>
<FluentButton OnClick="@ShowWarningAsync" Appearance="Appearance.Accent">Warning</FluentButton>
<FluentButton OnClick="@ShowErrorAsync" Appearance="Appearance.Accent">Error</FluentButton>
<FluentButton OnClick="@ShowInformationAsync" Appearance="Appearance.Accent">Information</FluentButton>
<FluentButton OnClick="@ShowConfirmationAsync" Appearance="Appearance.Accent">Confirmation</FluentButton>
<FluentButton OnClick="@ShowMessageBoxLongAsync" Appearance="Appearance.Accent">Long message</FluentButton>
<FluentButton OnClick="@ShowMessageBoxAsync" Appearance="Appearance.Accent">Custom message</FluentButton>
</FluentStack>

<p>
Last result: @(canceled == null ? "" : (canceled == true ? "❌ Canceled" : "✅ OK"))
</p>

@code
{
bool? canceled;

private async Task ShowSuccessAsync()
{
var dialog = await DialogService.ShowSuccessAsync("The action was a success", null, "Hooray!");
var result = await dialog.Result;
canceled = result.Cancelled;
}

private async Task ShowWarningAsync()
{
var dialog = await DialogService.ShowWarningAsync("This is your final warning", null, "Stop!");
var result = await dialog.Result;
canceled = result.Cancelled;
}

private async Task ShowErrorAsync()
{
var dialog = await DialogService.ShowErrorAsync("This is an error", null, "Oops");
var result = await dialog.Result;
canceled = result.Cancelled;
}

private async Task ShowInformationAsync()
{
var dialog = await DialogService.ShowInfoAsync("This is a message", null, "Confirm");
var result = await dialog.Result;
canceled = result.Cancelled;
}

private async Task ShowConfirmationAsync()
{
var dialog = await DialogService.ShowConfirmationAsync("Do you have two eyes?", "Yup", "Nope", "Eyes on you");
var result = await dialog.Result;
canceled = result.Cancelled;
}

private async Task ShowMessageBoxLongAsync()
{
var dialog = await DialogService.ShowInfoAsync("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum", null, "Excepteur");
var result = await dialog.Result;
canceled = result.Cancelled;
}

private async Task ShowMessageBoxAsync()
{
var dialog = await DialogService.ShowMessageBoxAsync(new DialogParameters<MessageBoxContent>()
{
Content = new()
{
Title = "My title",
MarkupMessage = new MarkupString("My <strong>customized</strong> message"),
Icon = new Icons.Regular.Size24.Games(),
IconColor = Color.Success,
},
PrimaryAction = "OK",
SecondaryAction = "Cancel",
Width = "300px",
});
var result = await dialog.Result;
canceled = result.Cancelled;
}
}
4 changes: 4 additions & 0 deletions examples/Demo/Shared/Pages/MessageBox/MessageBoxPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<p>The buttons below call the <strong>async</strong> MessageBox methods on the DialogService.</p>
</DemoSection>

<DemoSection Title="MessageBoxAsync" Component="@typeof(DialogMessageBoxAsyncCustomPrimary)">
<p>Same examples as above , but with custom primary botton texts</p>
</DemoSection>

<h2 id="documentation">Documentation</h2>

<ApiDocumentation Component="typeof(MessageBoxContent)" />
Expand Down
Loading

0 comments on commit 227e2b7

Please sign in to comment.