-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Aspnetcore has a sample of Blazor wasm standalone in-tree #64624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ilonatommy
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
ilonatommy:add-standalone-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+563
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d98e043
Add sample sources.
ilonatommy fe5a8bc
Fix "Generated code is not up to date" errors.
ilonatommy 00e9273
Merge branch 'main' into add-standalone-sample
ilonatommy 7b8d837
Add new sample to the doc for AI agent.
ilonatommy de6a9db
Merge branch 'main' into add-standalone-sample
ilonatommy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <Router AppAssembly="@typeof(App).Assembly" NotFoundPage="typeof(Pages.NotFound)"> | ||
| <Found Context="routeData"> | ||
| <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/> | ||
| <FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
| </Found> | ||
| </Router> | ||
18 changes: 18 additions & 0 deletions
18
src/Components/Samples/BlazorWasmStandalone/BlazorWasmStandalone.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
| <IsShippingPackage>false</IsShippingPackage> | ||
| <Nullable>enable</Nullable> | ||
| <StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders> | ||
| <ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="Microsoft.AspNetCore.Components.WebAssembly" /> | ||
| <Reference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
16 changes: 16 additions & 0 deletions
16
src/Components/Samples/BlazorWasmStandalone/Layout/MainLayout.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| @inherits LayoutComponentBase | ||
| <div class="page"> | ||
| <div class="sidebar"> | ||
| <NavMenu /> | ||
| </div> | ||
|
|
||
| <main> | ||
| <div class="top-row px-4"> | ||
| <a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a> | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
|
|
||
| <article class="content px-4"> | ||
| @Body | ||
| </article> | ||
| </main> | ||
| </div> | ||
77 changes: 77 additions & 0 deletions
77
src/Components/Samples/BlazorWasmStandalone/Layout/MainLayout.razor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| .page { | ||
| position: relative; | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| main { | ||
| flex: 1; | ||
| } | ||
|
|
||
| .sidebar { | ||
| background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); | ||
| } | ||
|
|
||
| .top-row { | ||
| background-color: #f7f7f7; | ||
| border-bottom: 1px solid #d6d5d5; | ||
| justify-content: flex-end; | ||
| height: 3.5rem; | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .top-row ::deep a, .top-row ::deep .btn-link { | ||
| white-space: nowrap; | ||
| margin-left: 1.5rem; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { | ||
| text-decoration: underline; | ||
| } | ||
|
|
||
| .top-row ::deep a:first-child { | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| } | ||
|
|
||
| @media (max-width: 640.98px) { | ||
| .top-row { | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| .top-row ::deep a, .top-row ::deep .btn-link { | ||
| margin-left: 0; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 641px) { | ||
| .page { | ||
| flex-direction: row; | ||
| } | ||
|
|
||
| .sidebar { | ||
| width: 250px; | ||
| height: 100vh; | ||
| position: sticky; | ||
| top: 0; | ||
| } | ||
|
|
||
| .top-row { | ||
| position: sticky; | ||
| top: 0; | ||
| z-index: 1; | ||
| } | ||
|
|
||
| .top-row.auth ::deep a:first-child { | ||
| flex: 1; | ||
| text-align: right; | ||
| width: 0; | ||
| } | ||
|
|
||
| .top-row, article { | ||
| padding-left: 2rem !important; | ||
| padding-right: 1.5rem !important; | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/Components/Samples/BlazorWasmStandalone/Layout/NavMenu.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <div class="top-row ps-3 navbar navbar-dark"> | ||
| <div class="container-fluid"> | ||
| <a class="navbar-brand" href="">BlazorWasmStandalone</a> | ||
| <button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu"> | ||
| <span class="navbar-toggler-icon"></span> | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu"> | ||
| <nav class="nav flex-column"> | ||
| <div class="nav-item px-3"> | ||
| <NavLink class="nav-link" href="" Match="NavLinkMatch.All"> | ||
| <span class="bi bi-house-door-fill-nav-menu" 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-nav-menu" 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-nav-menu" aria-hidden="true"></span> Weather | ||
| </NavLink> | ||
| </div> | ||
| </nav> | ||
| </div> | ||
|
|
||
| @code { | ||
| private bool collapseNavMenu = true; | ||
|
|
||
| private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; | ||
|
|
||
| private void ToggleNavMenu() | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| collapseNavMenu = !collapseNavMenu; | ||
| } | ||
| } | ||
83 changes: 83 additions & 0 deletions
83
src/Components/Samples/BlazorWasmStandalone/Layout/NavMenu.razor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| .navbar-toggler { | ||
| background-color: rgba(255, 255, 255, 0.1); | ||
| } | ||
|
|
||
| .top-row { | ||
| min-height: 3.5rem; | ||
| background-color: rgba(0,0,0,0.4); | ||
| } | ||
|
|
||
| .navbar-brand { | ||
| font-size: 1.1rem; | ||
| } | ||
|
|
||
| .bi { | ||
| display: inline-block; | ||
| position: relative; | ||
| width: 1.25rem; | ||
| height: 1.25rem; | ||
| margin-right: 0.75rem; | ||
| top: -1px; | ||
| background-size: cover; | ||
| } | ||
|
|
||
| .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-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-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"); | ||
| } | ||
|
|
||
| .nav-item { | ||
| font-size: 0.9rem; | ||
| padding-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .nav-item:first-of-type { | ||
| padding-top: 1rem; | ||
| } | ||
|
|
||
| .nav-item:last-of-type { | ||
| padding-bottom: 1rem; | ||
| } | ||
|
|
||
| .nav-item ::deep a { | ||
| color: #d7d7d7; | ||
| border-radius: 4px; | ||
| height: 3rem; | ||
| display: flex; | ||
| align-items: center; | ||
| line-height: 3rem; | ||
| } | ||
|
|
||
| .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; | ||
| } | ||
|
|
||
| @media (min-width: 641px) { | ||
| .navbar-toggler { | ||
| display: none; | ||
| } | ||
|
|
||
| .collapse { | ||
| /* Never collapse the sidebar for wide screens */ | ||
| display: block; | ||
| } | ||
|
|
||
| .nav-scrollable { | ||
| /* Allow sidebar to scroll for tall menus */ | ||
| height: calc(100vh - 3.5rem); | ||
| overflow-y: auto; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/Components/Samples/BlazorWasmStandalone/Pages/Counter.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| @page "/counter" | ||
|
|
||
| <PageTitle>Counter</PageTitle> | ||
|
|
||
| <h1>Counter</h1> | ||
|
|
||
| <p role="status">Current count: @currentCount</p> | ||
|
|
||
| <button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | ||
|
|
||
| @code { | ||
| private int currentCount = 0; | ||
|
|
||
| private void IncrementCount() | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| currentCount++; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| @page "/" | ||
|
|
||
| <PageTitle>Home</PageTitle> | ||
|
|
||
| <h1>Hello, world!</h1> | ||
|
|
||
| Welcome to your new app. |
5 changes: 5 additions & 0 deletions
5
src/Components/Samples/BlazorWasmStandalone/Pages/NotFound.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @page "/not-found" | ||
| @layout MainLayout | ||
|
|
||
| <h3>Not Found</h3> | ||
| <p>Sorry, the content you are looking for does not exist.</p> |
57 changes: 57 additions & 0 deletions
57
src/Components/Samples/BlazorWasmStandalone/Pages/Weather.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| @page "/weather" | ||
| @inject HttpClient Http | ||
|
|
||
| <PageTitle>Weather</PageTitle> | ||
|
|
||
| <h1>Weather</h1> | ||
|
|
||
| <p>This component demonstrates fetching data from the server.</p> | ||
|
|
||
| @if (forecasts == null) | ||
| { | ||
| <p><em>Loading...</em></p> | ||
| } | ||
| else | ||
| { | ||
| <table class="table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Date</th> | ||
| <th aria-label="Temperature in Celsius">Temp. (C)</th> | ||
| <th aria-label="Temperature in Fahrenheit">Temp. (F)</th> | ||
| <th>Summary</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| @foreach (var forecast in forecasts) | ||
| { | ||
| <tr> | ||
| <td>@forecast.Date.ToShortDateString()</td> | ||
| <td>@forecast.TemperatureC</td> | ||
| <td>@forecast.TemperatureF</td> | ||
| <td>@forecast.Summary</td> | ||
| </tr> | ||
| } | ||
| </tbody> | ||
| </table> | ||
| } | ||
|
|
||
| @code { | ||
| private WeatherForecast[]? forecasts; | ||
|
|
||
| protected override async Task OnInitializedAsync() | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json"); | ||
| } | ||
|
|
||
| public class WeatherForecast | ||
| { | ||
| public DateOnly Date { get; set; } | ||
|
|
||
| public int TemperatureC { get; set; } | ||
|
|
||
| public string? Summary { get; set; } | ||
|
|
||
| public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.AspNetCore.Components.Web; | ||
| using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
| using BlazorWasmStandalone; | ||
| using System.Net.Http; | ||
|
|
||
| var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
| builder.RootComponents.Add<App>("#app"); | ||
| builder.RootComponents.Add<HeadOutlet>("head::after"); | ||
|
|
||
| builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||
|
|
||
| await builder.Build().RunAsync(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.