-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,362 additions
and
1,230 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/LoreSoft.Blazor.Controls/Extensions/StringExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.