/// <summary> /// Add an icon /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current html element</param> /// <param name="icon">Icon to be rendered</param> /// <param name="size">[Optional] Icon size</param> /// <param name="htmlAttributes">[Optional] Extra html attributes</param> /// <returns>Html element with icon added</returns> /// <exception cref="FontAwesomeVersionException"> /// Thrown when a valid FontAwesome /// icon library version is not selected /// </exception> public static T AddIcon <T>(this T html, EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null) where T : IExtendedHtmlString { string prefix; if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V3) { prefix = "icon-"; } else if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V4) { prefix = "fa fa-"; } else { throw new FontAwesomeVersionException(); } List <string> cssClasses = new List <string> { prefix + icon.ToString().ToLowerInvariant().Replace("_", "-") }; if (size != EFontAwesomeIconSize.Normal) { cssClasses.Add(prefix + size.GetStringValue()); } html = AddIcon(html, cssClasses, htmlAttributes); return(html); }
/// <summary> /// Creates a Bootstrap Font-Awesome icon /// </summary> /// <param name="icon">Icon to be rendered</param> /// <param name="size">Icon size</param> /// <param name="htmlAttributes">Extra HTML attributes</param> /// <returns>A Bootstrap icon</returns> /// <exception cref="FontAwesomeVersionException">Thrown when a valid FontAwesome /// icon library version is not selected</exception> public static IHtmlComponent CreateIcon(EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null) { NameValueCollection attrsDictionary = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> cssClasses = new List <string>(); if (attrsDictionary.ContainsKey("class")) { cssClasses.AddRange(attrsDictionary["class"].Split(' ')); attrsDictionary.Remove("class"); } string prefix; switch (WebExtrasSettings.FontAwesomeVersion) { case EFontAwesomeVersion.V3: prefix = "icon-"; break; case EFontAwesomeVersion.V4: prefix = "fa fa-"; break; default: throw new FontAwesomeVersionException(); } cssClasses.Add(prefix + icon.ToString().ToLowerInvariant().Replace("_", "-")); if (size != EFontAwesomeIconSize.Normal) { cssClasses.Add(prefix + size.GetStringValue()); } HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(cssClasses); foreach (string key in attrsDictionary.Keys) { i.Attributes[key] = attrsDictionary[key]; } return(i); }
/// <summary> /// Set the icon size /// </summary> /// <param name="size">Icon size to set</param> /// <returns>Updated link</returns> public BootstrapIconlink SetIconSize(EFontAwesomeIconSize size) { m_icon.CssClasses.Add("fa-" + size.GetStringValue()); return(this); }