-
Notifications
You must be signed in to change notification settings - Fork 77
Style Refactoring #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Style Refactoring #243
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1fa4242
Style refactoring
hishamco d885737
Address the feedback
hishamco 306435e
Merge branch 'dev' into style-refactoring
hishamco e604d4c
tmp
hishamco 9898939
Merge branch 'style-refactoring' of https://github.com/hishamco/Blazo…
hishamco 4c82450
Add missing usings
hishamco 5491106
Fix the build
hishamco 9be5268
Add calculated css class
hishamco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| @inherits BaseWebFormsComponent | ||
| @inherits Component | ||
|
|
||
| @{ | ||
| 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> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| @inherits ButtonBaseComponent | ||
|
|
||
| <button type="@CalculatedButtonType" @onclick="Click" OnClientClick="@OnClientClick" style="@CalculatedStyle" class="@CssClass">@Text</button> | ||
| <button type="@CalculatedButtonType" @onclick="Click" OnClientClick="@OnClientClick" style="@Style" class="@CssClass">@Text</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,7 @@ | ||
| using BlazorComponentUtilities; | ||
| using BlazorWebFormsComponents.Enums; | ||
| using Microsoft.AspNetCore.Components; | ||
|
|
||
| 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"; | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 class Component : 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(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/BlazorWebFormsComponents/Extensions/HasStyleExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ITableItemStyle 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; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| @inherits BaseWebFormsComponent | ||
| @inherits Component | ||
|
|
||
| @if (Visible) | ||
| { | ||
|
|
||
| @if (NavigationUrl == null) | ||
| { | ||
| <a id="@ID" class="@CssClass" style="@CalculatedStyle" title="@ToolTip">@Text</a> | ||
| <a id="@ID" class="@CssClass" style="@Style" title="@ToolTip">@Text</a> | ||
| } | ||
| else | ||
| { | ||
| <a id="@ID" href="@NavigationUrl" target="@Target" title="@ToolTip" class="@CssClass" style="@CalculatedStyle">@Text</a> | ||
| <a id="@ID" href="@NavigationUrl" target="@Target" title="@ToolTip" class="@CssClass" style="@Style">@Text</a> | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.