Files
Servers/MoonlightServers.Frontend/UI/Components/Forms/Switch.razor

31 lines
819 B
Plaintext

@using System.Diagnostics.CodeAnalysis
@using Microsoft.AspNetCore.Components
@* TODO: Extract to mooncore? *@
@inherits InputBase<bool>
<div class="flex items-center gap-1">
<input @bind="CurrentValue" type="checkbox" class="switch switch-primary" id="switch-@GetHashCode()" />
<label class="label-text text-base" for="switch-@GetHashCode()">
@if (CurrentValue)
{
<span>On</span>
}
else
{
<span>Off</span>
}
</label>
</div>
@code
{
protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
{
validationErrorMessage = null;
result = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
return true;
}
}