Skip to content

Commit b8f4297

Browse files
authored
Add Hyperlink component (#147)
* Add HyperLink component, HyperLinkTarget enum, docs, unit test
1 parent 4835444 commit b8f4297

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ There are a significant number of controls in ASP.NET Web Forms, and we will foc
2222

2323
- Editor Controls
2424
- [Button](docs/Button.md)
25+
- [HyperLink](docs/HyperLink.md)
2526
- [Image](docs/Image.md)
2627
- [ImageButton](docs/ImageButton.md)
2728
- [Label](docs/Label.md)

docs/HyperLink.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# LinkButton
2+
3+
It may seem strange that we have a HyperLink component when there already is an HTML anchor and Blazor has features that enable C# interactions with that link, but we need to activate other features that were once present in Web Forms. Original Web Forms documentation is at: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.hyperlink?view=netframework-4.8
4+
5+
## Blazor Features Supported
6+
7+
- `NavigationUrl` the URL to link when HyperLink component is clicked
8+
- `Text` the text content of the HyperLink component
9+
- `Target` the target window or frame in which to display the Web page content linked to when the HyperLink component is clicked
10+
11+
## WebForms Syntax
12+
13+
```html
14+
<asp:HyperLink
15+
AccessKey="string"
16+
BackColor="color name|#dddddd"
17+
BorderColor="color name|#dddddd"
18+
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
19+
Inset|Outset"
20+
BorderWidth="size"
21+
CssClass="string"
22+
Enabled="True|False"
23+
EnableTheming="True|False"
24+
EnableViewState="True|False"
25+
Font-Bold="True|False"
26+
Font-Italic="True|False"
27+
Font-Names="string"
28+
Font-Overline="True|False"
29+
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
30+
Large|X-Large|XX-Large"
31+
Font-Strikeout="True|False"
32+
Font-Underline="True|False"
33+
ForeColor="color name|#dddddd"
34+
Height="size"
35+
ID="string"
36+
ImageUrl="uri"
37+
NavigateUrl="uri"
38+
OnDataBinding="DataBinding event handler"
39+
OnDisposed="Disposed event handler"
40+
OnInit="Init event handler"
41+
OnLoad="Load event handler"
42+
OnPreRender="PreRender event handler"
43+
OnUnload="Unload event handler"
44+
runat="server"
45+
SkinID="string"
46+
Style="string"
47+
TabIndex="integer"
48+
Target="string|_blank|_parent|_search|_self|_top"
49+
Text="string"
50+
ToolTip="string"
51+
Visible="True|False"
52+
Width="size"
53+
/>
54+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@inherits TestComponentBase
2+
3+
<SnapshotTest Description="Verify HTML format of HyperLink">
4+
<TestInput>
5+
<HyperLink Text="Go to Bing!!" NavigationUrl="https://www.bing.com" />
6+
</TestInput>
7+
<ExpectedOutput>
8+
<a href="https://www.bing.com" target="">Go to Bing!!</a>
9+
</ExpectedOutput>
10+
</SnapshotTest>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace BlazorWebFormsComponents.Enums
2+
{
3+
public class HyperLinkTarget
4+
{
5+
public static readonly string Blank = "_blank";
6+
7+
public static readonly string Parent = "_parent";
8+
9+
public static readonly string Search = "_search";
10+
11+
public static readonly string Self = "_self";
12+
13+
public static readonly string Top = "_top";
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@inherits BaseWebFormsComponent
2+
3+
@if (NavigationUrl == null)
4+
{
5+
<a id="@ID">@Text</a>
6+
}
7+
else
8+
{
9+
<a id="@ID" target="@Target" href="@NavigationUrl">@Text</a>
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace BlazorWebFormsComponents
4+
{
5+
public partial class HyperLink : BaseWebFormsComponent
6+
{
7+
[Parameter]
8+
public string NavigationUrl { get; set; }
9+
10+
[Parameter]
11+
public string Target { get; set; } = string.Empty;
12+
13+
[Parameter]
14+
public string Text { get; set; }
15+
}
16+
}

0 commit comments

Comments
 (0)