public static CssBuilder AddClasses(this CssBuilder builder, IEnumerable <string> values, Func <string, bool> condition = null) { foreach (var value in values ?? Enumerable.Empty <string>()) { builder.AddClass(value, condition?.Invoke(value) ?? true); } return(builder); }
public static CssBuilder AddEnumValue <TEnum>(this CssBuilder builder, string prefix, Func <TEnum> valueGetter, Func <bool> condition) where TEnum : Enum { Requires.Argument(builder, nameof(builder)) .IsNotNull() .Check(); Requires.Argument(prefix, nameof(prefix)) .IsNotNull() .Check(); Requires.Argument(valueGetter, nameof(valueGetter)) .IsNotNull() .Check(); return(builder.AddClass(() => $"{prefix}-{valueGetter.Invoke().GetCssClassPart()}", condition)); }
private IReadOnlyDictionary <string, object> CalculateAdditionalAttributes() { var additionalAttributes = AdditionalAttributes?.ToDictionary(pair => pair.Key, pair => pair.Value) ?? new Dictionary <string, object>(); if (!additionalAttributes.ContainsKey(HtmlAttributeNames.CLASS)) { additionalAttributes.Add(HtmlAttributeNames.CLASS, string.Empty); } additionalAttributes[HtmlAttributeNames.CLASS] = CssBuilder .AddClass( additionalAttributes[HtmlAttributeNames.CLASS] as string, !string.IsNullOrWhiteSpace(additionalAttributes[HtmlAttributeNames.CLASS] as string)) .Build(); return(new ReadOnlyDictionary <string, object>(additionalAttributes)); }