mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-14 13:58:21 +00:00
* try to speed up build times * Update deps * Update site deps and fix search issue * Small improvements * fix imports * Remove unused var
43 lines
992 B
TypeScript
43 lines
992 B
TypeScript
import { useDebounce } from '@vueuse/core';
|
|
import { nextTick, onMounted, ref, watch } from 'vue';
|
|
|
|
const useSearchInput = () => {
|
|
const searchInput = ref();
|
|
const searchQuery = ref<string>('');
|
|
const searchQueryDebounced = useDebounce<string>(searchQuery, 200);
|
|
|
|
watch(searchQueryDebounced, (searchString) => {
|
|
const newUrl = new URL(window.location.href);
|
|
|
|
if (searchString === '') {
|
|
newUrl.searchParams.delete('search');
|
|
} else {
|
|
newUrl.searchParams.set('search', searchString);
|
|
}
|
|
|
|
nextTick(() => {
|
|
window.history.replaceState({}, '', newUrl);
|
|
});
|
|
});
|
|
|
|
onMounted(() => {
|
|
const searchParams = new URLSearchParams(window.location.search);
|
|
|
|
if (searchParams.has('search')) {
|
|
searchQuery.value = searchParams.get('search');
|
|
}
|
|
|
|
if (searchParams.has('focus')) {
|
|
searchInput.value.focus();
|
|
}
|
|
});
|
|
|
|
return {
|
|
searchInput,
|
|
searchQuery,
|
|
searchQueryDebounced,
|
|
};
|
|
};
|
|
|
|
export default useSearchInput;
|