Skip to content

Commit

Permalink
Blazor WebAssembly 8.0 sample updates (dotnet#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Dec 14, 2023
1 parent ac94d42 commit f6ade77
Show file tree
Hide file tree
Showing 209 changed files with 1,048 additions and 779 deletions.
12 changes: 9 additions & 3 deletions 8.0/BlazorSample_BlazorWebApp/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
<CascadingValue Value="@theme">
<article class="content px-4">
@Body
</article>
</CascadingValue>
</main>
</div>

Expand All @@ -21,3 +23,7 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

@code {
private ThemeInfo theme = new() { ButtonClass = "btn-success" };
}
17 changes: 0 additions & 17 deletions 8.0/BlazorSample_BlazorWebApp/Components/MainLayout.razor

This file was deleted.

19 changes: 0 additions & 19 deletions 8.0/BlazorSample_BlazorWebApp/Components/Pages/Example.razor

This file was deleted.

47 changes: 0 additions & 47 deletions 8.0/BlazorSample_BlazorWebApp/Components/Pages/FetchData.razor

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@using System
@using System.IO
@using Microsoft.AspNetCore.Hosting
@using Microsoft.Extensions.Logging
@inject ILogger<FileUpload1> Logger
@inject IWebHostEnvironment Environment

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page "/navigate"
@using Microsoft.Extensions.Logging
@implements IDisposable
@inject ILogger<Navigate> Logger
@inject NavigationManager Navigation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/route-parameter/{text?}"
@page "/optional-parameter/{text?}"

<h1>Blazor is @Text!</h1>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page "/product-details/{ProductId:int?}"
@using Microsoft.Extensions.Logging
@inject ILogger<ProductDetails> Logger
@inject IProductRepository Product

Expand Down Expand Up @@ -50,6 +49,7 @@ else

/*
* Register the service in Program.cs:
* using static BlazorSample.Components.Pages.ProductDetails;
* builder.Services.AddScoped<IProductRepository, ProductRepository>();
*/

Expand All @@ -65,7 +65,7 @@ else
return Task.FromResult(
new ProductDetail()
{
ProductName = "Flowbee®",
ProductName = "Flowbee ",
Description = "The Revolutionary Haircutting System " +
"You've Come to Love! https://flowbee.com/"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

/*
* Register the service in Program.cs:
* using static BlazorSample.Components.Pages.TheSunmakers;
* builder.Services.AddScoped<IDataAccess, DataAccess>();
*/

Expand Down
33 changes: 33 additions & 0 deletions 8.0/BlazorSample_BlazorWebApp/Components/Pages/ThemedCounter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@page "/themed-counter"

<PageTitle>Themed Counter</PageTitle>

<h1>Themed Counter Example</h1>

<p>Current count: @currentCount</p>

<p>
<button @onclick="IncrementCount">
Increment Counter (Unthemed)
</button>
</p>

<p>
<button
class="btn @(ThemeInfo is not null ? ThemeInfo.ButtonClass : string.Empty)"
@onclick="IncrementCount">
Increment Counter (Themed)
</button>
</p>

@code {
private int currentCount = 0;

[CascadingParameter]
protected ThemeInfo? ThemeInfo { get; set; }

private void IncrementCount()
{
currentCount++;
}
}
12 changes: 0 additions & 12 deletions 8.0/BlazorSample_BlazorWebApp/Components/Pages/User.razor

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BlazorSample.UIThemeClasses;
namespace BlazorSample;

public class ThemeInfo
{
Expand Down
7 changes: 4 additions & 3 deletions 8.0/BlazorSample_WebAssembly/ComponentMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public class ComponentMetadata
namespace BlazorSample;

public class ComponentMetadata
{
public string? Name { get; set; }
public Dictionary<string, object> Parameters { get; set; } =
new Dictionary<string, object>();
public Dictionary<string, object> Parameters { get; set; } = [];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@inherits LayoutComponentBase

<PageTitle>Doctor Who® Database</PageTitle>

<header>
<h1>Doctor Who&trade; Episode Database</h1>
<h1>Doctor Who® Database</h1>
</header>

<nav>
Expand All @@ -17,7 +19,7 @@
</footer>

@code {
public string TrademarkMessage { get; set; } =
public string TrademarkMessage { get; set; } =
"Doctor Who is a registered trademark of the BBC. " +
"https://www.doctorwho.tv/";
"https://www.doctorwho.tv/ https://www.bbc.com";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@inherits LayoutComponentBase
@layout ProductionsLayout

<h1>Doctor Who&trade; Episode Database</h1>
<PageTitle>Doctor Who® Database</PageTitle>

<h1>Doctor Who® Database</h1>

<nav>
<a href="main-episode-list">Main Episode List</a>
Expand All @@ -16,7 +18,7 @@
</div>

@code {
public string TrademarkMessage { get; set; } =
public string TrademarkMessage { get; set; } =
"Doctor Who is a registered trademark of the BBC. " +
"https://www.doctorwho.tv/";
"https://www.doctorwho.tv/ https://www.bbc.com";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@inherits LayoutComponentBase
@using BlazorSample.UIThemeClasses

<div class="page">
<div class="sidebar">
Expand Down
56 changes: 33 additions & 23 deletions 8.0/BlazorSample_WebAssembly/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
<div class="top-row ps-3 navbar navbar-dark">
@using System.Reflection
@using System.Text.RegularExpressions

<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">BlazorSample</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="">Blazor Sample</a>
</div>
</div>

<div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu">
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />

<div class="nav-scrollable"
onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested" aria-hidden="true"></span> Weather
<span class="bi bi-house-door-fill-nav-menu"
aria-hidden="true"></span> Home
</NavLink>
</div>

@foreach (var name in GetRoutableComponents())
{
<div class="nav-item px-3">
<NavLink class="nav-link"
href="@Regex.Replace(name, @"(\B[A-Z]|\d+)", "-$1").ToLower()">
@Regex.Replace(name, @"(\B[A-Z]|\d+)", " $1")
</NavLink>
</div>
}

</nav>
</div>

@code {
private bool collapseNavMenu = true;

private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
public IEnumerable<string> GetRoutableComponents()
{
collapseNavMenu = !collapseNavMenu;
return Assembly.GetExecutingAssembly()
.ExportedTypes
.Where(t => t.IsSubclassOf(typeof(ComponentBase)))
.Where(c => c.GetCustomAttributes(inherit: true)
.OfType<RouteAttribute>()
.ToArray()
.Count() > 0)
.Where(c => c.Name != "Home" && c.Name != "Error")
.OrderBy(o => o.Name)
.Select(c => c.Name);
}
}
24 changes: 12 additions & 12 deletions 8.0/BlazorSample_WebAssembly/Components/Layout/NavMenu.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
background-size: cover;
}

.bi-house-door-fill {
.bi-house-door-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
}

.bi-plus-square-fill {
.bi-plus-square-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
}

.bi-list-nested {
.bi-list-nested-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
}

Expand All @@ -55,15 +55,15 @@
line-height: 3rem;
}

.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
}

.nav-item ::deep a:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.nav-item ::deep a:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}

@media (min-width: 641px) {
.navbar-toggler {
Expand All @@ -74,7 +74,7 @@
/* Never collapse the sidebar for wide screens */
display: block;
}

.nav-scrollable {
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
Expand Down
Loading

0 comments on commit f6ade77

Please sign in to comment.