Skip to content

Commit c61a266

Browse files
demo app update
1 parent 839406d commit c61a266

File tree

11 files changed

+105
-97
lines changed

11 files changed

+105
-97
lines changed

DemoApp/BlazorContextMenu.DemoApp.Client/BlazorContextMenu.DemoApp.Client.csproj

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<OutputType>Exe</OutputType>
6-
<RestoreAdditionalProjectSources>
7-
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
8-
https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
9-
</RestoreAdditionalProjectSources>
10-
<RazorLangVersion>3.0</RazorLangVersion>
4+
<TargetFramework>net6.0</TargetFramework>
115
</PropertyGroup>
126

137
<ItemGroup>
14-
<PackageReference Include="Blazor.ContextMenu" Version="1.6.0-beta-552" />
15-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.1.0-preview4.19579.2" />
16-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.1.0-preview4.19579.2" PrivateAssets="all" />
17-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.1.0-preview4.19579.2" />
8+
<PackageReference Include="Blazor.ContextMenu" Version="1.10.1" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0" PrivateAssets="all" />
11+
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
1812
</ItemGroup>
1913

2014
<ItemGroup>
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1-
using Microsoft.AspNetCore.Blazor.Hosting;
1+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
22
using Microsoft.Extensions.DependencyInjection;
33
using System;
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
46

57
namespace BlazorContextMenu.DemoApp.Client
68
{
79
public class Program
810
{
9-
public static void Main(string[] args)
11+
public static async Task Main(string[] args)
1012
{
11-
CreateHostBuilder(args).Build().Run();
12-
}
13+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
14+
builder.RootComponents.Add<App>("#app");
15+
16+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
17+
builder.Services.AddBlazorContextMenu(options =>
18+
{
19+
options.ConfigureTemplate("dark", template =>
20+
{
21+
template.MenuCssClass = "dark-menu";
22+
template.MenuItemCssClass = "dark-menu-item";
23+
template.MenuItemDisabledCssClass = "dark-menu-item--disabled";
24+
template.MenuItemWithSubMenuCssClass = "dark-menu-item--with-submenu";
25+
template.Animation = Animation.FadeIn;
26+
});
27+
28+
options.ConfigureTemplate("pink", template =>
29+
{
30+
template.MenuCssClass = "pink-menu";
31+
template.MenuItemCssClass = "pink-menu-item";
32+
template.MenuItemDisabledCssClass = "pink-menu-item--disabled";
33+
template.SeperatorHrCssClass = "pink-menu-seperator-hr";
34+
template.MenuItemWithSubMenuCssClass = "pink-menu-item--with-submenu";
35+
template.Animation = Animation.Slide;
36+
});
37+
});
1338

14-
public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
15-
BlazorWebAssemblyHost.CreateDefaultBuilder()
16-
.UseBlazorStartup<Startup>();
39+
await builder.Build().RunAsync();
40+
41+
}
1742
}
1843
}

