Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/AfterBlazorServerSide/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
});
}

public static Version ComponentVersion = typeof(IHasStyle).Assembly.GetName().Version;
public static Version ComponentVersion = typeof(IStyle).Assembly.GetName().Version;

}
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/BlazorWebFormsComponents/AdRotator.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@inherits BaseWebFormsComponent
@inherits BaseStyledComponent

@{
var activeAdvertisment = GetActiveAdvertisment();
}

@if (activeAdvertisment != null)
{
<a href="@activeAdvertisment.NavigateUrl" target="@Target" style="@CalculatedStyle" class="@CssClass"><img src="@activeAdvertisment.ImageUrl" width="@activeAdvertisment.Width" height="@activeAdvertisment.Height" alt="@activeAdvertisment.AlternateText" /></a>
<a href="@activeAdvertisment.NavigateUrl" target="@Target" style="@Style" class="@CssClass"><img src="@activeAdvertisment.ImageUrl" width="@activeAdvertisment.Width" height="@activeAdvertisment.Height" alt="@activeAdvertisment.AlternateText" /></a>
}
52 changes: 1 addition & 51 deletions src/BlazorWebFormsComponents/AdRotator.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.AspNetCore.Components;
using BlazorWebFormsComponents.Enums;
using BlazorComponentUtilities;

