component razor remade

tpBlazor
runtenick 2 years ago
parent eb317e8dc6
commit 9e0d0dfa4b

@ -1,5 +1,6 @@
<h3>Card</h3> @typeparam TItem
<div class="card text-center">
@code { @CardHeader(Item)
@CardBody(Item)
} @CardFooter
</div>

@ -0,0 +1,21 @@
using Blazorise;
using BlazorTp1.Models;
using Microsoft.AspNetCore.Components;
namespace BlazorTp1.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; }
}
}

@ -41,7 +41,6 @@
<CraftingItem Item="RecipeResult"/> <CraftingItem Item="RecipeResult"/>
</div> </div>
</div> </div>
<div class="col-12"> <div class="col-12">
<div>Actions</div> <div>Actions</div>
<div class="actions" id="actions"> <div class="actions" id="actions">

@ -25,10 +25,6 @@ namespace BlazorTp1.Components
public List<Item> RecipeItems { get; set; } public List<Item> RecipeItems { get; set; }
//se der ruim tirar esse attributo
[CascadingParameter]
public Crafting Parent { get; set; }
public Item RecipeResult public Item RecipeResult
{ {
get => this._recipeResult; get => this._recipeResult;
@ -47,7 +43,6 @@ namespace BlazorTp1.Components
[Parameter] [Parameter]
public List<CraftingRecipe> Recipes { get; set; } public List<CraftingRecipe> Recipes { get; set; }
/// <summary> /// <summary>
/// Gets or sets the java script runtime. /// Gets or sets the java script runtime.
/// </summary> /// </summary>

@ -0,0 +1,6 @@
.item {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}

@ -0,0 +1,12 @@
@typeparam TItem
<div>
@if ((Items?.Count ?? 0) != 0)
{
@foreach (var item in Items)
{
@ShowTemplate(item)
;
}
}
</div>

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;
namespace BlazorTp1.Components
{
public partial class ShowItems<TItem>
{
[Parameter]
public List<TItem> Items { get; set; }
[Parameter]
public RenderFragment<TItem> ShowTemplate { get; set; }
}
}

@ -1,5 +1,6 @@
@page "/" @page "/"
@using System.Globalization @using System.Globalization
@using BlazorTp1.Components
<PageTitle>Index</PageTitle> <PageTitle>Index</PageTitle>
@ -15,24 +16,6 @@ Welcome to your new app.
<Crafting Items="Items" Recipes="Recipes" /> <Crafting Items="Items" Recipes="Recipes" />
</div> </div>
<Card>
<CardHeader>
<div class="card-header">
My Templated Component
</div>
</CardHeader>
<CardBody>
<div class="card-body">
<h5>Welcome To Template Component</h5>
</div>
</CardBody>
<CardFooter>
<div class="card-footer text-muted">
Click Here
</div>
</CardFooter>
</Card>
<SurveyPrompt Title="How is Blazor working for you?" /> <SurveyPrompt Title="How is Blazor working for you?" />

@ -7,18 +7,25 @@ namespace BlazorTp1.Pages
public partial class Index public partial class Index
{ {
[Inject] [Inject]
public IDataService DataService { get; set; } public IDataService? DataService { get; set; }
public List<Item> Items { get; set; } = new List<Item>(); public List<Item> Items { get; set; } = new List<Item>();
private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>(); private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>();
protected override async Task OnInitializedAsync() protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
await base.OnInitializedAsync(); base.OnAfterRenderAsync(firstRender);
if (!firstRender)
{
return;
}
Items = await DataService.List(0, await DataService.Count()); Items = await DataService.List(0, await DataService.Count());
Recipes = await DataService.GetRecipes(); Recipes = await DataService.GetRecipes();
StateHasChanged();
} }
} }
} }

Loading…
Cancel
Save