ant-design-blazor/components/mentions/MentionsOption.razor.cs
Henry.zhang ef22dd5a1b feat: add mentions component (#286)
* feat: add mentions component

* fix: update with z-index

* feat: new mention components (unfinished)

* fix: show chinese letter for affix and tree

* refactor: clean code

* fix: the display position of the dropdown is consistent with the cursor

* fix: mistakes

Co-authored-by: ElderJames <shunjiey@hotmail.com>
Co-authored-by: zxyao <zxyao145@gmail.com>
2020-07-11 01:46:35 +08:00

64 lines
1.5 KiB
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
namespace AntDesign
{
public partial class MentionsOption
{
[CascadingParameter] public Mentions Mentions { get; set; }
[Parameter] public string Value { get; set; }
[Parameter] public bool Disable { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
public bool Selected { get; set; }
public bool Active { get; set; }
protected override void OnInitialized()
{
Mentions?.AddOption(this);
SetClassMap();
base.OnInitialized();
}
private void SetClassMap()
{
var prefixCls = "ant-mentions-dropdown-menu-item";
this.ClassMapper.Clear()
.Add(prefixCls)
.If($"{prefixCls}-disable", () => this.Disable)
.If($"{prefixCls}-selected", () => this.Selected)
.If($"{prefixCls}-active", () => this.Active)
;
InvokeStateHasChanged();
}
internal void OnMouseEnter()
{
this.Selected = true;
}
internal void OnMouseLeave()
{
this.Selected = false;
}
internal async Task OnClick(MouseEventArgs args)
{
if (args.Button == 0) //left click
{
await Mentions.OnOptionClick(this);
}
InvokeStateHasChanged();
}
}
}