-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathMainLayout.razor
312 lines (286 loc) · 10.8 KB
/
MainLayout.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
@using Syncfusion.Blazor;
@using Microsoft.AspNetCore.Components;
@using Microsoft.AspNetCore.Components.Routing;
@using Syncfusion.Blazor.Buttons;
@using Blazor_MAUI_Demos.Shared;
@using System.Globalization;
@using System.Text.RegularExpressions;
@inject IJSRuntime JsRuntime;
@inject NavigationManager UriHelper;
@inject SampleService SampleService;
@inject DeviceMode DeviceMode;
@inherits LayoutComponentBase;
@implements IDisposable;
<CascadingValue Value="@this">
<SpinnerComponent @ref="spinnerRef"></SpinnerComponent>
@*Set empty layout to home page and components which have open in new window functionality.*@
@{
var isEmptyLayout = SampleService.SampleInfo != null && !UriHelper.Uri.Contains(SampleService.SampleInfo.Url) && SampleService.SampleInfo.MappingSampleName != null;
}
@if (SampleUtils.IsHomePage(UriHelper) || isEmptyLayout)
{
foreach (var fileName in SampleBrowser.PreLoadFiles)
{
<link href="@fileName" as="font" type="font/woff2" crossorigin />
}
<CascadingValue Value="isDeviceMode" Name="IsDevice">
<div>
@Body
</div>
</CascadingValue>
}
else
{
<div class="sample-browser e-view sf-new" @onclick="OnAppClick">
<div class="sb-mobile-overlay sb-hide"></div>
<HeaderComponent @ref="headerRef" OnToggleClick="@OnToggleClick" OnRightToggleClick="@OnRightToggleClick" OnSearchRender="@OnSearchRender"></HeaderComponent>
<div class="sb-content e-view">
<div class="@searchContainer">
<div class="index-search-container">
<SearchComponent @ref="@searchRef"></SearchComponent>
</div>
</div>
<RightPaneComponent @ref="RightPaneRef">@Body</RightPaneComponent>
</div>
</div>
}
</CascadingValue>
<Syncfusion.Blazor.Popups.SfDialogProvider />
<style>
h1:focus {
outline: none;
}
</style>
@code {
[Inject]
protected SyncfusionBlazorService SyncfusionService { get; set; }
[Inject]
private NavigationManager navigationManager { get; set; }
private bool isDeviceMode { get; set; }
private bool isSearchIconClick { get; set; }
private string searchContainer { get; set; }
private bool rightSidebarExpanded { get; set; }
public SpinnerComponent spinnerRef { get; set; }
private DotNetObjectReference<object> dotnetObjectRef { get; set; }
private SearchComponent searchRef { get; set; }
public HeaderComponent headerRef { get; set; }
/// <summary>
/// Specifies the app is rendering in tablet or not.
/// </summary>
public bool isTablet { get; set; }
/// <summary>
/// LeftPane reference for outside usage.
/// </summary>
public LeftPaneComponent LeftPaneRef { get; set; }
/// <summary>
/// RightPane reference for outside usage.
/// </summary>
public RightPaneComponent RightPaneRef { get; set; }
/// <summary>
/// SampleNavigator reference for outside usage.
/// </summary>
public SampleNavigator SampleNavigatorRef { get; set; }
// Left sidebar click handler
private async Task OnToggleClick()
{
if (headerRef.isNotifyClicked)
{
headerRef.NotifyClicked();
}
if (SampleService.IsDevice && rightSidebarExpanded)
{
rightSidebarExpanded = !rightSidebarExpanded;
}
await JsRuntime.InvokeAsync<string>("callResizeEvent");
await ShowSearchLayout();
}
// Right sidebar click handler
private async Task OnRightToggleClick()
{
// Update right sidebar expand and collapse status
rightSidebarExpanded = !rightSidebarExpanded;
await ShowSearchLayout();
if (headerRef.isNotifyClicked)
{
headerRef.NotifyClicked();
}
}
// Home icon click handler.
private async Task HomeIconClick()
{
await LeftPaneRef.HomeButtonClick();
}
// Search icon click handler.
private async Task OnSearchRender()
{
await ShowSearchLayout(true);
}
// App click handler for collapse the sidebar components in device rendering.
private async Task OnAppClick()
{
this.CollapseSideBar();
if (headerRef != null && headerRef.dropdownRef != null)
{
if (!headerRef.dropdownRef.isthemepopupopen)
{
headerRef.dropdownRef.popupClass = SampleUtils.AddClass(headerRef.dropdownRef.popupClass, SampleUtils.DISPLAY_NONE);
}
headerRef.dropdownRef.isthemepopupopen = false;
headerRef.HidePreferences();
}
if (searchRef.IsFocusOut() && !isSearchIconClick)
{
// Await the search layout hide process for the search list selection.
await Task.Delay(200);
await ShowSearchLayout();
}
else
{
isSearchIconClick = false;
}
var isSettingsPopUpOpen = await JsRuntime.InvokeAsync<bool>("isSettingsPopUpOpen");
if(isSettingsPopUpOpen){
headerRef.OnSettingsClick();
}
}
// Location change event handler
private async void LocationChanged(object sender, LocationChangedEventArgs e)
{
// Get dynamic resource list.
var resources = SampleUtils.GetDynamicResources(UriHelper, SampleService);
var jsResources = SampleUtils.GetDynamicJSResources(UriHelper, SampleService);
if (resources.Count > 0)
{
await this.JsRuntime.InvokeVoidAsync("sfBlazorSB.loadResources", resources);
}
if (jsResources.Count > 0)
{
await this.JsRuntime.InvokeVoidAsync("sfBlazorSB.loadResources", jsResources);
}
}
/// <summary>
/// Show search layout in the demos page.
/// </summary>
public async Task ShowSearchLayout(bool isIconClick = false, bool isEscPressed = false)
{
if (isIconClick && searchContainer.Contains(SampleUtils.DISPLAY_NONE))
{
if (headerRef.isNotifyClicked)
{
headerRef.NotifyClicked();
}
isSearchIconClick = isIconClick;
searchContainer = SampleUtils.RemoveClass(searchContainer, SampleUtils.DISPLAY_NONE);
await searchRef.InputFocus();
}
else
{
searchContainer = SampleUtils.AddClass(searchContainer, SampleUtils.DISPLAY_NONE);
}
if (isEscPressed)
{
StateHasChanged();
}
}
/// <summary>
/// Collapse both right and left sidebar component.
/// </summary>
public void CollapseSideBar()
{
if (SampleService.IsDevice)
{
// Collapse left sidebar if it is expanded on document click
if (LeftPaneRef.IsExpanded())
{
LeftPaneRef.UpdateExpandedState();
}
// Collapse right sidebar if it is expanded on document click
if (rightSidebarExpanded)
{
rightSidebarExpanded = !rightSidebarExpanded;
}
}
}
/// <summary>
/// Update device mode while resizing window through UI.
/// </summary>
/// <param name="isDevice">Specifies the current resolution is device mode or not.</param>
[JSInvokable]
public void UpdateDeviceMode(bool isDevice, bool isTablet)
{
isDeviceMode = isDevice;
SampleService.IsDevice = isDevice;
if (isTablet)
{
RightPaneRef?.SampleNavigatorRef.Rerender(SampleService.IsDevice, isTablet);
}
StateHasChanged();
}
protected override async void OnInitialized()
{
base.OnInitialized();
UriHelper.LocationChanged += LocationChanged;
// Enable ripple effect to the material theme.
SyncfusionService.EnableRipple(UriHelper.Uri.IndexOf("material") > 0);
searchContainer = SampleUtils.SEARCH_OVERLAY + SampleUtils.SPACE + SampleUtils.DISPLAY_NONE;
//For getting the user preferred language for localization
string userSelectedCulture = null;
if (userSelectedCulture != null)
{
var customisedCulture = new CultureInfo(userSelectedCulture);
CultureInfo.DefaultThreadCurrentCulture = customisedCulture;
CultureInfo.DefaultThreadCurrentUICulture = customisedCulture;
}
// Condition to check whether the URL query params contains the proper theme name. If the URL query params donesn't contains the theme name, the URL redirects to existing component URL without query params.
// Due to this redirection, we can prevent our site from multiple vulnerability attacks from hackers.
string themeName = System.Web.HttpUtility.ParseQueryString(new Uri(this.navigationManager.Uri).Query).Get("theme");
if (!string.IsNullOrEmpty(themeName) && !SampleUtils.ThemeData.Any((theme => theme.ID == themeName)) && themeName != "tailwind" && themeName != "tailwind-dark")
{
this.navigationManager.NavigateTo(this.navigationManager.Uri.Split("?")[0], forceLoad: true);
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
// Add Spinner ref to the sample servie to get access in SampleBaseComponent class.
if (SampleService.Spinner == null)
{
SampleService.Spinner = spinnerRef;
}
dotnetObjectRef = DotNetObjectReference.Create<object>(this);
// Get device information for mobile sidebar rendering
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.iOS || Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.Android)
{
this.SampleService.IsDevice = false;
}
this.DeviceMode.Isdevice = this.SampleService.IsDevice;
this.isDeviceMode = this.SampleService.IsDevice;
if (this.SampleService.IsDevice)
{
LeftPaneRef?.UpdateExpandedState();
StateHasChanged();
}
// Update home page or demo page loaded property in SampleService.
SampleUtils.GetDynamicResources(UriHelper, SampleService);
}
else
{
// Refresh meta data for home page navigation.
if (UriHelper.BaseUri == UriHelper.Uri)
{
SampleService.MetaData?.Refresh();
}
}
if (!firstRender && LeftPaneRef != null && LeftPaneRef.NavMenuRef.isNavigate)
{
LeftPaneRef.NavMenuRef.isNavigate = false;
}
}
public void Dispose()
{
dotnetObjectRef?.Dispose();
UriHelper.LocationChanged -= LocationChanged;
}
}