Skip to content

Commit 04e2b80

Browse files
committed
Added WebColor - fixes #13
Modified: - Modified .gitignore to exclude macOS .files. - Changed Color to WebColor in all razor files. Updated tests to use hex color: - AfterBlazorServerSide: changed the second DataList in HeaderStyle.razor to use hex color #C84630 instead of Blue. - AfterBlazorServerSide: changed ComplexStyle.razor to use hex color #808080 instead of Gray. - Test: Changed ComplexStyle.razor to use hex #ff0000 instead of Red. - Test: Changed HeaderStyle.razor to use #0000ff instead of Blue. - To avoid razor syntax error "CS1024: Preprocessor directive expected" use "@("#hexrgb")" instead of "#hexrgb"
1 parent cc75852 commit 04e2b80

22 files changed

+228
-48
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,8 @@ ASALocalRun/
330330

331331
# MFractors (Xamarin productivity tool) working folder
332332
.mfractor/
333+
334+
# macOS
335+
.DS_Store
336+
.AppleDouble
337+
.LSOverride

samples/AfterBlazorServerSide/Pages/ControlSamples/DataList/ComplexStyle.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@page "/ControlSamples/DataList/ComplexStyle"
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44

55
<h2>DataList HeaderStyle sample</h2>
@@ -11,7 +11,7 @@
1111
<DataList @ref="simpleDataList"
1212
runat="server"
1313
EnableViewState="false"
14-
BackColor="Gray"
14+
BackColor="@("#808080")"
1515
BorderColor="Firebrick"
1616
BorderStyle="Groove"
1717
BorderWidth="2"

samples/AfterBlazorServerSide/Pages/ControlSamples/DataList/HeaderStyle.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@page "/ControlSamples/DataList/HeaderStyle"
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44
<h2>DataList HeaderStyle sample</h2>
55

@@ -27,7 +27,7 @@
2727
runat="server"
2828
EnableViewState="false"
2929
Context="Item"
30-
HeaderStyle-BackColor="Blue"
30+
HeaderStyle-BackColor="@("#C84630")"
3131
HeaderStyle-ForeColor="White"
3232
HeaderStyle-BorderColor="White"
3333
HeaderStyle-BorderStyle="Solid"

samples/AfterBlazorServerSide/Pages/ControlSamples/DataList/Index.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@page "/ControlSamples/DataList"
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44
<h2>DataList Component homepage</h2>
55

src/BlazorWebFormsComponents.Test/DataList/FlowLayout/HeaderStyle.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44
@using BlazorWebFormsComponents
55

src/BlazorWebFormsComponents.Test/DataList/FlowLayout/HeaderStyleCss.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44
@using BlazorWebFormsComponents
55

src/BlazorWebFormsComponents.Test/DataList/FlowLayout/HeaderStyleFont.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44
@using BlazorWebFormsComponents
55

src/BlazorWebFormsComponents.Test/DataList/FlowLayout/InlineHeaderStyle.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44

55
<Fixture Test="FirstTest">

src/BlazorWebFormsComponents.Test/DataList/FlowLayout/ItemStyle.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44

55
<Fixture Test="FirstTest">

src/BlazorWebFormsComponents.Test/DataList/TableLayout/ComplexStyle.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44

55

@@ -10,7 +10,7 @@
1010
CellSpacing="2"
1111
CellPadding="3"
1212
RepeatLayout="Table"
13-
BackColor="Red"
13+
BackColor="@("#ff0000")"
1414
Context="Item">
1515
<HeaderTemplate>My Widget List</HeaderTemplate>
1616
<ItemTemplate>@Item.Name</ItemTemplate>

src/BlazorWebFormsComponents.Test/DataList/TableLayout/FontStyle.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44

55

src/BlazorWebFormsComponents.Test/DataList/TableLayout/HeaderStyle.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44
@using BlazorWebFormsComponents
55

@@ -11,7 +11,7 @@
1111
RepeatLayout="Table"
1212
Context="Item">
1313
<ChildContent>
14-
<HeaderStyle BackColor="Blue" BorderStyle="Solid" BorderColor="Black" BorderWidth="2"></HeaderStyle>
14+
<HeaderStyle BackColor="@("#0000ff")" BorderStyle="Solid" BorderColor="Black" BorderWidth="2"></HeaderStyle>
1515
</ChildContent>
1616
<HeaderTemplate>My Widget List</HeaderTemplate>
1717
<ItemTemplate>@Item.Name</ItemTemplate>

