-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Breadcrumbs to IComponentGenerator
- Loading branch information
Showing
15 changed files
with
183 additions
and
212 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
6 changes: 3 additions & 3 deletions
6
src/GovUk.Frontend.AspNetCore.DocSamples/Pages/Breadcrumbs/Breadcrumbs.cshtml
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
@page | ||
|
||
<govuk-breadcrumbs collapse-on-mobile="true"> | ||
<govuk-breadcrumbs-item asp-controller="Home" asp-action="Index">Home</govuk-breadcrumbs-item> | ||
<govuk-breadcrumbs-item href="#" link-target="_blank">Passports, travel and living abroad</govuk-breadcrumbs-item> | ||
<govuk-breadcrumbs-item>Travel abroad</govuk-breadcrumbs-item> | ||
<item asp-controller="Home" asp-action="Index">Home</item> | ||
<item href="#" link-target="_blank">Passports, travel and living abroad</item> | ||
<item>Travel abroad</item> | ||
</govuk-breadcrumbs> |
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
48 changes: 48 additions & 0 deletions
48
src/GovUk.Frontend.AspNetCore/ComponentGeneration/DefaultComponentGenerator.Breadcrumbs.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,48 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace GovUk.Frontend.AspNetCore.ComponentGeneration; | ||
|
||
public partial class DefaultComponentGenerator | ||
{ | ||
internal const string BreadcrumbsElement = "div"; | ||
internal const bool BreadcrumbsDefaultCollapseOnMobile = false; | ||
internal const string BreadcrumbsItemElement = "li"; | ||
|
||
/// <inheritdoc/> | ||
public virtual HtmlTagBuilder GenerateBreadcrumbs(BreadcrumbsOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(options); | ||
options.Validate(); | ||
|
||
return new HtmlTagBuilder(BreadcrumbsElement) | ||
.WithCssClass("govuk-breadcrumbs") | ||
.WithCssClasses(ExplodeClasses(options.Classes?.ToHtmlString())) | ||
.When(options.CollapseOnMobile == true, b => b.WithCssClass("govuk-breadcrumbs--collapse-on-mobile")) | ||
.WithAttributes(options.Attributes) | ||
.WithAppendedHtml(new HtmlTagBuilder("ol") | ||
.WithCssClass("govuk-breadcrumbs__list") | ||
.WithAppendedHtml(options.Items!.Select(item => | ||
{ | ||
var content = GetEncodedTextOrHtml(item.Text, item.Html)!; | ||
var gotLink = item.Href.NormalizeEmptyString() is not null; | ||
|
||
return new HtmlTagBuilder(BreadcrumbsItemElement) | ||
.WithCssClass("govuk-breadcrumbs__list-item") | ||
.WithAttributes(item.ItemAttributes) | ||
.When( | ||
!gotLink, | ||
b => b | ||
.WithAttribute("aria-current", "page", encodeValue: false) | ||
.WithAppendedHtml(content)) | ||
.When( | ||
gotLink, | ||
b => b | ||
.WithAppendedHtml(new HtmlTagBuilder("a") | ||
.WithCssClass("govuk-breadcrumbs__link") | ||
.WithAttribute("href", item.Href!) | ||
.WithAttributes(item.Attributes) | ||
.WithAppendedHtml(content))); | ||
}))); | ||
} | ||
} |
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
12 changes: 0 additions & 12 deletions
12
src/GovUk.Frontend.AspNetCore/HtmlGeneration/BreadcrumbsItem.cs
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.Breadcrumbs.cs
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
13 changes: 7 additions & 6 deletions
13
src/GovUk.Frontend.AspNetCore/TagHelpers/BreadcrumbsContext.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
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
Oops, something went wrong.