Initial commit

This commit is contained in:
Jimmy Engström 2023-02-17 15:28:17 +01:00
parent 2190113c56
commit 3088165398
1765 changed files with 192085 additions and 0 deletions

View file

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Data.Models\Data.Models.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,11 @@
@page "/alerttest"
@using Components.RazorComponents
<Alert Style="Alert.AlertStyle.Danger">
This is a test
</Alert>
<Alert Style="Alert.AlertStyle.Success">
<ChildContent>
This is another test
</ChildContent>
</Alert>
<Alert Style="Alert.AlertStyle.Success"/>

View file

@ -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()
{
currentCount++;
}
}

View file

@ -0,0 +1,22 @@
@page "/counterwithparameter"
<h1>Counter</h1>
<p>Current count: @CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
[Parameter]
public int IncrementAmount { get; set; } = 1;
[Parameter]
public int CurrentCount { get; set; } = 0;
//private void IncrementCount()
//{
// CurrentCount+=IncrementAmount;
//}
[Parameter]
public EventCallback<int> CurrentCountChanged { get; set; }
private void IncrementCount()
{
CurrentCount += IncrementAmount;
CurrentCountChanged.InvokeAsync(CurrentCount);
}
}

View file

@ -0,0 +1,4 @@
<h3>ComponentWithError</h3>
<button @onclick="@(()=>{ throw new Exception("This is an error");})">Throw error</button>

View file

@ -0,0 +1,9 @@
@page "/customerrorboundary"
<ErrorBoundary>
<ChildContent>
<ComponentWithError />
</ChildContent>
<ErrorContent>
<h1 style="color: red;">Oops... something broke</h1>
</ErrorContent>
</ErrorBoundary>

View file

@ -0,0 +1,4 @@
@page "/errorboundary"
<ErrorBoundary>
<ComponentWithError />
</ErrorBoundary>

View file

@ -0,0 +1,13 @@
@page "/errorboundarytest"
<ErrorBoundary Context=ex>
<ChildContent>
<p>@(1/zero)</p>
</ChildContent>
<ErrorContent>
An error occured
@ex.Message
</ErrorContent>
</ErrorBoundary>
@code {
int zero = 0;
}

View file

@ -0,0 +1,30 @@
@page "/"
@using Data.Models.Interfaces
@using Data.Models
@inject IBlogApi _api
<ul>
<Virtualize ItemsProvider="LoadPosts" Context="p">
<li><a href="/Post/@p.Id">@p.Title</a></li>
</Virtualize>
</ul>
@code {
public int totalBlogposts { get; set; }
private async ValueTask<ItemsProviderResult<BlogPost>> LoadPosts(ItemsProviderRequest request)
{
if (totalBlogposts == 0)
{
totalBlogposts = await _api.GetBlogPostCountAsync();
}
var numblogposts = Math.Min(request.Count, totalBlogposts - request.StartIndex);
var blogposts = await _api.GetBlogPostsAsync(numblogposts, request.StartIndex);
return new ItemsProviderResult<BlogPost>(blogposts, totalBlogposts);
}
}

View file

@ -0,0 +1,10 @@
@page "/parentcounter"
<CounterWithParameterAndEvent IncrementAmount="@incrementamount" @bind-CurrentCount="currentcount"/>
The current count is: @currentcount
@code {
int incrementamount = 10;
int currentcount = 0;
}

View file

@ -0,0 +1,30 @@
@page "/post/{BlogPostId}"
@inject IBlogApi _api
@inject NavigationManager _navman
@if (BlogPost != null)
{
<PageTitle>@BlogPost.Title</PageTitle>
<HeadContent>
<meta property="og:title" content="@BlogPost.Title" />
<meta property="og:description" content="@(new string(BlogPost.Text.Take(100).ToArray()))" />
<meta property="og:image" content="@($"{_navman.BaseUri}/pathtoanimage.png")" />
<meta property="og:url" content="@_navman.Uri" />
<meta name="twitter:card" content="@(new string(BlogPost.Text.Take(100).ToArray()))" />
</HeadContent>
<h2>@BlogPost.Title</h2>
@((MarkupString)BlogPost.Text)
}
@code {
[Parameter]
public string BlogPostId { get; set; }
public BlogPost? BlogPost { get; set; }
protected async override Task OnParametersSetAsync()
{
BlogPost = await _api.GetBlogPostAsync(BlogPostId);
await base.OnParametersSetAsync();
}
}

View file

@ -0,0 +1,8 @@
@page "/setfocus"
<input @ref="textInput" />
<button @onclick="() => textInput.FocusAsync()">Set focus</button>
@code {
ElementReference textInput;
}

View file

@ -0,0 +1,20 @@
<div class="@($"alert alert-{Style.ToString().ToLower()}")" role="alert">
@ChildContent
</div>
@code{
[Parameter]
public RenderFragment ChildContent { get; set; } =@<b>This is a default value</b>;
[Parameter]
public AlertStyle Style { get; set; }
public enum AlertStyle
{
Primary,
Secondary,
Success,
Danger,
Warning,
Info,
Light,
Dark
}
}

View file

@ -0,0 +1,17 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>

View file

@ -0,0 +1,81 @@
.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:not(.auth) {
display: none;
}
.top-row.auth {
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;
}
}

View file

@ -0,0 +1,39 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">BlazorWebAssembly</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="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</div>
</nav>
</div>
@code {
private bool collapseNavMenu = true;
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}

View file

@ -0,0 +1,68 @@
.navbar-toggler {
background-color: rgba(255, 255, 255, 0.1);
}
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}
.navbar-brand {
font-size: 1.1rem;
}
.oi {
width: 2rem;
font-size: 1.1rem;
vertical-align: text-top;
top: -2px;
}
.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.25);
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;
}
}

View file

@ -0,0 +1,16 @@
<div class="alert alert-secondary mt-4">
<span class="oi oi-pencil me-2" aria-hidden="true"></span>
<strong>@Title</strong>
<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold link-dark" href="https://go.microsoft.com/fwlink/?linkid=2186157">brief survey</a>
</span>
and tell us what you think.
</div>
@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string? Title { get; set; }
}

View file

@ -0,0 +1,11 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Components.Pages
@using Components.Shared
@using Data.Models.Interfaces
@using Data.Models

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

View file

@ -0,0 +1,6 @@
// This is a JavaScript module that is loaded on demand. It can export any number of
// functions, and may import other JavaScript modules if required.
export function showPrompt(message) {
return prompt(message, 'Type anything here');
}