Skip to content

A Swiss Army knife for developers.

Added IUIInfoBar

Etienne Baudouxffca9420c5e5
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIInfoBar.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIInfoBar.cs
new file mode 100644
index 000000000..e2682af38
--- /dev/null
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIInfoBar.cs
@@ -0,0 +1,389 @@
+namespace DevToys.Api;
+
+/// <summary>
+/// A component that displays a bar aiming at indicating a relevant information to the user.
+/// </summary>
+public interface IUIInfoBar : IUIElement
+{
+ /// <summary>
+ /// Gets whether the bar is opened.
+ /// Default is false.
+ /// </summary>
+ bool IsOpened { get; }
+
+ /// <summary>
+ /// Gets whether the bar can be closed by the user on demand.
+ /// Default is true.
+ /// </summary>
+ bool IsClosable { get; }
+
+ /// <summary>
+ /// Gets whether the icon of the bar should be displayed or not.
+ /// Default is true.
+ /// </summary>
+ bool IsIconVisible { get; }
+
+ /// <summary>
+ /// Gets the title to display in the bar.
+ /// </summary>
+ string? Title { get; }
+
+ /// <summary>
+ /// Gets the description to display in the bar.
+ /// </summary>
+ string? Description { get; }
+
+ /// <summary>
+ /// Gets the text of the optional button to display in the bar.
+ /// A null or empty value will hide the button. The bar closes when the user click on the button.
+ /// </summary>
+ string? ActionButtonText { get; }
+
+ /// <summary>
+ /// Gets whether the optional button to display in the bar should be accented.
+ /// Default is false.
+ /// </summary>
+ bool IsActionButtonAccent { get; }
+
+ /// <summary>
+ /// Gets the severity of the information to display.
+ /// Default is <see cref="UIInfoBarSeverity.Informational"/>.
+ /// </summary>
+ UIInfoBarSeverity Severity { get; }
+
+ /// <summary>
+ /// Gets the action to run when the user explicitly close the bar.
+ /// </summary>
+ Func<ValueTask>? OnCloseAction { get; }
+
+ /// <summary>
+ /// Gets the action to run when the user clicks the action button.
+ /// The bar closes when the user click on the button.
+ /// </summary>
+ Func<ValueTask>? OnActionButtonClick { get; }
+
+ /// <summary>
+ /// Raised when <see cref="IsOpened"/> is changed.
+ /// </summary>
+ event EventHandler? IsOpenedChanged;
+
+ /// <summary>
+ /// Raised when <see cref="IsClosable"/> is changed.
+ /// </summary>
+ event EventHandler? IsClosableChanged;
+
+ /// <summary>
+ /// Raised when <see cref="IsIconVisible"/> is changed.
+ /// </summary>
+ event EventHandler? IsIconVisibleChanged;
+
+ /// <summary>
+ /// Raised when <see cref="Title"/> is changed.
+ /// </summary>
+ event EventHandler? TitleChanged;
+
+ /// <summary>
+ /// Raised when <see cref="Description"/> is changed.
+ /// </summary>
+ event EventHandler? DescriptionChanged;
+
+ /// <summary>
+ /// Raised when <see cref="ActionButtonText"/> is changed.
+ /// </summary>
+ event EventHandler? ActionButtonTextChanged;
+
+ /// <summary>
+ /// Raised when <see cref="IsActionButtonAccent"/> is changed.
+ /// </summary>
+ event EventHandler? IsActionButtonAccentChanged;
+
+ /// <summary>
+ /// Raised when <see cref="Severity"/> is changed.
+ /// </summary>
+ event EventHandler? SeverityChanged;
+
+ /// <summary>
+ /// Raised when <see cref="OnCloseAction"/> is changed.
+ /// </summary>
+ event EventHandler? OnCloseActionChanged;
+
+ /// <summary>
+ /// Raised when <see cref="OnActionButtonClick"/> is changed.
+ /// </summary>
+ event EventHandler? OnActionButtonClickChanged;
+}
+
+[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Title = {{{nameof(Title)}}}")]
+internal sealed class UIInfoBar : UIElement, IUIInfoBar
+{
+ private bool _isOpened;
+ private bool _isClosable = true;
+ private bool _isIconVisible = true;
+ private string? _title;
+ private string? _description;
+ private string? _actionButtonText;
+ private bool _isActionButtonAccent;
+ private UIInfoBarSeverity _severity = UIInfoBarSeverity.Informational;
+ private Func<ValueTask>? _onCloseAction;
+ private Func<ValueTask>? _onActionButtonClick;
+
+ internal UIInfoBar(string? id)
+ : base(id)
+ {
+ }
+
+ public bool IsOpened
+ {
+ get => _isOpened;
+ internal set => SetPropertyValue(ref _isOpened, value, IsOpenedChanged);
+ }
+
+ public bool IsClosable
+ {
+ get => _isClosable;
+ internal set => SetPropertyValue(ref _isClosable, value, IsClosableChanged);
+ }
+
+ public bool IsIconVisible
+ {
+ get => _isIconVisible;
+ internal set => SetPropertyValue(ref _isIconVisible, value, IsIconVisibleChanged);
+ }
+
+ public string? Title
+ {
+ get => _title;
+ internal set => SetPropertyValue(ref _title, value, TitleChanged);
+ }
+
+ public string? Description
+ {
+ get => _description;
+ internal set => SetPropertyValue(ref _description, value, DescriptionChanged);
+ }
+
+ public string? ActionButtonText
+ {
+ get => _actionButtonText;
+ internal set => SetPropertyValue(ref _actionButtonText, value, ActionButtonTextChanged);
+ }
+
+ public bool IsActionButtonAccent
+ {
+ get => _isActionButtonAccent;
+ internal set => SetPropertyValue(ref _isActionButtonAccent, value, IsActionButtonAccentChanged);
+ }
+
+ public UIInfoBarSeverity Severity
+ {
+ get => _severity;
+ internal set => SetPropertyValue(ref _severity, value, SeverityChanged);
+ }
+
+ public Func<ValueTask>? OnCloseAction
+ {
+ get => _onCloseAction;
+ internal set => SetPropertyValue(ref _onCloseAction, value, OnCloseActionChanged);
+ }
+
+ public Func<ValueTask>? OnActionButtonClick
+ {
+ get => _onActionButtonClick;
+ internal set => SetPropertyValue(ref _onActionButtonClick, value, OnActionButtonClickChanged);
+ }
+
+ public event EventHandler? IsOpenedChanged;
+ public event EventHandler? IsClosableChanged;
+ public event EventHandler? IsIconVisibleChanged;
+ public event EventHandler? TitleChanged;
+ public event EventHandler? DescriptionChanged;
+ public event EventHandler? ActionButtonTextChanged;
+ public event EventHandler? IsActionButtonAccentChanged;
+ public event EventHandler? SeverityChanged;
+ public event EventHandler? OnCloseActionChanged;
+ public event EventHandler? OnActionButtonClickChanged;
+}
+
+public static partial class GUI
+{
+ /// <summary>
+ /// Create a component that displays a bar aiming at indicating a relevant information to the user.
+ /// </summary>
+ public static IUIInfoBar InfoBar()
+ {
+ return InfoBar(null);
+ }
+
+ /// <summary>
+ /// Create a component that displays a bar aiming at indicating a relevant information to the user.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ public static IUIInfoBar InfoBar(string? id)
+ {
+ return new UIInfoBar(id);
+ }
+
+ /// <summary>
+ /// Create a component that displays a bar aiming at indicating a relevant information to the user.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ /// <param name="title">The title to display in the bar.</param>
+ public static IUIInfoBar InfoBar(string? id, string title)
+ {
+ return InfoBar(id).Title(title);
+ }
+
+ /// <summary>
+ /// Create a component that displays a bar aiming at indicating a relevant information to the user.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ /// <param name="title">The title to display in the bar.</param>
+ /// <param name="description">The description to display in the bar.</param>
+ public static IUIInfoBar InfoBar(string? id, string title, string description)
+ {
+ return InfoBar(id, title).Description(description);
+ }
+
+ /// <summary>
+ /// Create a component that displays a bar aiming at indicating a relevant information to the user.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ /// <param name="title">The title to display in the bar.</param>
+ /// <param name="description">The description to display in the bar.</param>
+ /// <param name="severity">The severity of the information to display.</param>
+ public static IUIInfoBar InfoBar(string? id, string title, string description, UIInfoBarSeverity severity)
+ {
+ var infoBar = (UIInfoBar)InfoBar(id, title, description);
+ infoBar.Severity = severity;
+ return infoBar;
+ }
+
+ /// <summary>
+ /// Sets the <see cref="IUIInfoBar.Title"/> of the bar.
+ /// </summary>
+ public static IUIInfoBar Title(this IUIInfoBar element, string? title)
+ {
+ ((UIInfoBar)element).Title = title;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the <see cref="IUIInfoBar.Description"/> of the bar.
+ /// </summary>
+ public static IUIInfoBar Description(this IUIInfoBar element, string? description)
+ {
+ ((UIInfoBar)element).Description = description;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the optional action button of the bar. The bar closes when the user click on the button.
+ /// </summary>
+ public static IUIInfoBar WithActionButton(this IUIInfoBar element, string text, bool isAccent, Func<ValueTask> actionOnClick)
+ {
+ var infoBar = (UIInfoBar)element;
+ infoBar.ActionButtonText = text;
+ infoBar.IsActionButtonAccent = isAccent;
+ infoBar.OnActionButtonClick = actionOnClick;
+ return infoBar;
+ }
+
+ /// <summary>
+ /// Sets the action to run when the user clicks the action button.
+ /// </summary>
+ public static IUIInfoBar OnClose(this IUIInfoBar element, Func<ValueTask>? actionOnClose)
+ {
+ ((UIInfoBar)element).OnCloseAction = actionOnClose;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the <see cref="IUIInfoBar.Severity"/> to <see cref="UIInfoBarSeverity.Informational"/>.
+ /// </summary>
+ public static IUIInfoBar Informational(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).Severity = UIInfoBarSeverity.Informational;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the <see cref="IUIInfoBar.Severity"/> to <see cref="UIInfoBarSeverity.Error"/>.
+ /// </summary>
+ public static IUIInfoBar Error(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).Severity = UIInfoBarSeverity.Error;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the <see cref="IUIInfoBar.Severity"/> to <see cref="UIInfoBarSeverity.Warning"/>.
+ /// </summary>
+ public static IUIInfoBar Warning(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).Severity = UIInfoBarSeverity.Warning;
+ return element;
+ }
+
+ /// <summary>
+ /// Sets the <see cref="IUIInfoBar.Severity"/> to <see cref="UIInfoBarSeverity.Success"/>.
+ /// </summary>
+ public static IUIInfoBar Success(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).Severity = UIInfoBarSeverity.Success;
+ return element;
+ }
+
+ /// <summary>
+ /// Shows the icon of the bar.
+ /// </summary>
+ public static IUIInfoBar ShowIcon(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).IsIconVisible = true;
+ return element;
+ }
+
+ /// <summary>
+ /// Hides the icon of the bar.
+ /// </summary>
+ public static IUIInfoBar HideIcon(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).IsIconVisible = false;
+ return element;
+ }
+
+ /// <summary>
+ /// Opens the bar.
+ /// </summary>
+ public static IUIInfoBar Open(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).IsOpened = true;
+ return element;
+ }
+
+ /// <summary>
+ /// Closes the bar.
+ /// </summary>
+ public static IUIInfoBar Close(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).IsOpened = false;
+ return element;
+ }
+
+ /// <summary>
+ /// Makes the bar closable explicitly by the user.
+ /// </summary>
+ public static IUIInfoBar Closable(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).IsClosable = true;
+ return element;
+ }
+
+ /// <summary>
+ /// Makes the bar not closable explicitly by the user.
+ /// </summary>
+ public static IUIInfoBar NonClosable(this IUIInfoBar element)
+ {
+ ((UIInfoBar)element).IsClosable = false;
+ return element;
+ }
+}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs
new file mode 100644
index 000000000..e059c9def
--- /dev/null
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs
@@ -0,0 +1,9 @@
+namespace DevToys.Api;
+
+public enum UIInfoBarSeverity
+{
+ Informational,
+ Error,
+ Success,
+ Warning
+}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs
index e2bbf8c16..cd967c5db 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs
@@ -13,9 +13,9 @@ public class UIToolView : INotifyPropertyChanged
/// <summary>
/// Creates a new instance of the <see cref="UIToolView"/> class.
/// </summary>
- /// <param name="rootElement">The root element of the tool's UI.</param>
/// <param name="isScrollable">Indicates whether the UI of the tool is scrollable or should fits to the window boundaries.</param>
- public UIToolView(IUIElement rootElement, bool isScrollable = false)
+ /// <param name="rootElement">The root element of the tool's UI.</param>
+ public UIToolView(bool isScrollable, IUIElement rootElement)
{
Guard.IsNotNull(rootElement);
IsScrollable = isScrollable;
diff --git a/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor b/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor
index 69319b50e..badc1346e 100644
--- a/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor
+++ b/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor
@@ -16,7 +16,7 @@
PaddingBottom="@PaddingBottom"
IsEnabled="@IsActuallyEnabled"
IsVisible="@IsVisible">
- @if (IsOpen)
+ @if (IsOpened)
{
<div id="@Id"
@ref="Element"
@@ -31,29 +31,25 @@
@if (Severity == InfoBarSeverity.Informational)
{
<svg aria-hidden="true" viewBox="406 64 213 875">
- <path fill="currentColor"
- d="M405.5,170.5C405.5,156.167 408.333,142.5 414,129.5C419.667,116.5 427.333,105.167 437,95.5C446.667,85.8334 457.917,78.1667 470.75,72.5C483.583,66.8334 497.333,64.0001 512,64C526.333,64.0001 540,66.8334 553,72.5C566,78.1667 577.333,85.8334 587,95.5C596.667,105.167 604.333,116.5 610,129.5C615.667,142.5 618.5,156.167 618.5,170.5C618.5,185.167 615.667,199 610,212C604.333,225 596.667,236.333 587,246C577.333,255.667 566.083,263.333 553.25,269C540.417,274.667 526.667,277.5 512,277.5C497.333,277.5 483.583,274.667 470.75,269C457.917,263.333 446.667,255.667 437,246C427.333,236.333 419.667,225 414,212C408.333,199 405.5,185.167 405.5,170.5ZM426.5,853.5L426.5,512C426.5,500.333 428.75,489.333 433.25,479C437.75,468.667 443.917,459.583 451.75,451.75C459.583,443.917 468.667,437.75 479,433.25C489.333,428.75 500.333,426.5 512,426.5C523.667,426.5 534.667,428.75 545,433.25C555.333,437.75 564.417,443.917 572.25,451.75C580.083,459.583 586.25,468.667 590.75,479C595.25,489.333 597.5,500.333 597.5,512L597.5,853.5C597.5,865.167 595.25,876.167 590.75,886.5C586.25,896.833 580.083,905.833 572.25,913.5C564.417,921.167 555.333,927.25 545,931.75C534.667,936.25 523.667,938.5 512,938.5C500.333,938.5 489.333,936.25 479,931.75C468.667,927.25 459.583,921.167 451.75,913.5C443.917,905.833 437.75,896.833 433.25,886.5C428.75,876.167 426.5,865.167 426.5,853.5Z" />
+ <path d="M405.5,170.5C405.5,156.167 408.333,142.5 414,129.5C419.667,116.5 427.333,105.167 437,95.5C446.667,85.8334 457.917,78.1667 470.75,72.5C483.583,66.8334 497.333,64.0001 512,64C526.333,64.0001 540,66.8334 553,72.5C566,78.1667 577.333,85.8334 587,95.5C596.667,105.167 604.333,116.5 610,129.5C615.667,142.5 618.5,156.167 618.5,170.5C618.5,185.167 615.667,199 610,212C604.333,225 596.667,236.333 587,246C577.333,255.667 566.083,263.333 553.25,269C540.417,274.667 526.667,277.5 512,277.5C497.333,277.5 483.583,274.667 470.75,269C457.917,263.333 446.667,255.667 437,246C427.333,236.333 419.667,225 414,212C408.333,199 405.5,185.167 405.5,170.5ZM426.5,853.5L426.5,512C426.5,500.333 428.75,489.333 433.25,479C437.75,468.667 443.917,459.583 451.75,451.75C459.583,443.917 468.667,437.75 479,433.25C489.333,428.75 500.333,426.5 512,426.5C523.667,426.5 534.667,428.75 545,433.25C555.333,437.75 564.417,443.917 572.25,451.75C580.083,459.583 586.25,468.667 590.75,479C595.25,489.333 597.5,500.333 597.5,512L597.5,853.5C597.5,865.167 595.25,876.167 590.75,886.5C586.25,896.833 580.083,905.833 572.25,913.5C564.417,921.167 555.333,927.25 545,931.75C534.667,936.25 523.667,938.5 512,938.5C500.333,938.5 489.333,936.25 479,931.75C468.667,927.25 459.583,921.167 451.75,913.5C443.917,905.833 437.75,896.833 433.25,886.5C428.75,876.167 426.5,865.167 426.5,853.5Z" />
</svg>
}
else if (Severity == InfoBarSeverity.Success)
{
<svg aria-hidden="true" viewBox="118 245 790 577">
- <path fill="currentColor"
- d="M117.5,554.5C117.5,547.167 118.917,540.25 121.75,533.75C124.583,527.25 128.417,521.583 133.25,516.75C138.083,511.917 143.75,508.083 150.25,505.25C156.75,502.417 163.667,501 171,501C185.333,501 197.833,506.333 208.5,517L384,692.5L815.5,261C826.167,250.333 838.833,245 853.5,245C860.833,245 867.75,246.417 874.25,249.25C880.75,252.083 886.417,256 891.25,261C896.083,266 899.917,271.75 902.75,278.25C905.583,284.75 907,291.5 907,298.5C907,313.167 901.667,325.833 891,336.5L421.5,805.5C416.5,810.5 410.75,814.417 404.25,817.25C397.75,820.083 391,821.5 384,821.5C369.667,821.5 357.167,816.167 346.5,805.5L133,592.5C122.667,582.167 117.5,569.5 117.5,554.5Z" />
+ <path d="M117.5,554.5C117.5,547.167 118.917,540.25 121.75,533.75C124.583,527.25 128.417,521.583 133.25,516.75C138.083,511.917 143.75,508.083 150.25,505.25C156.75,502.417 163.667,501 171,501C185.333,501 197.833,506.333 208.5,517L384,692.5L815.5,261C826.167,250.333 838.833,245 853.5,245C860.833,245 867.75,246.417 874.25,249.25C880.75,252.083 886.417,256 891.25,261C896.083,266 899.917,271.75 902.75,278.25C905.583,284.75 907,291.5 907,298.5C907,313.167 901.667,325.833 891,336.5L421.5,805.5C416.5,810.5 410.75,814.417 404.25,817.25C397.75,820.083 391,821.5 384,821.5C369.667,821.5 357.167,816.167 346.5,805.5L133,592.5C122.667,582.167 117.5,569.5 117.5,554.5Z" />
</svg>
}
else if (Severity == InfoBarSeverity.Warning)
{
<svg aria-hidden="true" viewBox="406 86 213 875">
- <path fill="currentColor"
- d="M426.5,512L426.5,170.5C426.5,158.833 428.75,147.833 433.25,137.5C437.75,127.167 443.917,118.167 451.75,110.5C459.583,102.833 468.667,96.75 479,92.25C489.333,87.75 500.333,85.5 512,85.5C523.667,85.5 534.667,87.75 545,92.25C555.333,96.75 564.417,102.833 572.25,110.5C580.083,118.167 586.25,127.167 590.75,137.5C595.25,147.833 597.5,158.833 597.5,170.5L597.5,512C597.5,523.667 595.25,534.667 590.75,545C586.25,555.333 580.083,564.417 572.25,572.25C564.417,580.083 555.333,586.25 545,590.75C534.667,595.25 523.667,597.5 512,597.5C500.333,597.5 489.333,595.25 479,590.75C468.667,586.25 459.583,580.083 451.75,572.25C443.917,564.417 437.75,555.333 433.25,545C428.75,534.667 426.5,523.667 426.5,512ZM405.5,853.5C405.5,838.833 408.333,825 414,812C419.667,799 427.333,787.667 437,778C446.667,768.333 457.917,760.667 470.75,755C483.583,749.333 497.333,746.5 512,746.5C526.667,746.5 540.417,749.333 553.25,755C566.083,760.667 577.333,768.333 587,778C596.667,787.667 604.333,799 610,812C615.667,825 618.5,838.833 618.5,853.5C618.5,868.167 615.667,881.917 610,894.75C604.333,907.583 596.667,918.833 587,928.5C577.333,938.167 566,945.833 553,951.5C540,957.167 526.333,960 512,960C497.333,960 483.583,957.167 470.75,951.5C457.917,945.833 446.667,938.167 437,928.5C427.333,918.833 419.667,907.583 414,894.75C408.333,881.917 405.5,868.167 405.5,853.5Z" />
+ <path d="M426.5,512L426.5,170.5C426.5,158.833 428.75,147.833 433.25,137.5C437.75,127.167 443.917,118.167 451.75,110.5C459.583,102.833 468.667,96.75 479,92.25C489.333,87.75 500.333,85.5 512,85.5C523.667,85.5 534.667,87.75 545,92.25C555.333,96.75 564.417,102.833 572.25,110.5C580.083,118.167 586.25,127.167 590.75,137.5C595.25,147.833 597.5,158.833 597.5,170.5L597.5,512C597.5,523.667 595.25,534.667 590.75,545C586.25,555.333 580.083,564.417 572.25,572.25C564.417,580.083 555.333,586.25 545,590.75C534.667,595.25 523.667,597.5 512,597.5C500.333,597.5 489.333,595.25 479,590.75C468.667,586.25 459.583,580.083 451.75,572.25C443.917,564.417 437.75,555.333 433.25,545C428.75,534.667 426.5,523.667 426.5,512ZM405.5,853.5C405.5,838.833 408.333,825 414,812C419.667,799 427.333,787.667 437,778C446.667,768.333 457.917,760.667 470.75,755C483.583,749.333 497.333,746.5 512,746.5C526.667,746.5 540.417,749.333 553.25,755C566.083,760.667 577.333,768.333 587,778C596.667,787.667 604.333,799 610,812C615.667,825 618.5,838.833 618.5,853.5C618.5,868.167 615.667,881.917 610,894.75C604.333,907.583 596.667,918.833 587,928.5C577.333,938.167 566,945.833 553,951.5C540,957.167 526.333,960 512,960C497.333,960 483.583,957.167 470.75,951.5C457.917,945.833 446.667,938.167 437,928.5C427.333,918.833 419.667,907.583 414,894.75C408.333,881.917 405.5,868.167 405.5,853.5Z" />
</svg>
}
else if (Severity == InfoBarSeverity.Error)
{
<svg aria-hidden="true" viewBox="172 171 683 683">
- <path fill="currentColor"
- d="M512.5,587.5L262.5,838C252.167,848.333 239.5,853.5 224.5,853.5C209.5,853.5 196.917,848.417 186.75,838.25C176.583,828.083 171.5,815.5 171.5,800.5C171.5,785.5 176.667,772.833 187,762.5L437,512L187,262C176.667,251.667 171.5,239.167 171.5,224.5C171.5,217.167 172.833,210.167 175.5,203.5C178.167,196.833 181.917,191.167 186.75,186.5C191.583,181.833 197.167,178.083 203.5,175.25C209.833,172.417 216.833,171 224.5,171C239.167,171 251.667,176.167 262,186.5L512.5,437L762.5,186.5C773.167,175.833 785.833,170.5 800.5,170.5C807.833,170.5 814.75,171.917 821.25,174.75C827.75,177.583 833.417,181.417 838.25,186.25C843.083,191.083 846.833,196.75 849.5,203.25C852.167,209.75 853.5,216.667 853.5,224C853.5,238.667 848.333,251.167 838,261.5L587.5,512L838,762.5C848.667,773.167 854,785.833 854,800.5C854,807.833 852.583,814.667 849.75,821C846.917,827.333 843.083,832.917 838.25,837.75C833.417,842.583 827.75,846.417 821.25,849.25C814.75,852.083 807.833,853.5 800.5,853.5C785.5,853.5 772.833,848.333 762.5,838Z" />
+ <path d="M512.5,587.5L262.5,838C252.167,848.333 239.5,853.5 224.5,853.5C209.5,853.5 196.917,848.417 186.75,838.25C176.583,828.083 171.5,815.5 171.5,800.5C171.5,785.5 176.667,772.833 187,762.5L437,512L187,262C176.667,251.667 171.5,239.167 171.5,224.5C171.5,217.167 172.833,210.167 175.5,203.5C178.167,196.833 181.917,191.167 186.75,186.5C191.583,181.833 197.167,178.083 203.5,175.25C209.833,172.417 216.833,171 224.5,171C239.167,171 251.667,176.167 262,186.5L512.5,437L762.5,186.5C773.167,175.833 785.833,170.5 800.5,170.5C807.833,170.5 814.75,171.917 821.25,174.75C827.75,177.583 833.417,181.417 838.25,186.25C843.083,191.083 846.833,196.75 849.5,203.25C852.167,209.75 853.5,216.667 853.5,224C853.5,238.667 848.333,251.167 838,261.5L587.5,512L838,762.5C848.667,773.167 854,785.833 854,800.5C854,807.833 852.583,814.667 849.75,821C846.917,827.333 843.083,832.917 838.25,837.75C833.417,842.583 827.75,846.417 821.25,849.25C814.75,852.083 807.833,853.5 800.5,853.5C785.5,853.5 772.833,848.333 762.5,838Z" />
</svg>
}
</span>
diff --git a/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.cs b/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.cs
index 7c3aa0d36..3a08ab175 100644
--- a/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.cs
@@ -8,7 +8,7 @@ public partial class InfoBar : StyledComponentBase
}
[Parameter]
- public bool IsOpen { get; set; }
+ public bool IsOpened { get; set; }
[Parameter]
public bool IsClosable { get; set; } = true;
@@ -44,7 +44,7 @@ public partial class InfoBar : StyledComponentBase
private void OnCloseButtonClicked()
{
- IsOpen = false;
+ IsOpened = false;
if (Closed.HasDelegate)
{
Closed.InvokeAsync();
diff --git a/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.scss b/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.scss
index 53eb4a6b2..131cf575c 100644
--- a/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.scss
+++ b/src/app/dev/DevToys.Blazor/Components/Feedback/InfoBar/InfoBar.razor.scss
@@ -60,25 +60,25 @@
&informational {
background-color: var(--info-bar-informational-severity-icon-background);
color: var(--info-bar-informational-severity-icon-foreground);
- fill: var(--info-bar-informational-severity-icon-foreground);
+ fill: var(--info-bar-informational-severity-icon-foreground) !important;
}
&success {
background-color: var(--info-bar-success-severity-icon-background);
color: var(--info-bar-success-severity-icon-foreground);
- fill: var(--info-bar-success-severity-icon-foreground);
+ fill: var(--info-bar-success-severity-icon-foreground) !important;
}
&warning {
background-color: var(--info-bar-warning-severity-icon-background);
color: var(--info-bar-warning-severity-icon-foreground);
- fill: var(--info-bar-warning-severity-icon-foreground);
+ fill: var(--info-bar-warning-severity-icon-foreground) !important;
}
&error {
background-color: var(--info-bar-error-severity-icon-background);
color: var(--info-bar-error-severity-icon-foreground);
- fill: var(--info-bar-error-severity-icon-foreground);
+ fill: var(--info-bar-error-severity-icon-foreground) !important;
}
}
@@ -87,7 +87,11 @@
font-size: 12px;
inline-size: 8px;
block-size: 8px;
- fill: currentColor;
+ fill: inherit;
+
+ path {
+ fill: inherit;
+ }
}
}
}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
index 78637b1ca..ddb752f1f 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
@@ -66,6 +66,10 @@
<UIFileSelectorPresenter UIFileSelector="@fileSelector"/>
break;
+ case IUIInfoBar infoBar:
+ <UIInfoBarPresenter UIInfoBar="@infoBar" />
+ break;
+
default:
throw new NotSupportedException($"Gui Tool component of type '{UIElement.GetType().FullName}' isn't supported.");
}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIInfoBarPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIInfoBarPresenter.razor
new file mode 100644
index 000000000..a2e3fb845
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIInfoBarPresenter.razor
@@ -0,0 +1,20 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits ComponentBase
+
+<InfoBar id="@UIInfoBar.Id"
+ IsVisible="@UIInfoBar.IsVisible"
+ IsEnabled="@UIInfoBar.IsEnabled"
+ HorizontalAlignment="@UIInfoBar.HorizontalAlignment"
+ VerticalAlignment="@UIInfoBar.VerticalAlignment"
+ IsOpened="@UIInfoBar.IsOpened"
+ IsClosable="@UIInfoBar.IsClosable"
+ IsIconVisible="@UIInfoBar.IsIconVisible"
+ Title="@UIInfoBar.Title"
+ Message="@UIInfoBar.Description"
+ ActionButtonText="@UIInfoBar.ActionButtonText"
+ IsActionButtonAccent="@UIInfoBar.IsActionButtonAccent"
+ Severity="@GetSeverity()"
+ Closed="@OnCloseAsync"
+ ActionButtonClicked="@OnActionButtonClickAsync">
+</InfoBar>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIInfoBarPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UIInfoBarPresenter.razor.cs
new file mode 100644
index 000000000..99cc3a5a6
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIInfoBarPresenter.razor.cs
@@ -0,0 +1,37 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UIInfoBarPresenter : ComponentBase
+{
+ [Parameter]
+ public IUIInfoBar UIInfoBar { get; set; } = default!;
+
+ internal async Task OnCloseAsync()
+ {
+ Guard.IsNotNull(UIInfoBar);
+ if (UIInfoBar.OnCloseAction is not null)
+ {
+ await UIInfoBar.OnCloseAction.Invoke(); // TODO: Try Catch and log?
+ }
+ }
+
+ internal async Task OnActionButtonClickAsync()
+ {
+ Guard.IsNotNull(UIInfoBar);
+ if (UIInfoBar.OnActionButtonClick is not null)
+ {
+ await UIInfoBar.OnActionButtonClick.Invoke(); // TODO: Try Catch and log?
+ }
+ }
+
+ private InfoBarSeverity GetSeverity()
+ {
+ return UIInfoBar.Severity switch
+ {
+ UIInfoBarSeverity.Informational => InfoBarSeverity.Informational,
+ UIInfoBarSeverity.Error => InfoBarSeverity.Error,
+ UIInfoBarSeverity.Success => InfoBarSeverity.Success,
+ UIInfoBarSeverity.Warning => InfoBarSeverity.Warning,
+ _ => InfoBarSeverity.Informational,
+ };
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs b/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs
index f2f9d2b61..ac3c11851 100644
--- a/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs
+++ b/src/app/dev/DevToys.Tools/Tools/Sample/SampleToolFactory.cs
@@ -69,6 +69,7 @@ internal sealed class SampleGuiTool : IGuiTool
public UIToolView View =>
new(
+ isScrollable: false,
_mainStack
.Vertical()
.WithChildren(
diff --git a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
index f5e4cc277..1005d520b 100644
--- a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
+++ b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
@@ -59,6 +59,7 @@ internal sealed class SettingsGuiTool : IGuiTool
public UIToolView View
=> new(
+ isScrollable: true,
Stack()
.Vertical()
.WithChildren(
@@ -102,6 +103,12 @@ internal sealed class SettingsGuiTool : IGuiTool
Button().Text("Bottom Center button").OnClick(OnBottomCenterButtonClickAsync),
Button().Text("Bottom Right button")),
NumberInput(),
+ InfoBar()
+ .Title("Title")
+ .Description("Description")
+ .Warning()
+ .WithActionButton("Click me", isAccent: false, null)
+ .Open(),
Grid()
.Rows(
(GridTestRow.FileSelection, Fraction(1)),
@@ -144,8 +151,7 @@ internal sealed class SettingsGuiTool : IGuiTool
.OriginalText("hello")
.Extendable()
.ReadOnly()
- .ModifiedText("hello world")),
- isScrollable: true);
+ .ModifiedText("hello world")));
public void OnDataReceived(string dataTypeName, object? parsedData)
{