-
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.
Add exit this page component generation
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/GovUk.Frontend.AspNetCore/ComponentGeneration/DefaultComponentGenerator.ExitThisPage.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,43 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using HtmlTags; | ||
|
||
namespace GovUk.Frontend.AspNetCore.ComponentGeneration; | ||
|
||
public partial class DefaultComponentGenerator | ||
{ | ||
internal const string ExitThisPageElement = "div"; | ||
|
||
/// <inheritdoc/> | ||
public HtmlTag GenerateExitThisPage(ExitThisPageOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(options); | ||
options.Validate(); | ||
|
||
return new HtmlTag(ExitThisPageElement) | ||
.AddEncodedAttributeIfNotNull("id", options.Id) | ||
.AddClass("govuk-exit-this-page") | ||
.AddClasses(ExplodeClasses(options.Classes)) | ||
.UnencodedAttr("data-module", "govuk-exit-this-page") | ||
.MergeEncodedAttributes(options.Attributes) | ||
.AddEncodedAttributeIf(options.ActivatedText.NormalizeEmptyString() is not null, "data-i18n.activated", HtmlEncode(options.ActivatedText)) | ||
.AddEncodedAttributeIf(options.TimedOutText.NormalizeEmptyString() is not null, "data-i18n.timed-out", HtmlEncode(options.TimedOutText)) | ||
.AddEncodedAttributeIf(options.PressTwoMoreTimesText.NormalizeEmptyString() is not null, "data-i18n.press-two-more-times", HtmlEncode(options.PressTwoMoreTimesText)) | ||
.AddEncodedAttributeIf(options.PressOneMoreTimeText.NormalizeEmptyString() is not null, "data-i18n.press-one-more-time", HtmlEncode(options.PressOneMoreTimeText)) | ||
.Append(GenerateButton(new ButtonOptions() | ||
{ | ||
Html = (options.Html.NormalizeEmptyString() ?? options.Text.NormalizeEmptyString()) is not null ? | ||
options.Html : | ||
new HtmlTag("span") | ||
.AddClass("govuk-visually-hidden") | ||
.Text("Emergency") | ||
.After(new HtmlTag(null).Text("Exit this page")) | ||
.ToHtmlString(), | ||
Text = options.Text.NormalizeEmptyString(), | ||
Classes = "govuk-button--warning govuk-exit-this-page__button govuk-js-exit-this-page-button", | ||
Href = options.RedirectUrl.NormalizeEmptyString() ?? "https://www.bbc.co.uk/weather", | ||
Attributes = ImmutableDictionary<string, string?>.Empty | ||
.Add("rel", "nofollow noreferrer") | ||
})); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/GovUk.Frontend.AspNetCore/ComponentGeneration/ExitThisPageOptions.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,24 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GovUk.Frontend.AspNetCore.ComponentGeneration; | ||
|
||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
public record ExitThisPageOptions | ||
{ | ||
public string? Text { get; set; } | ||
public string? Html { get; set; } | ||
public string? RedirectUrl { get; set; } | ||
public string? Id { get; set; } | ||
public string? Classes { get; set; } | ||
public IReadOnlyDictionary<string, string?>? Attributes { get; set; } | ||
public string? ActivatedText { get; set; } | ||
public string? TimedOutText { get; set; } | ||
public string? PressTwoMoreTimesText { get; set; } | ||
public string? PressOneMoreTimeText { get; set; } | ||
|
||
internal void Validate() | ||
{ | ||
|
||
} | ||
} |
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