Skip to content

Commit

Permalink
Add LabelType into application-wide Defaults (#873)
Browse files Browse the repository at this point in the history
* Added custom validation options to Inputs, added LabelType in Default
* revert HxInputBase custom validation parameters feature
* HxSetup.Defaults - LabelType, InputSize

---------

Co-authored-by: Robert Haken <[email protected]>
  • Loading branch information
mmonteagudo and hakenr authored Sep 30, 2024
1 parent e148bd0 commit fd0b333
Show file tree
Hide file tree
Showing 43 changed files with 214 additions and 119 deletions.
2 changes: 1 addition & 1 deletion BlazorAppTest/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void ConfigureServices(IServiceCollection services)
//HxInputDateRange.Defaults.InputSize = InputSize.Large;
//HxCalendar.Defaults.DateCustomizationProvider = request => new CalendarDateCustomizationResult { Enabled = request.Date < DateTime.Today };
//HxMessageBox.Defaults.ModalSettings.Centered = true;
HxPlaceholder.Defaults.Color = ThemeColor.Light;
//HxPlaceholder.Defaults.Color = ThemeColor.Light;
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
10 changes: 4 additions & 6 deletions Havit.Blazor.Components.Web.Bootstrap.Smart/HxSmartComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public class HxSmartComboBox : HxInputBaseWithInputGroups<string>, IInputWithPla

static HxSmartComboBox()
{
Defaults = new InputTextSettings()
{
InputSize = Bootstrap.InputSize.Regular,
};
Defaults = new InputTextSettings();
}

/// <summary>
Expand Down Expand Up @@ -89,11 +86,12 @@ static HxSmartComboBox()
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxInputNumber) + " has to be set.");
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize; InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

protected override void BuildRenderInput(RenderTreeBuilder builder)
{
Expand Down
10 changes: 4 additions & 6 deletions Havit.Blazor.Components.Web.Bootstrap.Smart/HxSmartTextArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public class HxSmartTextArea : HxInputBase<string>, IInputWithPlaceholder, IInpu

static HxSmartTextArea()
{
Defaults = new InputTextSettings()
{
InputSize = Bootstrap.InputSize.Regular,
};
Defaults = new InputTextSettings();
}

/// <summary>
Expand Down Expand Up @@ -95,11 +92,12 @@ static HxSmartTextArea()
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxInputNumber) + " has to be set.");
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize; InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

protected override void BuildRenderInput(RenderTreeBuilder builder)
{
Expand Down
7 changes: 2 additions & 5 deletions Havit.Blazor.Components.Web.Bootstrap/Files/HxInputFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public partial class HxInputFile : ComponentBase, ICascadeEnabledComponent, IFor

static HxInputFile()
{
Defaults = new InputFileSettings()
{
InputSize = Bootstrap.InputSize.Regular,
};
Defaults = new InputFileSettings();
}

/// <summary>
Expand Down Expand Up @@ -148,7 +145,7 @@ static HxInputFile()
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxInputFile) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Havit.Blazor.Components.Web.Bootstrap.Internal;

namespace Havit.Blazor.Components.Web.Bootstrap;
namespace Havit.Blazor.Components.Web.Bootstrap;

