TextBlock
Description
TextBlock is a display component used to render text in a consistent and customizable manner. It is part of the Components group and is useful for presenting static or dynamic text content in your web applications. By leveraging its fluent API, you can easily adjust text size, weight, alignment, color variants, wrapping behavior, and more.
Usage
Instantiate a TextBlock using the Tesserae.UI helper method. You can pass the desired text along with optional parameters to control HTML parsing, selection, initial text size, and weight. The component supports chaining additional formatting methods, such as setting the text size (e.g., Tiny, Small, Medium, etc.) and text weight (e.g., SemiBold).
Below is a basic example:
API reference
public class TextBlock : ComponentBase<TextBlock, HTMLElement>, ITextFormating, IHasBackgroundColor, IHasForegroundColor, ICanWrap, IRoundedStyleA text block component.
Constructors
public TextBlock(string text = string.Empty, bool treatAsHTML = false, bool selectable = false, TextSize textSize = TextSize.Small, TextWeight textWeight = TextWeight.Regular, string afterText = null)Initializes a new instance of the class.
Parameters
- text
- The text.
- treatAsHTML
- Whether to treat the text as HTML.
- selectable
- Whether the text is selectable.
- textSize
- The text size.
- textWeight
- The text weight.
- afterText
- Optional text to append.
Properties
public string Background { get ; set ; }Gets or sets the background color.
public string Foreground { get ; set ; }Gets or sets the foreground color.
public bool IsEnabled { get ; set ; }Gets or sets whether the component is enabled.
public bool IsSelectable { get ; set ; }Gets or sets whether the text is selectable.
public TextAlign TextAlign { get ; set ; }Gets or sets the text alignment.
public bool IsPrimary { get ; set ; }Gets or sets whether the text is primary color.
public bool IsSecondary { get ; set ; }Gets or sets whether the text is secondary color.
public bool IsSuccess { get ; set ; }Gets or sets whether the text is success color.
public bool IsDanger { get ; set ; }Gets or sets whether the text is danger color.
public bool IsInvalid { get ; set ; }Gets or sets whether the text is invalid color.
public virtual bool IsRequired { get ; set ; }Gets or sets whether the text block represents a required field.
public bool EnableEllipsis { get ; set ; }Gets or sets whether to enable ellipsis for overflowing text.
public bool EnableBreakSpaces { get ; set ; }Gets or sets whether to enable break-spaces.
Samples
Basic Text Display
This sample demonstrates how to create a simple text block with default styling.
Advanced Text Formatting
In this example, the TextBlock is customized with advanced styling options such as a larger text size, semi-bold weight, non-wrapping text, and a tooltip.