namespace Sandbox.UI;
public partial class TextEntry
{
///
/// The that displays
///
public IconPanel IconPanel { get; protected set; }
///
/// If set, will display a material icon at the end of the text entry.
///
[Property]
public string Icon
{
get => IconPanel?.Text;
set
{
if ( string.IsNullOrEmpty( value ) )
{
IconPanel?.Delete( true );
IconPanel = default;
}
else
{
IconPanel ??= AddChild( value );
IconPanel.Text = value;
}
SetClass( "has-icon", IconPanel.IsValid() );
}
}
bool _hasClearButton;
///
/// If true then Icon/IconPanel will be set to a clear button that clears the text when clicked.
///
public bool HasClearButton
{
get => _hasClearButton;
set
{
if ( _hasClearButton == value ) return;
_hasClearButton = value;
if ( _hasClearButton )
{
Icon = "cancel";
IconPanel.AddClass( "clearbutton" );
IconPanel.AddEventListener( "onclick", () =>
{
Text = string.Empty;
OnValueChanged();
} );
}
else
{
Icon = null;
}
}
}
}