Skip to content

Commit

Permalink
Initial button with Command feature (#124)
Browse files Browse the repository at this point in the history
* Started work on Button CommandName, CommandArgument and OnCommand feature
* Added Cascading Parent

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs

Co-Authored-By: Egil Hansen <egil@assimilated.dk>

* Updated with suggestions from @egil

Co-authored-by: Egil Hansen <egil@assimilated.dk>

* Fix #117 - Fix for Button
Will not require StateHasChanged to trigger updates.
Add Tests for Click and Command logic.

* Removed extra console.writeline in the click event

Co-authored-by: Mister Magoo <mister.magoo+githubsql@gmail.com>
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Co-authored-by: Cody Merritt Anhorn <cody.anhorn@hotmail.com>
  • Loading branch information
4 people committed Mar 13, 2020
1 parent 8f5716f commit 0db043a
Show file tree
Hide file tree
Showing 15 changed files with 1,150 additions and 954 deletions.
687 changes: 344 additions & 343 deletions .gitignore

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,8 @@ Portions of the [original .NET Framework](https://github.com/microsoft/reference

There are a significant number of controls in ASP.NET Web Forms, and we will focus on creating components in the following order:

- Editor Controls
- [Button](docs/Button.md)
- Data Controls
- Chart(?)
- [DataList](docs/DataList.md)
Expand Down
3 changes: 3 additions & 0 deletions docs/Button.md
@@ -0,0 +1,3 @@
# Button

It may seem strange that we have a Button component when there already is an HTML button and Blazor has features that enable C# interactions with that button, but we need to activate other features that were once present in Web Forms
@@ -0,0 +1,37 @@
@page "/ControlSamples/Button"

<h2>Button component home page</h2>

<Button CommandName="Foo" CommandArgument="bar" OnCommand="OnCommand" OnClick="OnClick">Click me!</Button>

<span style="font-weight: bold">@TheContent</span>

@code {

[Parameter]
public string TheContent { get; set; } = "Not clicked yet!";
public string bar = "bar";

/*
protected override void OnInitialized() {
TheContent = "Initialized";
Console.WriteLine("Initialized");
}
*/

void OnClick() {

TheContent = "I've been clicked";

}

void OnCommand(CommandEventArgs args) {

Console.WriteLine("Command fired");
TheContent = $"Command '{args.CommandName}'";

}



}
4 changes: 4 additions & 0 deletions samples/AfterBlazorServerSide/Shared/NavMenu.razor
Expand Up @@ -14,6 +14,10 @@

<TreeNode Text="Home" NavigateUrl="/">

<TreeNode Text="Editor Components">
<TreeNode Text="Button" NavigateUrl="/ControlSamples/Button">
</TreeNode>
</TreeNode>
<TreeNode Text="Data Components">

<TreeNode Text="DataList" NavigateUrl="/ControlSamples/DataList" Expanded="false">
Expand Down
@@ -0,0 +1,41 @@
@inherits TestComponentBase

<Fixture
Test="FirstTest"
>
<ComponentUnderTest>
@*<ListView Items="Widget.SimpleWidgetList"
ItemType="Widget"
Context="Item">
<ItemTemplate><span>@Item.Name</span></ItemTemplate>
<LayoutTemplate Context="itemPlaceholder">
<div>
<b>Header <Button @ref="MyButton">My Button</Button></b>
<br/>
@itemPlaceholder
</div>
</LayoutTemplate>
</ListView>
*@

<Button>
<Button @ref="MyButton">My Button</Button>
</Button>
</ComponentUnderTest>
</Fixture>

@code {

Button MyButton { get; set; }

void FirstTest() {

var cut = GetComponentUnderTest();
cut.FindAll("button").Count().ShouldNotBe(0);

MyButton.ShouldNotBeNull();
MyButton.Parent.ShouldNotBeNull("Cannot find the Parent component");

}

}
37 changes: 37 additions & 0 deletions src/BlazorWebFormsComponents.Test/Button/Click.razor
@@ -0,0 +1,37 @@
@inherits TestComponentBase


<Fixture Test="FirstTest">
<ComponentUnderTest>
<Button OnClick="OnClick">Click me!</Button>
</ComponentUnderTest>
</Fixture>


@code {

public string TheContent { get; set; } = "Not clicked yet!";

void OnClick()
{

TheContent = "I've been clicked";

}

void FirstTest()
{
// Given
var cut = GetComponentUnderTest();

TheContent.ShouldBe("Not clicked yet!");

// When
cut.Find("button").Click();

// Then
TheContent.ShouldBe("I've been clicked");

}

}
38 changes: 38 additions & 0 deletions src/BlazorWebFormsComponents.Test/Button/Command.razor
@@ -0,0 +1,38 @@
@inherits TestComponentBase


<Fixture Test="FirstTest">
<ComponentUnderTest>
<Button CommandName="Foo" CommandArgument="CommandArgument" OnCommand="OnCommand">Click me!</Button>
</ComponentUnderTest>
</Fixture>


@code {

public string TheContent { get; set; } = "No Command yet!";
public string CommandArgument = "bar";

void OnCommand(CommandEventArgs args)
{

TheContent = $"Command '{args.CommandName}' : '{args.CommandArgument.ToString()}'";

}

void FirstTest()
{
// Given
var cut = GetComponentUnderTest();

TheContent.ShouldBe("No Command yet!");

// When
cut.Find("button").Click();

// Then
TheContent.ShouldBe("Command 'Foo' : 'bar'");

}

}

0 comments on commit 0db043a

Please sign in to comment.