public IHtmlNode CellTag(DateTime day, string urlFormat, bool isOtherMonth) { IHtmlNode cell = new HtmlTag("td"); if (isOtherMonth) { cell.AddClass("t-other-month"); } else if(Calendar.Value != null && day.Day == Calendar.Value.Value.Day) { cell.AddClass(UIPrimitives.SelectedState); } if (Calendar.IsDateInRange(day)) { var href = GetUrl(day, urlFormat); IHtmlNode link = new HtmlTag("a") .AddClass(UIPrimitives.Link + (href != "#" ? " t-action-link" : string.Empty)) .Attribute("href", href) .Text(day.Day.ToString()); cell.Children.Add(link); } else { cell.Html(" "); } return cell; }
public void render_a_single_class_even_though_it_is_registered_more_than_once() { HtmlTag tag = new HtmlTag("div").Text("text"); tag.AddClass("a"); tag.ToCompacted().ShouldEqual("<div class=\"a\">text</div>"); tag.AddClass("a"); tag.ToCompacted().ShouldEqual("<div class=\"a\">text</div>"); }
public void do_not_allow_spaces_in_class_names() { HtmlTag tag = new HtmlTag("div").Text("text"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("a b c"); }); }
public static void ClickToEdit(ElementRequest request, HtmlTag tag) { if (tag.IsInputElement()) { var clickToEdit = request.Accessor.GetAttribute<ClickToEditAttribute>(); tag.AddClass("clickToEdit"); if (!string.IsNullOrEmpty(clickToEdit.Action)) { tag.Attr("ClickToEditAction", clickToEdit.Action); } } }
protected override IHtmlNode BuildCore() { var li = new HtmlTag("li"); if (tool.Template.HasValue()) { li.AddClass(UIPrimitives.Editor.Custom); tool.Template.Apply(li); } else { li.AddClass(UIPrimitives.Editor.ToolbarButton); var a = new HtmlTag("a") .Attributes(tool.HtmlAttributes) .Attribute("href", "#") .AddClass(UIPrimitives.Editor.ToolIcon); a.AppendTo(li); } return li; }
public void do_not_allow_start_with_number_in_class_names() { var tag = new HtmlTag("div").Text("text"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("4test"); }); }
public void do_not_allow_first_double_dashes_in_class_names() { var tag = new HtmlTag("div").Text("text"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("--test"); }); }
public void do_not_allow_special_characters_in_class_names() { var tag = new HtmlTag("div").Text("text"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("$test@@"); }); }
public void class_name_with_wrong_json() { var tag = new HtmlTag("div"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("[1,2,3}"); }); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("{a:1, a:2]"); }); }
public void render_metadata() { HtmlTag tag = new HtmlTag("div").Text("text"); tag.MetaData("a", 1); tag.MetaData("b", "b-value"); tag.ToCompacted().ShouldEqual("<div class=\"{'a':1,'b':'b-value'}\">text</div>"); // now with another class tag.AddClass("class1"); tag.ToCompacted().ShouldEqual("<div class=\"class1 {'a':1,'b':'b-value'}\">text</div>"); }
private IHtmlNode NavigationLink(string direction, DateTime? focusedDate, bool isDisabled) { IHtmlNode link = new HtmlTag("a") .Attribute("href", "#") .AddClass(UIPrimitives.Link, "t-nav-" + direction); if (isDisabled) link.AddClass("t-state-disabled"); if (direction == CalendarNavigation.Fast) { link.Text(focusedDate.Value.ToString("MMMM yyyy")); } else { link.Children.Add(new HtmlTag("span") .AddClass(UIPrimitives.Icon, "t-arrow-" + direction)); } return link; }
public static HtmlTag AddSafeClassName(this HtmlTag tag, string unsafeClassName) { return(tag.AddClass(unsafeClassName.Replace(" ", string.Empty))); }
public void add_a_class() { var tag = new HtmlTag("div"); tag.AddClass("a"); tag.ToString().ShouldEqual("<div class=\"a\"></div>"); }
private Tooltip() { _inner.Attr("type", "button"); _inner.AddClass("js-tooltip tooltip-btn"); _inner.AppendHtml("Tooltip"); }
protected internal virtual IHtmlContainer CreateCheckBoxesComponent(Choices choices, IModelMetadata modelMetadata) { if (modelMetadata == null) { throw new ArgumentNullException(nameof(modelMetadata)); } var id = this.HtmlIdFactory.Create(modelMetadata.ContainerType.Name + modelMetadata.PropertyName + "Input"); var container = new HtmlTag(this.HttpEncoder, HtmlTextWriterTag.Div); container.SetId(id); if (!string.IsNullOrEmpty(this.Settings.CheckBoxClass)) { container.AddClass(this.Settings.CheckBoxClass); } foreach (var property in modelMetadata.Properties) { var isChecked = false; if (choices != null) { switch (property.PropertyName) { case "Blue": isChecked = choices.Blue; break; case "Green": isChecked = choices.Green; break; case "Red": isChecked = choices.Red; break; default: break; } } id = this.HtmlIdFactory.Create(modelMetadata.ContainerType.Name + modelMetadata.PropertyName + "Checkbox" + property.PropertyName); var checkBox = new Input(this.HttpEncoder, InputType.CheckBox); checkBox.SetId(id); checkBox.SetName(modelMetadata.PropertyName + "." + property.PropertyName); checkBox.SetAttribute(HtmlAttributeKey.Value, true.ToString()); if (isChecked) { checkBox.SetAttribute(HtmlAttributeKey.Checked, HtmlAttributeKey.Checked); } container.Children.Add(checkBox); var label = new HtmlTag(this.HttpEncoder, HtmlTextWriterTag.Label); label.SetAttribute(HtmlAttributeKey.For, id); var displayText = property.GetDisplayName(); if (!string.IsNullOrEmpty(displayText)) { label.Children.Add(new HtmlText(this.HttpEncoder) { Value = displayText }); } container.Children.Add(label); } return(container); }
public void class_name_must_have_at_least_two_chars_if_starts_with_dash() { var tag = new HtmlTag("div").Text("text"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("-"); }); }
public void valid_class_names() { var tag = new HtmlTag("div").Text("text"); tag.AddClass("-test"); tag.ToString().ShouldEqual("<div class=\"-test\">text</div>"); tag.AddClass("_test"); tag.ToString().ShouldEqual("<div class=\"-test _test\">text</div>"); tag.AddClass("TEST_2-test"); tag.ToString().ShouldEqual("<div class=\"-test _test TEST_2-test\">text</div>"); tag.AddClass("-just-4-test"); tag.ToString().ShouldEqual("<div class=\"-test _test TEST_2-test -just-4-test\">text</div>"); }
public void render_multiple_classes() { var tag = new HtmlTag("div").Text("text"); tag.AddClass("a"); tag.AddClass("b"); tag.AddClass("c"); tag.ToString().ShouldEqual("<div class=\"a b c\">text</div>"); }
public static HtmlTag BorderRadius(this HtmlTag tag) { return(tag.AddClass("radius")); }
public void should_report_has_class_attribute_if_any_classes_added() { var tag = new HtmlTag("div"); tag.HasAttr("class").ShouldBeFalse(); tag.AddClass("first"); tag.HasAttr("class").ShouldBeTrue(); }
public static HtmlTag BorderRounded(this HtmlTag tag) { return(tag.AddClass("round")); }
public IHtmlContent EnumRadioButtonListFor <TProp>(Expression <Func <TModel, TProp> > property, Boolean inline, int xs = 0, int sm = 0, int md = 0, int lg = 0, int xl = 0) { var metadata = ExpressionMetadataProvider.FromLambdaExpression(property, new ViewDataDictionary <TModel>(new EmptyModelMetadataProvider(), new ModelStateDictionary()), Helper.MetadataProvider); Type propertyType = Nullable.GetUnderlyingType(metadata.ModelType) ?? metadata.ModelType; PropertyInfo propertyInfo = metadata.Metadata.ContainerType.GetProperty(metadata.Metadata.PropertyName); EnumDatasourceAttribute[] enumAttributes = propertyInfo.GetCustomAttributes(typeof(EnumDatasourceAttribute), false) as EnumDatasourceAttribute[]; var name = Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ExpressionHelper.GetExpressionText(property); Boolean valueAsString = false; if (enumAttributes.Length > 0) { propertyType = enumAttributes[0].Datasource; valueAsString = true; } var expression = ExpressionForInternal(property); var formGroup = CommonFormGroupFor(property, false, xs, sm, md, lg, xl); IEnumerable <Object> enumValues = Enum.GetValues(propertyType).Cast <Object>(); IEnumerable <SelectListItem> items = from enumValue in enumValues select new SelectListItem { Text = GetText(enumValue), Value = valueAsString ? enumValue.ToString() : ((Int32)enumValue).ToString(), Selected = (metadata.Model != null && enumValue.Equals(metadata.Model)) }; int i = 0; foreach (SelectListItem item in items) { var div = new HtmlTag("div").AddClass("form-check"); var radioLabel = new HtmlTag("label"); if (inline) { radioLabel.AddClass("form-check-inline"); } else { radioLabel.AddClass("form-check-label"); } var input = new HtmlTag("input") .AddClasses("form-check-input") .Attr("ng-model", expression) .Attr("name", name) .Attr("value", item.Value) .Attr("type", "radio"); radioLabel.Append(input).AppendHtml(" " + item.Text); div.Append(radioLabel); if (inline) { formGroup.Append(radioLabel); } else { formGroup.Append(div); } i++; } ApplyHelpToFormGroup(formGroup, metadata.Metadata); return(formGroup); }
public void do_not_allow_spaces_in_class_names() { var tag = new HtmlTag("div").Text("text"); typeof(ArgumentException).ShouldBeThrownBy(() => { tag.AddClass("a b c"); }); }
private HtmlTag CommonFormGroupFor <TProp>(Expression <Func <TModel, TProp> > property, bool showLabel = true, int xs = 0, int sm = 0, int md = 0, int lg = 0, int xl = 0, string dependentBinding = null) { var metadata = ExpressionMetadataProvider.FromLambdaExpression(property, new ViewDataDictionary <TModel>(new EmptyModelMetadataProvider(), new ModelStateDictionary()), Helper.MetadataProvider); Type propertyType = Nullable.GetUnderlyingType(metadata.ModelType) ?? metadata.ModelType; var name = Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ExpressionHelper.GetExpressionText(property); var expression = ExpressionForInternal(property); var touched = ExpressionForFormFieldTouched(property); var valid = ExpressionForFormFieldTouched(property); var submitted = ExpressionForFormSubmitted(); //Creates <div class="form-group has-feedback" // form-group-validation="Name"> var formGroup = new HtmlTag("div") .AddClasses("form-group"); if (xs != 0) { formGroup.AddClass("col-" + xs.ToString()); } else { formGroup.AddClass("hidden-xs-down"); } if (sm != 0) { formGroup.AddClass("col-sm-" + sm.ToString()); } else { formGroup.AddClass("hidden-sm-down"); } if (md != 0) { formGroup.AddClass("col-md-" + md.ToString()); } else { formGroup.AddClass("hidden-md-down"); } if (lg != 0) { formGroup.AddClass("col-lg-" + lg.ToString()); } else { formGroup.AddClass("hidden-lg-down"); } if (xl != 0) { formGroup.AddClass("col-xl-" + xl.ToString()); } else { formGroup.AddClass("hidden-xl-down"); } if (dependentBinding != null) { formGroup.Attr("ng-hide", "!" + dependentBinding); } var labelText = metadata.Metadata.DisplayName; //Creates <label class="form-control-label" for="Name">Name</label> var label = new HtmlTag("label") .AddClass("col-form-label") .Attr("for", name) .Text(labelText); if (!showLabel) { label.AddClass("sr-only"); } formGroup .Append(label); return(formGroup); }
public void attr_add_multiple_classes_with_space_separated_classes() { var tag = new HtmlTag("a"); tag.AddClass("added-class"); tag.Attr("class", "test-class1 test-class2"); tag.HasClass("added-class").ShouldBeTrue(); tag.HasClass("test-class1").ShouldBeTrue(); tag.HasClass("test-class2").ShouldBeTrue(); }
public void add_multiple_classes_at_once_with_multiple_spaces() { var tag = new HtmlTag("div").Text("text"); tag.AddClass("a b c d e "); tag.ToString().ShouldEqual("<div class=\"a b c d e\">text</div>"); }
public void set_the_class_attribute_to_null_should_remove_all_classes() { var tag = new HtmlTag("div"); tag.AddClass("first"); tag.AddClass("second"); tag.Attr("class", null); tag.ToString().ShouldEqual("<div></div>"); }
public void render_metadata() { var tag = new HtmlTag("div").Text("text"); tag.MetaData("a", 1); tag.MetaData("b", "b-value"); tag.ToString().ShouldEqual("<div data-:=\"{"a":1,"b":"b-value"}\">text</div>"); // now with another class tag.AddClass("class1"); tag.ToString().ShouldEqual("<div class=\"class1\" data-:=\"{"a":1,"b":"b-value"}\">text</div>"); }
public ErrorMessage(string value) { _inner.AddClass("status-msg"); _inner.Append(new HtmlTag("span", tag => tag.AddClass("error")).Text(value)); }