Skip to content

Commit dc4821f

Browse files
feat(drawer): two drawers on the same layout example (#49)
* feat(drawer): two drawers on the same layout example * chore(drawer): fix folder depth
1 parent bf413d8 commit dc4821f

30 files changed

+1385
-0
lines changed

drawer/two-drawers/TwoDrawers.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30413.136
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoDrawers", "TwoDrawers\TwoDrawers.csproj", "{1368A132-9B44-4B9C-9A08-684C9D85890B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1368A132-9B44-4B9C-9A08-684C9D85890B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1368A132-9B44-4B9C-9A08-684C9D85890B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1368A132-9B44-4B9C-9A08-684C9D85890B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1368A132-9B44-4B9C-9A08-684C9D85890B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C63496C3-7322-474C-B1A3-A05789950030}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<h1>Page not found</h1>
7+
<p>Sorry, but there's nothing here!</p>
8+
</NotFound>
9+
</Router>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace TwoDrawers.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace TwoDrawers.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
int currentCount = 0;
11+
12+
void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@page "/fetchdata"
2+
@using TwoDrawers.Data
3+
@inject WeatherForecastService ForecastService
4+
5+
<h1>Weather forecast</h1>
6+
7+
<p>This component demonstrates fetching data from a service.</p>
8+
9+
@if (forecasts == null)
10+
{
11+
<p><em>Loading...</em></p>
12+
}
13+
else
14+
{
15+
<table class="table">
16+
<thead>
17+
<tr>
18+
<th>Date</th>
19+
<th>Temp. (C)</th>
20+
<th>Temp. (F)</th>
21+
<th>Summary</th>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
@foreach (var forecast in forecasts)
26+
{
27+
<tr>
28+
<td>@forecast.Date.ToShortDateString()</td>
29+
<td>@forecast.TemperatureC</td>
30+
<td>@forecast.TemperatureF</td>
31+
<td>@forecast.Summary</td>
32+
</tr>
33+
}
34+
</tbody>
35+
</table>
36+
}
37+
38+
@code {
39+
WeatherForecast[] forecasts;
40+
41+
protected override async Task OnInitializedAsync()
42+
{
43+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
44+
}
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.<br />
6+
7+
<TelerikButton OnClick="@SayHelloHandler" Primary="true">Say Hello</TelerikButton>
8+
9+
<br />
10+
11+
@helloString
12+
13+
@code {
14+
MarkupString helloString;
15+
16+
void SayHelloHandler()
17+
{
18+
string msg = string.Format("Hello from <strong>Telerik Blazor</strong> at {0}.<br /> Now you can use C# to write front-end!", DateTime.Now);
19+
helloString = new MarkupString(msg);
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@page "/"
2+
@namespace TwoDrawers.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<title>TwoDrawers</title>
11+
<base href="~/" />
12+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
13+
<link href="css/site.css" rel="stylesheet" />
14+
<link rel="stylesheet" href="_content/Telerik.UI.for.Blazor/css/kendo-theme-default/all.css" />
15+
<script src="_content/Telerik.UI.for.Blazor/js/telerik-blazor.js" defer></script>
16+
</head>
17+
<body>
18+
<app><component type="typeof(App)" render-mode="ServerPrerendered" /></app>
19+
20+
<div id="blazor-error-ui">
21+
<environment include="Staging,Production">
22+
An error has occurred. This application may no longer respond until reloaded.
23+
</environment>
24+
<environment include="Development">
25+
An unhandled exception has occurred. See browser dev tools for details.
26+
</environment>
27+
<a href class="reload">Reload</a>
28+
<a class="dismiss">🗙</a>
29+
</div>
30+
31+
<script src="_framework/blazor.server.js"></script>
32+
</body>
33+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace TwoDrawers
13+
{
14+
public class Program
15+
{
16+
public static void Main(string[] args)
17+
{
18+
CreateHostBuilder(args).Build().Run();
19+
}
20+
21+
public static IHostBuilder CreateHostBuilder(string[] args) =>
22+
Host.CreateDefaultBuilder(args)
23+
.ConfigureWebHostDefaults(webBuilder =>
24+
{
25+
webBuilder.UseStaticWebAssets();
26+
webBuilder.UseStartup<Startup>();
27+
});
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:52532/",
7+
"sslPort": 44388
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"TwoDrawers": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
}
26+
}
27+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@inherits LayoutComponentBase
2+
3+
<style>
4+
.nested-drawer .k-widget.k-drawer {
5+
/* By default, the drawer items have a high z-index and without reducing it they may show up above the overlay the other drawer*/
6+
z-index: 1;
7+
}
8+
</style>
9+
10+
<TelerikRootComponent>
11+
12+
@* First, the Overlay mode drawer as it positions itself absolutely and so it should be as high in the DOM as possible
13+
in order to not be limited by the rules and positions of its parents *@
14+
<TelerikDrawer Data="@RightItems" Mode="@DrawerMode.Overlay" Position="@DrawerPosition.Right" @ref="@RightDrawerRef">
15+
<Content>
16+
17+
@* The nested drawer is the Push drawer - the CSS rule above reduces its z-index so it does not show up above the overlay of the other *@
18+
<TelerikDrawer Data="@Data"
19+
MiniMode="true"
20+
Mode="DrawerMode.Push"
21+
@ref="@DrawerRef"
22+
@bind-SelectedItem="@SelectedItem"
23+
Class="nested-drawer">
24+
<Content>
25+
26+
@* Here begins the actual content - for example, we start with buttons to toggle the drawers and the @Body later *@
27+
<TelerikButton OnClick="@(() => DrawerRef.ToggleAsync())" Icon="@IconName.Menu">Toggle LEFT drawer</TelerikButton>
28+
<TelerikButton OnClick="@(() => RightDrawerRef.ToggleAsync())" Icon="@IconName.Menu">Toggle RIGHT drawer</TelerikButton>
29+
30+
<div class="m-5">
31+
Selected Item: @SelectedItem?.Text
32+
@Body
33+
</div>
34+
</Content>
35+
</TelerikDrawer>
36+
</Content>
37+
</TelerikDrawer>
38+
39+
</TelerikRootComponent>
40+
41+
@code {
42+
TelerikDrawer<DrawerItem> DrawerRef { get; set; }
43+
TelerikDrawer<DrawerItem> RightDrawerRef { get; set; }
44+
DrawerItem SelectedItem { get; set; }
45+
46+
// the left (Push) drawer goes to the counter and fetch data pages
47+
IEnumerable<DrawerItem> Data { get; set; } = new List<DrawerItem>
48+
{
49+
new DrawerItem { Text = "Counter", Icon = IconName.Plus, Url = "counter"},
50+
new DrawerItem { Text = "FetchData", Icon = IconName.GridLayout, Url = "fetchdata"},
51+
};
52+
53+
//the right (overlay) drawer always goes to the home page for brevity and simplicity
54+
IEnumerable<DrawerItem> RightItems { get; set; } = new List<DrawerItem>
55+
{
56+
new DrawerItem { Text = "First", Icon = IconName.MinusOutline, Url= "/"},
57+
new DrawerItem { Text = "Second", Icon = IconName.MinusCircle, Url = "/"},
58+
};
59+
60+
public class DrawerItem
61+
{
62+
public string Text { get; set; }
63+
public string Icon { get; set; }
64+
public string Url { get; set; }
65+
}
66+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Components;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.HttpsPolicy;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
using TwoDrawers.Data;
13+
14+
namespace TwoDrawers
15+
{
16+
public class Startup
17+
{
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
// This method gets called by the runtime. Use this method to add services to the container.
26+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
27+
public void ConfigureServices(IServiceCollection services)
28+
{
29+
services.AddRazorPages();
30+
services.AddServerSideBlazor();
31+
services.AddTelerikBlazor();
32+
services.AddSingleton<WeatherForecastService>();
33+
}
34+
35+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
36+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
37+
{
38+
if (env.IsDevelopment())
39+
{
40+
app.UseDeveloperExceptionPage();
41+
}
42+
else
43+
{
44+
app.UseExceptionHandler("/Home/Error");
45+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
46+
app.UseHsts();
47+
}
48+
49+
app.UseHttpsRedirection();
50+
app.UseStaticFiles();
51+
52+
app.UseRouting();
53+
54+
app.UseEndpoints(endpoints =>
55+
{
56+
endpoints.MapDefaultControllerRoute();
57+
endpoints.MapControllers();
58+
59+
endpoints.MapBlazorHub();
60+
endpoints.MapFallbackToPage("/_Host");
61+
});
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)