parent
e258f278f0
commit
69b97da69f
@ -0,0 +1,6 @@
|
|||||||
|
@typeparam TItem
|
||||||
|
<div class="card text-center">
|
||||||
|
@CardHeader(Item)
|
||||||
|
@CardBody(Item)
|
||||||
|
@CardFooter
|
||||||
|
</div>
|
@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace BlazorProject.Components;
|
||||||
|
|
||||||
|
public partial class Card<TItem>
|
||||||
|
{
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment<TItem> CardBody { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment CardFooter { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment<TItem> CardHeader { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public TItem Item { get; set; }
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
@typeparam TItem
|
||||||
|
|
||||||
|
<div>
|
||||||
|
@if ((Items?.Count ?? 0) != 0)
|
||||||
|
{
|
||||||
|
@foreach (var item in Items)
|
||||||
|
{
|
||||||
|
@ShowTemplate(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace BlazorProject.Components;
|
||||||
|
|
||||||
|
public partial class ShowItems<TItem>
|
||||||
|
{
|
||||||
|
[Parameter]
|
||||||
|
public List<TItem> Items { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment<TItem> ShowTemplate { get; set; }
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using BlazorProject.Models;
|
||||||
|
|
||||||
|
namespace BlazorProject.Layout;
|
||||||
|
|
||||||
|
public partial class MainLayout
|
||||||
|
{
|
||||||
|
public List<Cake> Cakes { get; set; }
|
||||||
|
|
||||||
|
protected override Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
LoadCakes();
|
||||||
|
StateHasChanged();
|
||||||
|
return base.OnAfterRenderAsync(firstRender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadCakes()
|
||||||
|
{
|
||||||
|
Cakes = new List<Cake>
|
||||||
|
{
|
||||||
|
// items hidden for display purpose
|
||||||
|
new Cake
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Name = "Red Velvet",
|
||||||
|
Cost = 60
|
||||||
|
},
|
||||||
|
new Cake
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
Name = "Black Forest",
|
||||||
|
Cost = 50
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
@typeparam TItem
|
||||||
|
@using System.Diagnostics.CodeAnalysis
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>@TableHeader</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Items)
|
||||||
|
{
|
||||||
|
if (RowTemplate is not null)
|
||||||
|
{
|
||||||
|
<tr>@RowTemplate(item)</tr>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment? TableHeader { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment<TItem>? RowTemplate { get; set; }
|
||||||
|
|
||||||
|
[Parameter, AllowNull]
|
||||||
|
public IReadOnlyList<TItem> Items { get; set; }
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace BlazorProject.Models;
|
||||||
|
|
||||||
|
public class Cake
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public decimal Cost { get; set; }
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
@page "/pets1"
|
||||||
|
|
||||||
|
<h1>Pets</h1>
|
||||||
|
|
||||||
|
<TableTemplate Items="pets" Context="pet">
|
||||||
|
<TableHeader>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
</TableHeader>
|
||||||
|
<RowTemplate>
|
||||||
|
<td>@pet.PetId</td>
|
||||||
|
<td>@pet.Name</td>
|
||||||
|
</RowTemplate>
|
||||||
|
</TableTemplate>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<Pet> pets = new()
|
||||||
|
{
|
||||||
|
new Pet { PetId = 2, Name = "Mr. Bigglesworth" },
|
||||||
|
new Pet { PetId = 4, Name = "Salem Saberhagen" },
|
||||||
|
new Pet { PetId = 7, Name = "K-9" }
|
||||||
|
};
|
||||||
|
|
||||||
|
private class Pet
|
||||||
|
{
|
||||||
|
public int PetId { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
@page "/pets2"
|
||||||
|
|
||||||
|
<h1>Pets</h1>
|
||||||
|
|
||||||
|
<TableTemplate Items="pets">
|
||||||
|
<TableHeader>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
</TableHeader>
|
||||||
|
<RowTemplate Context="pet">
|
||||||
|
<td>@pet.PetId</td>
|
||||||
|
<td>@pet.Name</td>
|
||||||
|
</RowTemplate>
|
||||||
|
</TableTemplate>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<Pet> pets = new()
|
||||||
|
{
|
||||||
|
new Pet { PetId = 2, Name = "Mr. Bigglesworth" },
|
||||||
|
new Pet { PetId = 4, Name = "Salem Saberhagen" },
|
||||||
|
new Pet { PetId = 7, Name = "K-9" }
|
||||||
|
};
|
||||||
|
|
||||||
|
private class Pet
|
||||||
|
{
|
||||||
|
public int PetId { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue