Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Core/Utilities/CssBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Microsoft.Fast.Components.FluentUI.Utilities;
using System.Text;

namespace Microsoft.Fast.Components.FluentUI.Utilities;

public struct CssBuilder
{
private string? stringBuffer;
private StringBuilder stringBuffer;

/// <summary>
/// Creates a CssBuilder used to define conditional CSS classes used in a component.
Expand All @@ -17,12 +19,14 @@ public struct CssBuilder
/// </summary>
public static CssBuilder Empty() => new();

public CssBuilder() => stringBuffer = new();

/// <summary>
/// Creates a CssBuilder used to define conditional CSS classes used in a component.
/// Call Build() to return the completed CSS Classes as a string.
/// </summary>
/// <param name="value"></param>
public CssBuilder(string? value) => stringBuffer = value;
public CssBuilder(string? value) => stringBuffer = new(value);

/// <summary>
/// Adds a raw string to the builder that will be concatenated with the next class or value added to the builder.
Expand All @@ -31,7 +35,7 @@ public struct CssBuilder
/// <returns>CssBuilder</returns>
public CssBuilder AddValue(string? value)
{
stringBuffer += value;
stringBuffer.Append(value);
return this;
}

Expand Down Expand Up @@ -115,7 +119,7 @@ public CssBuilder AddClassFromAttributes(IReadOnlyDictionary<string, object> add
public string? Build()
{
// String buffer finalization code
return stringBuffer?.Trim();
return stringBuffer.ToString().Trim();
}

// ToString should only and always call Build to finalize the rendered string.
Expand Down
14 changes: 9 additions & 5 deletions src/Core/Utilities/StyleBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Microsoft.Fast.Components.FluentUI.Utilities;
using System.Text;

namespace Microsoft.Fast.Components.FluentUI.Utilities;

public struct StyleBuilder
{
private string? stringBuffer;
private StringBuilder stringBuffer;

/// <summary>
/// Creates a StyleBuilder used to define conditional in-line style used in a component. Call Build() to return the completed style as a string.
Expand All @@ -22,12 +24,14 @@ public struct StyleBuilder
/// </summary>
public static StyleBuilder Empty() => new();

public StyleBuilder() => stringBuffer = new();

/// <summary>
/// Creates a StyleBuilder used to define conditional in-line style used in a component. Call Build() to return the completed style as a string.
/// </summary>
/// <param name="prop"></param>
/// <param name="value"></param>
public StyleBuilder(string prop, string value) => stringBuffer = $"{prop}: {value};";
public StyleBuilder(string prop, string value) => stringBuffer = new($"{prop}:{value};");

/// <summary>
/// Adds a conditional in-line style to the builder with space separator and closing semicolon.
Expand All @@ -42,7 +46,7 @@ public struct StyleBuilder
/// <returns>StyleBuilder</returns>
private StyleBuilder AddRaw(string? style)
{
stringBuffer += style;
stringBuffer.Append(style);
return this;
}

Expand Down Expand Up @@ -146,7 +150,7 @@ public StyleBuilder AddStyleFromAttributes(IReadOnlyDictionary<string, object> a
public string? Build()
{
// String buffer finalization code
return stringBuffer?.Trim();
return stringBuffer.ToString().Trim();
}

// ToString should only and always call Build to finalize the rendered string.
Expand Down
12 changes: 7 additions & 5 deletions src/Core/Utilities/ValueBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace Microsoft.Fast.Components.FluentUI.Utilities;
using System.Text;

namespace Microsoft.Fast.Components.FluentUI.Utilities;

public class ValueBuilder
{
private string? stringBuffer;
private StringBuilder stringBuffer = new();

public bool HasValue => !string.IsNullOrWhiteSpace(stringBuffer);
public bool HasValue => stringBuffer.Length > 0;
/// <summary>
/// Adds a space separated conditional value to a property.
/// </summary>
Expand All @@ -16,9 +18,9 @@ public class ValueBuilder

private ValueBuilder AddRaw(string? style)
{
stringBuffer += style;
stringBuffer.Append(style);
return this;
}

public override string? ToString() => stringBuffer?.Trim();
public override string? ToString() => stringBuffer.ToString().Trim();
}