2019-12-20 00:20:53 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
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 TimelineItem : AntDomComponentBase
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment Dot { get; set; }
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Color { get; set; } = "blue";
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-06-07 19:41:00 +08:00
|
|
|
|
[CascadingParameter] public Timeline ParentTimeline { get; set; }
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
internal ClassMapper _headClassMapper = new ClassMapper();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
internal bool IsLast { get; set; } = false;
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
|
|
|
|
//'left' | 'alternate' | 'right'
|
2020-04-23 17:13:56 +08:00
|
|
|
|
internal string Position { get; set; } = "";
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
internal string HeadStyle { get; set; } = "";
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
internal string ItemClass => ClassMapper.Class;
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
private readonly string[] _defaultColors = new[] { "blue", "red", "green", "gray" };
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-07-21 23:48:43 +08:00
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
ParentTimeline?._items.Remove(this);
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-20 00:20:53 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2020-07-21 23:48:43 +08:00
|
|
|
|
ParentTimeline?.AddItem(this);
|
2020-04-23 17:13:56 +08:00
|
|
|
|
this.TryUpdateCustomColor();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
this.SetClassMap();
|
|
|
|
|
this.TryUpdateCustomColor();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
private void TryUpdateCustomColor()
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
HeadStyle = !_defaultColors.Contains(Color) ? $"border-color:{Color}" : "";
|
2019-12-20 00:20:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
internal void SetClassMap()
|
2019-12-20 00:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
var prefix = "ant-timeline-item";
|
|
|
|
|
ClassMapper.Clear().Add(prefix)
|
2020-04-23 17:13:56 +08:00
|
|
|
|
.If($"{prefix}-right", () => Position == "right")
|
|
|
|
|
.If($"{prefix}-left", () => Position == "left")
|
|
|
|
|
.If($"{prefix}-last", () => IsLast);
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
|
|
|
|
var headPrefix = "ant-timeline-item-head";
|
2020-04-23 17:13:56 +08:00
|
|
|
|
_headClassMapper.Clear().Add(headPrefix)
|
|
|
|
|
.If($"{headPrefix}-{Color}", () => _defaultColors.Contains(Color))
|
2019-12-20 00:20:53 +08:00
|
|
|
|
.If($"{headPrefix}-custom", () => Dot != null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|