Skip to content

Commit

Permalink
Main Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mckaragoz committed Oct 18, 2023
1 parent fb651ce commit 5c3ce1f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 38 deletions.
8 changes: 1 addition & 7 deletions BCSS.Test/CoreTests/BunitTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@

using System;
using System.Threading.Tasks;
using BCSS.Services;
using BCSS.Services;
using Bunit;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor;
using MudBlazor.Services;
using MudExtensions.Services;
using NUnit.Framework;

namespace BCSS.Test.Core
{
Expand Down
7 changes: 1 addition & 6 deletions BCSS.Test/CoreTests/ConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Bunit;
using BCSSViewer.Docs.Pages;
using FluentAssertions;
using MudBlazor;
using MudExtensions;
using FluentAssertions;
using BCSS.Services;
using Microsoft.AspNetCore.Components;

namespace BCSS.Test.Core
{
Expand Down
5 changes: 1 addition & 4 deletions BCSS.Test/CoreTests/RenderTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Bunit;
using BCSSViewer.Docs.Pages;
using BCSSViewer.Docs.Pages;
using FluentAssertions;
using MudBlazor;
using MudExtensions;

namespace BCSS.Test.Core
{
Expand Down
2 changes: 1 addition & 1 deletion BCSS/Component/BlazorCssProvider.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@namespace BCSS
@using BCSS.Services;
@using BCSS.Services
@inherits ComponentBase
@inject BcssService BcssService

Expand Down
38 changes: 32 additions & 6 deletions BCSS/Component/BlazorCssProvider.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,33 @@ public partial class BlazorCssProvider : ComponentBase
[Parameter]
public bool KeepSingleValue { get; set; }

/// <summary>
/// The spacing multiplier for px measured CSS properties like padding, margin, top, left, right, bottom.
/// </summary>
[Parameter]
public int Spacing { get; set; } = 1;

/// <summary>
/// The small size measured by pixels.
/// </summary>
[Parameter]
public int Sm { get; set; } = 600;

/// <summary>
/// The medium size measured by pixels.
/// </summary>
[Parameter]
public int Md { get; set; } = 960;

/// <summary>
/// The large size measured by pixels.
/// </summary>
[Parameter]
public int Lg { get; set; } = 1280;

/// <summary>
/// The extra large size measured by pixels.
/// </summary>
[Parameter]
public int Xl { get; set; } = 1920;

Expand Down Expand Up @@ -126,6 +141,10 @@ protected internal async Task<bool> IsValid(string propName, string propValue, b
return true;
}

/// <summary>
/// Check all BCSS classes if they are valid or not. The method will automatically removes stored and invalid BCSS classes.
/// </summary>
/// <returns></returns>
public async Task CheckAllValues()
{
List<BcssInfo> toBeDeletedInfos = new();
Expand Down Expand Up @@ -227,16 +246,23 @@ public void Update()
_shouldRender = false;
}

public void Clear(string key)
/// <summary>
/// Removes all BCSS classes (if key is null or empty) or matched classes (if key specified). If a BCSS class is currently using in the page, it will automatically add again.
/// </summary>
/// <param name="key"></param>
public void Clear(string? key = null)
{
if (string.IsNullOrEmpty(key))
{
_bcssInfos.Clear();
return;
}
_bcssInfos.RemoveAll(x => x.Key?.Split("-").First() == key.Split('-').First());
}

public void Clear()
{
_bcssInfos.Clear();
}

/// <summary>
/// Removes last added BcssInfo.
/// </summary>
public void ClearLast()
{
_bcssInfos.Remove(_bcssInfos.Last());
Expand Down
5 changes: 1 addition & 4 deletions BCSS/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace BCSS.Services
{
[ExcludeFromCodeCoverage]
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddBcss(this IServiceCollection services)
Expand Down
7 changes: 6 additions & 1 deletion BCSS/Services/BcssService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public void Reset()
Provider.Update();
}

/// <summary>
/// Adds unified classes with given user-created name and BCSS classes seperated with space.
/// </summary>
/// <param name="unifiedName"></param>
/// <param name="value"></param>
public void AddUnifiedClass(string unifiedName, string value)
{
if (Provider == null)
Expand Down Expand Up @@ -181,7 +186,7 @@ public void SetPerformanceMode(bool value)
#pragma warning restore BL0005
}

public async Task CheckValuesIsValid()
public async Task RemoveInvalidClasses()
{
if (Provider == null)
{
Expand Down
10 changes: 5 additions & 5 deletions BCSS/Services/BlazorCssConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static string Convert(string className, BlazorCssProvider? provider = nul
}

bool _shouldNotLowercase = false;
if (className.Contains("[") && className.Contains("/"))
if (className.Contains('[') && className.Contains('/'))
{
_shouldNotLowercase = true;
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public static string Convert(string className, BlazorCssProvider? provider = nul

if (string.Equals(fullKey, "bottom", StringComparison.InvariantCultureIgnoreCase))
{
return DimensionResult(processedValue, fullKey);
return DimensionResult(processedValue.Replace('n', '-'), fullKey);
}

if (string.Equals(fullKey, "box", StringComparison.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -306,7 +306,7 @@ public static string Convert(string className, BlazorCssProvider? provider = nul

if (string.Equals(fullKey, "left", StringComparison.InvariantCultureIgnoreCase))
{
return DimensionResult(processedValue, fullKey);
return DimensionResult(processedValue.Replace('n', '-'), fullKey);
}

if (string.Equals(fullKey, "min-height", StringComparison.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -541,7 +541,7 @@ public static string Convert(string className, BlazorCssProvider? provider = nul

if (string.Equals(fullKey, "right", StringComparison.InvariantCultureIgnoreCase))
{
return DimensionResult(processedValue, fullKey);
return DimensionResult(processedValue.Replace('n', '-'), fullKey);
}

if (string.Equals(fullKey, "rotate", StringComparison.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -663,7 +663,7 @@ public static string Convert(string className, BlazorCssProvider? provider = nul

if (string.Equals(fullKey, "top", StringComparison.InvariantCultureIgnoreCase))
{
return DimensionResult(processedValue, fullKey);
return DimensionResult(processedValue.Replace('n', '-'), fullKey);
}

if (string.Equals(fullKey, "translate", StringComparison.InvariantCultureIgnoreCase))
Expand Down
5 changes: 2 additions & 3 deletions BCSS/wwwroot/Bcss.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

function checkcss(propname, propvalue) {
function checkcss(propname, propvalue) {
var result = CSS.supports(propname, propvalue);
return result;
}
}
2 changes: 1 addition & 1 deletion BCSSViewer/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
<script src="_framework/blazor.server.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script src="_content/CodeBeam.MudBlazor.Extensions/MudExtensions.min.js"></script>
<script src="_content/CodeBeam.BCSS/Bcss.js"></script>
<script src="_content/CodeBeam.BCSS/Bcss.min.js"></script>
</body>
</html>

0 comments on commit 5c3ce1f

Please sign in to comment.