/// <summary>
        /// In HTML konvertieren
        /// </summary>
        /// <returns>Das Control als HTML</returns>
        public override IHtmlNode ToHtml()
        {
            var classes = new List <string>();

            classes.Add(Class);
            classes.Add("btn");

            var containerClasses = new List <string>();

            containerClasses.Add(ClassContainer);
            containerClasses.Add("btn-group");
            containerClasses.Add("btn-group-toggle");

            var buttonClasses = new List <string>();

            buttonClasses.Add(ClassDropDown);
            buttonClasses.Add("btn");
            buttonClasses.Add("dropdown-toggle");

            if (Outline)
            {
                switch (Layout)
                {
                case TypesLayoutButton.Primary:
                    classes.Add("btn-outline-primary");
                    buttonClasses.Add("btn-outline-primary");
                    break;

                case TypesLayoutButton.Success:
                    classes.Add("btn-outline-success");
                    buttonClasses.Add("btn-outline-success");
                    break;

                case TypesLayoutButton.Info:
                    classes.Add("btn-outline-info");
                    buttonClasses.Add("btn-outline-info");
                    break;

                case TypesLayoutButton.Warning:
                    classes.Add("btn-outline-warning");
                    buttonClasses.Add("btn-outline-warning");
                    break;

                case TypesLayoutButton.Danger:
                    classes.Add("btn-outline-danger");
                    buttonClasses.Add("btn-outline-danger");
                    break;

                case TypesLayoutButton.Light:
                    classes.Add("btn-outline-light");
                    buttonClasses.Add("btn-outline-light");
                    break;

                case TypesLayoutButton.Dark:
                    classes.Add("btn-outline-dark");
                    buttonClasses.Add("btn-outline-dark");
                    break;
                }
            }
            else
            {
                switch (Layout)
                {
                case TypesLayoutButton.Primary:
                    classes.Add("btn-primary");
                    buttonClasses.Add("btn-primary");
                    break;

                case TypesLayoutButton.Success:
                    classes.Add("btn-success");
                    buttonClasses.Add("btn-success");
                    break;

                case TypesLayoutButton.Info:
                    classes.Add("btn-info");
                    buttonClasses.Add("btn-info");
                    break;

                case TypesLayoutButton.Warning:
                    classes.Add("btn-warning");
                    buttonClasses.Add("btn-warning");
                    break;

                case TypesLayoutButton.Danger:
                    classes.Add("btn-danger");
                    buttonClasses.Add("btn-danger");
                    break;

                case TypesLayoutButton.Light:
                    classes.Add("btn-light");
                    buttonClasses.Add("btn-light");
                    break;

                case TypesLayoutButton.Dark:
                    classes.Add("btn-dark");
                    buttonClasses.Add("btn-dark");
                    break;
                }
            }

            switch (Size)
            {
            case TypesSize.Large:
                classes.Add("btn-lg");
                buttonClasses.Add("btn-lg");
                break;

            case TypesSize.Small:
                classes.Add("btn-sm");
                buttonClasses.Add("btn-sm");
                break;
            }

            if (Disabled)
            {
                classes.Add("disabled");
                buttonClasses.Add("disabled");
            }

            var html = new HtmlElementA(Text)
            {
                ID    = ID,
                Class = string.Join(" ", classes.Where(x => !string.IsNullOrWhiteSpace(x))),
                Role  = "button",
                Href  = Url
            };

            var dropdownButton = new HtmlElementP()
            {
                ID    = string.IsNullOrWhiteSpace(ID) ? "" : ID + "_btn",
                Class = string.Join(" ", buttonClasses.Where(x => !string.IsNullOrWhiteSpace(x))),
                //Style = StyleButton,
                DataToggle = "dropdown"
            };

            var dropdownElements = new HtmlElementUl
                                   (
                Items.Select
                (
                    x =>
                    x == null ?
                    new HtmlElementLi()
            {
                Class = "dropdown-divider", Inline = true
            } :
                    x is ControlDropdownMenuHeader ?
                    x.ToHtml() :
                    new HtmlElementLi(x.ToHtml().AddClass("dropdown-item"))
            {
            }
                )
                                   )
            {
                Class = HorizontalAlignment == TypesHorizontalAlignment.Right ? "dropdown-menu dropdown-menu-right" : "dropdown-menu"
            };

            if (Modal != null)
            {
                html.AddUserAttribute("data-toggle", "modal");
                html.AddUserAttribute("data-target", "#" + Modal.ID);
            }

            return(new HtmlElementDiv(html, dropdownButton, dropdownElements, Modal != null ? Modal.ToHtml() : null)
            {
                Class = string.Join(" ", containerClasses.Where(x => !string.IsNullOrWhiteSpace(x))),
            });
        }
