2020-10-14 13:56:59 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public partial class AvatarGroup : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int MaxCount { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string MaxStyle { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2021-09-10 19:06:50 +08:00
|
|
|
|
public Placement MaxPopoverPlacement { get; set; } = Placement.Top;
|
2020-10-14 13:56:59 +08:00
|
|
|
|
|
2021-03-12 17:02:11 +08:00
|
|
|
|
private ClassMapper _popoverClassMapper = new ClassMapper();
|
|
|
|
|
|
2020-10-14 13:56:59 +08:00
|
|
|
|
private bool _overflow;
|
|
|
|
|
private string _prefixCls = "ant-avatar-group";
|
|
|
|
|
|
|
|
|
|
private IList<Avatar> _shownAvatarList = new List<Avatar>();
|
|
|
|
|
private IList<Avatar> _hiddenAvatarList = new List<Avatar>();
|
|
|
|
|
|
2021-03-12 17:02:11 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
|
|
|
|
ClassMapper
|
|
|
|
|
.Add(_prefixCls)
|
|
|
|
|
.If($"{_prefixCls}-rtl", () => RTL);
|
|
|
|
|
|
|
|
|
|
_popoverClassMapper
|
|
|
|
|
.Add($"{_prefixCls}-popover")
|
|
|
|
|
.If($"{_prefixCls}-popover-rtl", () => RTL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 13:56:59 +08:00
|
|
|
|
internal void AddAvatar(Avatar item)
|
|
|
|
|
{
|
|
|
|
|
if (item.Position == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var avatarList = item.Position == "shown" ? _shownAvatarList : _hiddenAvatarList;
|
|
|
|
|
|
|
|
|
|
avatarList.Add(item);
|
|
|
|
|
|
|
|
|
|
if (MaxCount > 0 && avatarList.Count > MaxCount)
|
|
|
|
|
{
|
|
|
|
|
_overflow = true;
|
|
|
|
|
item.Overflow = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void RemoveAvatar(Avatar item)
|
|
|
|
|
{
|
|
|
|
|
if (item.Position == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var avatarList = item.Position == "shown" ? _shownAvatarList : _hiddenAvatarList;
|
|
|
|
|
|
|
|
|
|
avatarList.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|