From 07bf7f0e1fb8e5e535a7c1dddff6fa9a3d24bc34 Mon Sep 17 00:00:00 2001 From: mckaragoz <78308169+mckaragoz@users.noreply.github.com> Date: Tue, 29 Aug 2023 00:19:46 +0300 Subject: [PATCH] Key Hyphen Converter --- BCSS/Component/BlazorCssProvider.razor | 2 +- BCSS/Component/BlazorCssProvider.razor.cs | 40 ++++++++++++++++++++++- BCSS/Services/BCSSService.cs | 2 +- BCSS/Services/BlazorCssConverter.cs | 4 +-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/BCSS/Component/BlazorCssProvider.razor b/BCSS/Component/BlazorCssProvider.razor index 4962b7e..30a4d55 100644 --- a/BCSS/Component/BlazorCssProvider.razor +++ b/BCSS/Component/BlazorCssProvider.razor @@ -10,7 +10,7 @@ continue; } var processedValue = info.Value?.Split(' ') ?? new string[0]; - @($".{info.Key}{(info.Suffixes.Contains("hover") ? ":hover" : null)}{(info.Suffixes.Contains("focus") ? ":focus" : null)} {{ {string.Join("!important;", processedValue) + "!important;"} }}") + @($".{info.Key}{GetSuffixString(info.Suffixes)} {{ {string.Join("!important;", processedValue) + "!important;"} }}") } diff --git a/BCSS/Component/BlazorCssProvider.razor.cs b/BCSS/Component/BlazorCssProvider.razor.cs index 0e9b8dd..e8c1483 100644 --- a/BCSS/Component/BlazorCssProvider.razor.cs +++ b/BCSS/Component/BlazorCssProvider.razor.cs @@ -67,6 +67,18 @@ protected string GetMediaString(string breakpoint) return result; } + protected string GetSuffixString(List suffixes) + { + var result = string.Empty; + List match = _suffixes.Intersect(suffixes).ToList(); + if (match.Any()) + { + result = $":{match.First()}"; + } + + return result; + } + public void Update() { StateHasChanged(); @@ -90,6 +102,32 @@ public void ClearLast() StateHasChanged(); } - private List _breakpoints = new List() { "xs", "sm", "md", "lg", "xl" }; + private readonly List _breakpoints = new List() { "xs", "sm", "md", "lg", "xl" }; + private readonly List _suffixes = new List() + { + "active", + "checked", + "disabled", + "empty", + "enabled", + "hover", + "focus", + "focus-visible", + "focus-within", + "first-child", + "last-child", + "link", + "optional", + "out-of-range", + "read-only", + "read-write", + "required", + "root", + "target", + "valid", + "invalid", + "visited" + }; + } } diff --git a/BCSS/Services/BCSSService.cs b/BCSS/Services/BCSSService.cs index eb4a009..1b08076 100644 --- a/BCSS/Services/BCSSService.cs +++ b/BCSS/Services/BCSSService.cs @@ -43,7 +43,7 @@ public void Attach(BlazorCssProvider provider) protected string Decode(string value) { - return value.Replace("%", "--").Replace(".", "_-").Replace(":", "_1"); + return value.Replace("%", "--").Replace(".", "_-").Replace(":", "_1").Replace("/", "_2"); } diff --git a/BCSS/Services/BlazorCssConverter.cs b/BCSS/Services/BlazorCssConverter.cs index 5622394..1857802 100644 --- a/BCSS/Services/BlazorCssConverter.cs +++ b/BCSS/Services/BlazorCssConverter.cs @@ -16,7 +16,7 @@ public static List GetSuffixes(string className) return suffixes; } - string[] partials = key.Split(':'); + string[] partials = key.Replace('/', '-').Split(':'); for (int i = 0; i < partials.Length - 1; i++) { suffixes.Add(partials[i]); @@ -32,7 +32,7 @@ public static string Convert (string className) } string[] processedString = className.Split('-'); - string? key = processedString.First().Split(':').Last(); + string? key = processedString.First().Split(':').Last().Replace('/', '-'); string? value = processedString.Length < 2 ? string.Empty : className.Substring(processedString.First().Length + 1); if (string.IsNullOrEmpty(value))