public override HtmlNode Convert2Blazor(HtmlNode node) { var tagName = BlazorName; var tagTemplate = SingleTagNodeTemplate; string tagBody = null; var textValue = node.Attributes.AttributesWithName(TextAttributeName).FirstOrDefault()?.Value; var textModeValue = node.Attributes.AttributesWithName(TextModeAttributeName).FirstOrDefault()?.Value ?? string.Empty; if (textModeValue.Equals(MultiLineTextMode, StringComparison.InvariantCultureIgnoreCase)) { tagName = MultiLineTagName; tagTemplate = NodeTemplate; tagBody = textValue; } else if (textModeValue.Equals(PasswordTextMode, StringComparison.InvariantCultureIgnoreCase)) { NewAttributes = NewAttributes.Append(new ViewLayerControlAttribute(TypeAttributeName, TypeAttributePasswordValue)); } if (tagBody == null && textValue != null) { NewAttributes = NewAttributes.Append(new ViewLayerControlAttribute(ValueAttributeName, $"\"{textValue}\"")); } AddBooleanAttributeOnCondition(node, ReadOnlyAttributeName, ReadOnlyAttributeName, true); AddBooleanAttributeOnCondition(node, EnabledAttributeName, DisabledAttributeName, false); var joinedAttributesString = JoinAllAttributes(node.Attributes, NewAttributes); return(Convert2BlazorFromParts(tagTemplate, tagName, joinedAttributesString, tagBody)); }
private protected void AddBooleanAttributeOnCondition(HtmlNode node, string aspAttrName, string htmlAttrName, bool condition) { var aspAttrValue = node.Attributes.AttributesWithName(aspAttrName).FirstOrDefault()?.Value ?? string.Empty; if (aspAttrValue.Equals(condition.ToString(), StringComparison.InvariantCultureIgnoreCase)) { NewAttributes = NewAttributes.Append(new ViewLayerControlAttribute(htmlAttrName, BooleanAttributeTrueValue)); } }
public override HtmlNode Convert2Blazor(HtmlNode node) { var textValue = node.Attributes.AttributesWithName(TextAttributeName).FirstOrDefault()?.Value; var idValue = node.Attributes.AttributesWithName(IdentifierAttributeName).FirstOrDefault()?.Value; AddBooleanAttributeOnCondition(node, CheckedAttributeName, CheckedAttributeName, true); AddBooleanAttributeOnCondition(node, EnabledAttributeName, DisabledAttributeName, false); if (!string.IsNullOrEmpty(textValue)) { var containerNode = Convert2BlazorFromParts(NodeTemplate, ContainerTagName, null, null); // NOTE: If no is present, can't link label to radio button, so instead generate a new unique id if (idValue == null) { idValue = IncrementalViewIdGenerator.GetNewGeneratedId(); NewAttributes = NewAttributes.Append(new ViewLayerControlAttribute(IdentifierAttributeName, idValue)); } var joinedAttributesString = JoinAllAttributes(node.Attributes, NewAttributes); var radioButtonNode = Convert2BlazorFromParts(SingleTagNodeTemplate, BlazorName, joinedAttributesString, null); var labelAttrString = string.Format(LabelForAttributeTemplate, idValue); var labelNode = Convert2BlazorFromParts(NodeTemplate, LabelTagName, labelAttrString, textValue); containerNode.AppendChild(radioButtonNode); containerNode.AppendChild(labelNode); return(containerNode); } else { var joinedAttributesString = JoinAllAttributes(node.Attributes, NewAttributes); return(Convert2BlazorFromParts(SingleTagNodeTemplate, BlazorName, joinedAttributesString, null)); } }