Skip to content

Commit 3cf39cf

Browse files
authored
Update the templates CSS to leverage CSS isolation (#24380)
* Template changes * Template changes + scope computation update * Template updates * tmp * Fix style path * Webassembly template changes * Update tests * Undo blazor.server.js changes * WebAssembly cleanups * Undo unwanted change * Undo another unwanted change * Fix server-side login combinator * update tests, switch from app to div id=app
1 parent 28d5d49 commit 3cf39cf

File tree

18 files changed

+385
-318
lines changed

18 files changed

+385
-318
lines changed

src/ProjectTemplates/BlazorTemplates.Tests/BlazorServerTemplateTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public BlazorServerTemplateTest(ProjectFactoryFixture projectFactory, BrowserFix
3030
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/20172")]
3131
public async Task BlazorServerTemplateWorks_NoAuth()
3232
{
33+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
34+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
35+
3336
Project = await ProjectFactory.GetOrCreateProject("blazorservernoauth", Output);
3437

3538
var createResult = await Project.RunDotNetNewAsync("blazorserver");
@@ -88,6 +91,9 @@ public async Task BlazorServerTemplateWorks_NoAuth()
8891
[QuarantinedTest]
8992
public async Task BlazorServerTemplateWorks_IndividualAuth(bool useLocalDB)
9093
{
94+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
95+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
96+
9197
Project = await ProjectFactory.GetOrCreateProject("blazorserverindividual" + (useLocalDB ? "uld" : ""), Output);
9298

9399
var createResult = await Project.RunDotNetNewAsync("blazorserver", auth: "Individual", useLocalDB: useLocalDB);

src/ProjectTemplates/BlazorTemplates.Tests/BlazorWasmTemplateTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public override Task InitializeAsync()
4343
[Fact]
4444
public async Task BlazorWasmStandaloneTemplate_Works()
4545
{
46+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
47+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
48+
4649
var project = await ProjectFactory.GetOrCreateProject("blazorstandalone", Output);
4750
project.RuntimeIdentifier = "browser-wasm";
4851

@@ -81,6 +84,9 @@ public async Task BlazorWasmStandaloneTemplate_Works()
8184
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/20172")]
8285
public async Task BlazorWasmHostedTemplate_Works()
8386
{
87+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
88+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
89+
8490
var project = await ProjectFactory.GetOrCreateProject("blazorhosted", Output);
8591

8692
var createResult = await project.RunDotNetNewAsync("blazorwasm", args: new[] { "--hosted" });
@@ -134,6 +140,9 @@ private static async Task AssertCompressionFormat(AspNetProcess aspNetProcess, s
134140
[Fact]
135141
public async Task BlazorWasmStandalonePwaTemplate_Works()
136142
{
143+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
144+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
145+
137146
var project = await ProjectFactory.GetOrCreateProject("blazorstandalonepwa", Output);
138147
project.RuntimeIdentifier = "browser-wasm";
139148

@@ -173,6 +182,9 @@ public async Task BlazorWasmStandalonePwaTemplate_Works()
173182
[Fact]
174183
public async Task BlazorWasmHostedPwaTemplate_Works()
175184
{
185+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
186+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
187+
176188
var project = await ProjectFactory.GetOrCreateProject("blazorhostedpwa", Output);
177189

178190
var createResult = await project.RunDotNetNewAsync("blazorwasm", args: new[] { "--hosted", "--pwa" });
@@ -266,6 +278,9 @@ public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithOutLocalDB()
266278

267279
private async Task BlazorWasmHostedTemplate_IndividualAuth_Works(bool useLocalDb)
268280
{
281+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
282+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
283+
269284
var project = await ProjectFactory.GetOrCreateProject("blazorhostedindividual" + (useLocalDb ? "uld" : ""), Output);
270285

271286
var createResult = await project.RunDotNetNewAsync("blazorwasm", args: new[] { "--hosted", "-au", "Individual", useLocalDb ? "-uld" : "" });
@@ -333,6 +348,9 @@ private async Task BlazorWasmHostedTemplate_IndividualAuth_Works(bool useLocalDb
333348
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/23639")]
334349
public async Task BlazorWasmStandaloneTemplate_IndividualAuth_Works()
335350
{
351+
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
352+
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
353+
336354
var project = await ProjectFactory.GetOrCreateProject("blazorstandaloneindividual", Output);
337355
project.RuntimeIdentifier = "browser-wasm";
338356

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/_Host.cshtml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
<base href="~/" />
1515
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
1616
<link href="css/site.css" rel="stylesheet" />
17+
<link href="_content/BlazorServerWeb-CSharp/_framework/scoped.styles.css" rel="stylesheet" />
1718
</head>
1819
<body>
19-
<app>
20-
<component type="typeof(App)" render-mode="ServerPrerendered" />
21-
</app>
20+
<component type="typeof(App)" render-mode="ServerPrerendered" />
2221

2322
<div id="blazor-error-ui">
2423
<environment include="Staging,Production">
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
@inherits LayoutComponentBase
22

3-
<div class="sidebar">
4-
<NavMenu />
5-
</div>
6-
7-
<div class="main">
8-
<div class="top-row px-4 auth">
9-
<LoginDisplay />
10-
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
3+
<div class="page">
4+
<div class="sidebar">
5+
<NavMenu />
116
</div>
127

13-
<div class="content px-4">
14-
@Body
8+
<div class="main">
9+
<div class="top-row px-4 auth">
10+
<LoginDisplay />
11+
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
12+
</div>
13+
14+
<div class="content px-4">
15+
@Body
16+
</div>
1517
</div>
1618
</div>
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
@inherits LayoutComponentBase
22

3-
<div class="sidebar">
4-
<NavMenu />
5-
</div>
6-
7-
<div class="main">
8-
<div class="top-row px-4">
9-
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
3+
<div class="page">
4+
<div class="sidebar">
5+
<NavMenu />
106
</div>
117

12-
<div class="content px-4">
13-
@Body
8+
<div class="main">
9+
<div class="top-row px-4">
10+
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
11+
</div>
12+
13+
<div class="content px-4">
14+
@Body
15+
</div>
1416
</div>
1517
</div>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.page {
2+
position: relative;
3+
display: flex;
4+
flex-direction: column;
5+
}
6+
7+
.main {
8+
flex: 1;
9+
}
10+
11+
.sidebar {
12+
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
13+
}
14+
15+
.top-row {
16+
background-color: #f7f7f7;
17+
border-bottom: 1px solid #d6d5d5;
18+
justify-content: flex-end;
19+
height: 3.5rem;
20+
display: flex;
21+
align-items: center;
22+
}
23+
24+
.top-row ::deep a, .top-row .btn-link {
25+
white-space: nowrap;
26+
margin-left: 1.5rem;
27+
}
28+
29+
.top-row a:first-child {
30+
overflow: hidden;
31+
text-overflow: ellipsis;
32+
}
33+
34+
@media (max-width: 767.98px) {
35+
.top-row:not(.auth) {
36+
display: none;
37+
}
38+
39+
.top-row.auth {
40+
justify-content: space-between;
41+
}
42+
43+
.top-row a, .top-row .btn-link {
44+
margin-left: 0;
45+
}
46+
}
47+
48+
@media (min-width: 768px) {
49+
.page {
50+
flex-direction: row;
51+
}
52+
53+
.sidebar {
54+
width: 250px;
55+
height: 100vh;
56+
position: sticky;
57+
top: 0;
58+
}
59+
60+
.top-row {
61+
position: sticky;
62+
top: 0;
63+
z-index: 1;
64+
}
65+
66+
.main > div {
67+
padding-left: 2rem !important;
68+
padding-right: 1.5rem !important;
69+
}
70+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.navbar-toggler {
2+
background-color: rgba(255, 255, 255, 0.1);
3+
}
4+
5+
.top-row {
6+
height: 3.5rem;
7+
background-color: rgba(0,0,0,0.4);
8+
}
9+
10+
.navbar-brand {
11+
font-size: 1.1rem;
12+
}
13+
14+
.oi {
15+
width: 2rem;
16+
font-size: 1.1rem;
17+
vertical-align: text-top;
18+
top: -2px;
19+
}
20+
21+
.nav-item {
22+
font-size: 0.9rem;
23+
padding-bottom: 0.5rem;
24+
}
25+
26+
.nav-item:first-of-type {
27+
padding-top: 1rem;
28+
}
29+
30+
.nav-item:last-of-type {
31+
padding-bottom: 1rem;
32+
}
33+
34+
.nav-item ::deep a {
35+
color: #d7d7d7;
36+
border-radius: 4px;
37+
height: 3rem;
38+
display: flex;
39+
align-items: center;
40+
line-height: 3rem;
41+
}
42+
43+
.nav-item ::deep a.active {
44+
background-color: rgba(255,255,255,0.25);
45+
color: white;
46+
}
47+
48+
.nav-item ::deep a:hover {
49+
background-color: rgba(255,255,255,0.1);
50+
color: white;
51+
}
52+
53+
@media (min-width: 768px) {
54+
.navbar-toggler {
55+
display: none;
56+
}
57+
58+
.collapse {
59+
/* Never collapse the sidebar for wide screens */
60+
display: block;
61+
}
62+
}

0 commit comments

Comments
 (0)