Files
Nexus.Reader/src/NexusReader.UI.Shared/Components/Atoms/NexusSearchBox.razor
T

40 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@namespace NexusReader.UI.Shared.Components.Atoms
<div class="nexus-search-container @(IsActive ? "active" : "")">
<div class="search-wrapper">
<i class="nexus-icon @IconClass"></i>
<input type="text"
@bind="SearchValue"
@bind:event="oninput"
@onkeypress="HandleKeyPress"
placeholder="@Placeholder"
class="nexus-search-input" />
@if (!string.IsNullOrEmpty(SearchValue))
{
<button class="clear-btn" @onclick="ClearSearch">×</button>
}
</div>
</div>
@code {
[Parameter] public string Placeholder { get; set; } = "Search your library...";
[Parameter] public string IconClass { get; set; } = "bi bi-search";
[Parameter] public EventCallback<string> OnSearch { get; set; }
private string SearchValue { get; set; } = string.Empty;
private bool IsActive => !string.IsNullOrEmpty(SearchValue);
private async Task HandleKeyPress(KeyboardEventArgs e)
{
if (e.Key == "Enter")
{
await OnSearch.InvokeAsync(SearchValue);
}
}
private void ClearSearch()
{
SearchValue = string.Empty;
}
}