From 9dc0b090688116f1472cb0b0d7ee0f65cacf5366 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Fritz" Date: Thu, 27 Aug 2020 12:09:02 -0400 Subject: [PATCH] Added style, visible, and tooltip features to fix #226 --- samples/BeforeWebForms/BeforeWebForms.csproj | 8 ++ .../ControlSamples/Hyperlink/default.aspx | 36 +++++++++ .../ControlSamples/Hyperlink/default.aspx.cs | 22 ++++++ .../Hyperlink/default.aspx.designer.cs | 53 +++++++++++++ samples/BeforeWebForms/Default.aspx | 1 + samples/BeforeWebForms/Site.Master | 5 ++ .../HyperLink/Style.razor | 74 +++++++++++++++++++ src/BlazorWebFormsComponents/HyperLink.razor | 17 +++-- .../HyperLink.razor.cs | 29 +++++++- 9 files changed, 236 insertions(+), 9 deletions(-) create mode 100644 samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx create mode 100644 samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.cs create mode 100644 samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.designer.cs create mode 100644 src/BlazorWebFormsComponents.Test/HyperLink/Style.razor diff --git a/samples/BeforeWebForms/BeforeWebForms.csproj b/samples/BeforeWebForms/BeforeWebForms.csproj index 56f6efe49..f5269c468 100644 --- a/samples/BeforeWebForms/BeforeWebForms.csproj +++ b/samples/BeforeWebForms/BeforeWebForms.csproj @@ -116,6 +116,7 @@ + @@ -238,6 +239,13 @@ TemplateFields.aspx + + default.aspx + ASPXCodeBehind + + + default.aspx + Grouping.aspx ASPXCodeBehind diff --git a/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx b/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx new file mode 100644 index 000000000..bed8a8a1a --- /dev/null +++ b/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx @@ -0,0 +1,36 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="BeforeWebForms.ControlSamples.Hyperlink._default" MasterPageFile="~/Site.Master" %> + + + +

Hyperlink Demos

+ +

+ This hyperlink has Style! + + + +

+ +

+ This hyperlink has Tooltips! + + + +

+ +

+ This hyperlink is not visible + + + +

+ +

+ + This hyperlink is DataBinding! + + + +