namespace BlazorWebFormsComponents
{
public partial class AdRotator : BaseWebFormsComponent, IHasStyle
public partial class AdRotator : BaseStyledComponent
{
private static readonly string DefaultAlternateTextField = "AlternateText";
private static readonly string DefaultImageUrlField = "ImageUrl";
Expand All @@ -37,53 +34,6 @@ public partial class AdRotator : BaseWebFormsComponent, IHasStyle
[Parameter]
public EventCallback<AdCreatedEventArgs> OnAdCreated { 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();

internal Advertisment GetActiveAdvertisment()
{
if (string.IsNullOrEmpty(AlternateTextField))
Expand Down
38 changes: 38 additions & 0 deletions src/BlazorWebFormsComponents/BaseStyledComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using BlazorComponentUtilities;
using BlazorWebFormsComponents.Enums;
using Microsoft.AspNetCore.Components;

namespace BlazorWebFormsComponents
{
public abstract class BaseStyledComponent : BaseWebFormsComponent, IStyle
{
[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 FontInfo Font { get; set; } = new FontInfo();

protected string Style => this.ToStyle().Build().NullIfEmpty();
}
}
3 changes: 1 addition & 2 deletions src/BlazorWebFormsComponents/Button.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<button type="@CalculatedButtonType"
@onclick="Click"
OnClientClick="@OnClientClick"
style="@CalculatedStyle"
style="@Style"
class="@CalculatedCssClass"
disabled="@(Enabled ? null : "disabled")"
title="@ToolTip"
>@Text</button>
}
else { }
24 changes: 1 addition & 23 deletions src/BlazorWebFormsComponents/Button.razor.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
using BlazorComponentUtilities;
using BlazorWebFormsComponents.Enums;
using Microsoft.AspNetCore.Components;
using System;

namespace BlazorWebFormsComponents
{
public partial class Button : ButtonBaseComponent, IHasStyle
public partial class Button : ButtonBaseComponent
{

[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();

internal string CalculatedButtonType => CausesValidation ? "submit" : "button";

internal string CalculatedCssClass => Enabled ? CssClass : string.Concat(CssClass, " aspNetDisabled").Trim();
Expand All @@ -38,6 +17,5 @@ public partial class Button : ButtonBaseComponent, IHasStyle

[Parameter]
public string ToolTip { get; set; }

}
}
2 changes: 1 addition & 1 deletion src/BlazorWebFormsComponents/ButtonBaseComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BlazorWebFormsComponents
{
public abstract class ButtonBaseComponent : BaseWebFormsComponent, IButtonComponent
public abstract class ButtonBaseComponent : BaseStyledComponent, IButtonComponent
{

[Parameter]
Expand Down
10 changes: 2 additions & 8 deletions src/BlazorWebFormsComponents/DataList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace BlazorWebFormsComponents
{
public partial class DataList<ItemType> : DataBoundComponent<ItemType>, IHasStyle
public partial class DataList<ItemType> : DataBoundComponent<ItemType>, IStyle
{
private static readonly Dictionary<DataListEnum, string?> _GridLines = new Dictionary<DataListEnum, string?> {
{DataListEnum.None, null },
Expand Down Expand Up @@ -47,13 +47,7 @@ public partial class DataList<ItemType> : DataBoundComponent<ItemType>, IHasStyl
[Parameter] public BorderStyle BorderStyle { get; set; }
[Parameter] public Unit BorderWidth { get; set; }
[Parameter] public string CssClass { 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; }
[Parameter] public FontInfo Font { get; set; } = new FontInfo();
[Parameter] public WebColor ForeColor { get; set; }
[Parameter] public Unit Height { get; set; }
[Parameter] public Unit Width { get; set; }
Expand Down
88 changes: 88 additions & 0 deletions src/BlazorWebFormsComponents/Extensions/HasStyleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using BlazorComponentUtilities;
using BlazorWebFormsComponents.Enums;
using System;
using System.Collections.Generic;

namespace BlazorWebFormsComponents
{
public static class HasStyleExtensions
{
public static void CopyTo(this IStyle source, IStyle destination)
{

destination.BackColor = source.BackColor;
destination.BorderColor = source.BorderColor;
destination.BorderStyle = source.BorderStyle;
destination.BorderWidth = source.BorderWidth;
destination.CssClass = source.CssClass;
destination.ForeColor = source.ForeColor;
destination.Height = source.Height;
destination.Width = source.Width;
destination.Font.Bold = source.Font.Bold;
destination.Font.Italic = source.Font.Italic;
destination.Font.Names = source.Font.Names;
destination.Font.Overline = source.Font.Overline;
destination.Font.Size = source.Font.Size;
destination.Font.Strikeout = source.Font.Strikeout;
destination.Font.Underline = source.Font.Underline;

}

public static StyleBuilder ToStyle(this IHasTableItemStyle hasStyle) =>
((IStyle)hasStyle).ToStyle().AddStyle("white-space", "nowrap", !hasStyle.Wrap);


public static StyleBuilder ToStyle(this IStyle hasStyle) =>
StyleBuilder.Empty().AddStyle("background-color", () => ColorTranslator.ToHtml(hasStyle.BackColor.ToColor()).Trim(),
when: hasStyle.BackColor != default(WebColor))

.AddStyle("color", () => ColorTranslator.ToHtml(hasStyle.ForeColor.ToColor()).Trim(),
when: hasStyle.ForeColor != default(WebColor))

.AddStyle("border", v => v.AddValue(hasStyle.BorderWidth.ToString())
.AddValue(hasStyle.BorderStyle.ToString().ToLowerInvariant())
.AddValue(() => ColorTranslator.ToHtml(hasStyle.BorderColor.ToColor()), HasBorders(hasStyle)),
when: HasBorders(hasStyle))

.AddStyle("font-weight", "bold", hasStyle.Font.Bold)
.AddStyle("font-style", "italic", hasStyle.Font.Italic)
.AddStyle("font-family", hasStyle.Font.Names, !string.IsNullOrEmpty(hasStyle.Font.Names))
.AddStyle("font-size", hasStyle.Font.Size.ToString(), hasStyle.Font.Size != FontUnit.Empty)
.AddStyle("text-decoration", v => v.AddValue("underline", hasStyle.Font.Underline)
.AddValue("overline", hasStyle.Font.Overline)
.AddValue("line-through", hasStyle.Font.Strikeout)
, HasTextDecorations(hasStyle));

private static bool HasTextDecorations(IStyle hasStyle) =>
hasStyle.Font.Underline ||
hasStyle.Font.Overline ||
hasStyle.Font.Strikeout;

private static bool HasBorders(IStyle hasStyle) =>
hasStyle.BorderStyle != BorderStyle.None &&
hasStyle.BorderStyle != BorderStyle.NotSet &&
hasStyle.BorderWidth.Value > 0 &&
hasStyle.BorderColor != default(WebColor);

public static void SetFontsFromAttributes(this IFontStyle hasStyle, Dictionary<string, object> additionalAttributes)
{
if (additionalAttributes != null)
{
hasStyle.Font.Bold = additionalAttributes.GetValue("Font-Bold", bool.Parse, hasStyle.Font.Bold);
hasStyle.Font.Italic = additionalAttributes.GetValue("Font-Italic", bool.Parse, hasStyle.Font.Italic);
hasStyle.Font.Underline = additionalAttributes.GetValue("Font-Underline", bool.Parse, hasStyle.Font.Underline);

hasStyle.Font.Names = additionalAttributes.GetValue("Font-Names", a => a, hasStyle.Font.Names);
hasStyle.Font.Overline = additionalAttributes.GetValue("Font-Overline", bool.Parse, hasStyle.Font.Overline);
hasStyle.Font.Size = additionalAttributes.GetValue("Font-Size", FontUnit.Parse, hasStyle.Font.Size);
hasStyle.Font.Strikeout = additionalAttributes.GetValue("Font-Strikeout", bool.Parse, hasStyle.Font.Strikeout);
}
}

public static T GetValue<T>(this Dictionary<string, object> additionalAttributes, string key, Func<string, T> parser, T defaultValue) =>
additionalAttributes.TryGetValue(key, out var x) ? parser(x.ToString()) : defaultValue;


}

}
Loading