From d43b623a36d289e605ae2a8b9004ad37bcec2ed8 Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 11 May 2024 13:40:37 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20refactor(Pagination):=20move=20c?= =?UTF-8?q?ode=20to=20Masa.Blazor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Pagination/BPagination.razor | 8 --- .../Pagination/BPagination.razor.cs | 32 ------------ .../Components/Pagination/IPagination.cs | 25 ---------- .../Pagination/List/BPaginationList.razor | 9 ---- .../Pagination/List/BPaginationList.razor.cs | 7 --- .../List/Icon/BPaginationIcon.razor | 38 -------------- .../List/Icon/BPaginationIcon.razor.cs | 28 ----------- .../List/Items/BPaginationItems.razor | 49 ------------------- .../List/Items/BPaginationItems.razor.cs | 13 ----- .../PaginationAbstractProviderExtensions.cs | 13 ----- .../Pagination/PaginationIconTypes.cs | 8 --- 11 files changed, 230 deletions(-) delete mode 100644 src/Component/BlazorComponent/Components/Pagination/BPagination.razor delete mode 100644 src/Component/BlazorComponent/Components/Pagination/BPagination.razor.cs delete mode 100644 src/Component/BlazorComponent/Components/Pagination/IPagination.cs delete mode 100644 src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor delete mode 100644 src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor.cs delete mode 100644 src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor delete mode 100644 src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor.cs delete mode 100644 src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor delete mode 100644 src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor.cs delete mode 100644 src/Component/BlazorComponent/Components/Pagination/PaginationAbstractProviderExtensions.cs delete mode 100644 src/Component/BlazorComponent/Components/Pagination/PaginationIconTypes.cs diff --git a/src/Component/BlazorComponent/Components/Pagination/BPagination.razor b/src/Component/BlazorComponent/Components/Pagination/BPagination.razor deleted file mode 100644 index aa08dadf0..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/BPagination.razor +++ /dev/null @@ -1,8 +0,0 @@ -@namespace BlazorComponent -@inherits BDomComponentBase - - - - diff --git a/src/Component/BlazorComponent/Components/Pagination/BPagination.razor.cs b/src/Component/BlazorComponent/Components/Pagination/BPagination.razor.cs deleted file mode 100644 index d1a03f18d..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/BPagination.razor.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace BlazorComponent -{ - public partial class BPagination : BDomComponentBase - { - [Parameter] - public bool Dark { get; set; } - - [Parameter] - public bool Light { get; set; } - - [CascadingParameter(Name = "IsDark")] - public bool CascadingIsDark { get; set; } - - public bool IsDark - { - get - { - if (Dark) - { - return true; - } - - if (Light) - { - return false; - } - - return CascadingIsDark; - } - } - } -} diff --git a/src/Component/BlazorComponent/Components/Pagination/IPagination.cs b/src/Component/BlazorComponent/Components/Pagination/IPagination.cs deleted file mode 100644 index e6729ce65..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/IPagination.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace BlazorComponent -{ - public interface IPagination : IHasProviderComponent - { - string? HrefFormat { get; } - - string GetIcon(int index); - - IEnumerable GetItems(); - - bool PrevDisabled => default; - - bool NextDisabled => default; - - Task HandlePreviousAsync(MouseEventArgs args); - - Task HandleNextAsync(MouseEventArgs args); - - Task HandleItemClickAsync(StringNumber item); - - string? PrevIcon => default; - - int Value => default; - } -} diff --git a/src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor b/src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor deleted file mode 100644 index 842be3e33..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor +++ /dev/null @@ -1,9 +0,0 @@ -@namespace BlazorComponent -@typeparam TPagination -@inherits ComponentPartBase - -
    - @RenderPart(typeof(BPaginationIcon<>),(int)PaginationIconTypes.First,arg0Name:"ItemIndex") - @RenderPart(typeof(BPaginationItems<>)) - @RenderPart(typeof(BPaginationIcon<>),(int)PaginationIconTypes.Second,arg0Name:"ItemIndex") -