+ +
diff --git a/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.cs b/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.cs new file mode 100644 index 000000000..a3879379d --- /dev/null +++ b/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace BeforeWebForms.ControlSamples.Hyperlink +{ + public partial class _default : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + + } + + protected void HyperLink3_DataBinding(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.designer.cs b/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.designer.cs new file mode 100644 index 000000000..17e90b77a --- /dev/null +++ b/samples/BeforeWebForms/ControlSamples/Hyperlink/default.aspx.designer.cs @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace BeforeWebForms.ControlSamples.Hyperlink +{ + + + public partial class _default + { + + /// + /// styleLink control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HyperLink styleLink; + + /// + /// HyperLink1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HyperLink HyperLink1; + + /// + /// HyperLink2 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HyperLink HyperLink2; + + /// + /// HyperLink3 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HyperLink HyperLink3; + } +} diff --git a/samples/BeforeWebForms/Default.aspx b/samples/BeforeWebForms/Default.aspx index e9d2ebfa5..57cd3a25a 100644 --- a/samples/BeforeWebForms/Default.aspx +++ b/samples/BeforeWebForms/Default.aspx @@ -40,6 +40,7 @@

Editor Controls

diff --git a/samples/BeforeWebForms/Site.Master b/samples/BeforeWebForms/Site.Master index cfa39258c..d8df02431 100644 --- a/samples/BeforeWebForms/Site.Master +++ b/samples/BeforeWebForms/Site.Master @@ -88,6 +88,11 @@ + + + + + diff --git a/src/BlazorWebFormsComponents.Test/HyperLink/Style.razor b/src/BlazorWebFormsComponents.Test/HyperLink/Style.razor new file mode 100644 index 000000000..a1e53c10f --- /dev/null +++ b/src/BlazorWebFormsComponents.Test/HyperLink/Style.razor @@ -0,0 +1,74 @@ +@inherits TestComponentBase +@using static BlazorWebFormsComponents.WebColor +@using static BlazorWebFormsComponents.Enums.BorderStyle +@using BlazorWebFormsComponents + + + + + + + @code { + void HyperLink_Style(Fixture fixture) + { + + var cut = fixture.GetComponentUnderTest(); + + cut.Find("a").HasAttribute("style").ShouldBeTrue(); + var style = cut.Find("a").GetAttribute("style"); + + style.ShouldNotBeNull(); + style.ShouldContain("background-color:Blue"); + style.ShouldContain("color:White"); + + } + } + + + + + + + + + @code { + + private string RandomTooltip = new Random(828).Next(10000, 1000000).ToString(); + + + void HyperLink_Tooltip(Fixture fixture) + { + + var cut = fixture.GetComponentUnderTest(); + + cut.Find("a").HasAttribute("title").ShouldBeTrue(); + var attr = cut.Find("a").GetAttribute("title"); + + attr.ShouldNotBeNull(); + attr.ShouldBe(RandomTooltip); + + } + + } + + + + + + + + @code { + + void HyperLink_Visible(Fixture fixture) + { + + var cut = fixture.GetComponentUnderTest(); + + cut.FindAll("a").Count().ShouldBe(0, "Still rendered the anchor even though its not visible"); + + } + + } + + + diff --git a/src/BlazorWebFormsComponents/HyperLink.razor b/src/BlazorWebFormsComponents/HyperLink.razor index 3081c7583..e73117d53 100644 --- a/src/BlazorWebFormsComponents/HyperLink.razor +++ b/src/BlazorWebFormsComponents/HyperLink.razor @@ -1,10 +1,15 @@ @inherits BaseWebFormsComponent -@if (NavigationUrl == null) +@if (Visible) { - @Text -} -else -{ - @Text + + @if (NavigationUrl == null) + { + @Text + } + else + { + @Text + } + } diff --git a/src/BlazorWebFormsComponents/HyperLink.razor.cs b/src/BlazorWebFormsComponents/HyperLink.razor.cs index 10c4d4196..cba68af5a 100644 --- a/src/BlazorWebFormsComponents/HyperLink.razor.cs +++ b/src/BlazorWebFormsComponents/HyperLink.razor.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Components; +using BlazorComponentUtilities; +using BlazorWebFormsComponents.Enums; +using Microsoft.AspNetCore.Components; namespace BlazorWebFormsComponents { - public partial class HyperLink : BaseWebFormsComponent + public partial class HyperLink : BaseWebFormsComponent, IHasStyle { [Parameter] public string NavigationUrl { get; set; } @@ -10,7 +12,28 @@ public partial class HyperLink : BaseWebFormsComponent [Parameter] public string Target { get; set; } = string.Empty; - [Parameter] + [Parameter] public string Text { get; set; } + + [Parameter] public string ToolTip { get; set; } + + [Parameter] public WebColor BackColor { get; set; } + [Parameter] public WebColor BorderColor { get; set; } + [Parameter] public BorderStyle BorderStyle { get; set; } + [Parameter] public Unit BorderWidth { get; set; } + [Parameter] public string CssClass { get; set; } + [Parameter] public WebColor ForeColor { get; set; } + [Parameter] public Unit Height { get; set; } + [Parameter] public Unit Width { get; set; } + [Parameter] public bool Font_Bold { get; set; } + [Parameter] public bool Font_Italic { get; set; } + [Parameter] public string Font_Names { get; set; } + [Parameter] public bool Font_Overline { get; set; } + [Parameter] public FontUnit Font_Size { get; set; } + [Parameter] public bool Font_Strikeout { get; set; } + [Parameter] public bool Font_Underline { get; set; } + + private string CalculatedStyle => this.ToStyle().Build().NullIfEmpty(); + } }