Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed May 20, 2024
1 parent 822f770 commit 933721f
Show file tree
Hide file tree
Showing 26 changed files with 1,362 additions and 1,230 deletions.
81 changes: 81 additions & 0 deletions src/LoreSoft.Blazor.Controls/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#nullable enable

using System.Diagnostics.CodeAnalysis;

namespace LoreSoft.Blazor.Controls.Extensions;

/// <summary>
/// <see cref="String"/> extension methods
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Truncates the specified text.
/// </summary>
/// <param name="text">The text to truncate.</param>
/// <param name="keep">The number of characters to keep.</param>
/// <param name="ellipsis">The ellipsis string to use when truncating. (Default ...)</param>
/// <returns>
/// A truncate string.
/// </returns>
[return: NotNullIfNotNull(nameof(text))]
public static string? Truncate(this string? text, int keep, string ellipsis = "...")
{
if (string.IsNullOrEmpty(text))
return text;

if (string.IsNullOrEmpty(ellipsis))
ellipsis = string.Empty;

if (text.Length <= keep)
return text;

if (text.Length <= keep + ellipsis.Length || keep < ellipsis.Length)
return text.Substring(0, keep);

return string.Concat(text.Substring(0, keep - ellipsis.Length), ellipsis);
}

/// <summary>
/// Indicates whether the specified String object is null or an empty string
/// </summary>
/// <param name="item">A String reference</param>
/// <returns>
/// <c>true</c> if is null or empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? item)
{
return string.IsNullOrEmpty(item);
}

/// <summary>
/// Indicates whether a specified string is null, empty, or consists only of white-space characters
/// </summary>
/// <param name="item">A String reference</param>
/// <returns>
/// <c>true</c> if is null or empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? item)
{
if (item == null)
return true;

for (int i = 0; i < item.Length; i++)
if (!char.IsWhiteSpace(item[i]))
return false;

return true;
}

/// <summary>
/// Determines whether the specified string is not <see cref="IsNullOrEmpty"/>.
/// </summary>
/// <param name="value">The value to check.</param>
/// <returns>
/// <c>true</c> if the specified <paramref name="value"/> is not <see cref="IsNullOrEmpty"/>; otherwise, <c>false</c>.
/// </returns>
public static bool HasValue([NotNullWhen(true)] this string? value)
{
return !string.IsNullOrEmpty(value);
}
}
4 changes: 3 additions & 1 deletion src/LoreSoft.Blazor.Controls/LoadingBlock.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using LoreSoft.Blazor.Controls.Extensions;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

Expand Down Expand Up @@ -38,7 +40,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.CloseElement(); // div
}

if (!string.IsNullOrEmpty(LoadingText))
if (LoadingText.HasValue())
{
builder.OpenElement(6, "div");
builder.AddAttribute(7, "class", "loading-block-text");
Expand Down
14 changes: 14 additions & 0 deletions src/LoreSoft.Blazor.Controls/LoreSoft.Blazor.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>true</IsPackable>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,4 +18,16 @@
<EmbeddedResource Include="wwwroot\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>


<Target Name="SassCheck" BeforeTargets="PreBuild">
<Exec Command="sass --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCodeSass" />
</Exec>
<Error Condition="'$(ErrorCodeSass)' != '0'" Text="dart-sass is required for this project. install globally with 'npm i -g sass' " />
</Target>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="sass Styles/controls.scss:wwwroot/BlazorControls.css --style compressed --load-path=Styles" />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
using System.Timers;

using LoreSoft.Blazor.Controls.Utilities;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

using Timer = System.Timers.Timer;

namespace LoreSoft.Blazor.Controls;

public partial class ProgressBar : ComponentBase, IDisposable
public class ProgressBar : ComponentBase, IDisposable
{
private Timer _progressTimer;
private Timer _completeTimer;

[Inject]
protected ProgressBarState State { get; set; }

[Parameter]
public string Color { get; set; } = "#29d";

Expand All @@ -23,14 +29,15 @@ public partial class ProgressBar : ComponentBase, IDisposable
[Parameter]
public double MinimumProgress { get; set; } = 0.05;

[Inject]
protected ProgressBarState State { get; set; }
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> Attributes { get; set; } = [];


protected int Opacity { get; set; }

protected double Progress { get; set; }

protected string ClassName { get; set; }

protected string ContainerStyle => $"opacity: {Opacity}; transition: opacity {AnimationDuration}ms linear 0s;";

Expand All @@ -57,6 +64,45 @@ protected override void OnInitialized()

}

protected override void OnParametersSet()
{
// update only after parameters are set
ClassName = new CssBuilder("progress-container")
.MergeClass(Attributes)
.ToString();
}

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "div");
builder.AddAttribute(1, "class", ClassName);
builder.AddAttribute(2, "style", ContainerStyle);
builder.AddMultipleAttributes(3, Attributes);

