Files
decePubClient/Components/Daisy/DataInput/DRange.razor
T

54 lines
1.8 KiB
Plaintext
Raw Normal View History

@typeparam TValue
@inherits DInputBase<TValue>
@* daisyUI Range: https://daisyui.com/components/range/ . TValue is numeric; Min and Max are always rendered, as daisyUI
requires. *@
<input @attributes="InputAttributes" type="range" class="@CssClassFull" name="@NameAttribute" min="@Format(Min)"
max="@Format(Max)" step="@(Step is null ? null : Format(Step.Value))" value="@CurrentValueAsString"
@oninput="OnInput" @onchange="OnChange" aria-invalid="@(IsInvalid ? "true" : null)" />
@code {
[Parameter] public double Min { get; set; }
[Parameter] public double Max { get; set; } = 100;
[Parameter] public double? Step { get; set; }
[Parameter] public DColor Color { get; set; }
[Parameter] public DSize Size { get; set; }
[Parameter] public DDirection Direction { get; set; }
/// <summary>Update the bound value while dragging instead of on release.</summary>
[Parameter] public bool Immediate { get; set; }
string CssClassFull => Cx("range", IsInvalid ? "range-error" : ColorClass, SizeClass,
Direction == DDirection.Vertical ? "range-vertical" : null, CssClass);
string ColorClass => Color switch
{
DColor.Neutral => "range-neutral",
DColor.Primary => "range-primary",
DColor.Secondary => "range-secondary",
DColor.Accent => "range-accent",
DColor.Info => "range-info",
DColor.Success => "range-success",
DColor.Warning => "range-warning",
DColor.Error => "range-error",
_ => null
};
string SizeClass => Size switch
{
DSize.Xs => "range-xs",
DSize.Sm => "range-sm",
DSize.Lg => "range-lg",
DSize.Xl => "range-xl",
_ => null
};
static string Format(double value) => value.ToString(System.Globalization.CultureInfo.InvariantCulture);
void OnInput(ChangeEventArgs e)
{
if (Immediate)
CurrentValueAsString = e.Value?.ToString();
}
void OnChange(ChangeEventArgs e) => CurrentValueAsString = e.Value?.ToString();
}