DemoApp/BlazorContextMenu.DemoApp.Client/Sources/GridSample.razor

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<table class="table">
55
<thead>
66
<tr>
7-
<th width="30px">Vacation?</th>
7+
<th width="30px">Favorite?</th>
88
<th>Date</th>
99
<th>Temp. (C)</th>
1010
<th>Temp. (F)</th>
@@ -14,10 +14,10 @@
1414
<tbody>
1515
@foreach (var forecast in forecasts)
1616
{
17-
<ContextMenuTrigger WrapperTag="tr" MenuId="tableContextMenu" Data="forecast" CssClass="@((forecast.MarkedDangerous ? "table-danger" : ""))">
17+
<ContextMenuTrigger WrapperTag="tr" MenuId="tableContextMenu" Data="forecast" CssClass="@((forecast.Highlight ? "table-primary" : ""))">
1818
<td>
1919
@{
20-
if (forecast.Vacation)
20+
if (forecast.Favorite)
2121
{
2222
<i class="fas fa-star" style="color:gold"></i>
2323
}
@@ -33,15 +33,15 @@
3333
</table>
3434

3535
<ContextMenu Id="tableContextMenu">
36-
<Item OnClick="@ReloadClick"> <i class="fas fa-sync-alt blue-icon"></i> Reload</Item>
36+
<Item OnClick="@LoadData"> <i class="fas fa-sync-alt blue-icon"></i> Reload</Item>
3737
<Item OnClick="@DeleteClick"> <i class="fas fa-trash-alt red-icon"></i> Delete</Item>
3838
<Item>
3939
Set
4040
<SubMenu>
4141
<Item OnClick="VacationClick">
4242
@{
4343
var forecast = context.Data as WeatherForecast;
44-
if (forecast.Vacation)
44+
if (forecast.Favorite)
4545
{
4646
<i class="far fa-star" style="color:gold"></i>
4747
}
@@ -50,12 +50,12 @@
5050
<i class="fas fa-star" style="color:gold"></i>
5151
}
5252
}
53-
Vacation
53+
Favorite
5454
</Item>
5555
<Item OnClick="DangerousClick">
5656
@{
5757
var forecast = context.Data as WeatherForecast;
58-
if (forecast.MarkedDangerous)
58+
if (forecast.Highlight)
5959
{
6060
<i class="far fa-flag" style="color:orangered"></i>
6161
}
@@ -64,7 +64,7 @@
6464
<i class="fas fa-flag" style="color:orangered"></i>
6565
}
6666
}
67-
Dangerous
67+
Highlight
6868
</Item>
6969
</SubMenu>
7070
</Item>
@@ -74,12 +74,12 @@
7474
List<WeatherForecast> forecasts = new List<WeatherForecast>();
7575
protected override async Task OnInitializedAsync()
7676
{
77-
forecasts = (await httpClient.GetJsonAsync<WeatherForecast[]>("api/SampleData/WeatherForecasts")).ToList();
77+
await LoadData();
7878
}
7979

80-
async Task ReloadClick(ItemClickEventArgs e)
80+
async Task LoadData()
8181
{
82-
forecasts = (await httpClient.GetJsonAsync<WeatherForecast[]>("api/SampleData/WeatherForecasts")).ToList();
82+
forecasts = (await httpClient.GetFromJsonAsync<WeatherForecast[]>("api/SampleData/WeatherForecasts")).ToList();
8383
}
8484

8585
void DeleteClick(ItemClickEventArgs e)
@@ -92,13 +92,13 @@
9292
{
9393
e.IsCanceled = true;
9494
var currentForecast = e.Data as WeatherForecast;
95-
currentForecast.Vacation = !currentForecast.Vacation;
95+
currentForecast.Favorite = !currentForecast.Favorite;
9696
}
9797

9898
void DangerousClick(ItemClickEventArgs e)
9999
{
100100
e.IsCanceled = true;
101101
var currentForecast = e.Data as WeatherForecast;
102-
currentForecast.MarkedDangerous = !currentForecast.MarkedDangerous;
102+
currentForecast.Highlight = !currentForecast.Highlight;
103103
}
104104
}

DemoApp/BlazorContextMenu.DemoApp.Client/Startup.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
@using System.Net.Http
2-
@using Microsoft.AspNetCore.Components
2+
@using Microsoft.AspNetCore.Components.Forms
33
@using Microsoft.AspNetCore.Components.Routing
44
@using Microsoft.AspNetCore.Components.Web
5+
@using Microsoft.AspNetCore.Components.Web.Virtualization
6+
@using Microsoft.AspNetCore.Components.WebAssembly.Http
7+
@using Microsoft.JSInterop
58
@using BlazorContextMenu.DemoApp.Client
69
@using BlazorContextMenu.DemoApp.Shared
710
@using BlazorContextMenu.DemoApp.Client.Shared
811
@using System.Linq
9-
@using Microsoft.JSInterop
1012
@using BlazorContextMenu
11-
@using Microsoft.AspNetCore.Components.Forms
13+
@using System.Net.Http.Json

DemoApp/BlazorContextMenu.DemoApp.Client/wwwroot/css/site.css

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,38 @@ html, body {
44
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
55
}
66

