|
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 | // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
5 | 5 |
|
| 6 | +using Microsoft.AspNetCore.Components.Rendering; |
| 7 | +using Microsoft.AspNetCore.Components.Web; |
| 8 | +using System; |
| 9 | + |
6 | 10 | namespace BootstrapBlazor.Components; |
7 | 11 |
|
8 | 12 | /// <summary> |
9 | 13 | /// LinkButton 组件 |
10 | 14 | /// </summary> |
11 | | -public partial class LinkButton |
| 15 | +public sealed class LinkButton : ButtonBase |
12 | 16 | { |
13 | 17 | /// <summary> |
14 | 18 | /// 获得/设置 Url 默认为 # |
@@ -59,6 +63,48 @@ public partial class LinkButton |
59 | 63 |
|
60 | 64 | private bool TriggerClick => !IsDisabled || (string.IsNullOrEmpty(Url)); |
61 | 65 |
|
| 66 | + /// <summary> |
| 67 | + /// <inheritdoc /> |
| 68 | + /// </summary> |
| 69 | + /// <param name="builder"></param> |
| 70 | + protected override void BuildRenderTree(RenderTreeBuilder builder) |
| 71 | + { |
| 72 | + builder.OpenElement(0, TagName); |
| 73 | + builder.AddAttribute(1, "class", ClassString); |
| 74 | + builder.AddAttribute(2, "href", UrlString); |
| 75 | + builder.AddAttribute(3, "target", Target); |
| 76 | + builder.AddAttribute(4, "disabled", Disabled); |
| 77 | + builder.AddAttribute(5, "aria-disabled", DisabledString); |
| 78 | + builder.AddAttribute(6, "tabindex", Tab); |
| 79 | + builder.AddAttribute(7, "id", Id); |
| 80 | + builder.AddAttribute(8, "role", "button"); |
| 81 | + |
| 82 | + if (TriggerClick) |
| 83 | + { |
| 84 | + builder.AddAttribute(9, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, OnClickButton)); |
| 85 | + builder.AddEventPreventDefaultAttribute(10, "onclick", Prevent); |
| 86 | + builder.AddEventStopPropagationAttribute(11, "onclick", StopPropagation); |
| 87 | + } |
| 88 | + |
| 89 | + if (!string.IsNullOrEmpty(Icon)) |
| 90 | + { |
| 91 | + builder.AddContent(12, new MarkupString($"<i class=\"{Icon}\"></i>")); |
| 92 | + } |
| 93 | + |
| 94 | + if (!string.IsNullOrEmpty(ImageUrl)) |
| 95 | + { |
| 96 | + builder.AddContent(13, new MarkupString($"<img alt=\"img\" class=\"{ImageCss}\" src=\"{ImageUrl}\" />")); |
| 97 | + } |
| 98 | + |
| 99 | + if (!string.IsNullOrEmpty(Text)) |
| 100 | + { |
| 101 | + builder.AddContent(14, new MarkupString($"<span>{Text}</span>")); |
| 102 | + } |
| 103 | + |
| 104 | + builder.AddContent(15, ChildContent); |
| 105 | + builder.CloseElement(); |
| 106 | + } |
| 107 | + |
62 | 108 | private async Task OnClickButton() |
63 | 109 | { |
64 | 110 | if (OnClickWithoutRender != null) |
|
0 commit comments