Skip to content

Commit ba9a790

Browse files
authored
Users/dvoituron/dev v5/progressbar visible (#3771)
1 parent 47849c3 commit ba9a790

File tree

10 files changed

+126
-13
lines changed

10 files changed

+126
-13
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<FluentStack Orientation="@Orientation.Vertical">
2+
<div>
3+
Content before the ProgressBar
4+
</div>
5+
<FluentProgressBar Width="200px" Visible="@Visible" Style="height: 5px;" />
6+
<div>
7+
Content after the ProgressBar
8+
</div>
9+
</FluentStack>
10+
11+
<FluentSelect Items="@([true, false, null])"
12+
OptionText="@(i => GetVisibleText(i) )"
13+
TOption="bool?"
14+
@bind-Value="@Visible" />
15+
16+
@code
17+
{
18+
bool? Visible = true;
19+
20+
string GetVisibleText(bool? visible)
21+
{
22+
return $"Visible = {(visible.HasValue ? (visible == true ? "true" : "false") : "null")}";
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<FluentStack Orientation="@Orientation.Vertical">
2+
<div>
3+
Content before the ProgressBar
4+
</div>
5+
<FluentSpinner Visible="@Visible" />
6+
<div>
7+
Content after the ProgressBar
8+
</div>
9+
</FluentStack>
10+
11+
<FluentSelect Items="@([true, false, null])"
12+
OptionText="@(i => GetVisibleText(i) )"
13+
TOption="bool?"
14+
@bind-Value="@Visible" />
15+
16+
@code
17+
{
18+
bool? Visible = true;
19+
20+
string GetVisibleText(bool? visible)
21+
{
22+
return $"Visible = {(visible.HasValue ? (visible == true ? "true" : "false") : "null")}";
23+
}
24+
}

examples/Demo/FluentUI.Demo.Client/Documentation/Components/Progress/FluentProgressBar.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ The background color of the progress bar can be set using the `BackgroundColor`
4040

4141
{{ ProgressBarState }}
4242

43+
## Visible
44+
45+
The `Visible` parameter can be used to show or hide the progress bar.
46+
This parameter is nullable:
47+
- If `true` (default), the component is visible.
48+
- If `false`, the component is hidden.
49+
- If `null`, the component is hidden and not rendered.
50+
51+
{{ ProgressBarVisible }}
52+
4353
## API FluentProgressBar
4454

4555
{{ API Type=FluentProgressBar }}

examples/Demo/FluentUI.Demo.Client/Documentation/Components/Progress/FluentSpinner.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ In some situations, you may need to display a spinner on a dark background.
3838

3939
{{ SpinnerInverted }}
4040

41+
## Visible
42+
43+
The `Visible` parameter can be used to show or hide the progress bar.
44+
This parameter is nullable:
45+
- If `true` (default), the component is visible.
46+
- If `false`, the component is hidden.
47+
- If `null`, the component is hidden and not rendered.
48+
49+
{{ SpinnerVisible }}
50+
4151
## API FluentSpinner
4252

4353
{{ API Type=FluentSpinner }}

src/Core/Components/Progress/FluentProgressBar.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
33
@inherits FluentComponentBase
44

5-
@if (Visible)
5+
@if (Visible.HasValue)
66
{
77
@if (HasCustomStyle)
88
{

src/Core/Components/Progress/FluentProgressBar.razor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public partial class FluentProgressBar : FluentComponentBase, ITooltipComponent
2121

2222
/// <summary />
2323
protected string? StyleValue => DefaultStyleBuilder
24+
.AddStyle("visibility", "hidden", () => Visible == false)
2425
.AddStyle("width", Width, () => !string.IsNullOrEmpty(Width))
2526
.AddStyle("background-color", BackgroundColor, () => !string.IsNullOrEmpty(BackgroundColor))
2627
.Build();
@@ -52,10 +53,13 @@ public partial class FluentProgressBar : FluentComponentBase, ITooltipComponent
5253
public int? Value { get; set; }
5354

5455
/// <summary>
55-
/// Gets or sets the visibility of the component
56+
/// Gets or sets the visibility of the component.
57+
/// If `true` (default), the component is visible.
58+
/// If `false`, the component is hidden.
59+
/// If `null`, the component is hidden and not rendered.
5660
/// </summary>
5761
[Parameter]
58-
public bool Visible { get; set; } = true;
62+
public bool? Visible { get; set; } = true;
5963

6064
/// <summary>
6165
/// Gets or sets the component width.

src/Core/Components/Progress/FluentSpinner.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
33
@inherits FluentComponentBase
44

5-
@if (Visible)
5+
@if (Visible.HasValue)
66
{
77
<fluent-spinner id="@Id"
88
class="@ClassValue"

src/Core/Components/Progress/FluentSpinner.razor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ public partial class FluentSpinner : FluentComponentBase, ITooltipComponent
1717

1818
/// <summary />
1919
protected string? StyleValue => DefaultStyleBuilder
20+
.AddStyle("visibility", "hidden", () => Visible == false)
2021
.Build();
2122

2223
/// <summary>
23-
/// Gets or sets the visibility of the component
24+
/// Gets or sets the visibility of the component.
25+
/// If `true` (default), the component is visible.
26+
/// If `false`, the component is hidden.
27+
/// If `null`, the component is hidden and not rendered.
2428
/// </summary>
2529
[Parameter]
26-
public bool Visible { get; set; } = true;
30+
public bool? Visible { get; set; } = true;
2731

2832
/// <summary>
2933
/// Gets or sets whether the spinner should be shown in an inverted color scheme (i.e. light spinner on dark background)

tests/Core/Components/Progress/FluentProgressBarTests.razor

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,28 @@
3434
[Theory]
3535
[InlineData(true)]
3636
[InlineData(false)]
37-
public void FluentProgressBar_Visible(bool visible)
37+
[InlineData(null)]
38+
public void FluentProgressBar_Visible(bool? visible)
3839
{
3940
// Act
4041
var cut = Render(@<FluentProgressBar Visible="@visible" />);
4142

4243
// Assert
43-
if (visible)
44-
{
45-
Assert.NotEmpty(cut.Markup);
46-
}
47-
else
44+
switch (visible)
4845
{
49-
Assert.Empty(cut.Markup);
46+
case true:
47+
Assert.NotEmpty(cut.Markup);
48+
Assert.DoesNotContain("visibility: hidden", cut.Markup);
49+
break;
50+
51+
case false:
52+
Assert.NotEmpty(cut.Markup);
53+
Assert.Contains("visibility: hidden", cut.Markup);
54+
break;
55+
56+
default:
57+
Assert.Empty(cut.Markup);
58+
break;
5059
}
5160
}
5261

tests/Core/Components/Progress/FluentSpinnerTests.razor

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@
5959
}
6060
}
6161

62+
[Theory]
63+
[InlineData(true)]
64+
[InlineData(false)]
65+
[InlineData(null)]
66+
public void FluentSpinner_Visible(bool? visible)
67+
{
68+
// Act
69+
var cut = Render(@<FluentSpinner Visible="@visible" />);
70+
71+
// Assert
72+
switch (visible)
73+
{
74+
case true:
75+
Assert.NotEmpty(cut.Markup);
76+
Assert.DoesNotContain("visibility: hidden", cut.Markup);
77+
break;
78+
79+
case false:
80+
Assert.NotEmpty(cut.Markup);
81+
Assert.Contains("visibility: hidden", cut.Markup);
82+
break;
83+
84+
default:
85+
Assert.Empty(cut.Markup);
86+
break;
87+
}
88+
}
89+
6290
#pragma warning disable CS0618
6391
[Theory]
6492
[InlineData(ProgressStroke.Small, "small")]

0 commit comments

Comments
 (0)