using Connected.Extensions; using Connected.Utilities.BindingConverters; using Microsoft.AspNetCore.Components; namespace Connected.Components; public partial class RangeInput : InputBase> { private string _textStart, _textEnd; public RangeInput() { Value = new Range(); SetConverter(new RangeConverter()); } protected string Classname => InputCssHelper.GetClassname(this, () => !string.IsNullOrEmpty(Text) || Adornment == Adornment.Start || !string.IsNullOrWhiteSpace(PlaceholderStart) || !string.IsNullOrWhiteSpace(PlaceholderEnd)); /// /// Type of the input element. It should be a valid HTML5 input type. /// [Parameter] public InputType InputType { get; set; } = InputType.Text; internal override InputType GetInputType() => InputType; protected string InputClassname => InputCssHelper.GetInputClassname(this); protected string AdornmentClassname => InputCssHelper.GetAdornmentClassname(this); /// /// The short hint displayed in the start input before the user enters a value. /// [Parameter] public string PlaceholderStart { get; set; } /// /// The short hint displayed in the end input before the user enters a value. /// [Parameter] public string PlaceholderEnd { get; set; } protected string InputTypeString => InputType.ToDescriptionString(); /// /// ChildContent of the MudInput will only be displayed if InputType.Hidden and if its not null. /// [Parameter] public RenderFragment ChildContent { get; set; } private ElementReference _elementReferenceStart, _elementReferenceEnd; /// /// Custom separator icon, leave null for default. /// [Parameter] public string SeparatorIcon { get; set; } = Icons.Material.Filled.ArrowRightAlt; /// /// Focuses the start input of MudRangeInput /// /// public ValueTask FocusStartAsync() => _elementReferenceStart.FocusAsync(); /// /// Selects the start text of MudRangeInput /// /// public ValueTask SelectStartAsync() => _elementReferenceStart.SelectAsync(); /// /// Selects the specified range of the start text /// /// Start position of the selection /// End position of the selection /// public ValueTask SelectRangeStartAsync(int pos1, int pos2) => _elementReferenceStart.SelectRangeAsync(pos1, pos2); /// /// Focuses the end input of MudRangeInput /// /// public ValueTask FocusEndAsync() => _elementReferenceEnd.FocusAsync(); /// /// Selects the end text of MudRangeInput /// /// public ValueTask SelectEndAsync() => _elementReferenceEnd.SelectAsync(); /// /// Selects the specified range of the end text /// /// Start position of the selection /// End position of the selection /// public ValueTask SelectRangeEndAsync(int pos1, int pos2) => _elementReferenceEnd.SelectRangeAsync(pos1, pos2); public string TextStart { get => _textStart; set { if (_textStart == value) return; _textStart = value; SetTextAsync(RangeConverter.Join(_textStart, _textEnd)).AndForget(); } } public string TextEnd { get => _textEnd; set { if (_textEnd == value) return; _textEnd = value; SetTextAsync(RangeConverter.Join(_textStart, _textEnd)).AndForget(); } } protected override async Task UpdateTextPropertyAsync(bool updateValue) { await base.UpdateTextPropertyAsync(updateValue); RangeConverter.Split(Text, out _textStart, out _textEnd); } protected override async Task UpdateValuePropertyAsync(bool updateText) { await base.UpdateValuePropertyAsync(updateText); RangeConverter.Split(Text, out _textStart, out _textEnd); } }