Button
Description
The Button component provides an interactive UI element that the user can click to trigger an action. It is an essential component in the Tesserae UI library, used for actions such as form submission, command execution, and triggering events. The Button supports various visual styles like primary, success, danger, link, and icon-based buttons. It also supports spinner states for indicating loading actions.
Usage
A Button is typically instantiated using the Tesserae.UI helper method. You can customize its text, style, icons, and behavior using the provided methods and properties. The following example demonstrates how to create a standard button, a primary button, and a link button with a tooltip:
API reference
public class Button : ComponentBase<Button, HTMLButtonElement>, ITextFormating, IHasBackgroundColor, IHasForegroundColor, ICanWrap, IRoundedStyleThe standard clickable button component, with optional icons, loading state, primary/secondary variants and dropdown / split-button support.
Constructors
Properties
public string Background { get ; set ; }Gets or sets the CSS background of the component.
public string Foreground { get ; set ; }Gets or sets the CSS color (foreground) of the component.
public bool IsCompact { get ; set ; }Gets or set whenever button is rendered in a compact form
public bool IsLink { get ; set ; }Gets or set whenever button is rendered like a link
public bool IsEnabled { get ; set ; }Gets or sets whenever button is enabled
public bool CanWrap { get ; set ; }Gets or sets a value indicating whether the component's text can wrap onto multiple lines.
public bool EnableEllipsis { get ; set ; }Gets or sets a value indicating whether overflowing text is truncated with an ellipsis.
public TextWeight Weight { get ; set ; }Gets or sets the font weight of the component.
Methods
public Button DefaultLink()Renders the component as a default-toned hyperlink.
public void ToSpinner(string text = null)Replaces the button's content with an inline spinner (commonly used while an async action is in progress).
public void UndoSpinner()Restores the button's original content after was used.
public Button OnClickSpinWhile(Func<Task> action, string text = null, Action<Button, Exception> onError = null)Registers a callback invoked when the click spin while event fires.
public Button OnClickSpinWhile(Func<MouseEvent, Task> action, string text = null, Action<Button, Exception> onError = null)Registers a callback invoked when the click spin while event fires.
public Button OnClick(Action action)Registers a callback invoked when the click event fires.
public Button OnContextMenu(Action action)Registers a callback invoked when the context menu event fires.
public void SpinWhile(Func<Task> action, string text = null, Action<Button, Exception> onError = null)Runs the given async action while showing an inline spinner on the button. Restores the original button content on completion (or on error, optionally invoking the supplied error handler).
public Button WithFilterEffects()Returns the component configured with the given filter effects.
public Button NoBackground()Removes / disables the background on the component.
public Button LinkOnHover()Renders the component as a hyperlink only on hover.
public Button Color(string background, string textColor = "white", string borderColor = "white", string iconColor = "")Configures the component to color.
public Button SetIcon(Emoji icon, bool afterText = false)Sets the icon of the component.
public Button SetIcon(UIcons icon, string color = "", TextSize size = TextSize.Small, UIconsWeight weight = UIconsWeight.Regular, bool afterText = false)Sets the icon of the component.
public Button ReplaceContent(IComponent content)Replaces the content in the component.
public Button ReplaceText(HTMLSpanElement textSpan)Replaces the text in the component.
Samples
Basic Button Usage
The following sample creates a group of buttons showcasing standard, primary, link, icon, and spinner buttons: