Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FluentProgress] Add Width, Stroke, Color and BackgroundColor attributes #1121

Merged
merged 6 commits into from
Dec 14, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5752,6 +5752,16 @@
Gets or sets the current value.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgress.Visible">
<summary>
Gets or sets the visibility of the component
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgress.Width">
<summary>
Gets or sets the component width.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgress.Paused">
<summary>
Gets or sets a value indicating whether the progress element is paused.
Expand All @@ -5762,6 +5772,21 @@
Gets or sets the content to be rendered inside the component.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgress.Stroke">
<summary>
Gets or sets the stroke width of the progress bar. If not set, the default theme stroke width is used.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgress.Color">
<summary>
Gets or sets the color to be used for the progress bar. If not set, the default theme color is used.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgress.BackgroundColor">
<summary>
Gets or sets the color to be used for the background. If not set, the default theme color is used.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgressRing.Min">
<summary>
Gets or sets the minimum value
Expand All @@ -5787,6 +5812,21 @@
Gets or sets the content to be rendered inside the component.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgressRing.Width">
<summary>
Gets or sets the component width and height.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgressRing.Stroke">
<summary>
Gets or sets the stroke width of the progress ring. If not set, the default theme stroke width is used.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentProgressRing.Color">
<summary>
Gets or sets the color to be used for the progress ring. If not set, the default theme color is used.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1.Context">
<summary>
Gets context for this <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentRadio`1"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h4>Stroke and Color</h4>

<FluentSelect Label="Width" Items="@(new [] { ProgressStrokes.Thin, ProgressStrokes.Normal, ProgressStrokes.Large })" @bind-SelectedOption="@Stroke" Width="60px" />
<FluentCheckbox Label="Indeterminate" @bind-Value="@Indeterminate" />
<FluentSelect Label="Color" Items="@(Enum.GetValues<OfficeColor>())" @bind-SelectedOption="@Color" Width="100px" Height="200px" />
<FluentSlider Min="0" Max="100" Step="5" @bind-Value="@Percentage" Style="max-width: 200px; margin: 20px 0px;" Disabled="@Indeterminate" />

<FluentStack Style="margin: 30px;">
<FluentLabel Style="width: 20px;">@Percentage</FluentLabel>

<FluentProgress Min="0" Max="100" Value="@(Indeterminate ? null : Percentage)"
Width="200px"
Stroke="@Stroke"
Color="@(Color.ToAttributeValue())" />
</FluentStack>

@code
{
ProgressStrokes Stroke = ProgressStrokes.Normal;
int Percentage = 30;
bool Indeterminate = false;
OfficeColor Color = OfficeColor.Default;
}
2 changes: 2 additions & 0 deletions examples/Demo/Shared/Pages/Progress/ProgressPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

<DemoSection Title="Default" Component="@typeof(ProgressDefault)"></DemoSection>

<DemoSection Title="Stroke and Color" Component="@typeof(ProgressStroke)"></DemoSection>

<DemoSection Title="Paused" Component="@typeof(ProgressPaused)"></DemoSection>

<h2 id="documentation">Documentation</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<h4>Custom Sizes</h4>
<div style="display: grid; grid-gap: 12px; grid-auto-flow: column;">
<FluentStack>
<FluentProgressRing Min="0" Max="100" Value="20"></FluentProgressRing>
<FluentProgressRing Min="0" Max="100" Value="40" style="width: 42px; height: 42px;"></FluentProgressRing>
<FluentProgressRing Min="0" Max="100" Value="60" style="width: 62px; height: 62px;"></FluentProgressRing>
<FluentProgressRing Min="0" Max="100" Value="80" style="width: 82px; height: 82px;"></FluentProgressRing>
<FluentProgressRing Min="0" Max="100" Value="100" style="width: 102px; height: 102px;"></FluentProgressRing>
</div>
<div style="display: grid; grid-gap: 12px; grid-auto-flow: column;">
</FluentStack>
<FluentStack>
<FluentProgressRing></FluentProgressRing>
<FluentProgressRing style="width: 42px; height: 42px;"></FluentProgressRing>
<FluentProgressRing style="width: 62px; height: 62px;"></FluentProgressRing>
<FluentProgressRing style="width: 82px; height: 82px;"></FluentProgressRing>
<FluentProgressRing style="width: 102px; height: 102px;"></FluentProgressRing>
</div>
</FluentStack>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h4>Paused</h4>
<div style="width: 300px; display: grid; grid-gap: 12px; grid-auto-flow: column;">
<FluentStack>
<FluentProgressRing Paused="true" Min="0" Max="100" Value="75"></FluentProgressRing>
<FluentProgressRing Paused="true"></FluentProgressRing>
</div>
</FluentStack>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h4>Stroke and Color</h4>

<FluentSelect Label="Width" Items="@(new [] { ProgressStrokes.Thin, ProgressStrokes.Normal, ProgressStrokes.Large })" @bind-SelectedOption="@Stroke" Width="60px" />
<FluentCheckbox Label="Indeterminate" @bind-Value="@Indeterminate" />
<FluentSelect Label="Color" Items="@(Enum.GetValues<OfficeColor>())" @bind-SelectedOption="@Color" Width="100px" Height="200px" />
<FluentSlider Min="0" Max="100" Step="5" @bind-Value="@Percentage" Style="max-width: 200px; margin: 20px 0px;" Disabled="@Indeterminate" />

<FluentStack Style="margin: 30px;">
<FluentLabel Style="width: 20px;">@Percentage</FluentLabel>

<FluentProgressRing Value="@(Indeterminate ? null : Percentage)"
Width="32px"
Stroke="@Stroke"
Color="@(Color.ToAttributeValue())" />

<FluentProgressRing Value="@(Indeterminate ? null : Percentage)"
Width="64px"
Stroke="@Stroke"
Color="@(Color.ToAttributeValue())" />

<FluentProgressRing Value="@(Indeterminate ? null : Percentage)"
Width="128px"
Stroke="@Stroke"
Color="@(Color.ToAttributeValue())" />
</FluentStack>

@code
{
ProgressStrokes Stroke = ProgressStrokes.Normal;
int Percentage = 30;
bool Indeterminate = false;
OfficeColor Color = OfficeColor.Default;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

<DemoSection Title="Default" Component="@typeof(ProgressRingDefault)" />

<DemoSection Title="Stroke and Color" Component="@typeof(ProgressRingStroke)"></DemoSection>

<DemoSection Title="Paused" Component="@typeof(ProgressRingPaused)" />

<DemoSection Title="Custom sizes" Component="@typeof(ProgressRingCustomSizes)"></DemoSection>
Expand Down
20 changes: 19 additions & 1 deletion src/Core/Components/Progress/FluentProgress.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@
@inherits FluentComponentBase
@if (Visible)
{
<fluent-progress @ref=Element
if (Stroke != ProgressStrokes.Normal || !string.IsNullOrEmpty(Color) || !string.IsNullOrEmpty(BackgroundColor))
{
<style>
@if (Value == null)
{
@($" #{Id}::part(progress) {{ {StyleIndeterminate} }}")
@($" #{Id}::part(indeterminate-indicator-1) {{ {StyleIndeterminateIndicator} }}")
@($" #{Id}::part(indeterminate-indicator-2) {{ {StyleIndeterminateIndicator} }}")
}
else
{
@($" #{Id}::part(progress) {{ {StyleProgress} }}")
@($" #{Id}::part(determinate) {{ {StyleProgressIndicator} }}")
}
</style>
vnbaaij marked this conversation as resolved.
Show resolved Hide resolved
}

<fluent-progress id="@Id"
@ref=Element
class="@ClassValue"
style="@StyleValue"
min="@Min"
Expand Down
52 changes: 52 additions & 0 deletions src/Core/Components/Progress/FluentProgress.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ public partial class FluentProgress : FluentComponentBase
.Build();

protected string? StyleValue => new StyleBuilder(Style)
.AddStyle("width", Width, () => !string.IsNullOrEmpty(Width))
.Build();

public FluentProgress()
{
Id = Identifier.NewId();
}

/// <summary>
/// Gets or sets the minimum value.
/// </summary>
Expand All @@ -29,9 +35,18 @@ public partial class FluentProgress : FluentComponentBase
[Parameter]
public int? Value { get; set; }

/// <summary>
/// Gets or sets the visibility of the component
/// </summary>
[Parameter]
public bool Visible { get; set; } = true;

/// <summary>
/// Gets or sets the component width.
/// </summary>
[Parameter]
public string? Width { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the progress element is paused.
/// </summary>
Expand All @@ -43,4 +58,41 @@ public partial class FluentProgress : FluentComponentBase
/// </summary>
[Parameter]
public RenderFragment? ChildContent { get; set; }

/// <summary>
/// Gets or sets the stroke width of the progress bar. If not set, the default theme stroke width is used.
/// </summary>
[Parameter]
public ProgressStrokes Stroke { get; set; } = ProgressStrokes.Normal;

/// <summary>
/// Gets or sets the color to be used for the progress bar. If not set, the default theme color is used.
/// </summary>
[Parameter]
public string? Color { get; set; }

/// <summary>
/// Gets or sets the color to be used for the background. If not set, the default theme color is used.
/// </summary>
[Parameter]
public string? BackgroundColor { get; set; }

private (int BarHeight, int BackgroundHeight, string DefaultBackgroundColor) StrokeDetails => Stroke switch
{
ProgressStrokes.Thin => (2, 1, "--neutral-stroke-strong-rest"),
ProgressStrokes.Normal => (3, 1, "--neutral-stroke-strong-rest"),
ProgressStrokes.Large => (9, 6, "--neutral-stroke-rest"),
_ => throw new NotImplementedException(),
};
private string StyleProgress => $"height: calc((var(--stroke-width) * {StrokeDetails.BackgroundHeight}) * 1px); " +
$"background-color: {(string.IsNullOrEmpty(BackgroundColor) ? $"var({StrokeDetails.DefaultBackgroundColor})" : BackgroundColor)};";

private string StyleProgressIndicator => $"height: calc((var(--stroke-width) * {StrokeDetails.BarHeight}) * 1px); " +
$"background-color: {(string.IsNullOrEmpty(Color) ? "var(--accent-fill-rest)" : Color)};";

private string StyleIndeterminate => $"--stroke-width: {((double)StrokeDetails.BarHeight / 3d).ToString("0.00")}; " +
$"height: calc((1 * {StrokeDetails.BackgroundHeight}) * 1px); " +
$"background-color: {(string.IsNullOrEmpty(BackgroundColor) ? $"var({StrokeDetails.DefaultBackgroundColor})" : BackgroundColor)};";

private string StyleIndeterminateIndicator => $"background-color: {(string.IsNullOrEmpty(Color) ? "var(--accent-fill-rest)" : Color)};";
}
13 changes: 11 additions & 2 deletions src/Core/Components/Progress/FluentProgressRing.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
@inherits FluentComponentBase
@if (Visible)
{
<fluent-progress-ring @ref=Element
if (Stroke != ProgressStrokes.Normal || !string.IsNullOrEmpty(Color))
{
<style>
@($"#{Id}::part(background) {{ {StyleBackground} }}")
@($"#{Id}::part({(Value == null ? "indeterminate-indicator-1" : "determinate")}) {{ {StyleIndicator} }}")
</style>
}

vnbaaij marked this conversation as resolved.
Show resolved Hide resolved
<fluent-progress-ring id="@Id"
@ref=Element
class="@ClassValue"
style="@StyleValue"
min="@Min"
max="@Max"
value="@Value"
Paused="@Paused"
paused="@Paused"
@attributes="AdditionalAttributes">
@ChildContent
</fluent-progress-ring>
Expand Down
41 changes: 41 additions & 0 deletions src/Core/Components/Progress/FluentProgressRing.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ public partial class FluentProgressRing : FluentComponentBase
.Build();

protected string? StyleValue => new StyleBuilder(Style)
.AddStyle("width", Width, () => !string.IsNullOrEmpty(Width))
.AddStyle("height", Width, () => !string.IsNullOrEmpty(Width))
.Build();

public FluentProgressRing()
{
Id = Identifier.NewId();
}

/// <summary>
/// Gets or sets the minimum value
/// </summary>
Expand Down Expand Up @@ -44,4 +51,38 @@ public partial class FluentProgressRing : FluentComponentBase
/// </summary>
[Parameter]
public RenderFragment? ChildContent { get; set; }

/// <summary>
/// Gets or sets the component width and height.
/// </summary>
[Parameter]
public string? Width { get; set; }

/// <summary>
/// Gets or sets the stroke width of the progress ring. If not set, the default theme stroke width is used.
/// </summary>
[Parameter]
public ProgressStrokes Stroke { get; set; } = ProgressStrokes.Normal;

/// <summary>
/// Gets or sets the color to be used for the progress ring. If not set, the default theme color is used.
/// </summary>
[Parameter]
public string? Color { get; set; }

private (int Width, int Radius, int Dashoffset) StrokeDetails => Stroke switch
{
ProgressStrokes.Thin => (1, 7, 0),
ProgressStrokes.Normal => (2, 7, 0),
ProgressStrokes.Large => (4, 6, (int)(0.066 * (Value ?? 0) + 0.22)),
dvoituron marked this conversation as resolved.
Show resolved Hide resolved
_ => throw new NotImplementedException(),
};

private string StyleBackground => $"stroke-width: {StrokeDetails.Width}px; " +
$"r: {StrokeDetails.Radius}px;";

private string StyleIndicator => $"stroke-width: {StrokeDetails.Width}px; " +
$"r: {StrokeDetails.Radius}px; " +
$"stroke-dashoffset: {StrokeDetails.Dashoffset}px; " +
$"stroke: {(string.IsNullOrEmpty(Color) ? "var(--accent-fill-rest)" : Color )};";
}
8 changes: 8 additions & 0 deletions src/Core/Enums/ProgressStrokes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

public enum ProgressStrokes
{
Normal,
Thin,
Large,
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
</None>

<None Include="**\*.received.razor.html" />

<None Include="Progress\FluentProgressTests.razor" />
dvoituron marked this conversation as resolved.
Show resolved Hide resolved
<None Update="**\*.received.razor.html">
<ParentFile>$([System.String]::Copy('%(FileName)').Split('.')[0])</ParentFile>
<DependentUpon>%(ParentFile).razor</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<style>
#f29effe6b::part(background) { stroke-width: 2px; r: 7px; }
#f29effe6b::part(determinate) { stroke-width: 2px; r: 7px; stroke-dashoffset: 0px; stroke: red; }
</style>
<fluent-progress-ring id="xxx" min="0" max="100" value="30" backgroundcolor="gray" blazor:elementreference="xxx"></fluent-progress-ring>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<fluent-progress-ring id="xxx" min="10" max="80" blazor:elementreference="xxx">My content</fluent-progress-ring>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<fluent-progress-ring id="xxx" min="0" max="100" value="30" blazor:elementreference="xxx"></fluent-progress-ring>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<fluent-progress-ring id="xxx" min="0" max="100" value="30" paused="" blazor:elementreference="xxx"></fluent-progress-ring>
Loading