builder.OpenElement(4, "div");
builder.AddAttribute(5, "class", "progress-status-bar");
builder.AddAttribute(6, "style", BarStyle);

builder.OpenElement(7, "div");
builder.AddAttribute(8, "class", "progress-status-peg");
builder.AddAttribute(9, "style", PegStyle);
builder.CloseElement(); // peg

builder.CloseElement(); // bar

builder.OpenElement(10, "div");
builder.AddAttribute(11, "class", "progress-status-spinner");

builder.OpenElement(12, "div");
builder.AddAttribute(13, "class", "progress-status-spinner-icon");
builder.AddAttribute(14, "style", IconStyle);
builder.CloseElement(); // icon

builder.CloseElement(); // spinner

builder.CloseElement(); // container
}

private void OnComplete(object sender, ElapsedEventArgs e)
{
InvokeAsync(() =>
Expand Down
9 changes: 0 additions & 9 deletions src/LoreSoft.Blazor.Controls/ProgressBar.razor

This file was deleted.

65 changes: 65 additions & 0 deletions src/LoreSoft.Blazor.Controls/Skeleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.ComponentModel;

using LoreSoft.Blazor.Controls.Extensions;
using LoreSoft.Blazor.Controls.Utilities;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace LoreSoft.Blazor.Controls;

public class Skeleton : ComponentBase
{
[Parameter]
public string Width { set; get; }

[Parameter]
public string Height { set; get; }

[Parameter]
public SkeletonType Type { set; get; } = SkeletonType.Text;

[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> Attributes { get; set; } = [];

protected string ClassName { get; set; }

protected string Style { get; set; }

protected override void OnParametersSet()
{
var type = Type.ToString().ToLowerInvariant();

// update only after parameters are set
ClassName = new CssBuilder("skeleton")
.AddClass("skeleton-wave")
.AddClass($"skeleton-{type}")
.MergeClass(Attributes)
.ToString();

Style = new StyleBuilder()
.MergeStyle(Attributes)
.AddStyle("width", Width, (v) => v.HasValue())
.AddStyle("height", Height, (v) => v.HasValue())
.ToString();
}

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "span");
builder.AddAttribute(1, "class", ClassName);
builder.AddAttribute(2, "style", Style);
builder.AddMultipleAttributes(3, Attributes);
builder.CloseElement(); // span
}
}

public enum SkeletonType
{
[Description("text")]
Text,
[Description("circle")]
Circle,
[Description("rectangle")]
Rectangle
}
4 changes: 0 additions & 4 deletions src/LoreSoft.Blazor.Controls/Skeleton.razor

This file was deleted.

49 changes: 0 additions & 49 deletions src/LoreSoft.Blazor.Controls/Skeleton.razor.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/LoreSoft.Blazor.Controls/StateProvider.razor

This file was deleted.

27 changes: 0 additions & 27 deletions src/LoreSoft.Blazor.Controls/StateProvider.razor.cs

This file was deleted.

Loading

0 comments on commit 933721f

Please sign in to comment.