ant-design-blazor/components/timeline/TimelineItem.cs
Henry.zhang f9b615c2ca feat: add more demos (#197)
...for affix,back-top,breadcrumb,card,divider,typogragpy and timeline

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-06-07 19:41:00 +08:00

78 lines
2.2 KiB
C#

using Microsoft.AspNetCore.Components;
using System.Linq;
namespace AntDesign
{
public partial class TimelineItem : AntDomComponentBase
{
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public RenderFragment Dot { get; set; }
[Parameter]
public string Color { get; set; } = "blue";
[CascadingParameter] public Timeline ParentTimeline { get; set; }
internal ClassMapper _headClassMapper = new ClassMapper();
internal bool IsLast { get; set; } = false;
//'left' | 'alternate' | 'right'
internal string Position { get; set; } = "";
internal string HeadStyle { get; set; } = "";
internal string ItemClass => ClassMapper.Class;
private readonly string[] _defaultColors = new[] { "blue", "red", "green", "gray" };
public TimelineItem()
{
}
internal TimelineItem(RenderFragment childContent, RenderFragment dot, string @class)
{
this.ChildContent = childContent;
this.Dot = dot;
this.Class = @class;
}
protected override void OnInitialized()
{
ParentTimeline.AddItem(this);
this.TryUpdateCustomColor();
base.OnInitialized();
}
protected override void OnParametersSet()
{
this.SetClassMap();
this.TryUpdateCustomColor();
base.OnParametersSet();
}
private void TryUpdateCustomColor()
{
HeadStyle = !_defaultColors.Contains(Color) ? $"border-color:{Color}" : "";
}
internal void SetClassMap()
{
var prefix = "ant-timeline-item";
ClassMapper.Clear().Add(prefix)
.If($"{prefix}-right", () => Position == "right")
.If($"{prefix}-left", () => Position == "left")
.If($"{prefix}-last", () => IsLast);
var headPrefix = "ant-timeline-item-head";
_headClassMapper.Clear().Add(headPrefix)
.If($"{headPrefix}-{Color}", () => _defaultColors.Contains(Color))
.If($"{headPrefix}-custom", () => Dot != null);
}
}
}