7-
app {
7+
#blazor-error-ui {
8+
background: lightyellow;
9+
bottom: 0;
10+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
11+
display: none;
12+
left: 0;
13+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
14+
position: fixed;
15+
width: 100%;
16+
z-index: 1000;
17+
}
18+
19+
.valid.modified:not([type=checkbox]) {
20+
outline: 1px solid #26b050;
21+
}
22+
23+
.invalid {
24+
outline: 1px solid red;
25+
}
26+
27+
.validation-message {
28+
color: red;
29+
}
30+
31+
#blazor-error-ui .dismiss {
32+
cursor: pointer;
33+
position: absolute;
34+
right: 0.75rem;
35+
top: 0.5rem;
36+
}
37+
38+
#app {
839
position: relative;
940
display: flex;
1041
flex-direction: column;
@@ -91,7 +122,7 @@ app {
91122
}
92123

93124
@media (min-width: 768px) {
94-
app {
125+
#app {
95126
flex-direction: row;
96127
}
97128

DemoApp/BlazorContextMenu.DemoApp.Client/wwwroot/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
<link href="css/prism.css" rel="stylesheet" />
1313
<link href="css/dark-menu.css" rel="stylesheet" />
1414
<link href="css/pink-menu.css" rel="stylesheet" />
15+
<link href="BlazorContextMenu.DemoApp.Client.styles.css" rel="stylesheet" />
1516
</head>
1617
<body>
17-
<app>
18+
<div id="app">
1819
<div class="loader-box">
1920
<img src="spinner.svg" width="70" />
2021
<br />
@@ -25,7 +26,7 @@
2526

2627
<!-- Added to force fa load -->
2728
<i style="visibility:hidden" class="fas fa-exclamation"></i>
28-
</app>
29+
</div>
2930

3031
<script src="loader.js"></script>
3132
<script>

DemoApp/BlazorContextMenu.DemoApp.Server/BlazorContextMenu.DemoApp.Server.csproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
<RestoreAdditionalProjectSources>
6-
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
7-
https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
8-
</RestoreAdditionalProjectSources>
4+
<TargetFramework>net6.0</TargetFramework>
95
</PropertyGroup>
106

117
<ItemGroup>
@@ -15,8 +11,7 @@
1511
</ItemGroup>
1612

1713
<ItemGroup>
18-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="3.1.0-preview4.19579.2" />
19-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.0" />
2015
</ItemGroup>
2116

2217
<ItemGroup>

DemoApp/BlazorContextMenu.DemoApp.Server/Startup.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.AspNetCore.ResponseCompression;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Hosting;
6-
using Newtonsoft.Json.Serialization;
76
using System.Linq;
87

98
namespace BlazorContextMenu.DemoApp.Server
@@ -14,7 +13,7 @@ public class Startup
1413
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
1514
public void ConfigureServices(IServiceCollection services)
1615
{
17-
services.AddMvc().AddNewtonsoftJson();
16+
services.AddMvc();
1817
services.AddResponseCompression(opts =>
1918
{
2019
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
@@ -30,18 +29,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3029
if (env.IsDevelopment())
3130
{
3231
app.UseDeveloperExceptionPage();
33-
app.UseBlazorDebugging();
32+
app.UseWebAssemblyDebugging();
3433
}
3534

35+
app.UseBlazorFrameworkFiles();
3636
app.UseStaticFiles();
37-
app.UseClientSideBlazorFiles<Client.Startup>();
3837

3938
app.UseRouting();
4039

4140
app.UseEndpoints(endpoints =>
4241
{
4342
endpoints.MapDefaultControllerRoute();
44-
endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
43+
endpoints.MapFallbackToFile("index.html");
4544
});
4645
}
4746
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<LangVersion>7.3</LangVersion>
4+
<TargetFramework>net6.0</TargetFramework>
65
</PropertyGroup>
76

7+
<ItemGroup>
8+
<SupportedPlatform Include="browser" />
9+
</ItemGroup>
10+
811
</Project>

0 commit comments

Comments
 (0)