|
1 | | -namespace BlazorBootstrap; |
| 1 | +using System.Reflection.Metadata; |
| 2 | + |
| 3 | +namespace BlazorBootstrap; |
2 | 4 |
|
3 | 5 | public partial class Offcanvas : BlazorBootstrapComponentBase |
4 | 6 | { |
@@ -40,7 +42,17 @@ protected override async ValueTask DisposeAsyncCore( bool disposing ) |
40 | 42 | protected override async Task OnAfterRenderAsync( bool firstRender ) |
41 | 43 | { |
42 | 44 | if( firstRender ) |
43 | | - await JSRuntime.InvokeVoidAsync( "window.blazorBootstrap.offcanvas.initialize", Id, UseStaticBackdrop, CloseOnEscape, IsScrollable, objRef ); |
| 45 | + { |
| 46 | + object backdrop = Backdrop switch |
| 47 | + { |
| 48 | + BackdropType.None => false, |
| 49 | + BackdropType.Visible => true, |
| 50 | + BackdropType.Static => "static", |
| 51 | + _ => throw new InvalidOperationException( "Invalid backdrop value" ) |
| 52 | + }; |
| 53 | + |
| 54 | + await JSRuntime.InvokeVoidAsync( "window.blazorBootstrap.offcanvas.initialize", Id, backdrop, CloseOnEscape, IsScrollable, objRef ); |
| 55 | + } |
44 | 56 |
|
45 | 57 | await base.OnAfterRenderAsync( firstRender ); |
46 | 58 | } |
@@ -284,24 +296,26 @@ public bool IsVisible |
284 | 296 | [Parameter] |
285 | 297 | public string Title { get; set; } = default!; |
286 | 298 |
|
287 | | - [Obsolete( "Use `UseStaticBackdrop` parameter." )] |
288 | | - /// <summary> |
289 | | - /// Indicates whether to apply a backdrop on body while offcanvas is open. |
290 | | - /// </summary> |
291 | | - /// <remarks> |
292 | | - /// Default value is true. |
293 | | - /// </remarks> |
294 | 299 | [Parameter] |
295 | | - public bool UseBackdrop { get => this.UseStaticBackdrop; set => this.UseStaticBackdrop = value; } |
| 300 | + public BackdropType Backdrop { get; set; } = BackdropType.Visible; |
296 | 301 |
|
297 | | - /// <summary> |
298 | | - /// When `UseStaticBackdrop` is set to true, the offcanvas will not close when clicking outside of it. |
299 | | - /// </summary> |
300 | | - /// <remarks> |
301 | | - /// Default value is false. |
302 | | - /// </remarks> |
303 | | - [Parameter] |
304 | | - public bool UseStaticBackdrop { get; set; } = true; |
| 302 | + public enum BackdropType |
| 303 | + { |
| 304 | + /// <summary> |
| 305 | + /// Do not use a backdrop, the page will stay visible. |
| 306 | + /// </summary> |
| 307 | + None, |
| 308 | + |
| 309 | + /// <summary> |
| 310 | + /// Visible backdrop, the page will be covered by a backdrop |
| 311 | + /// </summary> |
| 312 | + Visible, |
| 313 | + |
| 314 | + /// <summary> |
| 315 | + /// Static backdrop, the page will be covered by a backdrop and the offcanvas will not close when clicking outside of it. |
| 316 | + /// </summary> |
| 317 | + Static |
| 318 | + } |
305 | 319 |
|
306 | 320 | #endregion |
307 | 321 | } |
0 commit comments