2020-09-16 13:58:16 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2020-08-10 14:21:24 +08:00
|
|
|
|
using OneOf;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Small numerical value or status descriptor for UI elements.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class BadgeRibbon : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Customize ribbon color
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Color { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set text contents of ribbon.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
2020-09-16 13:58:16 +08:00
|
|
|
|
public string Text { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment TextTemplate { get; set; }
|
2020-08-10 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set placement of ribbon.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Placement { get; set; } = "end";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wrapping this item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
private string PresetColor => Color.IsIn(_badgePresetColors) ? Color : null;
|
|
|
|
|
|
2020-09-16 13:58:16 +08:00
|
|
|
|
private string _colorStyle;
|
2020-08-10 14:21:24 +08:00
|
|
|
|
|
2020-09-16 13:58:16 +08:00
|
|
|
|
private string _cornerColorStyle;
|
2020-08-10 14:21:24 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the default CSS classes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetClassMap()
|
|
|
|
|
{
|
|
|
|
|
var prefixName = "ant-ribbon";
|
|
|
|
|
ClassMapper.Clear()
|
|
|
|
|
.Add(prefixName)
|
|
|
|
|
.Add($"{prefixName}-placement-{Placement}")
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.If($"{prefixName}-rtl", () => RTL)
|
2020-08-10 14:21:24 +08:00
|
|
|
|
.If($"{prefixName}-color-{PresetColor}", () => Color.IsIn(_badgePresetColors))
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetStyle()
|
|
|
|
|
{
|
|
|
|
|
if (PresetColor == null && !string.IsNullOrWhiteSpace(Color))
|
|
|
|
|
{
|
2020-09-16 13:58:16 +08:00
|
|
|
|
_colorStyle = $"background:{Color}; {Style}";
|
|
|
|
|
_cornerColorStyle = $"color:{Color}; {Style}";
|
2020-08-10 14:21:24 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-16 13:58:16 +08:00
|
|
|
|
_colorStyle = Style;
|
|
|
|
|
_cornerColorStyle = Style;
|
2020-08-10 14:21:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Startup code
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
SetClassMap();
|
|
|
|
|
SetStyle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs every time a parameter is set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
SetClassMap();
|
|
|
|
|
SetStyle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly string[] _badgePresetColors =
|
|
|
|
|
{
|
|
|
|
|
"pink", "red", "yellow", "orange", "cyan", "green", "blue", "purple", "geekblue", "magenta", "volcano",
|
|
|
|
|
"gold", "lime"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|