Skip to content

Commit

Permalink
⚙️ Add option to clear the search.
Browse files Browse the repository at this point in the history
  • Loading branch information
pheralb committed Jul 10, 2023
1 parent 9b57652 commit 465835b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/search.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script lang="ts">
export let searchTerm: string;
export let placeholder: string = 'Search...';
export let clearSearch: () => void;
import MagnifyingGlass from 'phosphor-svelte/lib/MagnifyingGlass';
import X from 'phosphor-svelte/lib/X';
</script>

<div class="relative w-full">
Expand All @@ -18,4 +20,15 @@
bind:value={searchTerm}
on:input
/>
{#if searchTerm.length > 0}
<div class="absolute inset-y-0 right-0 flex items-center pr-3">
<button
type="button"
class="focus:outline-none focus:ring-1 focus:ring-neutral-300"
on:click={clearSearch}
>
<X size={18} />
</button>
</div>
{/if}
</div>
6 changes: 6 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
return svgTitle.includes(searchTerm.toLowerCase());
}));
};
const clearSearch = () => {
searchTerm = '';
searchSvgs();
};
</script>

<svelte:head>
Expand All @@ -38,6 +43,7 @@
<Search
bind:searchTerm
on:input={searchSvgs}
clearSearch={() => clearSearch()}
placeholder={`Search ${filteredSvgs.length} logos...`}
/>
<Grid>
Expand Down
6 changes: 6 additions & 0 deletions src/routes/directory/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
return svgTitle.includes(searchTerm.toLowerCase());
}));
};
const clearSearch = () => {
searchTerm = '';
searchSvgs();
};
</script>

<svelte:head>
Expand All @@ -39,6 +44,7 @@
<Search
bind:searchTerm
on:input={searchSvgs}
clearSearch={() => clearSearch()}
placeholder={`Search ${filteredSvgs.length} ${category} logos...`}
/>
<Grid>
Expand Down

1 comment on commit 465835b

@vercel
Copy link

@vercel vercel bot commented on 465835b Jul 10, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

svgl – ./

svgl-git-main-pheralb.vercel.app
svgl.vercel.app
svgl-pheralb.vercel.app

Please sign in to comment.