52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using System.Xml;
|
|
using MBS.Core;
|
|
|
|
namespace MBS.Web.UI;
|
|
|
|
public abstract class WebControl : Control
|
|
{
|
|
private NanoId _NanoId = NanoId.Empty;
|
|
private string NanoIdString
|
|
{
|
|
get
|
|
{
|
|
if (_NanoId.IsEmpty)
|
|
{
|
|
_NanoId = NanoId.Generate(NanoId.CapitalAlphanumericNoSpecialChars, 8);
|
|
}
|
|
return _NanoId.ToString();
|
|
}
|
|
}
|
|
public string ClientId { get; set; } = "";
|
|
public ThemeColorPreset ThemeColorPreset { get; set;} = ThemeColorPreset.Unspecified;
|
|
|
|
protected override IEnumerable<string> GetStyleClasses()
|
|
{
|
|
List<string> styleClasses = new List<string>();
|
|
switch (ThemeColorPreset)
|
|
{
|
|
case ThemeColorPreset.Primary: styleClasses.Add("uwt-color-primary"); break;
|
|
case ThemeColorPreset.Warning: styleClasses.Add("uwt-color-warning"); break;
|
|
case ThemeColorPreset.Danger: styleClasses.Add("uwt-color-danger"); break;
|
|
}
|
|
if (Visible)
|
|
{
|
|
styleClasses.Add("uwt-visible");
|
|
}
|
|
return styleClasses;
|
|
}
|
|
|
|
protected override IDictionary<string, string> GetControlAttributes()
|
|
{
|
|
IDictionary<string, string> dict = base.GetControlAttributes();
|
|
if (String.IsNullOrEmpty(ClientId))
|
|
{
|
|
dict["id"] = String.Format("UWT{0}", NanoIdString);
|
|
}
|
|
else
|
|
{
|
|
dict["id"] = ClientId;
|
|
}
|
|
return dict;
|
|
}
|
|
} |