Skip to content

A Swiss Army knife for developers.

Added ProgressBar and ProgressRing components.

Etienne Baudouxab55a1b2639c
diff --git a/src/app/dev/DevToys.Blazor/Assets/javascript/popover.js b/src/app/dev/DevToys.Blazor/Assets/javascript/popover.js
index 5dbbfb68e..5d963b6a3 100644
--- a/src/app/dev/DevToys.Blazor/Assets/javascript/popover.js
+++ b/src/app/dev/DevToys.Blazor/Assets/javascript/popover.js
@@ -424,12 +424,15 @@ Popover.flipMargin = 0;
Popover.map = {};
Popover.contentObserver = null;
Popover.mainContainerClass = null;
+// constructor
+(() => {
+ window.addEventListener("scroll", () => {
+ Popover.placePopoverByClassSelector("popover-fixed");
+ Popover.placePopoverByClassSelector("popover-overflow-flip-always");
+ });
+ window.addEventListener("resize", () => {
+ Popover.placePopoverByClassSelector();
+ });
+})();
export default Popover;
-//window.addEventListener("scroll", () => {
-// Popover.placePopoverByClassSelector("popover-fixed");
-// Popover.placePopoverByClassSelector("popover-overflow-flip-always");
-//});
-//window.addEventListener("resize", () => {
-// Popover.placePopoverByClassSelector();
-//});
//# sourceMappingURL=popover.js.map
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Assets/javascript/popover.ts b/src/app/dev/DevToys.Blazor/Assets/javascript/popover.ts
index 534ff2fd7..86d862a90 100644
--- a/src/app/dev/DevToys.Blazor/Assets/javascript/popover.ts
+++ b/src/app/dev/DevToys.Blazor/Assets/javascript/popover.ts
@@ -57,6 +57,18 @@ class Popover {
private static contentObserver: ResizeObserver = null;
private static mainContainerClass: string = null;
+ // constructor
+ static {
+ window.addEventListener("scroll", () => {
+ Popover.placePopoverByClassSelector("popover-fixed");
+ Popover.placePopoverByClassSelector("popover-overflow-flip-always");
+ });
+
+ window.addEventListener("resize", () => {
+ Popover.placePopoverByClassSelector();
+ });
+ }
+
public static callback(id: string, mutationsList: MutationRecord[], observer: MutationObserver) {
for (const mutation of mutationsList) {
if (mutation.type === "attributes") {
@@ -472,13 +484,4 @@ class Popover {
}
}
-export default Popover;
-
-//window.addEventListener("scroll", () => {
-// Popover.placePopoverByClassSelector("popover-fixed");
-// Popover.placePopoverByClassSelector("popover-overflow-flip-always");
-//});
-
-//window.addEventListener("resize", () => {
-// Popover.placePopoverByClassSelector();
-//});
\ No newline at end of file
+export default Popover;
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/AutoSuggestBox/AutoSuggestBox.razor b/src/app/dev/DevToys.Blazor/Components/AutoSuggestBox/AutoSuggestBox.razor
index 188f3b941..58713e068 100644
--- a/src/app/dev/DevToys.Blazor/Components/AutoSuggestBox/AutoSuggestBox.razor
+++ b/src/app/dev/DevToys.Blazor/Components/AutoSuggestBox/AutoSuggestBox.razor
@@ -12,7 +12,7 @@
Placeholder="@Placeholder"
IsEnabled="@IsEnabled"
IsReadOnly="@IsReadOnly"
- OnTextChanged="@OnTextBoxTextChangedAsync"
+ TextChanged="@OnTextBoxTextChangedAsync"
@onkeydown="@OnTextBoxKeyPress"
@onfocusout="@OnTextBoxFocusLost">
<Buttons>
diff --git a/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor b/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor
new file mode 100644
index 000000000..13d8f2fce
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor
@@ -0,0 +1,36 @@
+@namespace DevToys.Blazor.Components
+@inherits StyledComponentBase
+
+<CascadingValue Value="this" IsFixed="true">
+ <svg @ref="Element"
+ tabindex="-1"
+ role="@((IsIndeterminate ? "status" : "progressbar"))"
+ class="progress-bar @((IsIndeterminate ? "indeterminate" : string.Empty)) @FinalCssClasses"
+ width="100%"
+ height="3"
+ style="@Style"
+ @attributes="AdditionalAttributes">
+ @if (IsIndeterminate)
+ {
+ <rect height="3"
+ ry="3"
+ class="progress-bar-track" />
+ <rect height="3"
+ ry="3"
+ class="progress-bar-track" />
+ }
+ else
+ {
+ <rect width="100%"
+ height="1"
+ rx="0.5"
+ y="1"
+ class="progress-bar-rail" />
+
+ <rect width="@(Value.ToPercentage())"
+ height="3"
+ rx="1.5"
+ class="progress-bar-track" />
+ }
+ </svg>
+</CascadingValue>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor.cs b/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor.cs
new file mode 100644
index 000000000..d6a27b400
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor.cs
@@ -0,0 +1,34 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace DevToys.Blazor.Components;
+
+public partial class ProgressBar : StyledComponentBase
+{
+ [Parameter]
+ [Range(0.0, 100.0, ErrorMessage = $"{nameof(Value)} must be between 0 and 100.")]
+ public double Value { get; set; }
+
+ [Parameter]
+ public bool IsIndeterminate { get; set; }
+
+ protected override void OnParametersSet()
+ {
+ if (IsIndeterminate && AdditionalAttributes is not null)
+ {
+ AdditionalAttributes.Remove("aria-valuemin");
+ AdditionalAttributes.Remove("aria-valuemax");
+ AdditionalAttributes.Remove("aria-valuenow");
+ }
+
+ if (!IsIndeterminate)
+ {
+ AdditionalAttributes ??= new Dictionary<string, object>();
+
+ AdditionalAttributes.TryAdd("aria-valuemin", 0);
+ AdditionalAttributes.TryAdd("aria-valuemax", 100);
+ AdditionalAttributes.TryAdd("aria-valuenow", Value);
+ }
+
+ base.OnParametersSet();
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor.scss b/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor.scss
new file mode 100644
index 000000000..dfa3d561e
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/ProgressBar/ProgressBar.razor.scss
@@ -0,0 +1,84 @@
+@use "../../Assets/sass/devtoys" as *;
+
+@keyframes indeterminate-1 {
+ 0% {
+ opacity: 1;
+ transform: translateX(-100%);
+ }
+
+ 70% {
+ opacity: 1;
+ transform: translateX(100%);
+ }
+
+ 70.01% {
+ opacity: 0;
+ }
+
+ 100% {
+ opacity: 0;
+ transform: translateX(-100%);
+ }
+}
+
+@keyframes indeterminate-2 {
+ 0% {
+ opacity: 0;
+ }
+
+ 50% {
+ opacity: 0;
+ transform: translateX(-100%);
+ }
+
+ 50.01% {
+ opacity: 1;
+ transform: translateX(-100%);
+ }
+
+ 100% {
+ transform: translateX(100%);
+ opacity: 1;
+ }
+}
+
+.progress-bar {
+ @include flex($align: center);
+ width: 100%;
+ height: 3px;
+ min-block-size: 3px;
+
+ &-track {
+ max-width: 50%;
+ height: 3px;
+ transition: 167ms linear fill;
+ fill: var(--accent-default);
+ }
+
+ &-rail {
+ fill: var(--control-strong-stroke-default);
+ width: 100%;
+ height: 1px;
+ }
+
+ &.indeterminate {
+ .progress-bar- {
+ &track {
+ fill: transparent;
+
+ &:first-of-type {
+ width: 40%;
+ fill: var(--accent-default);
+ animation: 2s ease 0s infinite normal none running indeterminate-1;
+ }
+
+ &:nth-of-type(2) {
+ width: 60%;
+ fill: var(--accent-default);
+ opacity: 0;
+ animation: 2s ease 0s infinite normal none running indeterminate-2;
+ }
+ }
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor b/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor
new file mode 100644
index 000000000..95331a3af
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor
@@ -0,0 +1,20 @@
+@namespace DevToys.Blazor.Components
+@inherits StyledComponentBase
+
+<CascadingValue Value="this" IsFixed="true">
+ <svg @ref="Element"
+ tabindex="-1"
+ role="@((IsIndeterminate ? "status" : "progressbar"))"
+ width="@(Size.ToPx())"
+ height="@(Size.ToPx())"
+ class="progress-ring @((IsIndeterminate ? "indeterminate" : string.Empty)) @FinalCssClasses"
+ style="@Style"
+ viewBox="0 0 16 16"
+ @attributes="AdditionalAttributes">
+ <circle cx="50%"
+ cy="50%"
+ r="@CircleElementR"
+ stroke-dasharray="3"
+ stroke-dashoffset="@(((100 - Value) / 100) * _circumference)" />
+ </svg>
+</CascadingValue>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor.cs b/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor.cs
new file mode 100644
index 000000000..455279781
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor.cs
@@ -0,0 +1,40 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace DevToys.Blazor.Components;
+
+public partial class ProgressRing : StyledComponentBase
+{
+ private const int CircleElementR = 7;
+ private readonly double _circumference = Math.PI * (CircleElementR * 2);
+
+ [Parameter]
+ [Range(0.0, 100.0, ErrorMessage = $"{nameof(Value)} must be between 0 and 100.")]
+ public double Value { get; set; }
+
+ [Parameter]
+ public int Size { get; set; } = 48;
+
+ [Parameter]
+ public bool IsIndeterminate { get; set; }
+
+ protected override void OnParametersSet()
+ {
+ if (IsIndeterminate && AdditionalAttributes is not null)
+ {
+ AdditionalAttributes.Remove("aria-valuemin");
+ AdditionalAttributes.Remove("aria-valuemax");
+ AdditionalAttributes.Remove("aria-valuenow");
+ }
+
+ if (!IsIndeterminate)
+ {
+ AdditionalAttributes ??= new Dictionary<string, object>();
+
+ AdditionalAttributes.TryAdd("aria-valuemin", 0);
+ AdditionalAttributes.TryAdd("aria-valuemax", 100);
+ AdditionalAttributes.TryAdd("aria-valuenow", Value);
+ }
+
+ base.OnParametersSet();
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor.scss b/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor.scss
new file mode 100644
index 000000000..6b691f708
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/ProgressRing/ProgressRing.razor.scss
@@ -0,0 +1,40 @@
+@keyframes progress-ring-indeterminate {
+ 0% {
+ stroke-dasharray: 0.01px 43.97px;
+ transform: rotate(0);
+ }
+
+ 50% {
+ stroke-dasharray: 21.99px 21.99px;
+ transform: rotate(450deg);
+ }
+
+ 100% {
+ stroke-dasharray: 0.01px 43.97px;
+ transform: rotate(1080deg);
+ }
+}
+
+.progress-ring {
+ outline: none;
+ min-inline-size: 16px;
+ min-block-size: 16px;
+
+ circle {
+ transform: rotate(-90deg);
+ transform-origin: 50% 50%;
+ transition: all 250ms linear;
+ fill: none;
+ stroke: var(--accent-default);
+
+ stroke: {
+ width: 1.5;
+ linecap: round;
+ dasharray: 43.97;
+ }
+ }
+
+ &.indeterminate circle {
+ animation: progress-ring-indeterminate 2s linear infinite;
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/TextBox/TextBox.razor.cs b/src/app/dev/DevToys.Blazor/Components/TextBox/TextBox.razor.cs
index 7cc8e97fd..6a5bdc99a 100644
--- a/src/app/dev/DevToys.Blazor/Components/TextBox/TextBox.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/TextBox/TextBox.razor.cs
@@ -64,7 +64,7 @@ public partial class TextBox : MefComponentBase
public RenderFragment? Buttons { get; set; }
[Parameter]
- public EventCallback<string?> OnTextChanged { get; set; }
+ public EventCallback<string?> TextChanged { get; set; }
internal ValueTask<bool> FocusAsync()
{
@@ -215,6 +215,6 @@ public partial class TextBox : MefComponentBase
private Task SetTextAsync(string text)
{
Text = text;
- return OnTextChanged.InvokeAsync(Text);
+ return TextChanged.InvokeAsync(Text);
}
}
diff --git a/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs b/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs
index fd4cd5c46..878705fcc 100644
--- a/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs
+++ b/src/app/dev/DevToys.Blazor/Core/Extensions/IJSRuntimeExtensions.cs
@@ -12,7 +12,7 @@ internal static class IJSRuntimeExtensions
/// <param name="args">JSON-serializable arguments.</param>
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation and resolves to true in case
/// no exception has occurred otherwise false.</returns>
- public static async ValueTask<bool> InvokeVoidWithErrorHandlingAsync(this IJSRuntime jsRuntime, string identifier, params object[] args)
+ public static async ValueTask<bool> InvokeVoidWithErrorHandlingAsync(this IJSRuntime jsRuntime, string identifier, params object?[]? args)
{
try
{
diff --git a/src/app/dev/DevToys.Blazor/Core/Extensions/WebUnitsExtensions.cs b/src/app/dev/DevToys.Blazor/Core/Extensions/WebUnitsExtensions.cs
index 9bb67535f..63d9d7d62 100644
--- a/src/app/dev/DevToys.Blazor/Core/Extensions/WebUnitsExtensions.cs
+++ b/src/app/dev/DevToys.Blazor/Core/Extensions/WebUnitsExtensions.cs
@@ -15,4 +15,16 @@ internal static class WebUnitsExtensions
internal static string ToPx(this double val) => $"{val.ToString("0.##", CultureInfo.InvariantCulture)}px";
internal static string ToPx(this double? val) => val != null ? val.Value.ToPx() : string.Empty;
+
+ internal static string ToPercentage(this int val) => $"{val}%";
+
+ internal static string ToPercentage(this int? val) => val != null ? val.Value.ToPercentage() : string.Empty;
+
+ internal static string ToPercentage(this long val) => $"{val}%";
+
+ internal static string ToPercentage(this long? val) => val != null ? val.Value.ToPercentage() : string.Empty;
+
+ internal static string ToPercentage(this double val) => $"{val.ToString("0.##", CultureInfo.InvariantCulture)}%";
+
+ internal static string ToPercentage(this double? val) => val != null ? val.Value.ToPercentage() : string.Empty;
}
diff --git a/src/app/dev/DevToys.Blazor/Pages/Index.razor b/src/app/dev/DevToys.Blazor/Pages/Index.razor
index 57ede1bdd..f586218c8 100644
--- a/src/app/dev/DevToys.Blazor/Pages/Index.razor
+++ b/src/app/dev/DevToys.Blazor/Pages/Index.razor
@@ -98,9 +98,13 @@
<Button IsEnabled="false" Appearance="ButtonAppearance.Accent">Set favorite</Button>
<Button IsEnabled="true" Appearance="ButtonAppearance.Stealth">Set favorite</Button>
<Button IsEnabled="false" Appearance="ButtonAppearance.Stealth">Set favorite</Button>
+ <ProgressRing IsIndeterminate="true" />
+ <ProgressRing Value="75" Size="32" />
<TextBox Header="First name" Placeholder="Normal" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
<TextBox Header="Middle name" Placeholder="Read only" IsReadOnly="true" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
<TextBox Header="Last name" Placeholder="Disabled" IsEnabled="false" Style="margin-top: 12px; margin-left: 8px; margin-right: 8px;" />
+ <ProgressBar IsIndeterminate="true" Style="margin: 8px; max-width: 150px;" />
+ <ProgressBar Value="75" Style="margin: 8px; max-width: 150px;" />
<CheckBox IsChecked="true" Text="An option" />
<CheckBox IsChecked="true" IsEnabled="false" Text="An option" />
<CheckBox IsChecked="false" IsEnabled="false" Text="An option" />