src/BlazorWebFormsComponents.Test/DataList/TableLayout/HeaderStyleCss.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44
@using BlazorWebFormsComponents
55

src/BlazorWebFormsComponents.Test/DataList/TableLayout/HeaderStyleFont.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33
@using static BlazorWebFormsComponents.Enums.BorderStyle
44
@using BlazorWebFormsComponents
55

src/BlazorWebFormsComponents.Test/DataList/TableLayout/InlineHeaderStyle.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44

55
<Fixture Test="FirstTest">

src/BlazorWebFormsComponents.Test/DataList/TableLayout/ItemStyle.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits TestComponentBase
2-
@using static System.Drawing.Color
2+
@using static BlazorWebFormsComponents.WebColor
33

44

55
<Fixture Test="FirstTest">

src/BlazorWebFormsComponents/DataList.razor.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ protected string? CalculatedGridLines { get {
9898

9999
protected string CalculatedStyle { get; set; }
100100

101-
[Parameter] public Color BackColor { get; set; }
102-
[Parameter] public Color BorderColor { get; set; }
101+
[Parameter] public WebColor BackColor { get; set; }
102+
[Parameter] public WebColor BorderColor { get; set; }
103103
[Parameter]public BorderStyle BorderStyle { get; set; }
104104
[Parameter]public Unit BorderWidth { get; set; }
105105
[Parameter]public string CssClass { get; set; }
@@ -110,7 +110,7 @@ protected string? CalculatedGridLines { get {
110110
[Parameter]public FontUnit Font_Size { get; set; }
111111
[Parameter]public bool Font_Strikeout { get; set; }
112112
[Parameter]public bool Font_Underline { get; set; }
113-
[Parameter]public Color ForeColor { get; set; }
113+
[Parameter]public WebColor ForeColor { get; set; }
114114
[Parameter]public Unit Height { get; set; }
115115
[Parameter]public HorizontalAlign HorizontalAlign { get; set; }
116116
[Parameter]public VerticalAlign VerticalAlign { get; set; }
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace System.Drawing
1+
namespace System.Drawing
62
{
73
public static class ColorHelpers
84
{
9-
105
public static Color GetColorFromHtml(this object obj)
116
{
12-
137
if (obj is Color) return (Color)obj;
148
if (!(obj is string)) return Color.Empty;
159

1610
var theString = obj.ToString();
1711
if (theString.Contains("#")) return ColorTranslator.FromHtml(theString);
1812
return Color.FromName(theString);
19-
2013
}
21-
2214
}
2315
}
16+
17+
namespace BlazorWebFormsComponents
18+
{
19+
public static class ColorHelpers
20+
{
21+
public static WebColor GetWebColorFromHtml(this object obj)
22+
{
23+
if (obj is WebColor) return (WebColor)obj;
24+
if (!(obj is string)) return WebColor.Empty;
25+
26+
var theString = obj.ToString();
27+
return new WebColor(theString);
28+
}
29+
}
30+
}

src/BlazorWebFormsComponents/IHasStyle.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ public interface IHasLayoutStyle
1515
// Cheer 100 ramblinggeek 07/1/20
1616

1717

18-
Color BackColor { get; set; }
18+
WebColor BackColor { get; set; }
1919

20-
Color BorderColor { get; set; }
20+
WebColor BorderColor { get; set; }
2121

2222
BorderStyle BorderStyle { get; set; }
2323

2424
Unit BorderWidth { get; set; }
2525

2626
string CssClass { get; set; }
2727

28-
Color ForeColor { get; set; }
28+
WebColor ForeColor { get; set; }
2929

3030
Unit Height { get; set; }
3131

@@ -72,12 +72,12 @@ public static string ToStyleString(this IHasStyle hasStyle)
7272
public static StringBuilder ToStyleString(this IHasStyle hasStyle, StringBuilder sb)
7373
{
7474

75-
if (hasStyle.BackColor != default(Color)) sb.Append($"background-color:{ColorTranslator.ToHtml(hasStyle.BackColor).Trim()};");
76-
if (hasStyle.ForeColor != default(Color)) sb.Append($"color:{ColorTranslator.ToHtml(hasStyle.ForeColor)};");
77-
if (hasStyle.BorderStyle != BorderStyle.None && hasStyle.BorderStyle != BorderStyle.NotSet && hasStyle.BorderWidth.Value > 0 && hasStyle.BorderColor != default(Color))
75+
if (hasStyle.BackColor != default(WebColor)) sb.Append($"background-color:{ColorTranslator.ToHtml(hasStyle.BackColor.ToColor()).Trim()};");
76+
if (hasStyle.ForeColor != default(WebColor)) sb.Append($"color:{ColorTranslator.ToHtml(hasStyle.ForeColor.ToColor())};");
77+
if (hasStyle.BorderStyle != BorderStyle.None && hasStyle.BorderStyle != BorderStyle.NotSet && hasStyle.BorderWidth.Value > 0 && hasStyle.BorderColor != default(WebColor))
7878
{
7979

80-
sb.Append($"border:{hasStyle.BorderWidth.ToString()} {hasStyle.BorderStyle.ToString().ToLowerInvariant()} {ColorTranslator.ToHtml(hasStyle.BorderColor)};");
80+
sb.Append($"border:{hasStyle.BorderWidth.ToString()} {hasStyle.BorderStyle.ToString().ToLowerInvariant()} {ColorTranslator.ToHtml(hasStyle.BorderColor.ToColor())};");
8181

8282
}
8383

src/BlazorWebFormsComponents/TableItemStyle.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using BlazorWebFormsComponents.Enums;
2-
using Microsoft.AspNetCore.Components;
32
using System;
43
using System.Collections.Generic;
54
using System.Drawing;
65
using System.Linq;
7-
using System.Text;
86

97
namespace BlazorWebFormsComponents
108
{
@@ -13,9 +11,9 @@ public class TableItemStyle : IHasStyle
1311

1412
internal TableItemStyle() { }
1513

16-
public Color BackColor { get; set; }
14+
public WebColor BackColor { get; set; }
1715

18-
public Color BorderColor { get; set; }
16+
public WebColor BorderColor { get; set; }
1917

2018
public BorderStyle BorderStyle { get; set; }
2119

@@ -37,7 +35,7 @@ internal TableItemStyle() { }
3735

3836
public bool Font_Underline { get; set; }
3937

40-
public Color ForeColor { get; set; }
38+
public WebColor ForeColor { get; set; }
4139

4240
public Unit Height { get; set; }
4341

@@ -87,7 +85,7 @@ private void FromAttributes(IEnumerable<KeyValuePair<string,object>> attributes)
8785
var outValue = propInfo.PropertyType switch
8886
{
8987
null => null,
90-
{ Name: nameof(Color) } => itemStyle.Value.GetColorFromHtml(),
88+
{ Name: nameof(WebColor) } => itemStyle.Value.GetWebColorFromHtml(),
9189
{ Name: nameof(Unit) } => new Unit(itemStyle.Value.ToString()),
9290
{ Name: nameof(FontUnit) } => FontUnit.Parse(itemStyle.Value.ToString()),
9391
{ IsEnum: true } => Enum.Parse(propInfo.PropertyType, itemStyle.Value.ToString()),

src/BlazorWebFormsComponents/UiStyle.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using BlazorWebFormsComponents.Enums;
22
using Microsoft.AspNetCore.Components;
33
using System.Collections.Generic;
4-
using System.Drawing;
54

65
namespace BlazorWebFormsComponents
76
{
@@ -15,10 +14,10 @@ public abstract class UiStyle : ComponentBase, IHasLayoutStyle
1514
public Dictionary<string, object> AdditionalAttributes { get; set; }
1615

1716
[Parameter]
18-
public Color BackColor { get; set; }
17+
public WebColor BackColor { get; set; }
1918

2019
[Parameter]
21-
public Color BorderColor { get; set; }
20+
public WebColor BorderColor { get; set; }
2221

2322
[Parameter]
2423
public BorderStyle BorderStyle { get; set; }
@@ -30,7 +29,7 @@ public abstract class UiStyle : ComponentBase, IHasLayoutStyle
3029
public string CssClass { get; set; }
3130

3231
[Parameter]
33-
public Color ForeColor { get; set; }
32+
public WebColor ForeColor { get; set; }
3433

3534
[Parameter]
3635
public Unit Height { get; set; }

0 commit comments

Comments
 (0)