ant-design-blazor/components/back-top/BackTop.razor.cs
TimChen 914dfed427 feat: complete backtop (#660)
* feat: complete backtop

* fix: backtop

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-10-09 10:59:52 +08:00

63 lines
1.7 KiB
C#

using System.Threading.Tasks;
using AntDesign.JsInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
namespace AntDesign
{
public partial class BackTop : AntDomComponentBase
{
[Inject]
public DomEventService DomEventService { get; set; }
[Parameter]
public string Icon { get; set; } = "vertical-align-top";
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public bool Visible { get; set; } = true;
/// <summary>
/// 回到顶部的目标控件
/// </summary>
[Parameter]
public string TargetSelector { get; set; }
protected ClassMapper BackTopContentClassMapper { get; set; } = new ClassMapper();
protected ClassMapper BackTopIconClassMapper { get; set; } = new ClassMapper();
[Parameter]
public EventCallback OnClick { get; set; }
protected async Task OnClickHandle()
{
if (string.IsNullOrWhiteSpace(TargetSelector))
await JsInvokeAsync<DomRect>(JSInteropConstants.BackTop);
else
await JsInvokeAsync<DomRect>(JSInteropConstants.BackTop, TargetSelector);
if (OnClick.HasDelegate)
await OnClick.InvokeAsync(null);
}
protected override void OnInitialized()
{
SetClass();
base.OnInitialized();
}
protected void SetClass()
{
string prefixCls = "ant-back-top";
ClassMapper.Add(prefixCls);
BackTopContentClassMapper.Add($"{prefixCls}-content");
BackTopIconClassMapper.Add($"{prefixCls}-icon");
}
}
}