Beispiel #1
0
 /// <summary>
 /// Creates a box. Do not pass null for the heading.
 /// </summary>
 /// <param name="heading">The box heading.</param>
 /// <param name="childControls">The box content.</param>
 /// <param name="headingLevel">The level of the box heading.</param>
 /// <param name="expanded">Set to true or false if you want users to be able to expand or close the box by clicking on the heading.</param>
 public Box(string heading, IEnumerable <Control> childControls, HeadingLevel headingLevel = HeadingLevel.H2, bool?expanded = null)
 {
     this.heading       = heading;
     this.headingLevel  = headingLevel;
     this.childControls = childControls.ToArray();
     this.expanded      = expanded;
 }
Beispiel #2
0
		public static string DoTitle(HeadingLevel hl, string title)
		{
			switch (hl)
			{
				case HeadingLevel.H1:
					return "<h1>" + title + "</h1>";
				case HeadingLevel.H2:
					return "<h2>" + title + "</h2>";
				case HeadingLevel.H3:
					return "<h3>" + title + "</h3>";
				case HeadingLevel.H4:
					return "<h4>" + title + "</h4>";
				default:
					throw new ArgumentException("hl");
			}
		}
Beispiel #3
0
        public static string DoTitle(HeadingLevel hl, string title)
        {
            switch (hl)
            {
            case HeadingLevel.H1:
                return("<h1>" + title + "</h1>");

            case HeadingLevel.H2:
                return("<h2>" + title + "</h2>");

            case HeadingLevel.H3:
                return("<h3>" + title + "</h3>");

            case HeadingLevel.H4:
                return("<h4>" + title + "</h4>");

            default:
                throw new ArgumentException("hl");
            }
        }
Beispiel #4
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (string.IsNullOrWhiteSpace(Id))
            {
                throw new Exception($"{nameof(Id)} cannot be blank");
            }

            if (Items is null || Items.Count < 1)
            {
                throw new Exception($"There must be at least one item in {nameof(Items)}");
            }

            // Default value is H2 as per component spec - https://design-system.service.gov.uk/components/accordion/
            if (!HeadingLevel.HasValue)
            {
                HeadingLevel = Enums.HTMLEnums.HeadingLevel.h2;
            }

            output.TagName = "div";
            output.Attributes.Add("class", "govuk-accordion");
            output.Attributes.Add("data-module", "govuk-accordion");

            if (!string.IsNullOrEmpty(Id))
            {
                output.Attributes.Add("id", Id);
            }

            var i = 1;

            foreach (var item in Items)
            {
                var headingInner = new TagBuilder("span");
                headingInner.AddCssClass("govuk-accordion__section-button");
                headingInner.Attributes.Add("id", $"{Id}-heading-{i}");
                if (item.HeadingHTML is not null)
                {
                    headingInner.InnerHtml.AppendHtml(item.HeadingHTML);
                }
                else if (item.HeadingText is not null)
                {
                    headingInner.InnerHtml.Append(item.HeadingText);
                }

                var heading = new TagBuilder(HeadingLevel.ToString());
                heading.AddCssClass("govuk-accordion__section-heading");
                heading.InnerHtml.AppendHtml(headingInner);

                var header = new TagBuilder("div");
                header.AddCssClass("govuk-accordion__section-header");
                header.InnerHtml.AppendHtml(heading);

                var container = new TagBuilder("div");
                container.AddCssClass("govuk-accordion__section");
                container.InnerHtml.AppendHtml(header);
                if (item.Expanded)
                {
                    container.AddCssClass("govuk-accordion__section--expanded");
                }

                if (item.SummaryHTML is not null || item.SummaryText is not null)
                {
                    var summary = new TagBuilder("div");
                    summary.AddCssClass("govuk-accordion__section-summary");
                    summary.AddCssClass("govuk-body");
                    summary.Attributes.Add("id", $"{Id}-summary-{i}");

                    if (item.SummaryHTML is not null)
                    {
                        summary.InnerHtml.AppendHtml(item.SummaryHTML);
                    }
                    else if (item.SummaryText is not null)
                    {
                        summary.InnerHtml.Append(item.SummaryText);
                    }

                    header.InnerHtml.AppendHtml(summary);
                }

                var content = new TagBuilder("div");
                content.AddCssClass("govuk-accordion__section-content");
                content.Attributes.Add("id", $"{Id}-content-{i}");
                content.Attributes.Add("aria-labelledby", $"{Id}-heading-{i}");
                if (item.ContentHTML is not null)
                {
                    content.InnerHtml.AppendHtml(item.ContentHTML);
                }
                else if (item.ContentText is not null)
                {
                    content.InnerHtml.Append(item.ContentText);
                }
                container.InnerHtml.AppendHtml(content);

                output.Content.AppendHtml(container);
                i++;
            }
        }
Beispiel #5
0
 public Heading(HeadingLevel level)
 {
     HeadingLevel = level;
 }
Beispiel #6
0
 public Heading(HeadingLevel level, string content, IMarkdown markdown) : base(content, markdown)
 {
     HeadingLevel = level;
 }
Beispiel #7
0
 public Heading(HeadingLevel level, string content)
 {
     HeadingLevel = level;
     Content      = content;
 }
Beispiel #8
0
 public Heading()
 {
     Level = HeadingLevel.H2;
 }
Beispiel #9
0
 public static void SetHeadingLevel(BindableObject view, HeadingLevel value) => view.SetValue(HeadingLevelProperty, value);
Beispiel #10
0
 public Heading(HeadingLevel level, string content)
 {
     this.Level = level;
     this.Controls.Add(new TextControl(content));
 }
Beispiel #11
0
 public Heading(HeadingLevel level)
     : this(level, null)
 {
 }