Skip to content

Commit

Permalink
build: merge LumexUI.Utilities with the main project
Browse files Browse the repository at this point in the history
  • Loading branch information
desmondinho committed Feb 22, 2025
1 parent 5e40b2f commit 61e940a
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 25 deletions.
7 changes: 0 additions & 7 deletions LumexUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LumexUI.Utilities", "src\LumexUI.Utilities\LumexUI.Utilities.csproj", "{92A1C629-AB3E-4264-B03D-407E09162902}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LumexUI.Docs.Generator", "docs\LumexUI.Docs.Generator\LumexUI.Docs.Generator.csproj", "{157B8BDD-2EEF-4A69-AEA5-CAA3650CF73C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5DBC44B8-5B92-4504-8B8F-91A1672251E6}"
Expand Down Expand Up @@ -42,10 +40,6 @@ Global
{F5DCF265-756B-4B25-AECA-15B9FF2DCB66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5DCF265-756B-4B25-AECA-15B9FF2DCB66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5DCF265-756B-4B25-AECA-15B9FF2DCB66}.Release|Any CPU.Build.0 = Release|Any CPU
{92A1C629-AB3E-4264-B03D-407E09162902}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92A1C629-AB3E-4264-B03D-407E09162902}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92A1C629-AB3E-4264-B03D-407E09162902}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92A1C629-AB3E-4264-B03D-407E09162902}.Release|Any CPU.Build.0 = Release|Any CPU
{157B8BDD-2EEF-4A69-AEA5-CAA3650CF73C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{157B8BDD-2EEF-4A69-AEA5-CAA3650CF73C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{157B8BDD-2EEF-4A69-AEA5-CAA3650CF73C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -76,7 +70,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F5DCF265-756B-4B25-AECA-15B9FF2DCB66} = {5DBC44B8-5B92-4504-8B8F-91A1672251E6}
{92A1C629-AB3E-4264-B03D-407E09162902} = {5DBC44B8-5B92-4504-8B8F-91A1672251E6}
{157B8BDD-2EEF-4A69-AEA5-CAA3650CF73C} = {3F4DE3FA-2636-440C-ACCC-137BAD95BAC4}
{06E849E9-A8EA-410B-83BC-0366524C4953} = {898610F1-A6C1-422C-84C9-C1E386957F31}
{2A341376-2409-422C-A7A9-1AE6E86F91D9} = {3F4DE3FA-2636-440C-ACCC-137BAD95BAC4}
Expand Down
1 change: 0 additions & 1 deletion docs/LumexUI.Docs.Client/LumexUI.Docs.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\LumexUI.Utilities\LumexUI.Utilities.csproj" />
<ProjectReference Include="..\..\src\LumexUI\LumexUI.csproj" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions docs/LumexUI.Docs.Client/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@using LumexUI.Docs.Client.Theme

@using LumexUI.Common
@using LumexUI.Extensions
@using LumexUI.Theme
@using LumexUI.Utilities

Expand Down
1 change: 1 addition & 0 deletions src/LumexUI/Components/Popover/LumexPopover.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the license here https://github.com/LumexUI/lumexui/blob/main/LICENSE

using LumexUI.Common;
using LumexUI.Extensions;
using LumexUI.Services;
using LumexUI.Styles;
using LumexUI.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Text;

using LumexUI.Extensions;
using LumexUI.Theme;
using LumexUI.Utilities;

Expand Down
2 changes: 1 addition & 1 deletion src/LumexUI/Components/Textbox/LumexTextbox.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the license here https://github.com/LumexUI/lumexui/blob/main/LICENSE

using LumexUI.Common;
using LumexUI.Utilities;
using LumexUI.Extensions;

using Microsoft.AspNetCore.Components;

Expand Down
25 changes: 25 additions & 0 deletions src/LumexUI/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) LumexUI 2024
// LumexUI licenses this file to you under the MIT license
// See the license here https://github.com/LumexUI/lumexui/blob/main/LICENSE

using System.ComponentModel;

namespace LumexUI.Extensions;

public static class EnumExtensions
{
public static string ToDescription( this Enum value )
{
var attributes = (DescriptionAttribute[])value
.GetType()
.GetField( value.ToString() )!
.GetCustomAttributes( typeof( DescriptionAttribute ), inherit: false );

return attributes is { Length: > 0 } ? attributes[0].Description : value.ToLowerInvariant();
}

public static string ToLowerInvariant( this Enum value )
{
return value.ToString().ToLowerInvariant();
}
}
14 changes: 0 additions & 14 deletions src/LumexUI/LumexUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>

<PropertyGroup>
<TargetsForTfmSpecificContentInPackage>
$(TargetsForTfmSpecificContentInPackage);AddUtilitiesToOutput
</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" Visible="false" PackagePath="" />
<None Include="..\..\README.md" Pack="true" Visible="false" PackagePath="" />
Expand All @@ -59,17 +53,9 @@

<ItemGroup>
<ProjectReference Include="..\LumexUI.Motion\LumexUI.Motion.csproj" />
<ProjectReference Include="..\LumexUI.Utilities\LumexUI.Utilities.csproj" />
<ProjectReference Include="..\LumexUI.Variants\LumexUI.Variants.csproj" />
</ItemGroup>

<!-- Add utilities to the build output -->
<Target Name="AddUtilitiesToOutput">
<ItemGroup>
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).Utilities.dll" PackagePath="lib\$(TargetFramework)" />
</ItemGroup>
</Target>

