1
+ // ------------------------------------------------------------------------
2
+ // MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // ------------------------------------------------------------------------
4
+
1
5
using System . Globalization ;
2
6
using Microsoft . AspNetCore . Components ;
3
7
using Microsoft . FluentUI . AspNetCore . Components . Extensions ;
@@ -18,9 +22,9 @@ public partial class FluentCounterBadge : FluentComponentBase, IDisposable
18
22
19
23
/// <summary />
20
24
protected string ? StyleValue => new StyleBuilder ( Style )
21
- . AddStyle ( "left" , $ "{ HorizontalPosition . ToString ( CultureInfo . InvariantCulture ) } %", ( ) => GlobalState . Dir == LocalizationDirection . LeftToRight )
22
- . AddStyle ( "right" , $ "{ HorizontalPosition . ToString ( CultureInfo . InvariantCulture ) } %", ( ) => GlobalState . Dir == LocalizationDirection . RightToLeft )
23
- . AddStyle ( "bottom" , $ "{ VerticalPosition . ToString ( CultureInfo . InvariantCulture ) } %")
25
+ . AddStyle ( "left" , $ "{ HorizontalPosition ? . ToString ( CultureInfo . InvariantCulture ) } %", ( ) => GlobalState . Dir == LocalizationDirection . LeftToRight )
26
+ . AddStyle ( "right" , $ "{ HorizontalPosition ? . ToString ( CultureInfo . InvariantCulture ) } %", ( ) => GlobalState . Dir == LocalizationDirection . RightToLeft )
27
+ . AddStyle ( "bottom" , $ "{ VerticalPosition ? . ToString ( CultureInfo . InvariantCulture ) } %")
24
28
. AddStyle ( "background-color" , GetBackgroundColor ( ) . ToAttributeValue ( ) )
25
29
. AddStyle ( "color" , GetFontColor ( ) . ToAttributeValue ( ) )
26
30
. AddStyle ( "border" , $ "1px solid { GetBorderColor ( ) . ToAttributeValue ( ) } ")
@@ -50,7 +54,7 @@ public partial class FluentCounterBadge : FluentComponentBase, IDisposable
50
54
/// Gets or sets the content you want inside the badge, to customize the badge content.
51
55
/// </summary>
52
56
[ Parameter ]
53
- public RenderFragment < int ? > ? BadgeTemplate { get ; set ; }
57
+ public RenderFragment < int ? > ? BadgeTemplate { get ; set ; }
54
58
55
59
/// <summary>
56
60
/// Gets or sets the maximum number that can be displayed inside the badge.
@@ -64,7 +68,7 @@ public partial class FluentCounterBadge : FluentComponentBase, IDisposable
64
68
/// Default value is 60 (80 when Dot=true).
65
69
/// </summary>
66
70
[ Parameter ]
67
- public int HorizontalPosition { get ; set ; }
71
+ public int ? HorizontalPosition { get ; set ; }
68
72
69
73
/// <summary>
70
74
/// Gets or sets the bottom position of the badge in percentage.
@@ -75,7 +79,7 @@ public partial class FluentCounterBadge : FluentComponentBase, IDisposable
75
79
[ Parameter ]
76
80
public int BottomPosition
77
81
{
78
- get => VerticalPosition ;
82
+ get => VerticalPosition ?? 60 ;
79
83
set => VerticalPosition = value ;
80
84
}
81
85
@@ -84,7 +88,7 @@ public int BottomPosition
84
88
/// Default value is 60 (80 when Dot=true).
85
89
/// </summary>
86
90
[ Parameter ]
87
- public int VerticalPosition { get ; set ; }
91
+ public int ? VerticalPosition { get ; set ; }
88
92
89
93
/// <summary>
90
94
/// Gets or sets the default design of this badge using colors from theme.
@@ -160,8 +164,9 @@ protected override Task OnParametersSetAsync()
160
164
161
165
protected override void OnInitialized ( )
162
166
{
163
- HorizontalPosition = Dot ? 80 : 60 ;
164
- VerticalPosition = Dot ? 80 : 60 ;
167
+ HorizontalPosition ??= Dot ? 80 : 60 ;
168
+ VerticalPosition ??= Dot ? 80 : 60 ;
169
+
165
170
GlobalState . OnChange += StateHasChanged ;
166
171
}
167
172
0 commit comments