Skip to content

Commit 07bf7f0

Browse files
committed
Key Hyphen Converter
1 parent 8ecd0d5 commit 07bf7f0

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

BCSS/Component/BlazorCssProvider.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
continue;
1111
}
1212
var processedValue = info.Value?.Split(' ') ?? new string[0];
13-
@($".{info.Key}{(info.Suffixes.Contains("hover") ? ":hover" : null)}{(info.Suffixes.Contains("focus") ? ":focus" : null)} {{ {string.Join("!important;", processedValue) + "!important;"} }}")
13+
@($".{info.Key}{GetSuffixString(info.Suffixes)} {{ {string.Join("!important;", processedValue) + "!important;"} }}")
1414
}
1515
</style>
1616

BCSS/Component/BlazorCssProvider.razor.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ protected string GetMediaString(string breakpoint)
6767
return result;
6868
}
6969

70+
protected string GetSuffixString(List<string> suffixes)
71+
{
72+
var result = string.Empty;
73+
List<string> match = _suffixes.Intersect(suffixes).ToList();
74+
if (match.Any())
75+
{
76+
result = $":{match.First()}";
77+
}
78+
79+
return result;
80+
}
81+
7082
public void Update()
7183
{
7284
StateHasChanged();
@@ -90,6 +102,32 @@ public void ClearLast()
90102
StateHasChanged();
91103
}
92104

93-
private List<string> _breakpoints = new List<string>() { "xs", "sm", "md", "lg", "xl" };
105+
private readonly List<string> _breakpoints = new List<string>() { "xs", "sm", "md", "lg", "xl" };
106+
private readonly List<string> _suffixes = new List<string>()
107+
{
108+
"active",
109+
"checked",
110+
"disabled",
111+
"empty",
112+
"enabled",
113+
"hover",
114+
"focus",
115+
"focus-visible",
116+
"focus-within",
117+
"first-child",
118+
"last-child",
119+
"link",
120+
"optional",
121+
"out-of-range",
122+
"read-only",
123+
"read-write",
124+
"required",
125+
"root",
126+
"target",
127+
"valid",
128+
"invalid",
129+
"visited"
130+
};
131+
94132
}
95133
}

BCSS/Services/BCSSService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Attach(BlazorCssProvider provider)
4343

4444
protected string Decode(string value)
4545
{
46-
return value.Replace("%", "--").Replace(".", "_-").Replace(":", "_1");
46+
return value.Replace("%", "--").Replace(".", "_-").Replace(":", "_1").Replace("/", "_2");
4747
}
4848

4949

BCSS/Services/BlazorCssConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static List<string> GetSuffixes(string className)
1616
return suffixes;
1717
}
1818

19-
string[] partials = key.Split(':');
19+
string[] partials = key.Replace('/', '-').Split(':');
2020
for (int i = 0; i < partials.Length - 1; i++)
2121
{
2222
suffixes.Add(partials[i]);
@@ -32,7 +32,7 @@ public static string Convert (string className)
3232
}
3333

3434
string[] processedString = className.Split('-');
35-
string? key = processedString.First().Split(':').Last();
35+
string? key = processedString.First().Split(':').Last().Replace('/', '-');
3636
string? value = processedString.Length < 2 ? string.Empty : className.Substring(processedString.First().Length + 1);
3737

3838
if (string.IsNullOrEmpty(value))

0 commit comments

Comments
 (0)