2020-04-23 17:13:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-12-20 00:20:53 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
2020-06-07 19:41:00 +08:00
|
|
|
|
public partial class Timeline : AntDomComponentBase
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 'left' | 'alternate' | 'right'
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Mode { get; set; }
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool Reverse { get; set; }
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment Pending { get; set; }
|
|
|
|
|
|
|
|
|
|
protected virtual RenderFragment LoadingDot { get; }
|
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
private TimelineItem PendingItem
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (this.Pending == null) return null;
|
2020-06-07 19:41:00 +08:00
|
|
|
|
var item = new TimelineItem(
|
2020-04-24 18:32:50 +08:00
|
|
|
|
childContent: !_isPendingBoolean ? Pending : null,
|
|
|
|
|
dot: PendingDot ?? LoadingDot,
|
|
|
|
|
@class: "ant-timeline-item-pending"
|
|
|
|
|
);
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
item.SetClassMap();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment PendingDot { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
private IList<TimelineItem> _items = new List<TimelineItem>();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
protected IList<TimelineItem> DisplayItems
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-06-07 19:41:00 +08:00
|
|
|
|
var pitems = PendingItem != null ? new[] { PendingItem } : Array.Empty<TimelineItem>();
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (Reverse)
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
return pitems.Concat(UpdateChildren(_items.Reverse())).ToList();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
return UpdateChildren(_items).Concat(pitems).ToList();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
private readonly bool _isPendingBoolean = false;
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
SetClassMap();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
SetClassMap();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
protected void SetClassMap()
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
var prefix = "ant-timeline";
|
|
|
|
|
ClassMapper.Clear()
|
|
|
|
|
.Add(prefix)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefix}-right", () => Mode == "right")
|
|
|
|
|
.If($"{prefix}-alternate", () => Mode == "alternate")
|
2019-12-20 00:20:53 +08:00
|
|
|
|
.If($"{prefix}-pending", () => Pending != null)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefix}-reverse", () => Reverse);
|
2019-12-20 00:20:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
internal void AddItem(TimelineItem item)
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
this._items.Add(item);
|
2019-12-20 00:20:53 +08:00
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
protected IEnumerable<TimelineItem> UpdateChildren(IEnumerable<TimelineItem> items)
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
if (!items.Any())
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
var length = items.Count();
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = items.ElementAt(i);
|
2020-04-23 17:13:56 +08:00
|
|
|
|
item.IsLast = i == length - 1;
|
|
|
|
|
item.Position =
|
|
|
|
|
this.Mode == "left" || Mode == null ? null
|
|
|
|
|
: this.Mode == "right" ? "right"
|
|
|
|
|
: this.Mode == "alternate" && i % 2 == 0 ? "left"
|
2019-12-20 00:20:53 +08:00
|
|
|
|
: "right";
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
item.SetClassMap();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
|
|
|
|
yield return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|