Skip to content

Commit ef5f584

Browse files
committed
Add Custom Classes
1 parent f76dc3d commit ef5f584

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

BCSS.Test/CoreTests/ConverterTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,25 @@ public void CaseInsensitiveTest()
105105
BlazorCssConverter.Convert("bgiMage-[/Paper.Png]").Should().Be("background-image:url(Paper.Png)");
106106
}
107107

108+
[Test]
109+
public void PrefixesTest()
110+
{
111+
BcssService service = new BcssService();
112+
service.Decode("hover:bg-yellow").Should().Be("hover_1bg-yellow");
113+
BlazorCssConverter.Convert("hover:bg-yellow").Should().Be("background:yellow");
114+
115+
service.Decode("h:bg-yellow").Should().Be("h_1bg-yellow");
116+
BlazorCssConverter.Convert("h:bg-yellow").Should().Be("background:yellow");
117+
118+
service.Decode("w:bg-yellow").Should().Be("w_1bg-yellow");
119+
BlazorCssConverter.Convert("w:bg-yellow").Should().Be("background:yellow");
120+
121+
service.Decode("sm:w:bg-yellow").Should().Be("sm_1w_1bg-yellow");
122+
BlazorCssConverter.Convert("sm:w:bg-yellow").Should().Be("background:yellow");
123+
124+
service.Decode("sm:bg-yellow").Should().Be("sm_1bg-yellow");
125+
BlazorCssConverter.Convert("sm:bg-yellow").Should().Be("background:yellow");
126+
}
127+
108128
}
109129
}

BCSS/Services/BcssService.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ public void Attach(BlazorCssProvider provider)
1919
}
2020

2121
string[] values = value.Split(' ');
22-
2322
foreach (var val in values)
2423
{
2524
string key = Decode(val);
25+
List<string> prefixes = BlazorCssConverter.GetPrefixes(val);
26+
27+
if (prefixes.Contains("c"))
28+
{
29+
continue;
30+
}
31+
2632
bool isDuplicated = Provider.CheckDuplicate(val);
2733
if (isDuplicated)
2834
{
@@ -32,7 +38,7 @@ public void Attach(BlazorCssProvider provider)
3238
string? result = BlazorCssConverter.Convert(val, Provider);
3339

3440
BcssInfo info = new();
35-
info.Prefixes = BlazorCssConverter.GetPrefixes(val);
41+
info.Prefixes = prefixes;
3642
info.Key = key;
3743
info.Value = result;
3844
_ = Provider.AddInfo(info);
@@ -55,7 +61,12 @@ public string? this[string key]
5561

5662
protected internal string Decode(string value)
5763
{
58-
return value.ToLower().Replace(":", "_1").Replace("/", "_2").Replace("*", "_3").Replace("#", "_4").Replace(",", "_5").Replace("+", "_6").Replace("%", "_7").Replace(".", "_8").Replace("[", null).Replace("]", null);
64+
string result = value.ToLower();
65+
if (result.StartsWith("c:"))
66+
{
67+
result = result.Substring(2);
68+
}
69+
return result.ToLower().Replace(":", "_1").Replace("/", "_2").Replace("*", "_3").Replace("#", "_4").Replace(",", "_5").Replace("+", "_6").Replace("%", "_7").Replace(".", "_8").Replace("[", null).Replace("]", null);
5970
}
6071

6172
public void SetBreakpoints(int xs = 0, int sm = 600, int md = 960, int lg = 1280, int xl = 1920)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@page "/syntax/customclasses"
2+
@namespace BCSSViewer.Docs.Pages
3+
4+
<MudContainer>
5+
<MudText Typo="Typo.h4">Custom Classes</MudText>
6+
7+
<MudStack Class="mt-4" Spacing="4">
8+
<CodeBlock Description="Users may have their predefined classes." Code="@("<style>\n\t.user-custom-class {\n\t\tbackground: yellow;\n\t}\n</style>")" />
9+
<CodeBlock Description="You can directly use these classes in BCSS." Code="@("<div class=\"@Bc[\"user-custom-class\"]\" />")" />
10+
<CodeBlock Description="Or you can use c (custom) prefix for slightly better performance." Code="@("<div class=\"@Bc[\"c:user-custom-class\"]\" />")" />
11+
</MudStack>
12+
13+
<PageBottomRouting PreviousHref="/syntax/vendorprefixes" PreviousText="Vendor Prefixes (webkit, moz, ms, o)" NextHref="/syntax/customvalues" NextText="Custom Values" />
14+
</MudContainer>

BCSSViewer.Docs/Pages/Syntax/VendorPrefixesPage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
<CodeBlock Description="Vendor prefixes implement like other prefixes. (with colon)." Code="@("w:bg-yellow\t//-webkit-background: yellow\nm:bg-yellow\t//-moz-background: yellow\nms:bg-yellow\t//-ms-background: yellow\no:bg-yellow\t//-o-background: yellow")" />
99
</MudStack>
1010

11-
<PageBottomRouting PreviousHref="/syntax/prefixes" PreviousText="Prefixes (Hover, Focus etc.)" NextHref="/syntax/customvalues" NextText="Custom Values" />
11+
<PageBottomRouting PreviousHref="/syntax/prefixes" PreviousText="Prefixes (Hover, Focus etc.)" NextHref="/syntax/customclasses" NextText="Custom Classes" />
1212
</MudContainer>

BCSSViewer.Docs/Shared/MainLayout.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<MudNavLink Match="NavLinkMatch.All" Href="/syntax/unitmeasurement">Unit Measurement (Px, Rem)</MudNavLink>
3333
<MudNavLink Match="NavLinkMatch.All" Href="/syntax/prefixes">Prefixes (Breakpoints, Hover, Focus etc.)</MudNavLink>
3434
<MudNavLink Match="NavLinkMatch.All" Href="/syntax/vendorprefixes">Vendor Prefixes (webkit, moz, ms, o)</MudNavLink>
35+
<MudNavLink Match="NavLinkMatch.All" Href="/syntax/customclasses">Custom Classes</MudNavLink>
3536
<MudNavLink Match="NavLinkMatch.All" Href="/syntax/customvalues">Custom Values & Colors</MudNavLink>
3637
<MudNavLink Match="NavLinkMatch.All" Href="/syntax/caseinsensitive">Case Insensitive</MudNavLink>
3738
</MudNavGroup>

BCSSViewer.Wasm/wwwroot/staticwebapp.config.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)