Skip to content

Commit d8ec476

Browse files
Add Literal componet (#145)
* Add Literal Component, docs, unit tests Co-authored-by: Jeffrey T. Fritz <[email protected]>
1 parent 48ee520 commit d8ec476

File tree

8 files changed

+103
-0
lines changed

8 files changed

+103
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ There are a significant number of controls in ASP.NET Web Forms, and we will foc
2626
- [ImageButton](docs/ImageButton.md)
2727
- [Label](docs/Label.md)
2828
- [LinkButton](docs/LinkButton.md)
29+
- [Literal](docs/Literal.md)
2930
- Data Controls
3031
- Chart(?)
3132
- [DataList](docs/DataList.md)

docs/Literal.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# LinkButton
2+
3+
The Literal component is meant to emulate the asp:Literal control in markup and is defined in the https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.literal?view=netframework-4.8
4+
5+
## Blazor Features Supported
6+
7+
- `Mode` specifies how the content in the Literal component is rendered
8+
- `Text` the text content of the Literal component
9+
10+
## WebForms Syntax
11+
12+
```html
13+
<asp:Literal
14+
EnableTheming="True|False"
15+
EnableViewState="True|False"
16+
ID="string"
17+
Mode="Transform|PassThrough|Encode"
18+
OnDataBinding="DataBinding event handler"
19+
OnDisposed="Disposed event handler"
20+
OnInit="Init event handler"
21+
OnLoad="Load event handler"
22+
OnPreRender="PreRender event handler"
23+
OnUnload="Unload event handler"
24+
runat="server"
25+
SkinID="string"
26+
Text="string"
27+
Visible="True|False"
28+
/>
29+
```
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 Literal">
4+
<TestInput>
5+
<Literal Text="This is normal text" />
6+
</TestInput>
7+
<ExpectedOutput>
8+
This is normal text
9+
</ExpectedOutput>
10+
</SnapshotTest>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@inherits TestComponentBase
2+
3+
@{
4+
var renderedText = "<b>This is encoded text</b>";
5+
}
6+
7+
<SnapshotTest Description="Verify HTML format of Literal is encoded">
8+
<TestInput>
9+
<Literal Text="<b>This is encoded text</b>" />
10+
</TestInput>
11+
<ExpectedOutput>
12+
@((MarkupString)renderedText)
13+
</ExpectedOutput>
14+
</SnapshotTest>
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 Literal is not encoded">
4+
<TestInput>
5+
<Literal Text="<b>This is bold text</b>" />
6+
</TestInput>
7+
<ExpectedOutput>
8+
<b>This is bold text</b>
9+
</ExpectedOutput>
10+
</SnapshotTest>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BlazorWebFormsComponents.Enums
2+
{
3+
public enum LiteralMode
4+
{
5+
Transform = 0,
6+
PassThrough = 1,
7+
Encode = 2
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@using System.Net
2+
@using BlazorWebFormsComponents.Enums
3+
4+
@inherits BaseWebFormsComponent
5+
6+
@functions {
7+
public string RenderedText => Mode == LiteralMode.Encode
8+
? WebUtility.HtmlEncode(Text)
9+
: Text;
10+
}
11+
12+
@if (Visible)
13+
{
14+
@((MarkupString)RenderedText)
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using BlazorWebFormsComponents.Enums;
2+
using BlazorWebFormsComponents.Interfaces;
3+
using Microsoft.AspNetCore.Components;
4+
5+
namespace BlazorWebFormsComponents
6+
{
7+
public partial class Literal : BaseWebFormsComponent, ITextComponent
8+
{
9+
[Parameter]
10+
public LiteralMode Mode { get; set; }
11+
12+
[Parameter]
13+
public string Text { get; set; }
14+
}
15+
}

0 commit comments

Comments
 (0)