entity actions component implementation.

pull/5890/head
İlkay İlknur 5 years ago
parent f4ad076809
commit b3ba2e3186

@ -0,0 +1,21 @@
@typeparam TItem
@using Blazorise
@if (ParentActions.Type == ActionType.Dropdown)
{
if (IsVisible && Primary == false)
{
<DropdownItem Clicked="@ActionClickedAsync">@Text</DropdownItem>
}
}
else
{
if (IsVisible)
{
<Blazorise.Button Block="true"
Color="Color.Primary"
Clicked="@ActionClickedAsync">
@Text
</Blazorise.Button>
}
}

@ -0,0 +1,33 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
namespace Volo.Abp.BlazoriseUI.Components
{
public partial class EntityAction<TItem> : ComponentBase
{
[Parameter]
public bool IsVisible { get; set; }
[Parameter]
public string Text { get; set; }
[Parameter]
public bool Primary { get; set; }
[Parameter]
public EventCallback<TItem> Clicked { get; set; }
[CascadingParameter]
public EntityActions<TItem> ParentActions { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
ParentActions.AddAction(this);
}
protected virtual async Task ActionClickedAsync()
{
await Clicked.InvokeAsync(ParentActions.Entity);
}
}
}

@ -0,0 +1,30 @@
@typeparam TItem
<CascadingValue Value="this">
@if (Type == ActionType.Dropdown)
{
<Dropdown>
@if (HasPrimaryAction)
{
<Blazorise.Button Block="true"
Color="Color.Primary"
Clicked="async ()=> await PrimaryAction.Clicked.InvokeAsync(Entity)">
@PrimaryAction.Text
</Blazorise.Button>
<DropdownToggle Color="@ToggleColor" Split="true" />
}
else
{
<DropdownToggle Color="@ToggleColor">
@ToggleText
</DropdownToggle>
}
<DropdownMenu>
@ChildContent
</DropdownMenu>
</Dropdown>
}
else
{
@ChildContent
}
</CascadingValue>

@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Linq;
using Blazorise;
using Microsoft.AspNetCore.Components;
namespace Volo.Abp.BlazoriseUI.Components
{
public partial class EntityActions<TItem> : ComponentBase
{
protected List<EntityAction<TItem>> Actions = new List<EntityAction<TItem>>();
protected bool HasPrimaryAction => Actions.Any(t => t.Primary);
protected EntityAction<TItem> PrimaryAction => Actions.FirstOrDefault(t => t.Primary);
protected internal ActionType Type => Actions.Count(t => t.IsVisible) > 1 ? ActionType.Dropdown : ActionType.Button;
[Parameter]
public Color ToggleColor { get; set; }
[Parameter]
public string ToggleText { get; set; }
[Parameter]
public TItem Entity { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
internal void AddAction(EntityAction<TItem> action)
{
Actions.Add(action);
StateHasChanged();
}
}
public enum ActionType
{
Dropdown,
Button
}
}
Loading…
Cancel
Save