protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) { context.SetButtonGroupContext(this); output.Attributes.Add("role", "group"); if (context.HasInputGroupContext()) { Size = BootstrapTagHelpers.Size.Default; if (!context.HasInputGroupAddonContext()) { output.TagName = "span"; output.AddCssClass("input-group-btn"); } context.RemoveInputGroupContext(); } else { output.TagName = "div"; if (Vertical) output.AddCssClass("btn-group-vertical"); else output.AddCssClass("btn-group"); if (Size.HasValue) output.AddCssClass("btn-group-" + Size.Value.GetDescription()); if (Justified) output.AddCssClass("btn-group-justified"); } }
protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) { bool hasNavContext = context.HasNavContext(); if (hasNavContext) { output.TagName = "li"; output.Attributes.Add("role", "presentation"); Context = null; Splitted = false; } else { output.TagName = "div"; output.AddCssClass("btn-group"); if (Size.HasValue && Size != BootstrapTagHelpers.Size.Default) output.AddCssClass("btn-group-" + Size.Value.GetDescription()); } if (context.HasInputGroupContext()) { Size = BootstrapTagHelpers.Size.Default; if (!context.HasInputGroupAddonContext()) { output.TagName = "span"; output.AddCssClass("input-group-btn"); } } if (Dropup) output.AddCssClass("dropup"); var buttonBuilder = new TagBuilder(Href == null && !hasNavContext ? "button" : "a"); buttonBuilder.InnerHtml.AppendHtml(Text); if (!hasNavContext) { buttonBuilder.AddCssClass("btn"); buttonBuilder.AddCssClass("btn-" + (Context ?? ButtonContext.Default).ToString().ToLower()); if (Href == null) buttonBuilder.Attributes.Add("type", "button"); if (ButtonId != null) buttonBuilder.Attributes.Add("id", ButtonId); else { buttonBuilder.Attributes.Add("href", Href); if (!Splitted) buttonBuilder.Attributes.Add("role", "button"); } } else { buttonBuilder.Attributes.Add("href",Href); } if (Splitted) { output.PreContent.Append(buttonBuilder); buttonBuilder = new TagBuilder("button") { Attributes = { {"type", "button"}, {"class", "btn btn-" + (Context ?? ButtonContext.Default).ToString().ToLower()} } }; } else buttonBuilder.InnerHtml.AppendHtml(" "); buttonBuilder.AddCssClass("dropdown-toggle"); buttonBuilder.Attributes.Add("data-toggle", "dropdown"); buttonBuilder.Attributes.Add("aria-haspopup", "true"); buttonBuilder.Attributes.Add("aria-expanded", "false"); buttonBuilder.InnerHtml.AppendHtml("<span class=\"caret\">"); output.PreContent.Append(buttonBuilder); output.PreContent.AppendHtml(RightAligned ? "<ul class=\"dropdown-menu dropdown-menu-right\">" : "<ul class=\"dropdown-menu\">"); output.PostContent.AppendHtml("</ul>"); }
protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) { output.AddCssClass("btn"); output.AddCssClass("btn-" + (Context ?? ButtonContext.Default).ToString().ToLower()); if (context.HasInputGroupContext()) { Size=BootstrapTagHelpers.Size.Default; if (!context.HasInputGroupAddonContext()) { output.PreElement.PrependHtml("<span class=\"input-group-btn\">"); output.PostElement.AppendHtml("</span>"); } } if (WrapInButtonGroup || !output.TagName.Equals("a", StringComparison.CurrentCultureIgnoreCase) && ButtonGroupJustified) { if (Size.HasValue && Size.Value != BootstrapTagHelpers.Size.Default) output.PreElement.SetHtmlContent( $"<div class=\"btn-group btn-group-{Size.Value.GetDescription()}\" role=\"group\">"); else output.PreElement.SetHtmlContent( $"<div class=\"btn-group\" role=\"group\">"); output.PostElement.SetHtmlContent("</div>"); } else if (Size.HasValue && Size.Value != BootstrapTagHelpers.Size.Default) output.AddCssClass("btn-" + Size.Value.GetDescription()); if (BlockStyle) output.AddCssClass("btn-block"); if (Pressed) { output.AddAriaAttribute("pressed", "true"); output.AddCssClass("active"); } if (Disabled) { if (output.TagName == "a") { output.AddCssClass("disabled"); if (context.AllAttributes.ContainsName("href")) { output.Attributes.RemoveAll("href"); output.Attributes.Add("data-href", context.AllAttributes["href"].Value); } } output.MergeAttribute("role", "button"); } }
private void ProcessCheckControl(TagHelperContext context, TagHelperOutput output) { if (InputGroupContext != null) { output.PreElement.Append(Label); if (!context.HasInputGroupAddonContext()) { output.PreElement.AppendHtml("<span class=\"input-group-addon\">"); output.PostElement.PrependHtml("</span>"); } } else if (IsInLabel) output.PostElement.Append(Label); else LabelTagHelper.WrapInLabel(output, Label, null, FormContext); if (!string.IsNullOrEmpty(HelpText)) if (InputGroupContext != null) InputGroupContext.Output.PostElement.AppendHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText)); else output.PostElement.AppendHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText)); if (!IsInLabel) { output.PreElement.PrependHtml(FormContext?.Inline ?? false ? $"<div class=\"{Type.ToLower()}-inline\">" : $"<div class=\"{Type.ToLower()}\">"); output.PostElement.AppendHtml("</div>"); if (FormGroupContext != null) FormGroupContext.WrapInDivForHorizontalForm(output, false); else if (FormContext != null) FormContext.WrapInDivForHorizontalForm(output, false); } }