Skip to content

Commit

Permalink
feat: readd reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-berlin committed Nov 15, 2023
1 parent ac70d26 commit 4f12685
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
35 changes: 21 additions & 14 deletions src/components/SearchWords.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@click="buttonActions"
>
<Transition name="fade-fast" mode="out-in">
<span v-if="toggleShowAndClearIcon" key="search" class="c-button--center-icon">
<span v-if="searchLength === 0" key="search" class="c-button--center-icon">
<Search default-class="c-word-search__search-icon" />
</span>
<span v-else key="del" class="c-button--center-icon">
Expand All @@ -34,7 +34,6 @@
<script setup lang="ts">
import { ref, computed } from "vue";
import Search from "virtual:icons/lucide/search";
import Command from "virtual:icons/lucide/command";
import X from "virtual:icons/lucide/x";
interface SearchWordsProps {
Expand All @@ -45,26 +44,34 @@ const { buttonPosition = "left" } = defineProps<SearchWordsProps>();
const search = ref("");
const searchLength = computed(() => search.value.length);
const toggleShowAndClearIcon = ref(true);
const emit = defineEmits(["update:search"]);
const updateSearch = () => {
/**
* Emits the search value to the parent component
*
* @return {void}
*/
const updateSearch = (): void => {
emit("update:search", search);
};
const buttonActions = () => {
if (searchLength.value > 0) {
search.value = "";
}
/**
* Handles the button actions
*
* @return {void}
*/
const buttonActions = (): void => {
if (searchLength.value > 0) resetSearch();
};
const toggleSearchClearIcons = () => {
if (searchLength.value === 0) {
toggleShowAndClearIcon.value = true;
} else {
toggleShowAndClearIcon.value = false;
}
/**
* Resets the search value
*
* @return {void}
*/
const resetSearch = (): void => {
search.value = "";
};
</script>

Expand Down
2 changes: 0 additions & 2 deletions src/components/WordList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ const wordSearchIndex = computed(() => {
};
const fuse = new Fuse(words, options);
console.log("index", fuse);
const results = fuse.search(search);
console.log("results", results);
const cleanResults = results.map((result) => {
return result.item;
Expand Down
8 changes: 2 additions & 6 deletions src/styles/components/_word-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

height: 100%;

&__item {
&:not(:last-of-type) {
.c-word-list__word-wrap {
padding-bottom: vars.$spacer * 1.75;
}
}
.c-word-list__word-wrap {
padding-bottom: vars.$spacer * 1.75;
}

&__word {
Expand Down

0 comments on commit 4f12685

Please sign in to comment.