Esempio n. 2
0
        /// <summary>
        /// In HTML konvertieren
        /// </summary>
        /// <returns>Das Control als HTML</returns>
        public override IHtmlNode ToHtml()
        {
            var classes = new List <string>();

            classes.Add(Class);

            switch (Color)
            {
            case TypesTextColor.Muted:
                classes.Add("text-muted");
                break;

            case TypesTextColor.Primary:
                classes.Add("text-primary");
                break;

            case TypesTextColor.Success:
                classes.Add("text-success");
                break;

            case TypesTextColor.Info:
                classes.Add("text-info");
                break;

            case TypesTextColor.Warning:
                classes.Add("text-warning");
                break;

            case TypesTextColor.Danger:
                classes.Add("text-danger");
                break;

            case TypesTextColor.Light:
                classes.Add("text-light");
                break;

            case TypesTextColor.Dark:
                classes.Add("text-dark");
                break;

            case TypesTextColor.White:
                classes.Add("text-white");
                break;
            }

            switch (BackgroundColor)
            {
            case TypesBackgroundColor.Primary:
                classes.Add("bg-primary");
                break;

            case TypesBackgroundColor.Secondary:
                classes.Add("bg-secondary");
                break;

            case TypesBackgroundColor.Success:
                classes.Add("bg-success");
                break;

            case TypesBackgroundColor.Info:
                classes.Add("bg-info");
                break;

            case TypesBackgroundColor.Warning:
                classes.Add("bg-warning");
                break;

            case TypesBackgroundColor.Danger:
                classes.Add("bg-danger");
                break;

            case TypesBackgroundColor.Light:
                classes.Add("bg-light");
                break;

            case TypesBackgroundColor.Dark:
                classes.Add("bg-dark");
                break;

            case TypesBackgroundColor.White:
                classes.Add("bg-white");
                break;

            case TypesBackgroundColor.Transparent:
                classes.Add("bg-transparent");
                break;
            }

            var param = GetParams();

            var html = new HtmlElementA(from x in Content select x.ToHtml())
            {
                ID      = ID,
                Class   = string.Join(" ", classes.Where(x => !string.IsNullOrWhiteSpace(x))),
                Style   = Style,
                Role    = Role,
                Alt     = Alt,
                Href    = Url + (param.Length > 0 ? "?" + param : string.Empty),
                Target  = Target,
                OnClick = OnClick
            };

            if (!string.IsNullOrWhiteSpace(Icon) && !string.IsNullOrWhiteSpace(Text))
            {
                html.Elements.Add(new HtmlElementSpan()
                {
                    Class = Icon
                });

                html.Elements.Add(new HtmlNbsp());
                html.Elements.Add(new HtmlNbsp());
                html.Elements.Add(new HtmlNbsp());
            }
            else if (!string.IsNullOrWhiteSpace(Icon) && string.IsNullOrWhiteSpace(Text))
            {
                html.AddClass(Icon);
            }

            if (!string.IsNullOrWhiteSpace(Text))
            {
                html.Elements.Add(new HtmlText(Text));
            }

            if (Modal != null)
            {
                html.AddUserAttribute("data-toggle", "modal");
                html.AddUserAttribute("data-target", "#" + Modal.ID);

                return(new HtmlList(html, Modal.ToHtml()));
            }

            if (!string.IsNullOrWhiteSpace(Tooltip))
            {
                html.AddUserAttribute("data-toggle", "tooltip");
                html.AddUserAttribute("title", Tooltip);
            }

            return(html);
        }
        /// <summary>
        /// In HTML konvertieren
        /// </summary>
        /// <returns>Das Control als HTML</returns>
        public override IHtmlNode ToHtml()
        {
            var classes = new List <string>();

            classes.Add(Class);
            classes.Add("btn");

            switch (Color)
            {
            case TypesTextColor.Muted:
                classes.Add("text-muted");
                break;

            case TypesTextColor.Primary:
                classes.Add("text-primary");
                break;

            case TypesTextColor.Success:
                classes.Add("text-success");
                break;

            case TypesTextColor.Info:
                classes.Add("text-info");
                break;

            case TypesTextColor.Warning:
                classes.Add("text-warning");
                break;

            case TypesTextColor.Danger:
                classes.Add("text-danger");
                break;

            case TypesTextColor.Light:
                classes.Add("text-light");
                break;

            case TypesTextColor.Dark:
                classes.Add("text-dark");
                break;

            case TypesTextColor.White:
                classes.Add("text-white");
                break;
            }

            if (Outline)
            {
                switch (Layout)
                {
                case TypesLayoutButton.Primary:
                    classes.Add("btn-outline-primary");
                    break;

                case TypesLayoutButton.Success:
                    classes.Add("btn-outline-success");
                    break;

                case TypesLayoutButton.Info:
                    classes.Add("btn-outline-info");
                    break;

                case TypesLayoutButton.Warning:
                    classes.Add("btn-outline-warning");
                    break;

                case TypesLayoutButton.Danger:
                    classes.Add("btn-outline-danger");
                    break;

                case TypesLayoutButton.Dark:
                    classes.Add("btn-outline-dark");
                    break;
                }
            }
            else
            {
                switch (Layout)
                {
                case TypesLayoutButton.Primary:
                    classes.Add("btn-primary");
                    break;

                case TypesLayoutButton.Success:
                    classes.Add("btn-success");
                    break;

                case TypesLayoutButton.Info:
                    classes.Add("btn-info");
                    break;

                case TypesLayoutButton.Warning:
                    classes.Add("btn-warning");
                    break;

                case TypesLayoutButton.Danger:
                    classes.Add("btn-danger");
                    break;

                case TypesLayoutButton.Light:
                    classes.Add("btn-light");
                    break;

                case TypesLayoutButton.Dark:
                    classes.Add("btn-dark");
                    break;
                }
            }

            switch (Size)
            {
            case TypesSize.Large:
                classes.Add("btn-lg");
                break;

            case TypesSize.Small:
                classes.Add("btn-sm");
                break;
            }

            if (Block)
            {
                classes.Add("btn-block");
            }

            switch (HorizontalAlignment)
            {
            case TypesHorizontalAlignment.Left:
                classes.Add("float-left");
                break;

            case TypesHorizontalAlignment.Right:
                classes.Add("float-right");
                break;
            }

            var html = new HtmlElementA()
            {
                Class = string.Join(" ", classes.Where(x => !string.IsNullOrWhiteSpace(x))),
                Role  = Role,
                Href  = Url
            };

            if (!string.IsNullOrWhiteSpace(Icon) && !string.IsNullOrWhiteSpace(Text))
            {
                html.Elements.Add(new HtmlElementSpan()
                {
                    Class = Icon
                });

                html.Elements.Add(new HtmlNbsp());
                html.Elements.Add(new HtmlNbsp());
                html.Elements.Add(new HtmlNbsp());
            }
            else if (!string.IsNullOrWhiteSpace(Icon) && string.IsNullOrWhiteSpace(Text))
            {
                html.AddClass(Icon);
            }

            if (!string.IsNullOrWhiteSpace(Text))
            {
                html.Elements.Add(new HtmlText(Text));
            }

            if (Content.Count > 0)
            {
                html.Elements.AddRange(Content.Select(x => x.ToHtml()));
            }

            if (Modal != null)
            {
                html.AddUserAttribute("data-toggle", "modal");
                html.AddUserAttribute("data-target", "#" + Modal.ID);

                return(new HtmlList(html, Modal.ToHtml()));
            }

            return(html);
        }