Exemplo n.º 1
0
 protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output)
 {
     output.TagName = "button";
     output.AddCssClass("close");
     output.MergeAttribute("type", "button");
     output.AddAriaAttribute("label", Text);
     output.Content.SetHtmlContent("<span aria-hidden=\"true\">&times;</span>");
     output.TagMode = TagMode.StartTagAndEndTag;
 }
 protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output)
 {
     output.AddCssClass("btn");
     output.AddCssClass("btn-" + (Context ?? ButtonContext.Default).ToString().ToLower());
     if (context.HasContextItem <InputGroupTagHelper>())
     {
         this.Size = BootstrapTagHelpers.Size.Default;
         if (!context.HasContextItem <AddonTagHelper>())
         {
             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");
     }
 }
Exemplo n.º 3
0
        protected override void RenderProcess(TagHelperContext context, TagHelperOutput output)
        {
            output.AddCssClass("btn");

            // Role
            if (output.TagName == "a")
            {
                output.MergeAttribute("role", "button");
            }

            // Color
            if (this.Color != Color.None)
            {
                output.AddCssClass(this.IsOutline ? $"btn-outline-{this.Color.GetColorInfo().Name}" : $"btn-{this.Color.GetColorInfo().Name}");
            }

            // Size
            if (this.Size != Size.Default)
            {
                output.AddCssClass($"btn-{this.Size.GetEnumInfo().Name}");
            }

            // Block
            if (this.IsBlock)
            {
                output.AddCssClass("btn-block");
            }

            // Active
            if (this.IsActive)
            {
                output.AddCssClass("active");
            }

            // Disable
            if (this.IsDisabled)
            {
                if (output.TagName == "a")
                {
                    output.AddCssClass("disabled");
                    output.AddAriaAttribute("disabled", "true");
                }
                else
                {
                    output.MergeAttribute("disabled", "disabled");
                }
            }
        }