<!-- Install npm dependencies if 'node_modules' is not present -->
<Target Name="Npm" BeforeTargets="BeforeBuild" Condition="!Exists('node_modules')">
<Message Text="Running npm ci..." Importance="high" />
Expand Down
135 changes: 135 additions & 0 deletions src/LumexUI/Utilities/ElementClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) LumexUI 2024
// LumexUI licenses this file to you under the MIT license
// See the license here https://github.com/LumexUI/lumexui/blob/main/LICENSE

namespace LumexUI.Utilities;

/// <summary>
/// Represents a CSS class for the rendered element.
/// </summary>
public record struct ElementClass
{
private string? _stringBuffer;

/// <summary>
/// Initializes a new instance of the <see cref="ElementClass"/> with the specified value.
/// </summary>
/// <param name="value">The value to initialize the <see cref="ElementClass"/> instance with.</param>
public ElementClass( string? value )
{
_stringBuffer = value;
}

/// <summary>
/// Creates a new instance of the <see cref="ElementClass"/>.
/// </summary>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public static ElementClass Empty() => new();

/// <summary>
/// Creates a new instance of the <see cref="ElementClass"/> with the specified value.
/// </summary>
/// <param name="value">The value to be set for the new <see cref="ElementClass"/> instance.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public static ElementClass Default( string? value ) => new( value );

/// <summary>
/// Adds a CSS class to the current <see cref="ElementClass"/> instance.
/// </summary>
/// <param name="value">The CSS class to add.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( string? value )
{
if( !string.IsNullOrEmpty( value ) )
{
_stringBuffer += " " + value;
}

return this;
}

/// <summary>
/// Conditionally adds a CSS class to the current <see cref="ElementClass"/> instance.
/// </summary>
/// <param name="value">The CSS class to add.</param>
/// <param name="when">A boolean value that determines whether the CSS class should be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( string? value, bool when ) => when ? Add( value ) : this;

/// <summary>
/// Conditionally adds a CSS class to the current <see cref="ElementClass"/> instance.
/// </summary>
/// <param name="value">The CSS class to add.</param>
/// <param name="when">A function that returns a boolean value determining whether the CSS class should be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( string? value, Func<bool> when ) => Add( value, when() );

/// <summary>
/// Conditionally adds a CSS class to the current <see cref="ElementClass"/> instance.
/// </summary>
/// <param name="value">A function that returns the CSS class to add.</param>
/// <param name="when">A boolean value that determines whether the CSS class should be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( Func<string?> value, bool when ) => when ? Add( value() ) : this;

/// <summary>
/// Conditionally adds a CSS class to the current <see cref="ElementClass"/> instance.
/// </summary>
/// <param name="value">A function that returns the CSS class to add.</param>
/// <param name="when">A function that returns a boolean value determining whether the CSS class should be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( Func<string?> value, Func<bool> when ) => Add( value, when() );

/// <summary>
/// Adds a CSS class from another <see cref="ElementClass"/> instance to the current instance.
/// </summary>
/// <param name="elementClass">The <see cref="ElementClass"/> instance whose CSS classes will be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( ElementClass elementClass ) => Add( elementClass.ToString() );

/// <summary>
/// Conditionally adds a CSS class from another <see cref="ElementClass"/> instance to the current instance.
/// </summary>
/// <param name="elementClass">The <see cref="ElementClass"/> instance whose CSS classes will be added.</param>
/// <param name="when">A boolean value that determines whether the CSS class should be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( ElementClass elementClass, bool when ) => when ? Add( elementClass.ToString() ) : this;

/// <summary>
/// Conditionally adds a CSS class from another <see cref="ElementClass"/> instance to the current instance.
/// </summary>
/// <param name="elementClass">The <see cref="ElementClass"/> instance whose CSS classes will be added.</param>
/// <param name="when">A function that returns a boolean value determining whether the CSS class should be added.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( ElementClass elementClass, Func<bool> when ) => Add( elementClass, when() );

/// <summary>
/// Conditionally adds a CSS class to the current <see cref="ElementClass"/> instance when it exists in the specified additional attributes.
/// </summary>
/// <param name="additionalAttributes">The additional attributes.</param>
/// <returns>An <see cref="ElementClass"/> instance.</returns>
public ElementClass Add( IReadOnlyDictionary<string, object>? additionalAttributes )
{
if( additionalAttributes is null )
{
return this;
}

if( additionalAttributes.TryGetValue( "class", out var value ) )
{
if( value is not null )
{
return Add( value.ToString() );
}
}

return this;
}

/// <summary>
/// Returns a string representation of the current <see cref="ElementClass"/> instance.
/// </summary>
/// <returns>A trimmed <see cref="string" /> representation of the CSS classes if the internal buffer is not empty; otherwise, an empty string.</returns>
public readonly override string ToString()
=> !string.IsNullOrEmpty( _stringBuffer ) ? _stringBuffer.Trim() : string.Empty;
}
Loading

0 comments on commit 61e940a

Please sign in to comment.