Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve filter input #59

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/components/Filter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

let filter: string = '';
let filterValid: boolean = false;
let focus: boolean = false;

function handleFocus() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For very simple handlers you can also define them inline

focus = true;
}

function filterChangeHandler(): () => void {
return debounce(() => {
Expand All @@ -26,6 +31,15 @@
}, 1000);
}

function resetQuery() {
focus = false;
filter = '';
}

function resetWidth() {
focus = false;
}

function applyFilter() {
console.log(`Going to parse ${filter}`);
if (filter == '') {
Expand All @@ -49,11 +63,17 @@
<section class="filter">
<input
class:input-error={filter && !filterValid}
class:input-focus={focus}
bind:value={filter}
placeholder="Filter destination port"
on:input={filterChangeHandler()}
on:focus={handleFocus}
on:blur={resetWidth}
/>
<Button disabled={!filterValid} onClick={applyFilter} text="Apply" />
{#if focus}
<Button onClick={resetQuery} text="Reset Query" />
{/if}
</section>

<style>
Expand All @@ -69,6 +89,10 @@
border: 1px solid #ff0000;
}

input.input-focus {
width: 75%;
}

input.input-error:focus {
outline: 1px solid #ff0000;
}
Expand Down