/// <summary>
/// Settings for the <see cref="HxInputFile"/> component.
/// </summary>
public record InputFileSettings : IInputSettingsWithSize
public record InputFileSettings
{
/// <summary>
/// The size of the input.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Havit.Blazor.Components.Web.Bootstrap.Internal;

namespace Havit.Blazor.Components.Web.Bootstrap;
namespace Havit.Blazor.Components.Web.Bootstrap;

/// <summary>
/// Settings for the <see cref="HxAutosuggest{TItem, TValue} "/> and derived components.
/// </summary>
public record AutosuggestSettings : InputSettings, IInputSettingsWithSize
public record AutosuggestSettings : InputSettings
{
/// <summary>
/// Icon displayed in the input when no item is selected.
Expand All @@ -31,4 +29,9 @@ public record AutosuggestSettings : InputSettings, IInputSettingsWithSize
/// The input size.
/// </summary>
public InputSize? InputSize { get; set; }

/// <summary>
/// The label type.
/// </summary>
public LabelType? LabelType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ public class HxAutosuggest<TItem, TValue> : HxInputBase<TValue>, IInputWithSize,
/// The size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxAutosuggest) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

/// <summary>
/// The offset between the dropdown and the input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static HxAutosuggest()
{
Defaults = new AutosuggestSettings()
{
InputSize = InputSize.Regular,
SearchIcon = BootstrapIcon.Search,
ClearIcon = BootstrapIcon.XLg,
MinimumLength = 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Havit.Blazor.Components.Web.Bootstrap.Internal;

namespace Havit.Blazor.Components.Web.Bootstrap;
namespace Havit.Blazor.Components.Web.Bootstrap;

/// <summary>
/// Settings for the <see cref="HxFormValue"/> and derived components.
/// </summary>
public record FormValueSettings : IInputSettingsWithSize
public record FormValueSettings
{
/// <summary>
/// Input size. The default is <see cref="InputSize.Regular"/>.
Expand Down
7 changes: 2 additions & 5 deletions Havit.Blazor.Components.Web.Bootstrap/Forms/HxFormValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public class HxFormValue : ComponentBase, IFormValueComponent, IFormValueCompone

static HxFormValue()
{
Defaults = new FormValueSettings()
{
InputSize = Bootstrap.InputSize.Regular,
};
Defaults = new FormValueSettings();
}

/// <summary>
Expand Down Expand Up @@ -90,7 +87,7 @@ static HxFormValue()
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxFormValue) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;


Expand Down
2 changes: 1 addition & 1 deletion Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected override void OnParametersSet()

if ((this is IInputWithLabelType inputWithLabelType)
&& (this is IInputWithPlaceholder inputWithPlaceholder)
&& (inputWithLabelType.LabelType == LabelType.Floating)
&& (inputWithLabelType.LabelTypeEffective == LabelType.Floating)
&& !String.IsNullOrEmpty(inputWithPlaceholder.Placeholder))
{
throw new InvalidOperationException($"Cannot use {nameof(IInputWithPlaceholder.Placeholder)} with floating labels.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static HxInputBase()
{
Defaults = new InputSettings()
{
ValidationMessageMode = ValidationMessageMode.Floating
ValidationMessageMode = ValidationMessageMode.Floating,
};
}
}
5 changes: 4 additions & 1 deletion Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class HxInputDate<TValue> : HxInputBase<TValue>, IInputWithPlaceholder, I
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxInputDate) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <summary>
Expand Down Expand Up @@ -101,6 +101,9 @@ public class HxInputDate<TValue> : HxInputBase<TValue>, IInputWithPlaceholder, I

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

protected override LabelValueRenderOrder RenderOrder => (LabelType == Bootstrap.LabelType.Floating) ? LabelValueRenderOrder.ValueOnly /* label rendered by HxInputDateInternal */ : LabelValueRenderOrder.LabelValue;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ static HxInputDate()
{
Defaults = new InputDateSettings()
{
InputSize = InputSize.Regular,
MinDate = HxCalendar.DefaultMinDate,
MaxDate = HxCalendar.DefaultMaxDate,
ShowClearButton = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ static HxInputDateRange()
{
Defaults = new InputDateRangeSettings()
{
InputSize = Bootstrap.InputSize.Regular,
MinDate = HxCalendar.DefaultMinDate,
MaxDate = HxCalendar.DefaultMaxDate,
ShowClearButton = true,
Expand Down Expand Up @@ -63,7 +62,7 @@ static HxInputDateRange()
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxInputDateRange) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class HxInputNumber<TValue> : HxInputBaseWithInputGroups<TValue>, IInputW
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxInputNumber) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <summary>
Expand All @@ -90,6 +90,8 @@ public class HxInputNumber<TValue> : HxInputBaseWithInputGroups<TValue>, IInputW

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

#pragma warning disable BL0007 // Component parameter 'Havit.Blazor.Components.Web.Bootstrap.HxInputNumber<TValue>.Decimals' should be auto property
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ static HxInputNumber()
{
Defaults = new InputNumberSettings()
{
InputSize = InputSize.Regular,
SelectOnFocus = true
};
}
Expand Down
1 change: 0 additions & 1 deletion Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ static HxInputText()
{
Defaults = new InputTextSettings()
{
InputSize = Bootstrap.InputSize.Regular,
SelectOnFocus = false
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract class HxInputTextBase : HxInputBaseWithInputGroups<string>, IInp
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + GetType().Name + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <summary>
Expand All @@ -67,6 +67,8 @@ public abstract class HxInputTextBase : HxInputBaseWithInputGroups<string>, IInp

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

/// <inheritdoc />
protected override void BuildRenderInput(RenderTreeBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HxMultiSelect<TValue, TItem> : HxInputBase<List<TValue>>, IInputWit
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxMultiSelect) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;
string IInputWithSize.GetInputSizeCssClass() => InputSizeEffective.AsFormSelectCssClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static HxMultiSelect()
{
Defaults = new MultiSelectSettings()
{
InputSize = InputSize.Regular,
AllowFiltering = false,
AllowSelectAll = false,
ClearFilterOnHide = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ public class HxSelect

static HxSelect()
{
Defaults = new SelectSettings()
{
InputSize = InputSize.Regular,
};
Defaults = new SelectSettings();
}
}
5 changes: 4 additions & 1 deletion Havit.Blazor.Components.Web.Bootstrap/Forms/HxSelectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public abstract class HxSelectBase<TValue, TItem> : HxInputBaseWithInputGroups<T
/// </summary>
[Parameter] public SelectSettings Settings { get; set; }

/// <inheritdoc cref="Bootstrap.LabelType" />
[Parameter] public LabelType? LabelType { get; set; }
protected LabelType LabelTypeEffective => LabelType ?? GetSettings()?.LabelType ?? GetDefaults()?.LabelType ?? HxSetup.Defaults.LabelType;
LabelType IInputWithLabelType.LabelTypeEffective => LabelTypeEffective;

/// <summary>
/// Returns an optional set of component settings.
Expand All @@ -37,7 +40,7 @@ public abstract class HxSelectBase<TValue, TItem> : HxInputBaseWithInputGroups<T
/// Size of the input.
/// </summary>
[Parameter] public InputSize? InputSize { get; set; }
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? throw new InvalidOperationException(nameof(InputSize) + " default for " + nameof(HxSelect) + " has to be set.");
protected InputSize InputSizeEffective => InputSize ?? GetSettings()?.InputSize ?? GetDefaults()?.InputSize ?? HxSetup.Defaults.InputSize;
InputSize IInputWithSize.InputSizeEffective => InputSizeEffective;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Havit.Blazor.Components.Web.Bootstrap;
/// <summary>
/// Settings for <see cref="HxInputDateRange"/>.
/// </summary>
public record InputDateRangeSettings : InputSettings, IInputSettingsWithSize
public record InputDateRangeSettings : InputSettings
{
/// <summary>
/// Input size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ namespace Havit.Blazor.Components.Web.Bootstrap;
/// <summary>
/// Settings for <see cref="HxInputDate{TValue}"/>.
/// </summary>
public record InputDateSettings : InputSettings, IInputSettingsWithSize
public record InputDateSettings : InputSettings
{
/// <summary>
/// Input size.
/// </summary>
public InputSize? InputSize { get; set; }

/// <summary>
/// The label type.
/// </summary>
public LabelType? LabelType { get; set; }

/// <summary>
/// Optional icon to display within the input.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using Havit.Blazor.Components.Web.Bootstrap.Internal;

namespace Havit.Blazor.Components.Web.Bootstrap;
namespace Havit.Blazor.Components.Web.Bootstrap;

/// <summary>
/// Settings for the <see cref="HxInputNumber{TValue}"/> and derived components.
/// </summary>
public record InputNumberSettings : InputSettings, IInputSettingsWithSize
public record InputNumberSettings : InputSettings
{
/// <summary>
/// The size of the input.
/// </summary>
public InputSize? InputSize { get; set; }

/// <summary>
/// The label type.
/// </summary>
public LabelType? LabelType { get; set; }

/// <summary>
/// A hint to browsers regarding the type of virtual keyboard configuration to use when editing.
/// </summary>
Expand Down
Loading

0 comments on commit fd0b333

Please sign in to comment.