Skip to content

Commit

Permalink
allow link styling (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailsKuzmins authored May 31, 2024
1 parent 317b022 commit 7eb5700
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Server/MudBlazor.Markdown.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ReactiveUI.Blazor" Version="20.0.1" />
<PackageReference Include="ReactiveUI.Blazor" Version="20.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions samples/WebAssembly/MudBlazor.Markdown.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.5" PrivateAssets="all" />
<PackageReference Include="ReactiveUI.Blazor" Version="20.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" PrivateAssets="all" />
<PackageReference Include="ReactiveUI.Blazor" Version="20.1.1" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

Expand Down
49 changes: 31 additions & 18 deletions src/MudBlazor.Markdown/Helpers/MudMarkdownStyling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@

public sealed class MudMarkdownStyling
{
public TableStyling Table { get; } = new();

public sealed class TableStyling
{
/// <summary>
/// If true, striped table rows will be used.
/// </summary>
public bool IsStriped { get; set; } = true;
/// <summary>
/// Styling properties for the table.
/// </summary>
public TableStyling Table { get; } = new();

/// <summary>
/// If true, table's cells will have left/right borders.
/// </summary>
public bool IsBordered { get; set; } = true;

/// <summary>
/// Child content of component.
/// </summary>
public int Elevation { set; get; } = 1;
}
/// <summary>
/// Styling properties for the link.
/// </summary>
public LinkStyling Link { get; } = new();

public sealed class TableStyling
{
/// <summary>
/// If true, striped table rows will be used.
/// </summary>
public bool IsStriped { get; set; } = true;

/// <summary>
/// If true, table's cells will have left/right borders.
/// </summary>
public bool IsBordered { get; set; } = true;

/// <summary>
/// Child content of component.
/// </summary>
public int Elevation { set; get; } = 1;
}

public sealed class LinkStyling
{
public Underline Underline { get; set; } = Underline.Hover;
}
}
1 change: 1 addition & 0 deletions src/MudBlazor.Markdown/MudMarkdown.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ protected virtual void RenderInlines(ContainerInline inlines, RenderTreeBuilder
{
builder.OpenComponent<MudLink>(ElementIndex++);
builder.AddAttribute(ElementIndex++, nameof(MudLink.Href), url);
builder.AddAttribute(ElementIndex++, nameof(MudLink.Underline), Styling.Link.Underline);
builder.AddAttribute(ElementIndex++, nameof(MudLink.ChildContent), (RenderFragment)(linkBuilder => RenderInlines(x, linkBuilder)));

if (url.IsExternalUri(NavigationManager?.BaseUri))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void RenderTableNotStriped()
{
Table =
{
IsStriped = false
}
IsStriped = false,
},
};

using var fixture = CreateFixture(value, styling: styling);
Expand Down Expand Up @@ -94,8 +94,8 @@ public void RenderTableNotBordered()
{
Table =
{
IsBordered = false
}
IsBordered = false,
},
};

using var fixture = CreateFixture(value, styling: styling);
Expand Down Expand Up @@ -144,11 +144,59 @@ public void RenderTableNoElevation()
{
Table =
{
Elevation = 0
}
Elevation = 0,
},
};

using var fixture = CreateFixture(value, styling: styling);
fixture.MarkupMatches(expected);
}

[Fact]
public void RenderLinkUnderlineAlways()
{
const string value = "[my link](https://www.mynihongo.org/)";

const string expected =
@"<article class='mud-markdown-body'>
<p class='mud-typography mud-typography-body1'>
<a rel='noopener noreferrer' href='https://www.mynihongo.org/' target='_blank' blazor:onclick='1' class='mud-typography mud-link mud-primary-text mud-link-underline-always mud-typography-body1'>my link</a>
</p>
</article>";

var styling = new MudMarkdownStyling
{
Link =
{
Underline = Underline.Always,
},
};

using var fixture = CreateFixture(value, styling: styling);
fixture.MarkupMatches(expected);
}

[Fact]
public void RenderLinkUnderlineNone()
{
const string value = "[my link](https://www.mynihongo.org/)";

const string expected =
@"<article class='mud-markdown-body'>
<p class='mud-typography mud-typography-body1'>
<a rel='noopener noreferrer' href='https://www.mynihongo.org/' target='_blank' blazor:onclick='1' class='mud-typography mud-link mud-primary-text mud-link-underline-none mud-typography-body1'>my link</a>
</p>
</article>";

var styling = new MudMarkdownStyling
{
Link =
{
Underline = Underline.None,
},
};

using var fixture = CreateFixture(value, styling: styling);
fixture.MarkupMatches(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.25.3" />
<PackageReference Include="bunit" Version="1.28.9" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MoqMicrosoftConfiguration" Version="1.0.5" />
Expand Down

0 comments on commit 7eb5700

Please sign in to comment.