-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add divider component (#6)
* chore(components): add basic divider component * chore(components): comment out `bg-border` class until theme provider is ready
- Loading branch information
1 parent
487e1f2
commit af579d7
Showing
7 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
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,12 @@ | ||
// 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.Common; | ||
|
||
public enum Orientation | ||
{ | ||
Horizontal, | ||
|
||
Vertical | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@namespace LumexUI | ||
@inherits LumexComponentBase | ||
|
||
<LumexComponent As="@As" | ||
Class="@RootClass" | ||
Style="@RootStyle" | ||
@attributes="@AdditionalAttributes"> | ||
</LumexComponent> | ||
|
||
@code { | ||
/// <summary> | ||
/// Gets or sets a value defining the divider's orientation. | ||
/// </summary> | ||
/// <remarks> | ||
/// Default value is <see cref="Orientation.Horizontal" /> | ||
/// </remarks> | ||
[Parameter] public Orientation Orientation { get; set; } | ||
|
||
private protected override string? RootClass => | ||
TwMerge.Merge( Divider.GetStyles( this ) ); | ||
|
||
private new string As => Orientation is Orientation.Horizontal ? "hr" : "div"; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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.Diagnostics.CodeAnalysis; | ||
|
||
using LumexUI.Common; | ||
using LumexUI.Utilities; | ||
|
||
namespace LumexUI.Styles; | ||
|
||
[ExcludeFromCodeCoverage] | ||
internal readonly record struct Divider | ||
{ | ||
private readonly static string _base = CssBuilder.Empty() | ||
// TODO: Uncomment when the theme provider is ready | ||
//.AddClass( "bg-border" ) | ||
.AddClass( "border-none" ) | ||
.Build(); | ||
|
||
private static string GetOrientationStyles( Orientation orientation ) => orientation switch | ||
{ | ||
Orientation.Horizontal => "w-full h-px", | ||
Orientation.Vertical => "h-full w-px", | ||
_ => throw new NotImplementedException() | ||
}; | ||
|
||
public static string GetStyles( LumexDivider divider ) | ||
{ | ||
var styles = new CssBuilder() | ||
.AddClass( _base ) | ||
.AddClass( GetOrientationStyles( divider.Orientation ) ) | ||
.AddClass( divider.Class ) | ||
.Build(); | ||
|
||
return styles; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 LumexUI.Common; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using TailwindMerge; | ||
|
||
namespace LumexUI.Tests.Components; | ||
|
||
public class DividerTests : TestContext | ||
{ | ||
public DividerTests() | ||
{ | ||
Services.AddSingleton<TwMerge>(); | ||
} | ||
|
||
[Fact] | ||
public void Divider_Horizontal_ShouldRenderAsHr() | ||
{ | ||
var cut = RenderComponent<LumexDivider>( p => p | ||
.Add( p => p.Orientation, Orientation.Horizontal ) | ||
); | ||
|
||
cut.Markup.Should().StartWith( "<hr" ); | ||
} | ||
|
||
[Fact] | ||
public void Divider_Vertical_ShouldRenderAsDiv() | ||
{ | ||
var cut = RenderComponent<LumexDivider>( p => p | ||
.Add( p => p.Orientation, Orientation.Vertical ) | ||
); | ||
|
||
cut.Markup.Should().StartWith( "<div" ); | ||
} | ||
} |