Skip to content

Commit

Permalink
Key Hyphen Converter
Browse files Browse the repository at this point in the history
  • Loading branch information
mckaragoz committed Aug 28, 2023
1 parent 8ecd0d5 commit 07bf7f0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion BCSS/Component/BlazorCssProvider.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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;"} }}")
}
</style>

Expand Down
40 changes: 39 additions & 1 deletion BCSS/Component/BlazorCssProvider.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ protected string GetMediaString(string breakpoint)
return result;
}

protected string GetSuffixString(List<string> suffixes)
{
var result = string.Empty;
List<string> match = _suffixes.Intersect(suffixes).ToList();
if (match.Any())
{
result = $":{match.First()}";
}

return result;
}

public void Update()
{
StateHasChanged();
Expand All @@ -90,6 +102,32 @@ public void ClearLast()
StateHasChanged();
}

private List<string> _breakpoints = new List<string>() { "xs", "sm", "md", "lg", "xl" };
private readonly List<string> _breakpoints = new List<string>() { "xs", "sm", "md", "lg", "xl" };
private readonly List<string> _suffixes = new List<string>()
{
"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"
};

}
}
2 changes: 1 addition & 1 deletion BCSS/Services/BCSSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}


Expand Down
4 changes: 2 additions & 2 deletions BCSS/Services/BlazorCssConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static List<string> 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]);
Expand All @@ -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))
Expand Down

0 comments on commit 07bf7f0

Please sign in to comment.