using Microsoft.AspNetCore.Components; using OneOf; namespace AntDesign { /// /// Small numerical value or status descriptor for UI elements. /// public partial class BadgeRibbon : AntDomComponentBase { /// /// Customize ribbon color /// [Parameter] public string Color { get; set; } /// /// Set text contents of ribbon. /// [Parameter] public string Text { get; set; } [Parameter] public RenderFragment TextTemplate { get; set; } /// /// Set placement of ribbon. /// [Parameter] public string Placement { get; set; } = "end"; /// /// Wrapping this item. /// [Parameter] public RenderFragment ChildContent { get; set; } private string PresetColor => Color.IsIn(_badgePresetColors) ? Color : null; private string _colorStyle; private string _cornerColorStyle; /// /// Sets the default CSS classes. /// private void SetClassMap() { var prefixName = "ant-ribbon"; ClassMapper.Clear() .Add(prefixName) .Add($"{prefixName}-placement-{Placement}") .If($"{prefixName}-rtl", () => RTL) .If($"{prefixName}-color-{PresetColor}", () => Color.IsIn(_badgePresetColors)) ; } private void SetStyle() { if (PresetColor == null && !string.IsNullOrWhiteSpace(Color)) { _colorStyle = $"background:{Color}; {Style}"; _cornerColorStyle = $"color:{Color}; {Style}"; } else { _colorStyle = Style; _cornerColorStyle = Style; } } /// /// Startup code /// protected override void OnInitialized() { base.OnInitialized(); SetClassMap(); SetStyle(); } /// /// Runs every time a parameter is set. /// 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" }; } }