Skip to content

Commit a8f7013

Browse files
Custom Checkbox
1 parent d949dfd commit a8f7013

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

src/Blazor.AdminLte.Site.Shared/Pages/Forms/General.razor

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
<ContentMain>
88
<Card>
99
<Title><CardTitle>Some simple link content</CardTitle></Title>
10-
<Body>Contents</Body>
10+
<Body>
11+
<FormGroup>
12+
@code{
13+
List<CustomCheckboxState> Checkboxes = new List<CustomCheckboxState>()
14+
{
15+
new CustomCheckboxState(){ Identifier = "customCheckbox1", Value="option1", Label=new MarkupString("Custom Checkbox")},
16+
new CustomCheckboxState(){ Identifier = "customCheckbox2", Value="option2", IsChecked=true, Label=new MarkupString("Custom Checkbox checked")},
17+
new CustomCheckboxState(){ Identifier = "customCheckbox3", Value="option3", IsDisabled=true, Label=new MarkupString("Custom Checkbox disabled")}
18+
};
19+
}
20+
@for (int i=0;i<Checkboxes.Count;i++)
21+
{
22+
<CustomCheckbox @bind-State="Checkboxes[i]" />
23+
}
24+
</FormGroup>
25+
</Body>
1126
</Card>
1227
</ContentMain>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@namespace Blazor.AdminLte
2+
<div class="custom-control custom-checkbox">
3+
<input class="custom-control-input" type="checkbox" id="@State.Identifier" value="@State.Value" disabled="@State.IsDisabled" checked="@State.IsChecked" @onchange="DoChange">
4+
<label for="@State.Identifier" class="custom-control-label">@State.Label</label>
5+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace Blazor.AdminLte
4+
{
5+
public partial class CustomCheckbox
6+
{
7+
[Parameter]
8+
public CustomCheckboxState State { get; set; }
9+
10+
[Parameter]
11+
public EventCallback<CustomCheckboxState> StateChanged { get; set; }
12+
13+
[Parameter]
14+
public RenderFragment ChildContent { get; set; }
15+
16+
[Parameter]
17+
public EventCallback<ChangeEventArgs> OnChange { get; set; }
18+
19+
private async void DoChange(ChangeEventArgs e)
20+
{
21+
if (OnChange.HasDelegate)
22+
await OnChange.InvokeAsync(e);
23+
}
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace Blazor.AdminLte
4+
{
5+
public class CustomCheckboxState
6+
{
7+
public bool? IsChecked { get; set; }
8+
public bool IsDisabled { get; set; }
9+
public string Value { get; set; }
10+
public string Identifier { get; set; }
11+
public MarkupString Label { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)