using Connected.Annotations; using Connected.Extensions; using Connected.Utilities; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; namespace Connected.Components; //TODO Maybe can inherit from MudBaseInput? public partial class Field : UIComponent { protected string Classname => new CssBuilder("mud-input") .AddClass($"mud-input-{Variant.ToDescriptionString()}") .AddClass($"mud-input-adorned-{Adornment.ToDescriptionString()}", Adornment != Adornment.None) .AddClass($"mud-input-margin-{Margin.ToDescriptionString()}", when: () => Margin != Margin.None) .AddClass("mud-input-underline", when: () => DisableUnderLine == false && Variant != Variant.Outlined) .AddClass("mud-shrink", when: () => !string.IsNullOrWhiteSpace(ChildContent?.ToString()) || Adornment == Adornment.Start) .AddClass("mud-disabled", Disabled) .AddClass("mud-input-error", Error && !string.IsNullOrEmpty(ErrorText)) .Build(); protected string InnerClassname => new CssBuilder("mud-input-slot") .AddClass("mud-input-root") .AddClass("mud-input-slot-nopadding", when: () => InnerPadding == false) .AddClass($"mud-input-root-{Variant.ToDescriptionString()}") .AddClass($"mud-input-adorned-{Adornment.ToDescriptionString()}", Adornment != Adornment.None) .AddClass($"mud-input-root-margin-{Margin.ToDescriptionString()}", when: () => Margin != Margin.None) .Build(); protected string AdornmentClassname => new CssBuilder("mud-input-adornment") .AddClass($"mud-input-adornment-{Adornment.ToDescriptionString()}", Adornment != Adornment.None) .AddClass($"mud-text", !string.IsNullOrEmpty(AdornmentText)) .AddClass($"mud-input-root-filled-shrink", Variant == Variant.Filled) .Build(); protected string InputControlClassname => new CssBuilder("mud-field") .AddClass(Class) .Build(); /// /// Child content of component. /// [Parameter] [Category(CategoryTypes.Field.Data)] public RenderFragment ChildContent { get; set; } /// /// Will adjust vertical spacing. /// [Parameter] [Category(CategoryTypes.Field.Appearance)] public Margin Margin { get; set; } = Margin.None; /// /// If true, the label will be displayed in an error state. /// [Parameter] [Category(CategoryTypes.Field.Validation)] public bool Error { get; set; } /// /// The ErrorText that will be displayed if Error true /// [Parameter] [Category(CategoryTypes.Field.Validation)] public string ErrorText { get; set; } /// /// The HelperText will be displayed below the text field. /// [Parameter] [Category(CategoryTypes.Field.Behavior)] public string HelperText { get; set; } /// /// If true, the field will take up the full width of its container. /// [Parameter] [Category(CategoryTypes.Field.Appearance)] public bool FullWidth { get; set; } /// /// If string has value the label text will be displayed in the input, and scaled down at the top if the field has value. /// [Parameter] [Category(CategoryTypes.Field.Behavior)] public string Label { get; set; } /// /// Variant can be Text, Filled or Outlined. /// [Parameter] [Category(CategoryTypes.Field.Appearance)] public Variant Variant { get; set; } = Variant.Text; /// /// If true, the input element will be disabled. /// [Parameter] [Category(CategoryTypes.Field.Behavior)] public bool Disabled { get; set; } /// /// Icon that will be used if Adornment is set to Start or End. /// [Parameter] [Category(CategoryTypes.Field.Behavior)] public string AdornmentIcon { get; set; } /// /// Text that will be used if Adornment is set to Start or End, the Text overrides Icon. /// [Parameter] [Category(CategoryTypes.Field.Behavior)] public string AdornmentText { get; set; } /// /// The Adornment if used. By default, it is set to None. /// [Parameter] [Category(CategoryTypes.Field.Behavior)] public Adornment Adornment { get; set; } = Adornment.None; /// /// The color of the adornment if used. It supports the theme colors. /// [Parameter] [Category(CategoryTypes.FormComponent.Appearance)] public ThemeColor AdornmentColor { get; set; } = ThemeColor.Default; /// /// Sets the Icon Size. /// [Parameter] [Category(CategoryTypes.Field.Appearance)] public Size IconSize { get; set; } = Size.Medium; /// /// Button click event if set and Adornment used. /// [Parameter] public EventCallback OnAdornmentClick { get; set; } /// /// If true, the inner contents padding is removed. /// [Parameter] [Category(CategoryTypes.Field.Appearance)] public bool InnerPadding { get; set; } = true; /// /// If true, the field will not have an underline. /// [Parameter] [Category(CategoryTypes.Field.Appearance)] public bool DisableUnderLine { get; set; } }