66namespace MudExtensions . UnitTests . Mocks
77{
88#pragma warning disable CS1998 // Justification - Implementing IResizeListenerService
9+ [ Obsolete ( "Replaced by IBrowserViewportService. Remove in v7." ) ]
910 public class MockResizeService : IResizeService
1011 {
1112 private int _width , _height ;
@@ -72,19 +73,30 @@ public bool IsMediaSize(Breakpoint breakpoint, Breakpoint reference)
7273
7374 public async Task < Breakpoint > GetBreakpoint ( ) => GetBreakpointInternal ( ) ;
7475
75- public Task < Guid > Subscribe ( Action < BrowserWindowSize > callback ) => Task . FromResult ( new Guid ( ) ) ;
76- public Task < Guid > Subscribe ( Action < BrowserWindowSize > callback , ResizeOptions options ) => Task . FromResult ( new Guid ( ) ) ;
77- public Task < bool > Unsubscribe ( Guid subscriptionId ) => Task . FromResult ( true ) ;
76+ [ Obsolete ( $ "Use { nameof ( SubscribeAsync ) } instead. This will be removed in v7.") ]
77+ public Task < Guid > Subscribe ( Action < BrowserWindowSize > callback ) => SubscribeAsync ( callback ) ;
78+
79+ public Task < Guid > SubscribeAsync ( Action < BrowserWindowSize > callback ) => Task . FromResult ( new Guid ( ) ) ;
80+
81+ [ Obsolete ( $ "Use { nameof ( SubscribeAsync ) } instead. This will be removed in v7.") ]
82+ public Task < Guid > Subscribe ( Action < BrowserWindowSize > callback , ResizeOptions options ) => SubscribeAsync ( callback , options ) ;
83+
84+ public Task < Guid > SubscribeAsync ( Action < BrowserWindowSize > callback , ResizeOptions options ) => Task . FromResult ( new Guid ( ) ) ;
85+
86+ [ Obsolete ( $ "Use { nameof ( UnsubscribeAsync ) } instead. This will be removed in v7.") ]
87+ public Task < bool > Unsubscribe ( Guid subscriptionId ) => UnsubscribeAsync ( subscriptionId ) ;
88+
89+ public Task < bool > UnsubscribeAsync ( Guid subscriptionId ) => Task . FromResult ( true ) ;
7890
7991 private Breakpoint GetBreakpointInternal ( )
8092 {
81- if ( _width >= ResizeListenerService . BreakpointDefinitions [ Breakpoint . Xl ] )
93+ if ( _width >= BreakpointGlobalOptions . DefaultBreakpointDefinitions [ Breakpoint . Xl ] )
8294 return Breakpoint . Xl ;
83- else if ( _width >= ResizeListenerService . BreakpointDefinitions [ Breakpoint . Lg ] )
95+ else if ( _width >= BreakpointGlobalOptions . DefaultBreakpointDefinitions [ Breakpoint . Lg ] )
8496 return Breakpoint . Lg ;
85- else if ( _width >= ResizeListenerService . BreakpointDefinitions [ Breakpoint . Md ] )
97+ else if ( _width >= BreakpointGlobalOptions . DefaultBreakpointDefinitions [ Breakpoint . Md ] )
8698 return Breakpoint . Md ;
87- else if ( _width >= ResizeListenerService . BreakpointDefinitions [ Breakpoint . Sm ] )
99+ else if ( _width >= BreakpointGlobalOptions . DefaultBreakpointDefinitions [ Breakpoint . Sm ] )
88100 return Breakpoint . Sm ;
89101 else
90102 return Breakpoint . Xs ;
@@ -98,4 +110,39 @@ public ValueTask DisposeAsync()
98110 }
99111 }
100112#pragma warning restore CS1998
113+
114+ internal class BreakpointGlobalOptions
115+ {
116+ /// <summary>
117+ /// Default breakpoint definitions
118+ /// </summary>
119+ internal static Dictionary < Breakpoint , int > DefaultBreakpointDefinitions { get ; set ; } = new ( )
120+ {
121+ [ Breakpoint . Xxl ] = 2560 ,
122+ [ Breakpoint . Xl ] = 1920 ,
123+ [ Breakpoint . Lg ] = 1280 ,
124+ [ Breakpoint . Md ] = 960 ,
125+ [ Breakpoint . Sm ] = 600 ,
126+ [ Breakpoint . Xs ] = 0 ,
127+ } ;
128+
129+ /// <summary>
130+ /// Retrieves the default or user-defined breakpoint definitions based on the provided <paramref name="options"/>.
131+ /// If user-defined breakpoint definitions are available in the <paramref name="options"/>, a copy is returned to prevent unintended modifications.
132+ /// Otherwise, the default <see cref="DefaultBreakpointDefinitions"/> breakpoint definitions are returned.
133+ /// </summary>
134+ /// <param name="options">The resize options containing breakpoint definitions, if any.</param>
135+ /// <returns>A dictionary containing the breakpoint definitions.</returns>
136+ internal static Dictionary < Breakpoint , int > GetDefaultOrUserDefinedBreakpointDefinition ( ResizeOptions options )
137+ {
138+ if ( options . BreakpointDefinitions is not null && options . BreakpointDefinitions . Count != 0 )
139+ {
140+ // Copy as we don't want any unexpected modification
141+ return options . BreakpointDefinitions . ToDictionary ( entry => entry . Key , entry => entry . Value ) ;
142+ }
143+
144+ return DefaultBreakpointDefinitions . ToDictionary ( entry => entry . Key , entry => entry . Value ) ;
145+ }
146+ }
147+
101148}
0 commit comments