[WIP] initialize search bar

This commit is contained in:
2025-07-21 00:53:26 +02:00
parent 189a26e0e8
commit a2b8e0e6ae
3 changed files with 49 additions and 15 deletions

View File

@@ -1,22 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
import { Address } from "ChillMainAssets/types";
import {Address} from "ChillMainAssets/types"; import SearchBar from "ChillMainAssets/vuejs/AddressPicker/Component/SearchBar.vue";
interface AddressPickerProps { interface AddressPickerProps {
suggestions?: Address[]; suggestions?: Address[];
} }
const props = withDefaults(defineProps<AddressPickerProps>(), { const props = withDefaults(defineProps<AddressPickerProps>(), {
suggestions: [] suggestions: () => [],
}); });
const onSearch = function (search: string) {
console.log("onSearch", search);
};
</script> </script>
<template> <template>
<p>test</p> <search-bar @search="onSearch"></search-bar>
<p>test</p>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss"></style>
</style>

View File

@@ -0,0 +1,31 @@
<script setup lang="ts">
const emits = defineEmits<{
search: [search: string];
}>();
let searchTimer = 0;
let searchString: string;
const onInput = function (event: InputEvent) {
const target = event.target as HTMLInputElement;
const value = target.value;
searchString = value;
if (0 === searchTimer) {
window.clearTimeout(searchTimer);
searchTimer = 0;
}
searchTimer = window.setTimeout(() => {
if (value === searchString) {
emits("search", value);
}
}, 500);
};
</script>
<template>
<input type="search" @input="onInput" />
</template>
<style scoped lang="scss"></style>

View File

@@ -1,10 +1,12 @@
import {createApp} from "vue"; import { createApp } from "vue";
import AddressPicker from "ChillMainAssets/vuejs/AddressPicker/AddressPicker.vue"; import AddressPicker from "ChillMainAssets/vuejs/AddressPicker/AddressPicker.vue";
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener("DOMContentLoaded", async () => {
document.querySelectorAll<HTMLDivElement>('div[data-address-picker]').forEach((elem): void => { document
.querySelectorAll<HTMLDivElement>("div[data-address-picker]")
.forEach((elem): void => {
const app = createApp(AddressPicker); const app = createApp(AddressPicker);
app.mount(elem); app.mount(elem);
}) });
}) });