\ No newline at end of file diff --git a/src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor.cs b/src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor.cs deleted file mode 100644 index 0a5c1f987..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/List/BPaginationList.razor.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace BlazorComponent -{ - public partial class BPaginationList where TPagination : IPagination - { - - } -} diff --git a/src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor b/src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor deleted file mode 100644 index 120a1a785..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor +++ /dev/null @@ -1,38 +0,0 @@ -@namespace BlazorComponent -@typeparam TPagination -@inherits ComponentPartBase - -
  • - @CreatePaginationNavigation() -
  • - -@code { - - private RenderFragment CreatePaginationNavigation() => builder => - { - builder.OpenElement(0, HrefFormat is null ? "button" : "a"); - builder.AddAttribute(1, "class", CssProvider.GetClass(IconClassName())); - builder.AddAttribute(2, "onclick", HandleAsync); - builder.AddAttribute(3, "__internal_preventDefault_onclick", true); - if (HrefFormat is null) - { - builder.AddAttribute(4, "type", "button"); - } - else if (!Disabled) - { - builder.AddAttribute(5, "href", string.Format(HrefFormat, ItemIndex == -1 ? Value - 1 : Value + 1)); - } - - builder.AddContent(6, (RenderFragment)(childBuilder => - { - childBuilder.OpenComponent(0); - childBuilder.AddMultipleAttributes(1, GetAttributes(typeof(BIcon))); - // childBuilder.AddContent(2, _ => _.AddContent(0, GetIcon)); - childBuilder.AddAttribute(2, "ChildContent", (RenderFragment)(childBuilder2 => { childBuilder2.AddContent(0, GetIcon); })); - childBuilder.CloseComponent(); - })); - - builder.CloseElement(); - }; - -} diff --git a/src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor.cs b/src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor.cs deleted file mode 100644 index fd2e3b264..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/List/Icon/BPaginationIcon.razor.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace BlazorComponent -{ - public partial class BPaginationIcon where TPagination : IPagination - { - [Parameter] - public int ItemIndex { get; set; } - - public int Value => Component.Value; - - public string? HrefFormat => Component.HrefFormat; - - public string GetIcon => Component.GetIcon(ItemIndex); - - public bool Disabled => ItemIndex == (int)PaginationIconTypes.First ? Component.PrevDisabled : Component.NextDisabled; - - public string IconClassName() => $"navigation{(Disabled ? "-disabled" : string.Empty)}"; - - public string PrevIcon => Component.PrevIcon; - - public async Task HandleAsync(MouseEventArgs args) - { - if (GetIcon == PrevIcon) - await Component.HandlePreviousAsync(args); - else - await Component.HandleNextAsync(args); - } - } -} diff --git a/src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor b/src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor deleted file mode 100644 index 90bd9da70..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor +++ /dev/null @@ -1,49 +0,0 @@ -@namespace BlazorComponent -@typeparam TPagination -@inherits ComponentPartBase - -@foreach (var item in GetItems()) -{ -
  • - @if (item.IsT0) - { - - @item - - } - else - { - @CreatePaginationItem(item) - } -
  • -} - -@code { - - private RenderFragment CreatePaginationItem(StringNumber item) => builder => - { - var itemClass = item.AsT1 == Value ? "current-item" : "item"; - - builder.OpenElement(0, HrefFormat is null ? "button" : "a"); - builder.AddAttribute(1, "class", CssProvider.GetClass(itemClass)); - builder.AddAttribute(2, "onclick", () => HandleItemClickAsync(item)); - - // TODO: hide this if the component is not interactive - // https://github.com/dotnet/aspnetcore/issues/49401 - builder.AddAttribute(3, "__internal_preventDefault_onclick", true); - - if (HrefFormat is null) - { - builder.AddAttribute(4, "type", "button"); - } - else - { - builder.AddAttribute(5, "href", string.Format(HrefFormat, item)); - } - - builder.AddContent(6, item); - - builder.CloseElement(); - }; - -} diff --git a/src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor.cs b/src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor.cs deleted file mode 100644 index e80d90e86..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/List/Items/BPaginationItems.razor.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace BlazorComponent -{ - public partial class BPaginationItems where TPagination : IPagination - { - public string? HrefFormat => Component.HrefFormat; - - public IEnumerable GetItems() => Component.GetItems(); - - public int Value => Component.Value; - - public async Task HandleItemClickAsync(StringNumber item) => await Component.HandleItemClickAsync(item); - } -} diff --git a/src/Component/BlazorComponent/Components/Pagination/PaginationAbstractProviderExtensions.cs b/src/Component/BlazorComponent/Components/Pagination/PaginationAbstractProviderExtensions.cs deleted file mode 100644 index 0be1b368e..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/PaginationAbstractProviderExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace BlazorComponent -{ - public static class PaginationAbstractProviderExtensions - { - public static ComponentAbstractProvider ApplyPaginationDefault(this ComponentAbstractProvider abstractProvider) - { - return abstractProvider - .Apply(typeof(BPaginationItems<>), typeof(BPaginationItems)) - .Apply(typeof(BPaginationIcon<>), typeof(BPaginationIcon)) - .Apply(typeof(BPaginationList<>), typeof(BPaginationList)); - } - } -} diff --git a/src/Component/BlazorComponent/Components/Pagination/PaginationIconTypes.cs b/src/Component/BlazorComponent/Components/Pagination/PaginationIconTypes.cs deleted file mode 100644 index dbdf31a84..000000000 --- a/src/Component/BlazorComponent/Components/Pagination/PaginationIconTypes.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace BlazorComponent -{ - public enum PaginationIconTypes - { - First = -1, - Second = -2 - } -}