Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/Core/Components/MessageBar/FluentMessageBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,31 @@
<div class="fluent-messagebar-message">
@if (!String.IsNullOrEmpty(Title))
{
<span class="title">@((MarkupString)Title)</span>
<span class="title">
@if (Content?.UseMarkupString == true)
{
@((MarkupString)Title)
}
else
{
@Title
}
</span>
}
@if (ChildContent is not null)
{
@ChildContent
}
else
{
@((MarkupString)Content!.Body!)
@if (Content?.UseMarkupString == true)
{
@((MarkupString)Content!.Body!)
}
else
{
@(Content!.Body)
}
}
@if (Link is not null)
{
Expand Down Expand Up @@ -84,7 +100,14 @@
@if (!String.IsNullOrEmpty(Title))
{
<div class="fluent-messagebar-notification-message" title="@Title">
@((MarkupString)(Title))
@if (Content?.UseMarkupString == true)
{
@((MarkupString)Title)
}
else
{
@Title
}
</div>
}

Expand All @@ -105,7 +128,14 @@
@ChildContent
@if (!String.IsNullOrEmpty(Content?.Body))
{
@((MarkupString)Content.Body)
@if (Content?.UseMarkupString == true)
{
@((MarkupString)Content.Body)
}
else
{
@Content?.Body
}
}
@if (Link is not null)
{
Expand Down
7 changes: 7 additions & 0 deletions src/Core/Components/MessageBar/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public string? Title
}
}

/// <summary>
/// Indicates whether the title and body should be rendered as markup string.
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
/// Only use it with fully trusted, sanitized content.
/// </summary>
internal bool UseMarkupString => Options.UseMarkupString;

/// <summary>
/// Gets or sets the message to be shown in the message bar.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Core/Components/MessageBar/Services/IMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// This file is licensed to you under the MIT License.
// ------------------------------------------------------------------------

using Microsoft.AspNetCore.Components;

namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary />
Expand All @@ -28,6 +30,9 @@ public interface IMessageService : IDisposable
/// <summary />
Message ShowMessageBar(string title, MessageIntent intent, string section);

/// <summary />
Message ShowMessageBar(MarkupString title, MessageIntent intent, string section);

/// <summary />
Task<Message> ShowMessageBarAsync(Action<MessageOptions> options);

Expand All @@ -40,6 +45,9 @@ public interface IMessageService : IDisposable
/// <summary />
Task<Message> ShowMessageBarAsync(string title, MessageIntent intent, string section);

/// <summary />
Task<Message> ShowMessageBarAsync(MarkupString title, MessageIntent intent, string section);

/// <summary />
void Clear(string? section = null);

Expand Down
7 changes: 7 additions & 0 deletions src/Core/Components/MessageBar/Services/MessageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class MessageOptions
/// </summary>
public string? Title { get; set; }

/// <summary>
/// Indicates whether the <see cref="Title"/> and <see cref="Body"/> should be rendered as markup string.
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
/// Only use it with fully trusted, sanitized content.
/// </summary>
public bool UseMarkupString { get; set; } = false;

/// <summary>
/// Gets or sets the message to be shown in the message bar after the title.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions src/Core/Components/MessageBar/Services/MessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ public Message ShowMessageBar(string title, MessageIntent intent, string section
});
}

/// <summary>
/// Show a message based on the provided parameters in a message bar.
/// </summary>
/// <param name="title"> Main info.
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
/// Only use it with fully trusted, sanitized content.</param>
/// <param name="intent">Intent of the message</param>
/// <param name="section">Section to show the message bar in </param>
/// <returns></returns>
public Message ShowMessageBar(MarkupString title, MessageIntent intent, string section)
{
return ShowMessageBar(options =>
{
options.Title = title.Value;
options.UseMarkupString = true;
options.Intent = intent;
options.Section = section;
});
}

/// <summary>
/// Show a message based on the provided options in a message bar.
/// </summary>
Expand Down Expand Up @@ -200,6 +220,26 @@ public async Task<Message> ShowMessageBarAsync(string title, MessageIntent inten
});
}

/// <summary>
/// Show a message based on the provided parameters in a message bar.
/// </summary>
/// <param name="title"> Main info.
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
/// Only use it with fully trusted, sanitized content.</param>
/// <param name="intent">Intent of the message</param>
/// <param name="section">Section to show the message bar in </param>
/// <returns></returns>
public async Task<Message> ShowMessageBarAsync(MarkupString title, MessageIntent intent, string section)
{
return await ShowMessageBarAsync(options =>
{
options.Title = title.Value;
options.UseMarkupString = true;
options.Intent = intent;
options.Section = section;
});
}

/// <summary>
/// Show a message based on the provided message options in a message bar.
/// </summary>
Expand Down
Loading