Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

refactor(TPopup): 用动画实现淡入淡出效果,并完成代码的重构和优化,提升性能 #273

Merged
merged 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions doc/TDesign.Docs.ServerSide/TDesign.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions doc/TDesign.Docs.Shared/Pages/TestPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
@using Test=TDesign.Docs.Shared.Pages.Components.Data.TablePage
@layout EmptyLayout

<TTable TItem="Test.User" Data="Test.User.GetData()">
<TPopup Content="弹出一个层">
<TButton>悬浮</TButton>
</TPopup>

@*<TTable TItem="Test.User" Data="Test.User.GetData()">
<TTableExpandColumn>
<h4>Name:@context.Name</h4>
</TTableExpandColumn>
Expand All @@ -25,4 +29,4 @@
{

}
}
}*@
33 changes: 5 additions & 28 deletions doc/TDesign.Docs.WebAssembly/wwwroot/TDesign.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/TDesign/Components/Forms/TSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
@inherits TDesignInputComonentBase<TValue>
@typeparam TValue

<TPopup @ref="RefPopup" Trigger="PopupTrigger.Click" AdditionalStyle="position:absolute">
<TPopup @ref="RefPopup" Trigger="PopupTrigger.Click" Placement="PopupPlacement.Bottom">
<ChildContent>
<div class="t-select__wrap">
<div class="@GetCssClassString()">
<TInputText @bind-Value="SelectedLabel" Readonly SuffixIcon="@(RefPopup.Visible?IconName.ChevronUp:IconName.ChevronDown)" AutoWidth="AutoWidth" Placeholder="@Placeholder" Disabled="Disabled" Size="Size"/>
<TInputText @bind-Value="SelectedLabel" Readonly SuffixIcon="@(RefPopup.Visible?IconName.ChevronUp:IconName.ChevronDown)" AutoWidth="AutoWidth" placeholder="@Placeholder" Disabled="Disabled" Size="Size"/>

</div>
</div>
Expand Down
39 changes: 10 additions & 29 deletions src/TDesign/Components/Popup/Popper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,44 @@ namespace TDesign;
/// <summary>
/// 表示 popper 对象。
/// </summary>
public class Popper : IAsyncDisposable
public class Popper :DomNode, IAsyncDisposable
{
private readonly IJSObjectReference _tdesignJsObj;
private readonly IJSObjectReference? _popper;
private readonly PopperOptions? _options;

private readonly PopperOptions? _options;

/// <summary>
/// Initializes a new instance of the <see cref="Popper"/> class.
/// </summary>
internal Popper(IJSObjectReference tdesignJsObj, IJSObjectReference popper, PopperOptions options)
internal Popper(IJSObjectReference? customizeModule = null, IJSObjectReference? internalModule = null,PopperOptions? options=default) : base(customizeModule, internalModule)
{
_tdesignJsObj = tdesignJsObj;
this._popper = popper;
this._options = options;
}

/// <summary>
/// 同步更新 popper 实例。 用于低频更新。
/// </summary>
public ValueTask ForceUpdateAsync()
{
return _popper!.InvokeVoidAsync("forceUpdate");
}
public ValueTask ForceUpdateAsync() => InternalModule!.InvokeVoidAsync("forceUpdate");

/// <summary>
/// 异步更新 popper 实例,并返回一个 promise, 用于高频更新。
/// </summary>
public ValueTask<PopperState?> UpdateAsync()
{
return _popper!.InvokeAsync<PopperState?>("update");
}
public ValueTask<PopperState?> UpdateAsync() => InternalModule!.InvokeAsync<PopperState?>("update");

/// <summary>
/// 更新实例的选项。
/// </summary>
/// <param name="options">要更新的实例。</param>
/// <returns></returns>
public ValueTask<PopperState?> SetOptionsAsync(PopperOptions options)
{
return _popper!.InvokeAsync<PopperState?>("setOptons", options);
}
public ValueTask<PopperState?> SetOptionsAsync(PopperOptions options) => InternalModule!.InvokeAsync<PopperState?>("setOptons", options);

/// <summary>
/// 销毁实例。
/// </summary>
public ValueTask HideAsync(ElementReference? popupElement)
{
return _tdesignJsObj!.InvokeVoidAsync("popup.hide", _popper,popupElement, _options);
}
public ValueTask HideAsync(ElementReference? popupElement)
=> CustomizeModule!.InvokeVoidAsync("popup.hide", InternalModule, popupElement, _options);

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
if ( _popper is not null )
if ( InternalModule is not null )
{
await _popper.DisposeAsync();
await InternalModule.DisposeAsync();
}
}
}
9 changes: 5 additions & 4 deletions src/TDesign/Components/Popup/PopperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ public static class PopperExtensions
/// <param name="selectorRef">触发 popup 组件的元素引用。</param>
/// <param name="popupRef">Popup组件元素的引用。</param>
/// <param name="options">Popup的配置。</param>
public static async ValueTask<Popper> InvokePopupAsync(this IJSRuntime js, ElementReference selectorRef, ElementReference popupRef, PopperOptions options)
public static async ValueTask<Popper> InvokePopupAsync(this IJSRuntime js, ElementReference selectorRef, ElementReference popupRef, PopperOptions options,Func<Task> clickToHide)
{
var tdesignJsObj = await js.ImportTDesignScriptAsync();
var popperObject = await tdesignJsObj.Module.InvokeAsync<IJSObjectReference>("popup.show", selectorRef, popupRef, options, DotNetObjectReference.Create(options));
var tdesignModule = await js.ImportAsync("./_content/TDesign/lib/tdesign-blazor-popup.js");

return new (tdesignJsObj.Module,popperObject, options);
var popperModule = await tdesignModule.Module.InvokeAsync<IJSObjectReference>("popup.show", selectorRef, popupRef, options, DotNetObjectReference.Create(options),JSInvokeMethodFactory.Create(clickToHide));

return new(tdesignModule.Module, popperModule, options);
}
}
5 changes: 0 additions & 5 deletions src/TDesign/Components/Popup/PopperOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public class PopperOptions
[JsonConverter(typeof(EnumDescriptionConverter<PopperStrategy>))]
[JsonPropertyName("strategy")]
public PopperStrategy Strategy { get; set; } = PopperStrategy.Absolute;
/// <summary>
/// 获取或设置显示或隐藏弹出层的延迟时间,单位毫秒。默认 400 毫秒。
/// </summary>
[JsonPropertyName("timeout")]
public int Timeout { get; set; } = 400;

[JsonIgnore]
public Action<PopperState>? OnFirstUpdate { get; set; }
Expand Down
Loading