Skip to content

Commit

Permalink
Added Hero editor component in Blazor
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenoage committed Nov 8, 2023
1 parent f11172a commit f5faafa
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Blazor/Components/Counter.razor.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
div {
display: inline-block;
border: 2px solid black;
background: #eee;
border: 2px solid #55328c;
background: #f0eaf7;
padding: 1em;
margin: 1em;
background-image: url("assets/blazor-icon.png");
background-repeat: no-repeat;
}
29 changes: 29 additions & 0 deletions Blazor/Components/HeroEditor.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="container">
<div><span>id: </span>@Hero.id</div>
<div>
<label for="hero-name">Hero name: </label>
<input id="hero-name" @bind="newName" placeholder="Hero name" @bind:event="oninput" @onkeyup="UpdateHero" />
</div>
</div>

@code {

[Parameter]
public Hero Hero { get; set; } = new(0, "");

[Parameter]
public EventCallback<Hero> HeroChanged { get; set; }

private string newName = "";


protected override void OnParametersSet() {
newName = Hero.name;
}

private async Task UpdateHero() {
Hero = Hero with { name = newName };
await HeroChanged.InvokeAsync(Hero);
}

}
9 changes: 9 additions & 0 deletions Blazor/Components/HeroEditor.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
div.container {
display: inline-block;
border: 2px solid #55328c;
background: #f0eaf7;
padding: 30px;
margin: 1em;
background-image: url("assets/blazor-icon.png");
background-repeat: no-repeat;
}
20 changes: 17 additions & 3 deletions Blazor/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

<h1>Blazor Components Test Project</h1>

<Counter />
<Counter />
<Counter />
<div>
<Counter />
<Counter />
<Counter />
</div>

<HeroEditor Hero="@testHero" HeroChanged="OnHeroChanged"/>

@code {
private Hero testHero = new(5, "Arnold");

private void OnHeroChanged(Hero hero) {
testHero = hero;
Console.WriteLine("Hero changed: " + hero);
}

}
Binary file added Blazor/wwwroot/assets/blazor-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f5faafa

Please sign in to comment.